CSES - Shared codeLink to this code: https://cses.fi/paste/794d2a00d7d366cd7baf9a/
#include <bits/stdc++.h>
using namespace std;

#define int int64_t

const int MOD = 1e9 + 7;

int expo(int a, int b) {
    if (b == 0) return 1;
    if (b == 1) return a;

    int res = expo(a, b/2);
    res = (res * res) % MOD;
    if (b % 2 != 0) {
        res = (a * res) % MOD;
    }

    return res;
}

signed main() {
    int n;cin>>n;
    int group = (n * n) / 4;

    if (n % 2 != 0) group++;
    group %= (MOD-1);
    int sum = 0;

    // rotation by 180 degrees
    sum += expo(2, (((n * n) / 2) + (n % 2 != 0)) % (MOD-1));

    // rotation by 90 degrees
    sum += expo(2, group);

    // rotation by 270 degrees
    sum += expo(2, group);

    // no rotation
    sum += expo(2, n*n);

    sum %= MOD;

    // dividing by 4, e.g multiplying by the inverse of 4
    int inv = expo(4, MOD-2);
    sum = (sum * inv) % MOD;
    cout << sum << "\n";
}