const
  KEYLEN = 3;
  N = 5;
  M = 2*N;


type 
  tkey = string[KEYLEN];
  tval = string;
  ps = ^tval;
  pk = ^tkey;

Const
  NotError : tval = 'Not in table';

VAR
  Y : array [0..M-1] of ps;
  X : array [0..M-1] of pk;

Function Hash(key : tkey):word;
var
  i : byte;
  res : real;
begin
  res := 0;
  for i := 1 to KEYLEN do res := res + ord(key[i]);
  res := Frac(sqrt(res));
  Hash := trunc(res * M);
end;
  
Procedure AddPair(key:tkey;val:tval);
var
  nv : ps;
  nk : pk;
  c  : 0..M-1;
begin
  c := Hash(Key);
  while X[C] <> nil do c:=(c+1) mod M;
  New(nv);NV^ := val;
  New(nk);NK^ := key;
  X[C] := NK;
  Y[C] := NV;
end;

Function GetValue(key : tkey):tval;
var
  c : 0..M-1;
begin
  c := Hash(Key);
  while (X[C]^ <> Key) and (X[C] <> nil) do c:=(c+1) mod M;
  if X[C] <> nil then GetValue := Y[C]^
  else
    GetValue := NotError;   
end;

var
  i : 0..M-1;
begin
  for i := 0 to M-1 do begin X[i] := nil; y[i]:=nil;end;
  AddPair('SPB','Saint Petersburg');
  AddPair('MOS','Moscow');
  AddPair('_NY','New York');
  AddPair('TUA','Tula');
  AddPair('Sux','SuxxCity');
  WriteLn(GetValue('SPB'));
  WriteLn(GetValue('_NY'));
  WriteLn(GetValue('MOC'));
  WriteLn(GetValue('Sux'));
end.