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
#include <bits/stdc++.h>
using namespace std;

const string A_PERSON = "Algosia";
const string B_PERSON = "Bajtek";

pair<int, int> encode(int a, int b) {
    if (a + b != 1001) return {1001 - a, 1001 - b};
    return {(a + 499) % 1000 + 1, (b + 499) % 1000 + 1};
}

pair<int, int> decode(int a, int b) {
    if (a + b != 1001) return {1001 - a, 1001 - b};
    return {(a + 499) % 1000 + 1, (b + 499) % 1000 + 1};
}


int main(){
    string name;
    int a, b, c, d;
    cin >> name;
    cin >> a >> b;
    if (name == A_PERSON) {
        tie(c, d) = encode(a, b);
    }
    if (name == B_PERSON) {
        tie(c, d) = decode(a, b);
    }
    cout << c << " " << d << endl;
    return 0;
}