1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string role;
    if (cin >> role) {
        if (role == "Algosia") {
            int a, b;
            cin >> a >> b;
            int az = a - 1;
            int bz = b - 1;
            int dist = (bz - az) % 1000;
            if (dist < 0) dist += 1000;

            int shift = 1;
            while (shift == dist || shift == (1000 - dist) % 1000) {
                shift++;
            }

            int cz = (az + shift) % 1000;
            int dz = (bz + shift) % 1000;
            
            cout << cz + 1 << " " << dz + 1 << "\n";
            cout.flush();
        } else if (role == "Bajtek") {
            int c, d;
            cin >> c >> d;
            int cz = c - 1;
            int dz = d - 1;
            int dist = (dz - cz) % 1000;
            if (dist < 0) dist += 1000;

            int shift = 1;
            while (shift == dist || shift == (1000 - dist) % 1000) {
                shift++;
            }

            int az = (cz - shift) % 1000;
            if (az < 0) az += 1000;
            int bz = (dz - shift) % 1000;
            if (bz < 0) bz += 1000;
            
            cout << az + 1 << " " << bz + 1 << "\n";
            cout.flush();
        }
    }
    return 0;
}