Language: C++

#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>

#include <cstdint>
#include <iomanip>
#include <cstring>

using namespace std;

using ll = long long;
#define ALL(a) (a).begin(), (a).end()

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)

const int MOD = 1000000007;

#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()

#include <iostream>
#include <cmath>
using namespace std;

bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
    if (x <= 1)
    { // 1以下である場合は素数でないことがすぐにわかる
        return false;
    }
    // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
    int n = (int)sqrt((double)x);
    for (int i = 2; i <= n; i++)
    {
        if (x % i == 0)
        { // 割り切る整数がある場合、即判定終了
            return false;
        }
    }
    return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m)
{
    if (n == 0)
        return 1;
    if (n % 2 == 0)
        return myPow(x * x % m, n / 2, m);
    else
        return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
    if (a >= b)
        return a - b;
    if (a < b)
        return b - a;
}
constexpr double dabs(double a, double b)
{
    if (a >= b)
        return a - b;
    if (a < b)
        return b - a;
}
constexpr ll min(ll a, ll b)
{
    if (a >= b)
        return b;
    if (a < b)
        return a;
}

constexpr ll max(ll a, ll b)
{
    if (a >= b)
        return a;
    if (a < b)
        return b;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};

class UnionFind
{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    //作るときはParentの値を全て-1にする
    //こうすると全てバラバラになる
    UnionFind(int N)
    {
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループに属しているか調べる
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A)
    {
        return -Parent[root(A)]; //親をとってきたい]
    }
    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }
    //AとBをくっ付ける
    bool connect(int A, int B)
    {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B)
        {
            //すでにくっついてるからくっ付けない
            return false;
        }

        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらひっくり返しちゃう。
        if (size(A) < size(B))
            swap(A, B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    }
};

long long fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void yn(bool flag)
{
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return;
}
void YN(bool flag)
{
    if (flag)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return;
}

std::vector<ll> enum_div(ll n) //nの約数を列挙
{
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i != 1 && i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp &operator+=(const Fp &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
    {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

// グラフセット
struct Edge
{
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
    V comp(V &l, V &r) { return max(l, r); };

    vector<V> val;
    SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1)
    {
        if (r <= x || y <= l)
            return def;
        if (x <= l && r <= y)
            return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v)
    {
        i += NV;
        val[i] = v;
        while (i > 1)
            i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};

typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
    int H = A.size();
    int W = B[0].size();
    int K = A[0].size();

    matrix C(H, vector<ll>(W, 0));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            for (int k = 0; k < K; k++)
            {
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= MOD;
            }
        }
    }
    return C;
}

// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0; // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n)
    {
        for (int iter = 0; iter < 2; ++iter)
            dat[iter].assign(n + 1, UNITY_SUM);
    }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x)
    {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x)
    {
        sub_add(0, a, x * -(a - 1));
        sub_add(1, a, x);
        sub_add(0, b, x * (b - 1));
        sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a)
    {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b)
    {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print()
    {
        for (int i = 1; i < (int)dat[0].size(); ++i)
            cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

using Graph = vector<vector<ll>>;

void print(const std::vector<int> &v)
{
    std::for_each(v.begin(), v.end(), [](int x) {
        std::cout << x << " ";
    });
    std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
    if (log10(a) + log10(b) >= 19.0)
        return -1;
    else
        return a * b;
}
int GetRandom(int min, int max)
{
    return min + (int)(rand() * (max - min + 1.0) / (1.0 + RAND_MAX));
}
// konpairu command
//  g++ code.cpp -std=c++14 -I .
//cout << std::setprecision(30) << ans << endl;#include <bits/stdc++.h>#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <bitset>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <cctype>
#include <fstream>
#include <numeric>
#include <cassert>

#include <cstdint>
#include <iomanip>
#include <cstring>
using namespace std;
using ll = long long;
#define ALL(a) (a).begin(), (a).end()

#define FOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (long long int i = (a); i >= (b); i--)

const int MOD = 1000000007;

#define LLONG_MAXs 9223372036854775800 / 2
//#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define ALL(a) (a).begin(), (a).end()

#include <iostream>
#include <cmath>
using namespace std;

bool isPrimeNum(ll x)
{ // 素数である場合 true を返す
    if (x <= 1)
    { // 1以下である場合は素数でないことがすぐにわかる
        return false;
    }
    // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
    int n = (int)sqrt((double)x);
    for (int i = 2; i <= n; i++)
    {
        if (x % i == 0)
        { // 割り切る整数がある場合、即判定終了
            return false;
        }
    }
    return true; // 割り切る整数がない場合、素数である
}

ll myPow(ll x, ll n, ll m)
{
    if (n == 0)
        return 1;
    if (n % 2 == 0)
        return myPow(x * x % m, n / 2, m);
    else
        return x * myPow(x, n - 1, m) % m;
}

constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll abs(ll a, ll b)
{
    if (a >= b)
        return a - b;
    if (a < b)
        return b - a;
}
constexpr double dabs(double a, double b)
{
    if (a >= b)
        return a - b;
    if (a < b)
        return b - a;
}
constexpr ll min(ll a, ll b)
{
    if (a >= b)
        return b;
    if (a < b)
        return a;
}

constexpr ll max(ll a, ll b)
{
    if (a >= b)
        return a;
    if (a < b)
        return b;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};

class UnionFind
{
public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    //作るときはParentの値を全て-1にする
    //こうすると全てバラバラになる
    UnionFind(int N)
    {
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループに属しているか調べる
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A)
    {
        return -Parent[root(A)]; //親をとってきたい]
    }
    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }
    //AとBをくっ付ける
    bool connect(int A, int B)
    {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B)
        {
            //すでにくっついてるからくっ付けない
            return false;
        }

        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらひっくり返しちゃう。
        if (size(A) < size(B))
            swap(A, B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    }
};

long long fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 510000; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

void yn(bool flag)
{
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return;
}
void YN(bool flag)
{
    if (flag)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return;
}

std::vector<ll> enum_div(ll n) //nの約数を列挙
{
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i != 1 && i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

// modint: mod 計算を int を扱うように扱える構造体
template <int MOD>
struct Fp
{
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD)
    {
        if (val < 0)
            val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator-() const noexcept
    {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp &operator+=(const Fp &r) noexcept
    {
        val += r.val;
        if (val >= MOD)
            val -= MOD;
        return *this;
    }
    constexpr Fp &operator-=(const Fp &r) noexcept
    {
        val -= r.val;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr Fp &operator*=(const Fp &r) noexcept
    {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp &operator/=(const Fp &r) noexcept
    {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b)
        {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0)
            val += MOD;
        return *this;
    }
    constexpr bool operator==(const Fp &r) const noexcept
    {
        return this->val == r.val;
    }
    constexpr bool operator!=(const Fp &r) const noexcept
    {
        return this->val != r.val;
    }
    friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept
    {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept
    {
        if (n == 0)
            return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1)
            t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

// グラフセット
struct Edge
{
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
#define def 0
template <class V, int NV>
struct SegTree
{ //[l,r)
    V comp(V &l, V &r) { return max(l, r); };

    vector<V> val;
    SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1)
    {
        if (r <= x || y <= l)
            return def;
        if (x <= l && r <= y)
            return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2);
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v)
    {
        i += NV;
        val[i] = v;
        while (i > 1)
            i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};

typedef vector<vector<long long>> matrix;
matrix mul_mod(matrix A, matrix B)
{
    int H = A.size();
    int W = B[0].size();
    int K = A[0].size();

    matrix C(H, vector<ll>(W, 0));
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            for (int k = 0; k < K; k++)
            {
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= MOD;
            }
        }
    }
    return C;
}

// 区間加算にも対応した BIT
template <class Abel>
struct BIT
{
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0; // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n)
    {
        for (int iter = 0; iter < 2; ++iter)
            dat[iter].assign(n + 1, UNITY_SUM);
    }

    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x)
    {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x)
    {
        sub_add(0, a, x * -(a - 1));
        sub_add(1, a, x);
        sub_add(0, b, x * (b - 1));
        sub_add(1, b, x * (-1));
    }

    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a)
    {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b)
    {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }

    /* debug */
    void print()
    {
        for (int i = 1; i < (int)dat[0].size(); ++i)
            cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};
//cout << std::setprecision(30) << ans << endl;

using Graph = vector<vector<ll>>;

void print(const std::vector<int> &v)
{
    std::for_each(v.begin(), v.end(), [](int x) {
        std::cout << x << " ";
    });
    std::cout << std::endl;
}
const double PI = 3.14159265358979323846;
ll times_cap(ll a, ll b)
{
    if (log10(a) + log10(b) >= 19.0)
        return -1;
    else
        return a * b;
}

int main()
{

    ll R, C, K;
    cin >> R >> C >> K;

    int sc[R][C] = {};

    FOR(i, 0, K - 1)
    {
        ll tp1, tp2, tp3;
        cin >> tp1 >> tp2 >> tp3;
        tp1--;
        tp2--;
        sc[tp1][tp2] = tp3;
    }

    long dp[R][C][4] = {};
    dp[0][0][1] = sc[0][0];
    FOR(i, 0, R - 1)
    {
        FOR(j, 0, C - 1)
        {
            FOR(k, 0, 3)
            {
                if (i < R - 1)
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                if (i < R - 1)
                    dp[i + 1][j][1] = max(dp[i][j][k] + sc[i + 1][j], dp[i + 1][j][k]);

                if (j < C - 1)
                    dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                if (j < C - 1 && k != 3)
                    dp[i][j + 1][k + 1] = max(dp[i][j][k] + sc[i][j + 1], dp[i][j + 1][k + 1]);
                if (k != 3)
                    dp[i][j][k + 1] = max(dp[i][j][k], dp[i][j][k + 1]);
            }
        }
    }


    ll ans = 0;
    FOR(i, 0, 3)
    {
        ans = max(ans, dp[R - 1][C - 1][i]);
    }
    cout << ans << endl;

    return 0;
}


Compiler output:
a.cc:498:11: error: redefinition of 'const int MOD'
  498 | const int MOD = 1000000007;
      |           ^~~
a.cc:35:11: note: 'const int MOD' previously defined here
   35 | const int MOD = 1000000007;
      |           ^~~
a.cc:508:6: error: redefinition of 'bool isPrimeNum(ll)'
  508 | bool isPrimeNum(ll x)
      |      ^~~~~~~~~~
a.cc:45:6: note: 'bool isPrimeNum(ll)' previously defined here
   45 | bool isPrimeNum(ll x)
      |      ^~~~~~~~~~
a.cc:526:4: error: redefinition of 'll myPow(ll, ll, ll)'
  526 | ll myPow(ll x, ll n, ll m)
      |    ^~~~~
a.cc:63:4: note: 'll myPow(ll, ll, ll)' previously defined here
   63 | ll myPow(ll x, ll n, ll m)
      |    ^~~~~
a.cc:536:14: error: redefinition of 'constexpr ll gcd(ll, ll)'
  536 | constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
      |              ^~~
a.cc:73:14: note: 'constexpr ll gcd(ll, ll)' previously defined here
   73 | constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
      |              ^~~
a.cc:537:14: error: redefinition of 'constexpr ll lcm(ll, ll)'
  537 | constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
      |              ^~~
a.cc:74:14: note: 'constexpr ll lcm(ll, ll)' previously defined here
   74 | constexpr ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
      |              ^~~
a.cc:538:14: error: redefinition of 'constexpr ll abs(ll, ll)'
  538 | constexpr ll abs(ll a, ll b)
      |              ^~~
a.cc:75:14: note: 'constexpr ll abs(ll, ll)' previously defined here
   75 | constexpr ll abs(ll a, ll b)
      |              ^~~
a.cc:545:18: error: redefinition of 'constexpr double dabs(double, double)'
  545 | constexpr double dabs(double a, double b)
      |                  ^~~~
a.cc:82:18: note: 'constexpr double dabs(double, double)' previously defined here
   82 | constexpr double dabs(double a, double b)
      |                  ^~~~
a.cc:552:14: error: redefinition of 'constexpr ll min(ll, ll)'
  552 | constexpr ll min(ll a, ll b)
      |              ^~~
a.cc:89:14: note: 'constexpr ll min(ll, ll)' previously defined here
   89 | constexpr ll min(ll a, ll b)
      |              ^~~
a.cc:560:14: error: redefinition of 'constexpr ll max(ll, ll)'
  560 | constexpr ll max(ll a, ll b)
      |              ^~~
a.cc:97:14: note: 'constexpr ll max(ll, ll)' previously defined here
   97 | constexpr ll max(ll a, ll b)
      |              ^~~
a.cc:568:5: error: redefinition of 'int dx [4]'
  568 | int dx[4] = {1, 0, -1, 0};
      |     ^~
a.cc:105:5: note: 'int dx [4]' previously defined here
  105 | int dx[4] = {1, 0, -1, 0};
      |     ^~
a.cc:569:5: error: redefinition of 'int dy [4]'
  569 | int dy[4] = {0, 1, 0, -1};
      |     ^~
a.cc:106:5: note: 'int dy [4]' previously defined here
  106 | int dy[4] = {0, 1, 0, -1};
      |     ^~
a.cc:571:5: error: redefinition of 'int dx8 [8]'
  571 | int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
      |     ^~~
a.cc:108:5: note: 'int dx8 [8]' previously defined here
  108 | int dx8[8] = {1, 0, -1, 0, 1, -1, 1, -1};
      |     ^~~
a.cc:572:5: error: redefinition of 'int dy8 [8]'
  572 | int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
      |     ^~~
a.cc:109:5: note: 'int dy8 [8]' previously defined here
  109 | int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
      |     ^~~
a.cc:574:7: error: redefinition of 'class UnionFind'
  574 | class UnionFind
      |       ^~~~~~~~~
a.cc:111:7: note: previous definition of 'class UnionFind'
  111 | class UnionFind
      |       ^~~~~~~~~
a.cc:630:11: error: redefinition of 'long long int fac [510000]'
  630 | long long fac[510000], finv[510000], inv[510000];
      |           ^~~
a.cc:167:11: note: 'long long int fac [510000]' previously declared here
  167 | long long fac[510000], finv[510000], inv[510000];
      |           ^~~
a.cc:630:24: error: redefinition of 'long long int finv [510000]'
  630 | long long fac[510000], finv[510000], inv[510000];
      |                        ^~~~
a.cc:167:24: note: 'long long int finv [510000]' previously declared here
  167 | long long fac[510000], finv[510000], inv[510000];
      |                        ^~~~
a.cc:630:38: error: redefinition of 'long long int inv [510000]'
  630 | long long fac[510000], finv[510000], inv[510000];
      |                                      ^~~
a.cc:167:38: note: 'long long int inv [510000]' previously declared here
  167 | long long fac[510000], finv[510000], inv[510000];
      |                                      ^~~
a.cc:633:6: error: redefinition of 'void COMinit()'
  633 | void COMinit()
      |      ^~~~~~~
a.cc:170:6: note: 'void COMinit()' previously defined here
  170 | void COMinit()
      |      ^~~~~~~
a.cc:647:11: error: redefinition of 'long long int COM(int, int)'
  647 | long long COM(int n, int k)
      |           ^~~
a.cc:184:11: note: 'long long int COM(int, int)' previously defined here
  184 | long long COM(int n, int k)
      |           ^~~
a.cc:656:11: error: redefinition of 'long long int modinv(long long int, long long int)'
  656 | long long modinv(long long a, long long m)
      |           ^~~~~~
a.cc:193:11: note: 'long long int modinv(long long int, long long int)' previously defined here
  193 | long long modinv(long long a, long long m)
      |           ^~~~~~
a.cc:673:6: error: redefinition of 'void yn(bool)'
  673 | void yn(bool flag)
      |      ^~
a.cc:210:6: note: 'void yn(bool)' previously defined here
  210 | void yn(bool flag)
      |      ^~
a.cc:685:6: error: redefinition of 'void YN(bool)'
  685 | void YN(bool flag)
      |      ^~
a.cc:222:6: note: 'void YN(bool)' previously defined here
  222 | void YN(bool flag)
      |      ^~
a.cc:698:17: error: redefinition of 'std::vector<long long int> enum_div(ll)'
  698 | std::vector<ll> enum_div(ll n) //nの約数を列挙
      |                 ^~~~~~~~
a.cc:235:17: note: 'std::vector<long long int> enum_div(ll)' previously defined here
  235 | std::vector<ll> enum_div(ll n) //nの約数を列挙
      |                 ^~~~~~~~
a.cc:718:8: error: redefinition of 'struct Fp<MOD>'
  718 | struct Fp
      |        ^~
a.cc:255:8: note: previous definition of 'struct Fp<MOD>'
  255 | struct Fp
      |        ^~
a.cc:797:8: error: redefinition of 'struct Edge'
  797 | struct Edge
      |        ^~~~
a.cc:334:8: note: previous definition of 'struct Edge'
  334 | struct Edge
      |        ^~~~
a.cc:806:8: error: redefinition of 'struct SegTree<V, NV>'
  806 | struct SegTree
      |        ^~~~~~~
a.cc:343:8: note: previous definition of 'struct SegTree<V, NV>'
  343 | struct SegTree
      |        ^~~~~~~
a.cc:834:8: error: redefinition of 'matrix mul_mod(matrix, matrix)'
  834 | matrix mul_mod(matrix A, matrix B)
      |        ^~~~~~~
a.cc:371:8: note: 'matrix mul_mod(matrix, matrix)' previously defined here
  371 | matrix mul_mod(matrix A, matrix B)
      |        ^~~~~~~
a.cc:857:8: error: redefinition of 'struct BIT<Abel>'
  857 | struct BIT
      |        ^~~
a.cc:394:8: note: previous definition of 'struct BIT<Abel>'
  394 | struct BIT
      |        ^~~
a.cc:909:6: error: redefinition of 'void print(const std::vector<int>&)'
  909 | void print(const std::vector<int> &v)
      |      ^~~~~
a.cc:445:6: note: 'void print(const std::vector<int>&)' previously defined here
  445 | void print(const std::vector<int> &v)
      |      ^~~~~
a.cc:916:14: error: redefinition of 'const double PI'
  916 | const double PI = 3.14159265358979323846;
      |              ^~
a.cc:452:14: note: 'const double PI' previously defined here
  452 | const double PI = 3.14159265358979323846;
      |              ^~
a.cc:917:4: error: redefinition of 'll times_cap(ll, ll)'
  917 | ll times_cap(ll a, ll b)
      |    ^~~~~~~~~
a.cc:453:4: note: 'll times_cap(ll, ll)' previously defined here
  453 | ll times_cap(ll a, ll b)
      |    ^~~~~~~~~
a.cc: In function 'constexpr ll max(ll, ll)':
a.cc:103:1: warning: control reaches end of non-void function [-Wreturn-type]
  103 | }
      | ^