#include<iostream>

using namespace std;

int kei(int n) {
	long int ans;
	if (n == 1)return 1;
	else if (n == 2)return 2;
	else if (n == 3)return 4;
	else
	{
		ans = kei(n - 1) + kei(n - 2) + kei(n - 3);
		return ans;
	}
}



int main() {
	long int N[1000],ans[1000],c=0,c2;
	while (1) {
		cin >> N[c];
		if (N[c] == 0)break;
		ans[c] = kei(N[c]);
		++c;
	}
	c = 0;

	while (true) {
		if (N[c] == 0)break;
		else
		{
			cout << ans[c]<<endl;
			++c;
		}

	}

}