{this stuff is absolutely free for non-commercial use. 
(c) pascal for DOS programming by 'hrych' aka 'kom1' aka 'jopka', jopka@kvidex.ru
(c) labirints design by unkhown author. there are older than 1989.}

Program Hrych;
Uses CRT;
Var
  i,j,k,x: word;
  c2,sg: word;
  s: string;
  lab, x0, y0, mx, my, b: byte; dx: integer;
  uk,len: byte;
  n: longint;
  flag:byte;
  sss: string[10];
Const
  lt=331; rt=333; up=328; dn=336; esc=27; enter=13; ctrl_r=18; ctrl_z=26;
  fig: array[0..15] of char = '  . ()▒▒    ><██';
  lnum=60;
  parol: array[2..lnum] of longint =
        (      10822,73134,14080,39373,78731,34282,51827,94880,21505,
         17677,62659,69262,17485,69630,79771,29758,72062,81259,21215,
         52167,70001,88364,74388,20001,72523,83366,93427,75745,68614,
         19435,10792,44567,98733,18732,13894,19847,93652,76334,47823,
         41056,19869,37746,22931,93018,56160,39534,93340,87194,28428,
         23987,85456,28472,99276,55767,22972,76432,54111,54336,67326);


  z: array[0..4448] of byte = (
0,255,3,0,0,0,48,48,0,0,0,0,11,3,0,0,0,63,248,3,0,0,48,8,50,0,0,240,51,63,3,240,255,3,243,243,255,67,61,130,0,0,0,212,255,243,
207,252,67,13,48,0,252,240,255,0,255,255,0,0,0,255,255,255,112,193,0,252,23,140,32,124,193,254,195,23,0,60,124,193,12,242,255,
207,139,12,35,136,200,48,192,0,12,255,255,255,0,0,0,255,255,0,0,12,0,3,0,48,46,15,0,192,8,14,0,0,47,50,252,255,143,204,127,
21,60,130,240,87,0,130,192,87,193,255,255,255,255,3,0,0,0,0,0,192,255,63,0,0,0,48,84,13,240,255,255,15,85,3,12,48,136,64,213,
0,163,46,200,80,53,192,32,0,50,84,13,48,202,34,254,255,255,15,50,0,3,0,3,204,255,255,0,192,0,8,15,0,0,48,232,10,3,0,0,12,48,
240,0,0,0,255,255,15,0,0,0,0,0,255,3,0,0,12,252,15,0,48,251,48,0,192,0,200,255,255,243,3,95,5,143,224,127,21,128,40,207,85,
240,130,48,255,255,131,240,0,0,140,8,3,0,240,243,12,0,0,12,48,0,0,240,255,0,255,15,63,23,204,243,23,252,192,23,0,202,23,204,
200,215,207,200,255,200,194,192,224,200,192,8,194,192,240,192,192,255,255,0,0,192,255,240,255,3,255,12,143,242,0,2,192,131,
240,3,255,252,239,63,194,79,205,136,72,53,3,252,213,140,50,87,51,252,252,207,63,0,0,0,240,15,0,0,48,252,255,255,48,128,128,
200,48,142,12,194,48,136,48,192,63,206,240,207,179,136,240,192,3,200,14,204,15,2,136,200,252,195,255,255,240,195,15,0,48,0,
12,0,48,0,12,0,112,85,13,0,112,85,13,0,112,85,13,0,240,255,15,0,0,0,0,240,255,3,0,192,80,13,0,255,67,53,0,12,0,213,0,48,60,
84,3,192,243,80,13,192,207,255,63,0,163,242,0,252,15,34,255,63,176,8,12,60,8,2,8,242,255,163,200,255,0,140,0,3,0,240,207,15,
0,0,48,12,0,0,192,48,0,0,0,195,0,0,0,252,3,0,0,0,0,240,15,0,0,240,255,48,0,0,192,0,192,0,0,0,195,63,63,252,240,63,63,192,60,
255,128,202,0,51,10,40,2,87,253,160,14,32,92,213,35,48,138,114,85,255,192,32,192,85,13,3,35,34,87,53,204,255,207,95,213,48,
48,136,112,85,195,207,40,226,255,15,48,131,0,48,0,192,140,138,202,0,0,51,0,48,3,0,204,255,255,12,0,48,0,0,48,0,192,255,255,
255,0,0,0,0,240,15,0,0,255,12,3,0,252,240,203,0,192,3,128,48,0,60,136,62,15,0,195,62,0,3,192,140,40,243,3,48,32,195,200,255,
255,0,131,50,240,63,143,0,0,124,0,63,252,255,95,212,252,3,0,87,55,0,0,192,85,13,0,0,240,255,3,0,0,0,240,255,63,192,196,196,
0,71,68,3,76,68,12,112,68,52,192,68,196,0,63,240,3,252,192,15,255,207,255,15,0,0,60,34,34,242,35,34,242,44,34,226,48,32,2,195,
240,63,12,255,192,63,0,0,255,255,3,0,240,3,15,255,3,63,0,12,3,255,131,178,12,67,197,51,56,62,115,199,195,179,48,64,197,227,
0,50,115,199,3,60,188,72,197,35,15,12,123,199,143,130,128,96,197,44,252,63,192,195,12,12,240,255,255,252,15,0,0,0,0,255,255,
255,255,12,0,0,0,51,243,255,0,204,12,34,226,48,51,32,2,207,207,44,226,95,61,3,34,124,245,252,42,242,213,3,48,207,87,255,15,
60,95,13,240,63,0,63,0,192,0,12,0,0,255,63,0,0,192,63,0,0,252,195,0,0,60,12,3,0,48,136,12,0,252,44,240,15,48,8,47,48,192,48,
32,227,0,195,0,32,255,60,255,62,0,51,94,213,12,204,96,69,56,255,195,85,13,12,3,63,255,63,140,194,48,0,48,12,192,0,192,255,3,
3,0,0,252,15,0,0,255,3,0,48,240,0,0,3,12,255,48,194,63,12,131,34,224,240,195,2,60,12,15,34,207,8,207,211,12,251,194,205,15,
88,223,48,192,81,13,163,92,213,48,252,255,15,195,0,0,240,15,0,0,0,192,255,15,192,255,15,192,0,12,192,136,12,192,202,192,255,
255,204,95,85,15,204,128,85,245,204,204,95,85,0,252,192,63,63,251,195,2,131,48,51,136,10,227,51,3,34,191,50,243,63,0,2,51,0,
63,63,48,3,0,3,48,48,0,240,255,15,3,0,0,192,63,0,0,240,255,255,15,0,0,67,240,192,0,0,48,7,0,12,192,255,243,213,252,3,15,95,
253,3,240,63,242,21,128,12,194,3,80,60,243,60,252,239,239,8,3,243,252,48,192,139,50,195,128,50,35,227,51,12,0,0,0,0,195,255,
255,255,255,48,0,0,0,0,252,3,0,0,255,15,0,0,0,0,0,3,252,3,0,0,0,240,63,2,3,0,0,0,48,240,0,255,0,0,0,48,62,60,192,0,0,0,48,48,
252,207,0,0,0,48,43,2,204,0,0,0,48,136,252,204,0,0,0,48,3,194,204,0,0,0,48,195,14,204,0,0,0,60,255,192,204,0,0,0,12,194,255,
204,252,3,0,15,32,0,194,15,255,255,195,143,56,50,80,213,3,240,0,48,60,92,213,163,10,240,255,62,112,223,15,240,0,0,0,112,213,
60,252,255,255,255,64,213,48,12,0,0,192,255,240,240,15,0,0,0,192,63,0,0,192,255,255,63,0,0,87,85,213,0,192,223,221,93,3,0,3,
85,85,13,0,12,34,66,52,0,252,255,252,255,192,63,48,192,195,192,3,200,0,35,15,195,206,207,47,240,140,32,2,35,34,51,140,60,0,
176,204,128,255,254,251,48,255,240,192,0,195,0,203,3,51,10,3,12,140,12,2,12,240,51,202,32,63,0,204,0,35,15,0,48,255,255,12,
0,192,0,0,48,0,0,255,255,255,0,0,192,255,255,3,192,5,3,3,192,5,0,3,192,5,195,63,240,255,195,240,48,0,0,192,48,12,15,195,255,
60,252,243,131,240,63,195,51,130,48,194,131,32,48,240,255,60,255,63,192,0,3,0,192,255,3,0,0,0,0,0,255,0,192,255,255,63,252,
15,12,48,12,194,192,195,136,8,50,34,48,188,8,12,35,32,243,3,255,255,255,60,131,56,92,85,227,48,3,195,85,245,12,195,243,76,85,
195,48,3,128,85,133,12,51,242,92,85,195,48,136,195,85,53,14,35,48,188,255,195,48,34,255,136,32,14,207,0,136,136,192,207,240,
255,8,32,192,12,0,192,252,255,204,255,207,2,0,192,0,192,192,255,255,15,0,252,15,0,0,0,0,192,255,15,0,0,0,0,195,240,15,0,0,0,
140,203,240,0,192,255,63,12,3,255,255,87,193,184,12,14,3,95,5,3,176,48,0,124,17,128,195,8,176,240,21,60,44,11,195,192,87,241,
56,0,254,255,255,255,195,186,48,0,0,0,140,195,224,0,0,0,48,12,3,3,0,0,192,63,252,15,0,0,0,192,63,0,0,0,192,255,255,3,0,0,87,
85,253,3,0,28,81,53,12,0,112,85,149,50,0,192,0,244,195,63,240,255,63,200,192,192,0,8,136,32,3,195,0,131,56,12,60,255,3,195,
48,48,2,48,240,207,240,224,192,60,12,195,0,239,15,48,60,35,128,12,195,192,252,15,48,207,60,15,176,51,8,34,48,192,12,174,194,
192,0,63,8,0,255,3,192,195,48,12,0,0,252,255,63,0,0,0,0,192,63,0,0,0,252,63,252,15,240,255,3,0,3,3,12,0,34,207,204,0,195,63,
194,0,52,192,0,32,51,223,13,240,254,139,200,119,3,12,192,0,255,253,0,35,240,255,112,247,255,171,15,0,220,61,0,12,176,251,71,
207,63,171,10,48,213,51,128,0,12,76,245,12,60,15,192,95,61,255,239,255,195,255,15,0,48,192,48,0,255,255,15,240,15,0,255,255,
3,192,0,192,0,48,0,240,15,60,255,12,3,207,60,192,192,168,8,58,48,204,35,12,12,243,32,255,255,160,226,48,3,15,84,205,12,204,
69,51,48,243,213,252,143,112,53,0,15,252,15,0,255,3,0,252,255,255,255,15,0,87,192,0,3,63,240,85,129,207,140,12,92,85,131,48,
8,3,87,213,48,204,204,195,255,255,8,50,195,15,3,176,47,207,3,243,128,0,35,8,204,12,207,207,240,191,51,35,10,128,128,0,204,8,
224,203,255,63,243,255,3,60,0,252,0,192,255,3,0,0,0,252,255,0,0,195,48,0,192,8,12,0,252,60,3,252,35,204,3,3,0,195,195,136,255,
200,48,202,48,56,44,8,44,204,131,14,40,63,10,195,32,15,192,63,194,195,126,61,240,79,87,253,15,83,85,61,192,85,64,13,240,255,
255,3,0,0,0,0,255,3,0,192,255,243,3,255,192,255,0,63,34,200,255,240,44,2,200,192,87,1,138,8,2,251,23,243,12,252,62,195,87,1,
204,15,48,192,87,1,204,131,240,203,215,255,131,48,252,243,255,0,3,63,0,48,0,0,255,255,255,63,0,252,15,0,192,192,255,15,140,
252,192,192,8,160,12,60,255,192,240,51,204,15,3,195,60,48,10,32,3,3,51,242,255,63,3,195,12,248,15,204,32,0,194,60,240,63,207,
255,255,195,95,53,130,124,85,163,195,23,53,130,124,85,2,195,15,255,255,207,63,0,0,0,252,255,0,0,195,240,63,240,48,92,253,12,
14,87,48,35,43,21,204,224,112,69,51,48,254,255,191,0,128,200,15,131,50,48,255,15,175,12,0,3,192,3,192,255,63,0,240,15,0,0,0,
195,255,255,0,60,60,12,12,192,224,136,192,63,44,8,35,14,255,224,179,8,192,195,48,3,42,60,2,8,62,255,35,178,195,48,240,240,195,
47,3,12,87,1,48,192,127,85,253,3,192,85,255,0,0,92,61,0,0,192,213,0,0,0,252,15,0,0,0,0,240,15,192,255,48,192,3,224,192,35,60,
63,35,50,194,252,243,128,195,85,139,12,87,13,56,92,5,202,115,197,8,204,255,139,48,0,12,252,0,176,60,0,192,48,0,0,255,0,255,
255,255,15,192,195,15,8,200,255,60,202,3,50,192,163,50,255,3,51,242,195,48,200,227,56,192,3,53,255,255,133,204,87,53,206,95,
53,200,127,61,192,255,255,255,0,255,255,255,240,255,3,3,204,127,213,3,58,0,80,213,3,243,3,79,213,207,243,195,64,213,140,8,192,
60,255,12,226,195,0,192,255,12,255,60,207,195,44,240,60,192,35,8,243,252,255,51,34,192,12,0,131,60,207,12,0,163,0,40,12,0,207,
243,35,12,0,12,48,3,12,0,252,63,255,15,0,0,0,252,3,0,0,252,240,0,0,255,32,12,0,48,32,194,63,0,35,48,2,243,63,12,3,50,215,239,
242,239,127,205,192,255,60,213,236,60,207,67,205,12,32,0,213,12,252,243,67,205,207,51,60,213,240,242,47,127,13,3,15,48,215,
60,250,32,243,207,0,168,50,0,140,252,0,3,192,192,252,63,0,252,15,0,0,0,255,255,63,0,0,92,85,192,255,255,112,85,1,195,3,195,
245,35,128,0,12,87,136,12,63,48,92,237,255,0,195,240,3,12,44,140,63,12,138,8,62,200,48,8,236,240,0,195,207,51,200,255,15,12,
34,207,3,0,48,128,32,12,0,192,3,51,48,0,0,252,207,255,0,0,0,240,3,0,0,252,255,15,192,85,192,3,220,13,242,240,85,51,60,83,53,
12,63,0,203,203,207,15,2,204,130,136,195,204,32,242,204,240,195,195,12,240,60,207,32,131,48,252,34,240,3,12,255,3,192,63,0,
0,0,0,0,240,3,0,0,0,0,223,15,0,0,0,192,85,3,240,255,255,127,213,0,15,60,0,95,245,255,160,15,194,87,1,60,0,40,14,85,3,15,242,
40,115,213,240,131,60,194,60,63,204,243,63,63,0,0,243,128,32,255,243,195,140,63,204,255,204,63,3,2,3,0,3,192,32,139,248,195,
0,48,234,8,204,63,0,12,48,40,3,0,0,255,15,252,0,0,0,0,255,3,0,0,0,0,240,207,255,15,51,0,194,12,248,56,239,213,12,99,5,195,28,
205,51,48,203,44,8,48,195,255,207,63,0,0,0,240,255,0,0,0,0,255,3,3,0,0,0,12,204,252,15,0,0,48,50,8,240,255,0,240,194,207,3,
0,3,252,160,136,12,15,252,63,0,32,240,255,60,240,240,255,207,0,51,204,207,15,0,255,236,12,51,63,255,124,49,32,207,32,8,251,
197,62,60,195,204,0,212,243,200,252,3,243,92,3,8,3,252,15,112,205,12,15,0,240,255,53,48,15,0,0,0,215,255,48,0,0,0,92,0,192,
0,0,0,240,240,195,3,0,0,0,255,255,3,0,0,192,255,0,0,0,240,192,3,0,0,60,0,3,0,0,15,10,3,0,192,163,32,3,0,192,8,32,3,255,192,
128,242,63,195,255,63,15,48,23,0,0,160,50,55,255,63,15,60,55,255,127,44,254,87,85,85,12,200,255,255,255,15,194,0,0,0,60,252,
0,0,0,240,15,0,252,255,3,48,15,252,195,8,8,12,131,136,58,140,206,192,188,0,2,51,8,170,254,248,207,192,131,85,3,207,87,173,60,
95,5,252,64,213,48,207,85,235,48,87,13,195,0,0,12,255,188,63,0,3,12,0,252,63,0,0,255,255,255,0,12,0,0,15,48,204,138,48,192,
178,195,195,192,243,140,204,3,3,178,48,3,12,140,192,12,240,136,192,51,192,48,60,200,0,3,60,58,243,255,10,12,204,85,195,255,
63,119,197,3,0,92,5,12,0,112,21,48,0,192,255,255,0,0,0,0,0,255,63,0,192,255,48,252,3,48,48,32,192,240,207,202,243,48,15,0,51,
60,255,240,227,130,32,124,5,48,15,3,95,13,0,243,243,87,195,15,130,240,255,63,15,12,12,0,0,255,255,3,0,255,255,195,63,0,48,240,
240,15,3,0,3,2,131,48,0,48,204,51,0,255,0,143,128,232,12,12,240,15,195,136,192,255,195,63,192,95,61,176,12,243,95,213,3,192,
48,243,85,253,255,12,11,252,213,192,192,51,14,92,13,15,0,8,206,255,60,234,195,8,12,192,192,48,63,252,0,12,8,11,255,0,192,255,
48,48,0,0,0,252,255,3,0,0,252,15,0,0,0,3,3,0,0,192,204,255,3,0,48,0,200,255,3,140,188,252,192,0,243,143,0,50,192,252,207,176,
252,63,252,243,2,192,131,131,48,207,243,0,0,204,213,252,255,240,67,5,3,240,207,92,205,0,0,48,63,51,0,0,12,0,12,0,0,255,255,
3,0,192,63,0,0,192,240,0,0,192,192,3,0,192,40,15,0,252,130,60,240,15,32,48,63,204,255,48,3,204,85,50,51,32,85,51,131,204,81,
51,63,252,243,51,240,15,194,251,0,252,8,192,0,192,240,192,0,192,255,255,0,0,240,255,255,15,0,95,0,3,3,240,5,2,200,0,95,52,179,
60,192,69,51,35,204,127,53,12,48,51,60,3,0,192,12,34,63,204,60,35,32,48,3,195,175,192,204,204,0,3,2,51,255,195,56,255,3,192,
176,192,192,192,48,12,63,240,0,12,195,0,48,192,195,63,0,252,63,0,0,252,255,255,15,0,48,192,15,48,0,192,0,136,240,15,240,207,
128,8,48,240,8,251,143,200,252,192,12,252,32,51,130,48,8,243,207,188,255,236,32,252,243,240,51,51,8,15,128,128,192,200,252,
63,12,15,227,48,92,241,191,48,204,112,85,53,202,50,195,85,213,0,0,12,87,85,255,63,60,252,255,15,192,63,0,255,243,15,0,87,51,
252,3,87,63,8,3,87,61,130,63,95,245,128,48,127,197,35,50,243,0,131,48,195,51,63,255,35,179,32,192,131,128,0,194,3,35,138,252,
195,255,195,15,243,0,255,0,63,0,0,0,0,252,3,0,0,0,60,252,15,0,0,48,0,48,255,3,192,248,195,15,12,0,215,224,12,51,0,92,3,128,
206,15,112,204,176,8,240,255,53,60,0,239,192,135,32,243,32,0,95,15,2,3,255,127,188,15,252,15,192,5,242,63,0,0,195,192,0,0,0,
252,255,3,0,0,0,192,63,255,3,195,15,12,140,128,48,48,252,251,192,51,12,195,195,1,12,195,215,48,12,28,243,48,123,45,195,200,
53,12,51,195,48,140,92,251,48,64,12,243,195,48,252,0,255,240,240,255,251,35,0,8,15,15,12,252,255,255,63,252,255,255,255,255,
15,3,15,3,3,3,195,8,128,128,128,192,252,207,48,240,243,254,3,243,254,63,48,240,8,76,85,13,140,252,12,83,85,255,3,63,255,255,
215,192,252,3,0,192,53,2,195,60,63,127,61,195,63,3,3,95,207,15,15,0,0,214,0,192,51,48,240,48,240,240,255,252,255,255,63,63,
0,0,12,12,32,143,48,34,2,51,192,179,143,195,243,0,243,32,202,63,130,204,60,0,0,12,12,0,255,255,255,255,255,255,0,252,255,255,
255,255,255,0,0,0,0,192,3,200,0,240,12,60,252,63,63,236,243,239,192,123,21,48,51,12,32,87,61,51,35,51,115,213,3,51,178,2,87,
189,51,51,226,123,213,3,51,160,2,87,13,48,131,3,243,255,248,243,48,191,130,128,12,12,192,8,242,192,192,255,192,192,255,15,0,
252,255,15,0,0,255,255,255,51,0,192,63,243,255,12,63,35,34,200,3,0,11,252,11,58,252,48,60,227,3,239,128,48,192,32,242,3,204,
128,48,192,60,48,3,15,255,51,48,0,0,3,87,85,63,112,85,53,0,255,255,3,0,0,0,252,3,192,255,255,240,0,15,2,128,252,63,240,60,240,
213,179,34,186,95,61,3,0,3,213,131,243,43,80,61,130,130,124,213,191,0,192,255,15,195,255,15,0,240,15,0,0,0,0,0,0,240,255,0,
0,0,0,252,15,48,0,0,0,0,195,51,252,15,0,0,192,0,93,3,3,252,207,63,222,21,192,0,3,63,60,83,245,60,192,8,0,207,117,61,3,252,63,
3,51,253,207,0,3,227,206,92,255,51,192,8,2,48,19,192,12,240,60,200,207,240,48,3,48,8,242,243,63,207,0,252,254,254,240,207,51,
192,63,3,0,240,195,12,48,200,224,63,252,58,255,15,0,50,195,63,236,192,255,12,206,0,0,0,48,48,8,243,240,240,255,15,60,252,240,
255,15,0,0,252,3,0,0,0,0,0,0,0,252,3,0,0,0,0,0,48,12,0,0,0,0,0,192,240,255,15,0,0,240,255,195,0,48,0,0,192,192,204,204,192,
3,0,0,35,0,194,131,12,0,0,63,206,48,3,240,255,63,12,194,224,140,50,48,195,60,3,3,240,3,200,12,51,44,48,63,12,163,51,204,0,62,
194,192,35,204,252,191,200,0,15,3,2,212,195,0,63,35,242,195,31,15,192,131,2,8,192,87,61,60,60,32,236,240,85,244,51,8,51,62,
124,21,253,207,131,48,50,92,69,63,12,32,255,192,84,209,15,48,48,12,195,80,244,3,192,255,63,252,255,255,0,0,0,0,0,255,3,0,0,
0,0,48,240,15,0,0,0,0,35,192,63,252,3,0,48,48,14,255,48,255,255,63,3,2,3,115,1,48,194,63,195,48,151,48,32,12,50,210,115,207,
136,60,60,192,13,215,2,3,15,160,220,112,141,8,34,15,60,13,183,50,15,200,142,220,112,13,0,15,12,192,13,215,255,15,63,255,223,
51,10,0,0,0,0,244,195,255,255,255,255,67,253,15,0,0,0,240,255,0);

  lb2: array[0..lnum+lnum+lnum-1] of word = ({x,y,xc,yc,first byte; c-chelovek}
$0B16,$080C,0, $0A0E,$0407,61, $0A11,$010E,97, $0D17,$0A09,140,
$0D11,$070E,215, $0B0C,$0109,271, $0C0D,$0205,305, $1110,$0601,345,
$1211,$0A01,414, $1415,$0502,491, $0F13,$0307,597, $100D,$0D06,669,
$0D14,$0407,722, $0D11,$0407,788, $1111,$0606,844, $0F0E,$0503,917,
$1012,$020A,970, $0D16,$020F,1043, $141C,$010C,1115, $1415,$0406,1256,
$0E10,$0A02,1362, $1416,$040B,1419, $0E19,$0705,1530, $1315,$0F05,1618,
$1117,$0911,1718, $0F0F,$0404,1816, $0D17,$0B0A,1873, $110F,$0106,1948,
$0B18,$0913,2012, $140E,$0608,2079, $0C0F,$090D,2150, $1012,$0208,2196,
$0F0D,$0401,2269, $0F0C,$0A0A,2318, $1014,$010A,2364, $1312,$0807,2445,
$0F15,$0D09,2531, $0F0E,$030A,2610, $1217,$050B,2663, $0B0B,$0108,2767,
$1319,$070D,2798, $0F14,$0811,2917, $120D,$0102,2993, $1011,$030F,3052,
$0B13,$0709,3121, $1116,$0E0B,3174, $0F13,$0309,3268, $0F10,$0B07,3340,
$1013,$0702,3401, $1015,$0905,3478, $0E10,$0905,3563, $0E15,$0C05,3620,
$130D,$0704,3694, $1417,$0B04,3756, $0F16,$0805,3872, $100E,$070B,3955,
$0B12,$0507,4012, $141B,$0E15,4062, $141D,$0D0D,4198, $101A,$0806,4344);

