Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint{
    int x;

    Mint() : x(0) {}
    Mint(long long t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(int n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }

    Mint & operator *= (Mint a){
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

/*
    MODint依存
*/
template <typename T>
struct Comb{
    vector<T> fac, fin;

    Comb(int sz) : fac(sz + 1), fin(sz + 1){
        fac[0] = fin[sz] = T(1);
        for(int i = 1; i <= sz; i++){
            fac[i] = fac[i - 1] * T(i);
        }
        fin[sz] /= fac[sz];
        for(int i = sz - 1; i >= 0; i--){
            fin[i] = fin[i + 1] * T(i + 1);
        }
    }

    /* 階乗 */
    inline T fact(int k) const { return fac[k]; }

    inline T finv(int k) const { return fin[k]; }

    /* 順列 */
    T P(int n, int k) const {
        if(k < 0 || n < k) return T(0);
        return fac[n] * fin[n - k];
    }

    /* 組み合わせ */
    T C(int n, int k) const {
        if(k < 0 || n < k) return T(0);
        return fac[n] / fac[n - k] / fac[k];
    }

    /* 重複組み合わせ */
    T H(int n, int k) const {
        if(n < 0 || k < 0) return T(0);
        return k == 0 ? T(1) : C(n + k - 1, k);
    }

    /* ベル数 */
    T B(int n, int k) const {
        if(n == 0) return T(1);
        k = min(k, n);
        vector<T> dp(k + 1);
        dp[0] = T(1);
        for(int i = 1; i <= k; i++){
            if(i & 1) dp[i] = dp[i - 1] - fin[i];
            else dp[i] = dp[i - 1] + fin[i];
        }
        T res(0);
        for(int i = 1; i <= k; i++){
            /* MODint依存 */
            res += T(i).pow(n) * fin[i] * dp[k - i];
        }
        return res;
    }

    /* スターリング数 */
    T S(int n, int k) const {
        T res(0);
        for(int i = 1; i <= k; i++){
            /* MODint依存 */
            T t = C(k, i) * T(i).pow(n);
            if((k - i) & 1) res -= t;
            else res += t;
        }
        return res * fin[k];
    }
};

/*
    P(5, 3)の場合 : 
    0 + 0 + 5 = 0 + 1 + 4 = 0 + 2 + 3 = 1 + 1 + 3 = 1 + 2 + 2
    よって、P(5, 3) = 5
*/
template <typename T>
struct Partition{
    vector<vector<T>> dp;

    Partition(int sz) : dp(sz + 1, vector<T>(sz + 1)){
        dp[0][0] = T(1);
        for(int i = 0; i <= sz; i++){
            for(int j = 1; j <= sz; j++){
                if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
                else dp[i][j] = dp[i][j - 1];
            }
        }   
    }

    /* 分割数 */
    T P(int n, int k){
        if(n < 0 || k < 0) return T(0);
        return dp[n][k];
    }
};

/*
    MODint依存
    計算量 : O(k)
*/
template <typename T>
T C(long long n, int k){
    T num(1), denom(1);
    for(int i = 0; i < k; i++){
        num *= T(n - i);
        denom *= T(i + 1);
    }
    return num / denom;
}

signed main() {
    int n;
    cin >> n;
    string a;
    cin >> a;
    vector<int> b(n);
    rep(i, n) {
        b[i] = a[i] - '0';
    }
    Comb<ll> C(n);
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if(i % 2 == 0)
            ans += abs(b[i + 1] - b[i]) * C.C(n - 2, i);
        else
            ans -= abs(b[i + 1] - b[i]) * C.C(n - 2, i);
        ans += 3;
        ans %= 3;
    }
    cout << ans << endl;
    return 0;
}#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <int MOD = 1000000007>
struct Mint{
    int x;

    Mint() : x(0) {}
    Mint(long long t){
        x = t % MOD;
        if(x < 0) x += MOD;
    }
    
    Mint pow(int n){
        Mint res(1), t(x);
        while(n > 0){
            if(n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint & operator += (Mint a){
        x += a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }
    
    Mint & operator -= (Mint a){
        x += MOD - a.x;
        if(x >= MOD) x -= MOD;
        return *this;
    }

    Mint & operator *= (Mint a){
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint & operator /= (Mint a){
        return (*this) *= a.inv();
    }

    Mint operator + (Mint a) const { return Mint(x) += a; }
    Mint operator - (Mint a) const { return Mint(x) -= a; }
    Mint operator * (Mint a) const { return Mint(x) *= a; }
    Mint operator / (Mint a) const { return Mint(x) /= a; }

    Mint operator - () const{ return Mint(-x); }

    bool operator == (const Mint a){ return x == a.x; }
    bool operator != (const Mint a){ return x != a.x; }
    bool operator < (const Mint a){ return x < a.x; }

    friend ostream & operator << (ostream & os, const Mint &a){
        return os << a.x;
    }

    friend istream & operator >> (istream & is, Mint &a){
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

/*
    MODint依存
*/
template <typename T>
struct Comb{
    vector<T> fac, fin;

    Comb(int sz) : fac(sz + 1), fin(sz + 1){
        fac[0] = fin[sz] = T(1);
        for(int i = 1; i <= sz; i++){
            fac[i] = fac[i - 1] * T(i);
        }
        fin[sz] /= fac[sz];
        for(int i = sz - 1; i >= 0; i--){
            fin[i] = fin[i + 1] * T(i + 1);
        }
    }

    /* 階乗 */
    inline T fact(int k) const { return fac[k]; }

    inline T finv(int k) const { return fin[k]; }

    /* 順列 */
    T P(int n, int k) const {
        if(k < 0 || n < k) return T(0);
        return fac[n] * fin[n - k];
    }

    /* 組み合わせ */
    T C(int n, int k) const {
        if(k < 0 || n < k) return T(0);
        return fac[n] / fac[n - k] / fac[k];
    }

    /* 重複組み合わせ */
    T H(int n, int k) const {
        if(n < 0 || k < 0) return T(0);
        return k == 0 ? T(1) : C(n + k - 1, k);
    }

    /* ベル数 */
    T B(int n, int k) const {
        if(n == 0) return T(1);
        k = min(k, n);
        vector<T> dp(k + 1);
        dp[0] = T(1);
        for(int i = 1; i <= k; i++){
            if(i & 1) dp[i] = dp[i - 1] - fin[i];
            else dp[i] = dp[i - 1] + fin[i];
        }
        T res(0);
        for(int i = 1; i <= k; i++){
            /* MODint依存 */
            res += T(i).pow(n) * fin[i] * dp[k - i];
        }
        return res;
    }

    /* スターリング数 */
    T S(int n, int k) const {
        T res(0);
        for(int i = 1; i <= k; i++){
            /* MODint依存 */
            T t = C(k, i) * T(i).pow(n);
            if((k - i) & 1) res -= t;
            else res += t;
        }
        return res * fin[k];
    }
};

/*
    P(5, 3)の場合 : 
    0 + 0 + 5 = 0 + 1 + 4 = 0 + 2 + 3 = 1 + 1 + 3 = 1 + 2 + 2
    よって、P(5, 3) = 5
*/
template <typename T>
struct Partition{
    vector<vector<T>> dp;

    Partition(int sz) : dp(sz + 1, vector<T>(sz + 1)){
        dp[0][0] = T(1);
        for(int i = 0; i <= sz; i++){
            for(int j = 1; j <= sz; j++){
                if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
                else dp[i][j] = dp[i][j - 1];
            }
        }   
    }

    /* 分割数 */
    T P(int n, int k){
        if(n < 0 || k < 0) return T(0);
        return dp[n][k];
    }
};

/*
    MODint依存
    計算量 : O(k)
*/
template <typename T>
T C(long long n, int k){
    T num(1), denom(1);
    for(int i = 0; i < k; i++){
        num *= T(n - i);
        denom *= T(i + 1);
    }
    return num / denom;
}

signed main() {
    int n;
    cin >> n;
    string a;
    cin >> a;
    vector<int> b(n);
    rep(i, n) {
        b[i] = a[i] - '0';
    }
    Comb<ll> C(n);
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        if(i % 2 == 0)
            ans += abs(b[i + 1] - b[i]) * C.C(n - 2, i);
        else
            ans -= abs(b[i + 1] - b[i]) * C.C(n - 2, i);
        ans += 3;
        ans %= 3;
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc:220:2: error: stray '#' in program
  220 | }#include <bits/stdc++.h>
      |  ^
a.cc:220:3: error: 'include' does not name a type
  220 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:226:11: error: redefinition of 'const int INF'
  226 | const int INF = 1e9;
      |           ^~~
a.cc:7:11: note: 'const int INF' previously defined here
    7 | const int INF = 1e9;
      |           ^~~
a.cc:227:17: error: redefinition of 'const long long int LINF'
  227 | const long long LINF = 1e18;
      |                 ^~~~
a.cc:8:17: note: 'const long long int LINF' previously defined here
    8 | const long long LINF = 1e18;
      |                 ^~~~
a.cc:228:17: error: redefinition of 'const long long int MOD'
  228 | const long long MOD = 1e9 + 7;
      |                 ^~~
a.cc:9:17: note: 'const long long int MOD' previously defined here
    9 | const long long MOD = 1e9 + 7;
      |                 ^~~
a.cc:230:21: error: redefinition of default argument for 'int MOD'
  230 | template <int MOD = 1000000007>
      |                     ^~~~~~~~~~
a.cc:11:21: note: original definition appeared here
   11 | template <int MOD = 1000000007>
      |                     ^~~~~~~~~~
a.cc:310:8: error: redefinition of 'struct Comb<T>'
  310 | struct Comb{
      |        ^~~~
a.cc:91:8: note: previous definition of 'struct Comb<T>'
   91 | struct Comb{
      |        ^~~~
a.cc:384:8: error: redefinition of 'struct Partition<T>'
  384 | struct Partition{
      |        ^~~~~~~~~
a.cc:165:8: note: previous definition of 'struct Partition<T>'
  165 | struct Partition{
      |        ^~~~~~~~~
a.cc:409:3: error: redefinition of 'template<class T> T C(long long int, int)'
  409 | T C(long long n, int k){
      |   ^
a.cc:190:3: note: 'template<class T> T C(long long int, int)' previously declared here
  190 | T C(long long n, int k){
      |   ^
a.cc:418:8: error: redefinition of 'int main()'
  418 | signed main() {
      |        ^~~~
a.cc:199:8: note: 'int main()' previously defined here
  199 | signed main() {
      |        ^~~~