Problem:
Score : 800 points

Problem Statement

Given is a positive even number N.

Find the number of strings s of length N consisting of A, B, and C that satisfy the following condition:

s can be converted to the empty string by repeating the following operation:

Choose two consecutive characters in s and erase them. However, choosing AB or BA is not allowed.

For example, ABBC satisfies the condition for N=4, because we can convert it as follows: ABBC → (erase BB) → AC → (erase AC) → (empty).

The answer can be enormous, so compute the count modulo 998244353.

Constraints

2 \leq N \leq 10^7

N is an even number.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of strings that satisfy the conditions, modulo 998244353.

Sample Input 1

2

Sample Output 1

7

Except AB and BA, all possible strings satisfy the conditions.

Sample Input 2

10

Sample Output 2

50007

Sample Input 3

1000000

Sample Output 3

210055358

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define yes { cout << "YES" << endl; exit(0); }
#define no { cout << "NO" << endl; exit(0); }
#define impossible { cout << "Impossible" << endl; exit(0); }

using namespace std;

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

const int Nmax = 1e7 + 5, Mod = 998244353;

int n;
int doi[Nmax], fact[Nmax], ifact[Nmax];

static int inm(int x, int y)
{
    return (ll) x * y % Mod;
}

void add_to(int &x, int y)
{
    x += y; if(x >= Mod) x -= Mod;
}

void inm_to(int &x, int y)
{
    x = (ll) x * y % Mod;
}

static int comb(int n, int k)
{
    return inm( fact[n], inm(ifact[k], ifact[n-k]) );
}

int power(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b&1) inm_to(ans, a);
        b >>= 1;
        inm_to(a, a);
    }
    return ans;
}

int main()
{
    //freopen("inputC", "r", stdin);
    // freopen("output", "w", stdout);
    cin.sync_with_stdio(false); cin.tie(0);

    cin >> n;

    int i;
    int ans = 1;
    
    doi[0] = 1; fact[0] = 1; ifact[0] = 1;
    for(i=1; i<=n; ++i) inm_to(ans, 3), doi[i] = inm(doi[i-1], 2), fact[i] = inm(fact[i-1], i);

    ifact[n] = power(fact[n], Mod-2);
    for(i=n-1; i; --i) ifact[i] = inm(ifact[i+1], i+1);

    int wrong = 0;
    for(i=n/2+1; i<=n; ++i)
        add_to( wrong, inm (comb(n, i), doi[n-i] ) );
    
    inm_to(wrong, 2);
    add_to(ans, Mod - wrong);

    cout << ans << '\n';

    return 0;
}