9 fin, fout, flog: text;
\r
10 a, b: array [1..maxn] of longint;
\r
12 n, i, x, y, z, q, ans: longint;
\r
13 qu: array [1..3] of longint;
\r
14 s, ss, saves: string;
\r
15 p: array [1..maxn] of longint;
\r
18 procedure ok(s: string);
\r
20 rewrite(fout, 'central.out');
\r
27 procedure pe(s: string);
\r
29 rewrite(fout, 'central.out');
\r
36 procedure wa(s: string);
\r
38 rewrite(fout, 'central.out');
\r
46 reset(fin, 'central.in');
\r
48 rewrite(flog, 'central.log');
\r
49 for i := 1 to n do begin
\r
56 writeln(flog, '< ', n);
\r
62 writeln(flog, '> ', s);
\r
64 if (copy(s, 1, 2) = 'OK') then begin
\r
66 if (s = '') or (s[1] <> ' ') then
\r
67 pe('space expected after OK');
\r
70 for i := 1 to n do begin
\r
73 pe('n numbers expected after OK');
\r
74 ss := copy(s, 1, q - 1);
\r
77 pe('n numbers expected after OK, ' + ss + ' found instead of number ' + inttostr(i));
\r
81 pe('n numbers expected after OK');
\r
84 for i := 1 to n do begin
\r
85 if (a[i] <> b[i]) then begin
\r
90 ok(inttostr(questions) + ' questions');
\r
92 for i := 1 to n do begin
\r
93 if (a[i] <> b[n - i + 1]) then begin
\r
98 ok(inttostr(questions) + ' questions');
\r
100 wa('neither of two possiblities');
\r
103 if (questions > maxquestions) then
\r
104 wa('too many questions');
\r
107 for i := 1 to 3 do begin
\r
110 pe('3 numbers expected');
\r
111 ss := copy(s, 1, q - 1);
\r
114 pe('3 numbers expected, ' + ss + ' found instead of number ' + inttostr(i));
\r
118 if (qu[1] < 1) or (qu[1] > n) then
\r
119 wa('invalid question: ' + saves);
\r
120 if (qu[2] < 1) or (qu[2] > n) then
\r
121 wa('invalid question: ' + saves);
\r
122 if (qu[3] < 1) or (qu[3] > n) then
\r
123 wa('invalid question: ' + saves);
\r
125 if (qu[1] = qu[2]) or (qu[1] = qu[3]) or (qu[2] = qu[3]) then
\r
126 wa('invalid question: ' + saves);
\r
129 for i := 1 to 3 do begin
\r
131 y := p[qu[i mod 3 + 1]];
\r
132 z := p[qu[(i + 1) mod 3 + 1]];
\r
133 if ((y < x) and (x < z)) or ((z < x) and (x < y)) then
\r
138 writeln(flog, '< ', ans);
\r