alexjercan/bugnet huggingface dataset:
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

long long mpow(long long x, int n) {
  long long r = 1;
  while (n > 0) {
    if (n & 1)
      r = r * x % 1000000007;
    x = x * x % 1000000007;
    n >>= 1;
  }
  return r;
}

int main() {
  int n, k;
  cin >> n >> k;

  long long sumg = 0;
  long long cntg[100010];
  for (int i = k; 0 < i; i--) {
    long long cntb = k / i;
    cntg[i] = mpow(cntb, n);
    for (int j = 2; j * i <= k; j++) {
      cntg[i] += (1000000007 - cntg[j * i]);
      cntg[i] %= 1000000007;
      if (cntg[i] < 0)
        cout << 1;
    }
    sumg += cntg[i] * i;
    sumg %= 1000000007;
  }

  cout << sumg << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

long long mpow(long long x, int n) {
  long long r = 1;
  while (n > 0) {
    if (n & 1)
      r = r * x % 1000000007;
    x = x * x % 1000000007;
    n >>= 1;
  }
  return r;
}

int main() {
  int n, k;
  cin >> n >> k;

  long long sumg = 0;
  vector<long long> cntg(k);
  for (int i = k; 0 < i; i--) {
    long long cntb = k / i;
    cntg[i] = mpow(cntb, n);
    for (int j = 2; j * i <= k; j++) {
      cntg[i] += (1000000007 - cntg[j * i]);
      cntg[i] %= 1000000007;
      if (cntg[i] < 0)
        cout << 1;
    }
    sumg += cntg[i] * i;
    sumg %= 1000000007;
  }

  cout << sumg << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  ll N, K;
  cin >> N >> K;

  ll ans = 0;
  ll num[K + 1];
  for (ll i = K; i >= 1; i--) {
    num[i] = modpow(K / i, N);
    for (ll j = 2; i * j <= K; j++)
      num[i] = (num[i] - num[i * j] + MOD) % MOD;
    ans = (ans + i * num[i]) % MOD;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  ll N, K;
  cin >> N >> K;

  ll ans = 0;
  ll num[N + 1];
  for (ll i = K; i >= 1; i--) {
    num[i] = modpow(K / i, N);
    for (ll j = 2; i * j <= K; j++)
      num[i] = (num[i] - num[i * j] + MOD) % MOD;
    ans = (ans + i * num[i]) % MOD;
  }

  cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const int N = 200042;
const int m = 1e9 + 7;
int add(int x, int y) {
  x += y;
  while (x >= m)
    x -= m;
  while (x < 0)
    x += m;
  return x;
}
ll mul(ll x, ll y) {
  ll ans = (x * 1ll * y) % m;
  while (ans < 0)
    ans += m;
  return ans;
}
int binpow(int x, int y) {
  int z = 1;
  while (y) {
    if (y & 1)
      z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
int inv(int x) { return binpow(x, m - 2); }
int divide(int x, int y) { return mul(x, inv(y)); }
int fact[N];
void precalc() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k) { return divide(fact[n], mul(fact[k], fact[n - k])); }
int A(int n, int m) { return divide(fact[n], fact[n - m]); }
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  precalc();

  int n = 0, k = 0, ans = 0, one = 0;

  cin >> n >> k;

  vector<int> toadd(k + 1);

  for (int i = 1; i <= k; i++)
    toadd[i] = i;

  for (int i = 1; i <= k; i++) {
    for (int j = 2 * i; j <= k; j += i)
      toadd[j] -= toadd[i];
  }

  for (int i = 1; i <= k; i++)
    ans = add(ans, mul(toadd[i], binpow(k / i, n)));

  cout << ans;

  return 0;
}
/*

*/


Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const int N = 200042;
const int m = 1e9 + 7;
int add(int x, int y) {
  x += y;
  while (x >= m)
    x -= m;
  while (x < 0)
    x += m;
  return x;
}
ll mul(ll x, ll y) {
  ll ans = (x * 1ll * y) % m;
  while (ans < 0)
    ans += m;
  return ans;
}
int binpow(int x, int y) {
  int z = 1;
  while (y) {
    if (y & 1)
      z = mul(z, x);
    x = mul(x, x);
    y >>= 1;
  }
  return z;
}
int inv(int x) { return binpow(x, m - 2); }
int divide(int x, int y) { return mul(x, inv(y)); }
int fact[N];
void precalc() {
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = mul(fact[i - 1], i);
}
int C(int n, int k) { return divide(fact[n], mul(fact[k], fact[n - k])); }
int A(int n, int m) { return divide(fact[n], fact[n - m]); }
int main() {

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  precalc();

  int n = 0, k = 0, ans = 0, one = 0;

  cin >> n >> k;

  vector<int> toadd(k + 1);

  for (int i = 1; i <= 1e5; i++)
    toadd[i] = i;

  for (int i = 1; i <= 1e5; i++) {
    for (int j = 2 * i; j <= 1e5; j += i)
      toadd[j] -= toadd[i];
  }

  for (int i = 1; i <= k; i++)
    ans = add(ans, mul(toadd[i], binpow(k / i, n)));

  cout << ans;

  return 0;
}
/*

*/
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

ll yaku(ll a, ll b) {
  if (a > b)
    return yaku(b, a);
  else {
    if (b % a == 0)
      return a;
    else
      return yaku(b % a, a);
  }
}

long long ruijou(ll n, ll k) {
  if (k == 0)
    return 1;
  ll x = k / 2;
  long long t = ruijou(n, x);
  t = (t * t) % mod;
  if (k % 2 == 1)
    return (n * t) % mod;
  else
    return t % mod;
}

int main() {
  ll N, K;
  cin >> N >> K;
  vec ans(K + 1, 0);
  for (ll i = K; i > 0; i--) {
    ll p = K / i;
    ans.at(i) = ruijou(p, N);
    if (p > 1) {
      REP(j, 2, p + 1) ans.at(i) = (ans.at(i) + mod - ans.at(i * j));
    }
  }
  ll ANS = 0;
  REP(i, 1, K + 1) ANS = (ANS + ans.at(i) * i) % mod;
  cout << ANS << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
vec dx = {1, 0, -1, 0};
vec dy = {0, 1, 0, -1};

mat mul(mat &A, mat &B) {
  mat C(A.size(), vec(B[0].size()));
  for (int i = 0; i < A.size(); i++) {
    for (int k = 0; k < B.size(); k++) {
      for (int j = 0; j < B[0].size(); j++) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % mod;
      }
    }
  }
  return C;
}

mat marui(mat A, ll n) {
  mat B(A.size(), vec(A.size()));
  for (int i = 0; i < A.size(); i++)
    B[i][i] = 1;
  while (n > 0) {
    if (n & 1)
      B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

ll yaku(ll a, ll b) {
  if (a > b)
    return yaku(b, a);
  else {
    if (b % a == 0)
      return a;
    else
      return yaku(b % a, a);
  }
}

int main() {
  ll N, K;
  cin >> N >> K;
  mat fn(K + 1, vec(K + 1, 0));

  REP(i, 1, K + 1) REP(j, 1, K + 1) fn[i][yaku(i, j)]++;
  fn = marui(fn, N - 1);
  ll ans = 0;
  REP(i, 1, K + 1) REP(j, 1, K + 1) ans = (ans + fn[i][j] * j) % mod;
  cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int n, k;

ll modpow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

ll dp[1 << 17];

main() {
  cin >> n >> k;
  ll ans = 0;
  for (int i = k; i >= 1; i--) {
    dp[i] = modpow(k / i, n);
    for (int j = 2 * i; j <= k; j += i)
      dp[i] -= dp[j];
    ans += i * dp[i] % mod;
  }
  cout << ans % mod << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

// ll G[100100][100100100];

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<ll> st1, st2;
ll n, k, ans = 0;

ll f(vector<ll> st, int id) {
  if (id == n - 1) {
    for (ll num : st) {
      ans += num;
      ans %= mod;
      // cout << num << endl;
    }
    return ans;
  }
  vector<ll> st3;
  for (ll num : st)
    for (ll i = 1; i <= k; ++i)
      st3.push_back(gcd(i, num) % mod);
  f(st3, id + 1);
  return ans;
}

int main() {
  cin >> n >> k;
  for (ll i = 1; i <= k; ++i)
    st1.push_back(i);
  cout << f(st1, 0) << endl;
  return 0;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

// abc162_e.cpp
// Sun Apr 12 20:58:02 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) {
    return 1;
  }
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) {
    res = res * x % mod; // nが奇数の場合はxを余分にかける。
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll njou[100010];
  njou[0] = 0;
  for (int i = 1; i < 100010; i++) {
    njou[i] = mod_pow(i, n, MOD);
  }

  ll ans = njou[k];
  ll counted = 0;
  ll counts[100010];
  fill(counts, counts + 100010, 0);
  for (int i = k; i >= 2; i--) {
    ll yakusu = k / i;
    ll tmp = njou[yakusu];
    if (yakusu >= 2) {
      for (int j = 2; j <= yakusu; j++) {
        tmp = ((tmp - counts[i * j]) % MOD + MOD) % MOD;
      }
    }
    ll tmp2 = (tmp * (i - 1)) % MOD;
    ans = (ans + tmp2) % MOD;
    counted = (counted + tmp) % MOD;
    counts[i] = tmp;
  }

  cout << ans << endl;
  //	ll modify = ((njou[k]-counted)%MOD+MOD)%MOD;
  //	ans = (ans + modify)%MOD;
  //	cout << njou[k] << endl;
  //	cout << modify << endl;
  //	cout << ans << endl;
}

Error: TLE

Fixed submission:

// abc162_e.cpp
// Sun Apr 12 20:58:02 2020

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll = long long;
typedef pair<int, int> P;

ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) {
    return 1;
  }
  ll res = mod_pow(x * x % mod, n / 2, mod);
  if (n & 1) {
    res = res * x % mod; // nが奇数の場合はxを余分にかける。
  }
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;

  ll njou[100010];
  njou[0] = 0;
  for (int i = 1; i < 100010; i++) {
    njou[i] = mod_pow(i, n, MOD);
  }

  ll ans = njou[k];
  ll counted = 0;
  ll counts[100010];
  fill(counts, counts + 100010, 0);
  for (int i = k; i >= 2; i++) {
    ll yakusu = k / i;
    ll tmp = njou[yakusu];
    for (int j = 2; j <= yakusu; j++) {
      tmp -= counts[i * j];
    }
    ll tmp2 = (tmp * (i - 1)) % MOD;
    ans = (ans + tmp2) % MOD;
    counted = (counted + tmp) % MOD;
    counts[i] = tmp;
  }

  cout << ans << endl;
  //	ll modify = ((njou[k]-counted)%MOD+MOD)%MOD;
  //	ans = (ans + modify)%MOD;
  //	cout << njou[k] << endl;
  //	cout << modify << endl;
  //	cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

long BIG = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(K + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

long BIG = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(N + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }
  cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

long BIG = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(K + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

long BIG = 1000000007;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(N + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }

  cout << ans << endl;
}
Problem p02715 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
ll mypw(ll n, ll m) {
  if (m <= 1)
    return n;
  ll k = mypw(n, m / 2) % M;
  k = (k * k) % M;
  if (m & 1)
    return (k * n) % M;
  else
    return k;
}
int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  vector<ll> c(k + 1);
  for (ll i = k; i >= 1; i--) {
    c[i] = mypw(k / i, n);
    for (ll j = i * 2; j <= k; j += i) {
      c[i] -= c[j];
      if (c[i] < 0)
        c[i] += M;
    }
    ans = (ans + (c[i] * i) % M) % M;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
ll mypw(ll n, ll m) {
  ll k = 1;
  for (ll i = 0; i < m; i++) {
    k = (k * (n % M)) % M;
  }
  return k;
}
int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  vector<ll> c(k + 1);
  for (ll i = k; i >= 1; i--) {
    c[i] = mypw(k / i, n);
    for (ll j = i * 2; j <= k; j += i) {
      c[i] -= c[j];
      if (c[i] < 0)
        c[i] += M;
    }
    ans = (ans + (c[i] * i) % M) % M;
  }
  cout << ans << endl;
  return 0;
}
Problem p02716 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define ll long long
#define AC                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
const ll N = 2e5;
ll dp[N][2];
ll arr[N];

int main() {
  AC ll n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  dp[2][0] = arr[1];
  dp[2][1] = arr[2];
  for (int i = 3; i <= n; i++) {
    if (i & 1) {
      dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
                 arr[i];
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    } else {
      dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
      dp[i][0] = arr[i - 1] + dp[i - 2][0];
    }
  }
  cout << max(dp[n][0], dp[n][1]) << '\\n';
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define ll long long
#define AC                                                                     \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
const ll N = 20005;
ll dp[N][2];
ll arr[N];

int main() {
  AC ll n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  dp[2][0] = arr[1];
  dp[2][1] = arr[2];
  for (int i = 3; i <= n; i++) {
    if (i & 1) {
      dp[i][1] = max({dp[i - 2][1], dp[i - 2][0], dp[i - 3][1], dp[i - 3][0]}) +
                 arr[i];
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    } else {
      dp[i][1] = max(dp[i - 2][1], dp[i - 2][0]) + arr[i];
      dp[i][0] = arr[i - 1] + dp[i - 2][0];
    }
  }
  cout << max(dp[n][0], dp[n][1]) << '\\n';
}
Problem p02716 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) cin >> A[i];

  if (N == 2) {
    cout << max(A[0], A[1]) << endl;
    return 0;
  }

  vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
  dp[0][0] = A[0];
  dp[1][1] = A[1];
  dp[2][0] = A[0] + A[2];
  dp[2][2] = A[2];
  for (int i = 3; i < N; i++) {
    dp[i][0] = dp[i - 2][0] + A[i];
    dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
    dp[i][2] = max(
        dp[i - 2][2] + A[i],
        max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
  }

  if (N % 2 == 0)
    cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
  else
    cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL << (n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) cin >> A[i];

  vector<vector<long long>> dp(N, vector<long long>(3, (-1) * LINF));
  dp[0][0] = A[0];
  dp[1][1] = A[1];
  dp[2][0] = A[0] + A[2];
  dp[2][2] = A[2];
  for (int i = 3; i < N; i++) {
    dp[i][0] = dp[i - 2][0] + A[i];
    dp[i][1] = max(dp[i - 2][1] + A[i], dp[i - 3][0] + A[i]);
    dp[i][2] = max(
        dp[i - 2][2] + A[i],
        max(dp[i - 3][1] + A[i], i > 3 ? dp[i - 4][0] + A[i] : (-1) * LINF));
  }

  if (N % 2 == 0)
    cout << max(dp[N - 2][0], dp[N - 1][1]) << endl;
  else
    cout << max(dp[N - 3][0], max(dp[N - 2][1], dp[N - 1][2])) << endl;

  return 0;
}
Problem p02716 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

int dp[200100][5];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N;
  cin >> N;
  vi a(N);
  rep(i, 0, N) cin >> a[i];

  rep(i, 0, N + 100) rep(j, 0, 4) dp[i][j] = -inf;
  dp[0][0] = 0;

  rep(i, 0, N) rep(j, 0, 3) {
    chmax(dp[i + 1][j + 1], dp[i][j]);
    int now = dp[i][j];
    if ((i + j) % 2 == 0)
      now += a[i];
    chmax(dp[i + 1][j], now);
  }

  cout << dp[N][1 + N % 2] << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}
template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

int dp[100100][5];

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N;
  cin >> N;
  vi a(N);
  rep(i, 0, N) cin >> a[i];

  rep(i, 0, N) rep(j, 0, 4) dp[i][j] = (-1LL << 60);
  dp[0][0] = 0;

  rep(i, 0, N) rep(j, 0, 3) {
    chmax(dp[i + 1][j + 1], dp[i][j]);
    int now = dp[i][j];
    if ((i + j) % 2 == 0)
      now += a[i];
    chmax(dp[i + 1][j], now);
  }

  cout << dp[N][1 + N % 2] << endl;
  return 0;
}