lb3: array[0..22] of byte =
  (0,12,  18,15, 19,16, 20,20, 22,48, 23,49, 26,52, 29,53, 34,58, 38,59, 44,60, 47);
   { nachalo dannyh v lb3 i numbers lab`ov, gde est' bochki na mestah}
  lb3a:array[0..46] of word = {x,y}
($0104,$0106,$0108,$010a,$0205,$0207,$0209,$0304,$0306,$0308,
 $030a,$0405,$0407,$0409,$0504,$0506,$0508,$050a,$0a09,$0a0a,
 $040f,$0411,$090a,$0407,$0308,$0209,$0603,$0803,$0a03,$0509,
 $0709,$0a09,$0c09,$0a08,$030f,$050f,$070f,$090f,$1213,$1115,
 $1017,$0f19,$0e1b,$0c1c,$0703,$0a03,$0d17);

var lb,lb1: array[1..600] of byte; {lb1-otmenit' hod}
const nnm=5;
type
  res = record
    name: string[10];
    result: word
  end;

var
  playername: string [10];
  f: file of res;
  res1: res;
  a1: array[0..lnum*10-1] of res;

const
  fname:string[12]='labs.dat';


Procedure w(x,y,c: byte; s: string);
Begin
  if x>0 then gotoxy(x,y);
  if c>0 then textattr:=c;
  write(s)
end;

Procedure wl(x:word; n:byte);
begin w(x0+((x-1) mod mx)*2,y0+(x-1) div mx,$7,copy(fig,n*2+1,2)) end;

Function upcase(c:char):char;
begin
  case c of
    'a'..'z', 'а'..'п': upcase:=chr(byte(c)-32);
    'р'..'я': upcase:=chr(byte(c)-64-16);
  else upcase:=c
  end
end;

Function locase(c:char):char;
begin
  case c of
  'A'..'Z', 'А'..'П': locase:=chr(byte(c)+32);
  'Р'..'Я': locase:=chr(byte(c)+64+16);
  else locase:=c
  end
end;

Procedure Zag(n:byte);
Begin
  clrscr;
  w(1,1, $70, ' JOPKA БК-01 ');
  textattr:=7;
  w(1,25,0,'(Ъ) Хрыч 1989, 1997, 2000, 2006.');
End;


Procedure rk;
begin c2:=byte(readkey); if c2=0 then c2:=256+byte(readkey) end;

Procedure wu(x: word; c: byte);
begin
  mem[$b800:x]:=c
end;

Procedure line(x:word; kol:byte; dx:integer; b:byte);
var i:word;
begin for i:=0 to kol-1 do wu(x+dx*i*2,b) end;

Function Menu(x,y,len,max:byte):byte;
Var
  n: byte;
Begin
  n:=1;
  repeat
    line((x+(y+n)*80)*2+1,len,1,$70);
    rk;
    line((x+(y+n)*80)*2+1,len,1,$07);
    case c2 of
      dn: if n<max then inc(n);
      up: if n>1 then dec(n);
      49..57: if c2-48<=max then begin n:=c2-48; c2:=enter end;
    end;
  until (c2=esc)or(c2=enter);
  if c2=enter then mem[$b800:(x+(y+n-2)*80-3)*2]:=16 else {c2=esc} n:=0;
  menu:=n
End;

function wu1(x: word):byte;
begin
  wu1:=mem[$b800:x]
end;

var xo:word; b1,b2,b1o,b2o:byte;

Procedure save_otm;
begin lb1:=lb; xo:=x; b1o:=b1; b2o:=b2 end;

Procedure  QWE;
Begin   wl(x,6);
        w(65,7,0,'Осталось: '); write(b1-b2,'  ');
        w(65,9,0,'На месте: '); write(b2,'  ');
        w(65,11,0,'Шагов: '); write(sg,' ');
end;


Procedure ASD;
begin
      for i:=0 to 9 do begin
        str(a1[i+(lab-1)*10].result,s);
        if s<>'9999' then begin
          w(65,14+i,7,a1[i+(lab-1)*10].name);
          w(77,14+i,7,s)
        end;
      end;
end;


BEGIN {=====================================================================}
     zag(0);
     w(6,9,0,'                             J O P K A  ');

     line(880*2,79,1,196);
     w(6,14,0,'    Управляя крестом, Вы должны');
     w(6,15,0,' загнать все шары на свои места               ████████████████');
     w(6,16,0,' (точки)  за  минимальное число               ██><    (). ▒▒██');
     w(6,17,0,' шагов.                                       ████████████████');
     w(20,20,0,'Введите пароль или нажмите Enter : ');
     readln(s); val(s,n,i);
     lab:=1; if i=0 then for i:=2 to lnum do if n=parol[i] then lab:=i;

     assign(f,fname);
     {$I-} reset(f); {$I+}
     if ioresult<>0 then begin
       rewrite(f);
       res1.name:='Noname';
       res1.result:=0;
       write(f,res1);
       res1.name:='*';
       res1.result:=9999;
       for i:=0 to lnum*10-1 do write(f,res1);
       close(f);
       reset(f)
     end;
     read(f,res1);
     playername:=res1.name;
     for i:=0 to lnum*10-1 do read(f,a1[i]);
     close(f);

     zag(4);
     w(30,10,7,'Name ('+playername+' by default): '); readln(sss);
     if sss>'' then playername:=sss;


     REPEAT
      zag(4);
      ASD;
      w(65,1,7,'* '); write(playername,' *');
      w(65,3,7,'Номер: '); write(lab);
      if lab>1 then begin w(65,5,7,'Пароль: '); write(parol[lab]) end;
      w(35,25,0,'Space - сброс, ^Z - отменить ход, Esc - конец');
      i:=(lab-1)*3;
      mx:=lo(lb2[i]);  my:=hi(lb2[i]);  x:=lo(lb2[i+1])+hi(lb2[i+1])*mx+1;
      n:=lb2[i+2];
      x0:=32-mx; y0:=13-my div 2;  b1:=0; b2:=0;
      flag:=0;
      for i:=1 to my*mx do begin
        b:=(z[n] shr (flag*2))and 3;
        inc(flag); if flag=4 then begin flag:=0; inc(n) end;
        if b=3 then b:=7;
        wl(i,b);
        lb[i]:=b;
        if b=2 then inc(b1);
      end;
      for k:=0 to 10 do if lb3[k*2+1]=lab then begin
        for j:=lb3[k*2] to lb3[k*2+2]-1 do begin
          i:=lo(lb3a[j])+mx*hi(lb3a[j]);
          wl(i,3); lb[i]:=3;  inc(b2); inc(b1);
        end;
      end;
      sg:=0; dx:=0; save_otm;
      repeat
        QWE; gotoxy(1,1);
        rk;
        wl(x,lb[x]);
        case c2 of
          dn: dx:=mx; up: dx:=-mx; lt: dx:=-1; rt: dx:=1;
          ctrl_z: begin
            lb:=lb1; for i:=1 to my*mx do wl(i,lb[i]);
            x:=xo; b1:=b1o; b2:=b2o; {dec(sg); - multiple undo's error} dx:=0;
            QWE
          end;
        end;
        if dx<>0 then begin
            if lb[x+dx]<2 then inc(x,dx)
            else if (lb[x+dx]in[2,3])and(lb[x+dx+dx]<2) then begin
              save_otm;
              b2:=b2 - lb[x+dx]and 1 + lb[x+dx+dx]and 1;
              inc(lb[x+dx+dx],2);
              dec(lb[x+dx],2);
              wl(x+dx+dx,lb[x+dx+dx]);
              x:=x+dx;
              inc(sg);
              QWE
            end
        end;
      until (b1-b2=0)or(c2=esc)or(c2=32);

      QWE;
      if b1-b2=0 then begin
        for i:=9 downto 0 do begin
          if sg<a1[i+(lab-1)*10].result then begin
            if i<9 then a1[i+1+(lab-1)*10]:=a1[i+(lab-1)*10];
            a1[i+(lab-1)*10].result:=sg;
            a1[i+(lab-1)*10].name:=playername
          end
        end;
        ASD;
      {  rk; // remed 29-1-2006}
      readln;
        c2:=0;
        inc(lab);
        if lab>lnum then begin
          zag(4);
          w(31,10,7,'ЭТО НЕВОЗМОЖНО !');
          w(27,12,7,'Вы прошли все лабиринты.');
          w(20,14,7,'Но  мультфильма, к сожалению, не будет.');
          w(33,17,7,'Жми Enter.');
          readln;
          c2:=esc
        end;
      end;
     UNTIL (c2=esc);

     rewrite(f);
     seek(f,0);
     res1.name:=playername;
     write(f,res1);
     for i:=0 to lnum*10-1 do write(f,a1[i]);
     close(f);

     c2:=0;
    end.
