/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
using namespace std;
int n;
int a[1005];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
a[1] = 0;
a[0] = 1;
for (int i = 2; i <= 1000; i++){
a[i] = (a[i - 1] + 2 * a[i - 2]) % 10000;
}
while(scanf("%d", &n) == 1){
if(!n) break;
printf("%d\n", a[n]);
}
return 0;
}
/**/