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
#include <iostream>
#include <string>

static inline int op(int x, int delta)
{
	return (x + 1000 + delta) % 1000;
}

using namespace std;

int main(void)
{
	string line;
	int delta = 0;
	cin >> line;
	delta = line[0] == 'A' ? +1 : -1;
	int a, b;
	cin >> a >> b;
	a--;
	b--;
	if ((a - b + 1000) % 1000 == 1 || (b - a + 1000) % 1000 == 1)
		delta *= 2;
	a = op(a, delta);
	b = op(b, delta);
	cout << a + 1 << ' ' << b + 1 << endl;
	return 0;
}