Go: package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func CountPatterns(i int, patternNums []int) int {
	if patternNums[i] != 0 {
		return patternNums[i]
	}
	if i == 0 {
		return 1
	}
	patternNums[i] += CountPatterns(i-1, patternNums)
	if i > 1 {
		patternNums[i] += CountPatterns(i-2, patternNums)
	}
	if i > 2 {
		patternNums[i] += CountPatterns(i-3, patternNums)
	}
	return patternNums[i]
}

func Solve(N int) int {
	patternNums := MakeFilledInts(N+1, 0)
	return (CountPatterns(N, patternNums) + 3649) / 3650
}

func main() {
	for N := scan.Int(); N != 0; N = scan.Int() {
		ans := Solve(N)
		fmt.Println(ans)
	}
}

// --------------------------------------------------------------------------------
// Input

var scan = NewScanner()

type Scanner struct{ *bufio.Scanner }

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 100000000)
	return &Scanner{sc}
}

func (s *Scanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Strings(l int) []string {
	if l == 0 {
		return []string{}
	}
	sl := make([]string, l, l)
	for i := range sl {
		sl[i] = s.String()
	}
	return sl
}

func (s *Scanner) Int() int {
	n, _ := strconv.Atoi(s.String())
	return n
}

func (s *Scanner) Ints(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *Scanner) Int64() int64 {
	n, _ := strconv.ParseInt(s.String(), 10, 64)
	return n
}

func (s *Scanner) BigInt() *big.Int {
	return big.NewInt(s.Int64())
}

func (s *Scanner) BigInts(l int) []*big.Int {
	if l == 0 {
		return []*big.Int{}
	}
	sl := make([]*big.Int, l, l)
	for i := range sl {
		sl[i] = s.BigInt()
	}
	return sl
}

func (s *Scanner) Float64() float64 {
	f, _ := strconv.ParseFloat(s.String(), 64)
	return f
}

func (s *Scanner) Floats64(l int) []float64 {
	if l == 0 {
		return []float64{}
	}
	sl := make([]float64, l, l)
	for i := range sl {
		sl[i] = s.Float64()
	}
	return sl
}

// --------------------------------------------------------------------------------
// Output

const (
	Yes = "Yes"
	No  = "No"

	YES = "YES"
	NO  = "NO"
)

func PrintBool(v bool, trueStr, falseStr string) {
	if v {
		fmt.Println(trueStr)
	} else {
		fmt.Println(falseStr)
	}
}

// --------------------------------------------------------------------------------
// sort.BigIntSlice

type BigIntSlice []*big.Int

func (sl BigIntSlice) Len() int {
	return len(sl)
}

func (sl BigIntSlice) Less(i, j int) bool {
	return sl[i].Cmp(sl[j]) == -1
}

func (sl BigIntSlice) Swap(i, j int) {
	sl[i], sl[j] = sl[j], sl[i]
}

// --------------------------------------------------------------------------------
// Mint

const (
	Mod = 1000000007
)

type Mint int

func NewMint(value int) Mint {
	return Mint((value%Mod + Mod) % Mod)
}

func (x Mint) Add(y Mint) Mint {
	if v := x + y; v >= Mod {
		return v - Mod
	} else {
		return v
	}
}

func (x Mint) Sub(y Mint) Mint {
	if v := x + Mod - y; v >= Mod {
		return v - Mod
	} else {
		return v
	}
}

func (x Mint) Mul(y Mint) Mint {
	return (x * y) % Mod
}

func (x Mint) pow(n int) Mint {
	if n == 0 {
		return Mint(1)
	}
	a := x.pow(n >> 1)
	a = a.Mul(a)
	if n&1 != 0 {
		a = a.Mul(x)
	}
	return a
}

func (x Mint) Inverse() Mint {
	return x.pow(Mod - 2)
}

func (x Mint) Div(y Mint) Mint {
	return x * y.Inverse()
}

func (x Mint) Neg() Mint {
	return NewMint(int(-x))
}

// --------------------------------------------------------------------------------
// Factorial

type Factorial struct {
	fact        []Mint
	factInverse []Mint
}

func NewFactorial(n int) *Factorial {
	f := new(Factorial)
	f.init(n)
	return f
}

func (f *Factorial) init(n int) {
	fact := make([]Mint, n+1, n+1)
	fact[0] = NewMint(1)
	for i := 1; i <= n; i++ {
		fact[i] = fact[i-1].Mul(NewMint(i))
	}

	inv := make([]Mint, n+1, n+1)
	inv[n] = fact[n].Inverse()
	for i := n; i >= 1; i-- {
		inv[i-1] = inv[i].Mul(NewMint(i))
	}

	f.fact = fact
	f.factInverse = inv
}

func (f *Fa

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while( cin>>n ,n){  // nが0ならwhileを抜けます。

		int dp[50]={};  // 階段のかわり　（　余裕を持って50段用意しています　）

		dp[0]=1;        // 今０段目にいる。（　階段を登っていない通り数は１つ　）    （　まだ階段を登っていない　＝　0段目にいる　）

		for(int i=0;i<n;i++){  // i段目で３通りの飛び方を試す

			dp[i+1] += dp[i];   // 1段先に飛ぶ  (1段先にi段目までの通り数を足す)
			dp[i+2] += dp[i];   // 2段先に飛ぶ　(2段先にi段目までの通り数を足す)
			dp[i+3] += dp[i];   // 3段先に飛ぶ　(3段先にi段目までの通り数を足す)

		}

        /*   dp[n] に　n段目に飛んでいく通り数が入ってます　*/

		cout<< ( (dp[n]/10)/365 + 1 )<<endl;  //  1日に10回飛ぶ　＝　割る10。  １年間あたり　＝　割る365。　いい感じにしたいので１を足す
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int ans[30]={},tans=0;
signed main(){
  int N;
  int dp[30]={};
  dp[0]=1;
  for(int i=1;i<=30;i++){
    //cout << i << endl;
    if(i==1) dp[i]=dp[i-1];
    else if(i==2) dp[i]=dp[i-1]+dp[i-2];
    /*else{
      int tmp=dp[i-1]+dp[i-2]+dp[i-3];
      dp[i]=tmp%3650;
      tans+=floor(tmp/3650);
      ans[i]=ans[i-1]+tans;
    }*/
    else dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
  }

  while(cin >> N && N!=0){
  cout << ceil((double)dp[N]/3650.0) << endl;
  //cout << dp[N] << endl;
}
  return 0;
}

C++: #include <cstdio>

using namespace std;

int dp[31];

int main()
{
	dp[0] = 1;

	for (int i = 1; i <= 30; ++i) {
		for (int j = 1; j <= 3; ++j) {
			if (i-j >= 0) dp[i] += dp[i - j];
		}
	}

	int n;

	while (scanf("%d", &n), n) {
		printf("%d\n", (dp[n] + 3649) / 3650);
	}
}

C++: #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int n;

	
	while(cin >> n && n){
	int a[33];
	a[0] = a[1] = 0;
	a[2] = 1;
	for(int i = 3;i < n+3;i++){
		a[i] = a[i-3] + a[i-1] + a[i-2];
	}
	int res = a[n+2]/10/365;
	if(a[n+2]% 3650 != 0)
		res ++;
	cout << res << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

int compare_int(const void* a, const void* b) { return *(int*) a - *(int*) b; }

int n, dp[31];

int func(int p) {
	if (p == n) {
		return 1;
	}
	int cnt = 0;
	for (int i = p + 1; n >= i && 3 + p >= i; i++) {
		if (dp[i] == -1) dp[i] = func(i);
		cnt += dp[i];
	}
	return cnt;
}

int main() {
	while (scanf("%d", &n) != EOF) {
		if (n == 0) return 0;
		memset(dp, -1, sizeof(dp));
		printf("%d\n", ((func(0)+9) / 10 + 364) / 365);
	}
}

C++: #include <iostream>
using namespace std;
int main(void){
  while(true){

      int y=0,n;
      int a[31]={0};
      cin >> n;

      if(n==0)    break;

      a[1]=1;
      a[2]=2;
      a[3]=4;
      for(int i=4;i<31;i++){
          a[i]=a[i-1]+a[i-2]+a[i-3];
      }

      y=(a[n]/10)/365+1;
      cout << y << endl;

  }
}

C++: #include<iostream>

using namespace std;

int main(){
  int n, i;
  while(cin >> n && n != 0) {
    int dp[n+1] = {};
    dp[1] = 1;
    dp[2] = 2;
    dp[3] = 4;

    for(i = 4; i <= n; i++) {
      dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
    }

    i = 0;
    
    while(dp[n] > 0) {
      dp[n]-=3650;
      i++;
    }
    
    cout <<  i  << endl;
  }
  
  return 0;
}