#include <stdio.h>

long long n, res, MOD=1000000007;

long long pow(int a, long long b) {
    if(a==0) return 0;
    else if(a==1 || b==0) return 1;
    else {

        long long P = pow(a, b/2)%MOD;
        
        if(b%2) return (P%MOD)*(P%MOD)*(a%MOD);
        else return (P%MOD)*(P%MOD);
    }
}

int main() {

    scanf("%lld", &n);

    if(n==1) res=4;
    else if(n==2) res=12;
    else {
        if(n%2) {
            res=pow(3, n)+1;
        }
        else {
            res=pow(3, n)+3;
        }
    }

    printf("%lld", res%MOD);
}

Embed on website

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