#include <stdio.h>

int dp[1001];

int top_down(int n) {
    if (n==1) return 1;
    if (n==2) return 3;

    if(dp[n]!=-1) return dp[n];

    dp[n]=(top_down(n-1)+2*top_down(n-2))%10007;
    return dp[n];
}


int main() {
    int n;
    scanf("%d",&n);

    for(int i=0; i<=n; i++) {
        dp[i]=-1;
    }

    printf("%d",top_down(n));
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: