#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
int a, b, c;
a = 1, b = 1, c = 1;
for(int i = 4; i <= 20190324; i += 3)
{
a = (a + b + c) % 10000;
b = (a + b + c) % 10000;
c = (a + b + c) % 10000;
}
if(20190324 % 3 == 0) cout << c << endl;
else if(20190324 % 3 == 1) cout << a << endl;
else if(20190324 % 3 == 2) cout << b << endl;
return 0;
}