prithivMLmods/Coder-Stat huggingface dataset:
Problem p02618 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using ll = long long;

vector<int> c;
vector<vector<int>> s;
int D;
vector<int> v;
vector<set<int>> U;

ll calc() {
  ll ans = 0;
  vector<int> last(26, 0);
  for (int i = 0; i < D; i++) {
    last[v[i] - 1] = i + 1;
    ans += s[i][v[i] - 1];
    // cout<<s[i][v[i] - 1]<<endl;
    for (int j = 0; j < 26; j++) {
      ans -= (ll)(i + 1 - last[j]) * c[j];
    }
  }
  return ans;
}

int retrnd(int n) { // 乱数生成
  std::random_device rnd;
  std::mt19937 mt(rnd());
  std::uniform_int_distribution<> rand100(0, n);
  return rand100(mt);
}

int main() {
  cin >> D;
  for (int i = 0; i < 26; i++) {
    int a;
    cin >> a;
    c.push_back(a);
  }
  for (int i = 0; i < D; i++) {
    vector<int> a;
    for (int j = 0; j < 26; j++) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    s.push_back(a);
  }
  U = vector<set<int>>(26);
  for (int i = 0; i < D; i++) {
    v.push_back(retrnd(25) + 1);
  }
  int now = calc();
  int try_cnt = 10000;
  for (int cnt = 0; cnt < try_cnt; cnt++) {
    int rnd = retrnd(D - 1);
    for (int i = 1; i < 27; i++) {
      int prev = v[rnd];
      v[rnd] = i;
      int w = calc();
      if (now > w) {
        v[rnd] = prev;
      } else {
        now = w;
      }
    }
  }
  for (int i = 0; i < D; i++) {
    cout << v[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using ll = long long;

vector<int> c;
vector<vector<int>> s;
int D;
vector<int> v;
vector<set<int>> U;

ll calc() {
  ll ans = 0;
  vector<int> last(26, 0);
  for (int i = 0; i < D; i++) {
    last[v[i] - 1] = i + 1;
    ans += s[i][v[i] - 1];
    // cout<<s[i][v[i] - 1]<<endl;
    for (int j = 0; j < 26; j++) {
      ans -= (ll)(i + 1 - last[j]) * c[j];
    }
  }
  return ans;
}

int retrnd(int n) { // 乱数生成
  std::random_device rnd;
  std::mt19937 mt(rnd());
  std::uniform_int_distribution<> rand100(0, n);
  return rand100(mt);
}

int main() {
  cin >> D;
  for (int i = 0; i < 26; i++) {
    int a;
    cin >> a;
    c.push_back(a);
  }
  for (int i = 0; i < D; i++) {
    vector<int> a;
    for (int j = 0; j < 26; j++) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    s.push_back(a);
  }
  U = vector<set<int>>(26);
  for (int i = 0; i < D; i++) {
    v.push_back(retrnd(25) + 1);
  }
  int now = calc();
  int try_cnt = 1000;
  for (int cnt = 0; cnt < try_cnt; cnt++) {
    int rnd = retrnd(D - 1);
    for (int i = 1; i < 27; i++) {
      int prev = v[rnd];
      v[rnd] = i;
      int w = calc();
      if (now > w) {
        v[rnd] = prev;
      } else {
        now = w;
      }
    }
  }
  for (int i = 0; i < D; i++) {
    cout << v[i] << endl;
  }
}
Problem p02618 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;

int main() {
  ll d;
  cin >> d;
  vector<ll> c(26);
  rep(i, 26) { cin >> c[i]; }
  vector<vector<pll>> s(d);
  rep(i, d) {
    rep(j, 26) {
      ll v;
      cin >> v;
      s[i].push_back(make_pair(v, j + 1));
    }
    sort(s[i].rbegin(), s[i].rend());
  }
  vector<ll> ans(d), used(26);
  ll tot = d;
  ll cnt = 0;
  while (tot) {
    rep(i, 26) {
      if (used[s[tot - 1][i].se - 1] == 0) {
        used[s[tot - 1][i].se - 1] = 1;
        ans[tot - 1] = s[tot - 1][i].se;
        tot--;
        cnt++;
        break;
      }
    }
    if (cnt == 26) {
      used = vector<ll>(26, 0LL);
    }
  }
  rep(i, d) { cout << ans[i] << endl; }
  return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pll pair<ll, ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define lb(c, x) distance(c.begin(), lower_bound(all(c), x))
#define ub(c, x) distance(c.begin(), upper_bound(all(c), x))

using namespace std;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const ll mod = 1e9 + 7;

int main() {
  ll d;
  cin >> d;
  vector<ll> c(26);
  rep(i, 26) { cin >> c[i]; }
  vector<vector<pll>> s(d);
  rep(i, d) {
    rep(j, 26) {
      ll v;
      cin >> v;
      s[i].push_back(make_pair(v, j + 1));
    }
    sort(s[i].rbegin(), s[i].rend());
  }
  vector<ll> ans(d), used(26);
  ll tot = d;
  ll cnt = 0;
  while (tot) {
    rep(i, 26) {
      if (used[s[tot - 1][i].se - 1] == 0) {
        used[s[tot - 1][i].se - 1] = 1;
        ans[tot - 1] = s[tot - 1][i].se;
        tot--;
        cnt++;
        break;
      }
    }
    if (cnt == 26) {
      for (ll i = d - 27; i >= 0; i--) {
        ans[i] = s[i][0].se;
        tot--;
      }
      break;
    }
  }
  rep(i, d) { cout << ans[i] << endl; }
  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

ll c[30], s[370][30];
ll score[30], last_day[30];
int t[5];

ll calc(int day, int contest) {
  score[contest] += s[day][contest];
  last_day[contest] = day;

  rep(i, 1, 27) score[i] -= c[i] * (day - last_day[i]);

  ll sum = 0;
  rep(i, 1, 27) sum += score[i];
  return sum;
}

int main(void) {
  int d;
  cin >> d;
  rep(i, 1, 27) cin >> c[i];
  rep(i, 1, d + 1) rep(j, 1, 27) cin >> s[i][j];

  rep(i, 0, d) cin >> t[i];

  rep(i, 0, d) { printf("%lld\n", calc(i + 1, t[i])); }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18 + 99);
static const int INF = 1e9 + 99;

ll c[30], s[370][30];
ll score[30], last_day[30];
int t[370];

ll calc(int day, int contest) {
  score[contest] += s[day][contest];
  last_day[contest] = day;

  rep(i, 1, 27) score[i] -= c[i] * (day - last_day[i]);

  ll sum = 0;
  rep(i, 1, 27) sum += score[i];
  return sum;
}

int main(void) {
  int d;
  cin >> d;
  rep(i, 1, 27) cin >> c[i];
  rep(i, 1, d + 1) rep(j, 1, 27) cin >> s[i][j];

  rep(i, 0, d) cin >> t[i];

  rep(i, 0, d) { printf("%lld\n", calc(i + 1, t[i])); }

  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

signed main() {
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];
  vector<int> t(26);
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }

  int score = 0;
  vector<int> lt(26, -1);
  rep(i, D) {
    score += s[i][t[i]];
    lt[t[i]] = i;
    rep(j, 26) score -= c[j] * (i - lt[j]);
    cout << score << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

signed main() {
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];
  vector<int> t(D);
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }

  int score = 0;
  vector<int> lt(26, -1);
  rep(i, D) {
    score += s[i][t[i]];
    lt[t[i]] = i;
    rep(j, 26) score -= c[j] * (i - lt[j]);
    cout << score << endl;
  }
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26), t(26), last(26, -1);
  vector<vector<ll>> s(365, vector<ll>(26));
  rep(i, 0, 26) cin >> c[i];
  rep(i, 0, D) { rep(j, 0, 26) cin >> s[i][j]; }
  rep(i, 0, D) {
    cin >> t[i];
    t[i]--;
  }
  ll res = 0;
  rep(d, 0, D) {
    res += s[d][t[d]];
    last[t[d]] = d;
    rep(j, 0, 26) { res -= c[j] * (d - last[j]); }
    cout << res << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main() {
  ll D;
  cin >> D;
  vector<ll> c(26), t(D), last(26, -1);
  vector<vector<ll>> s(365, vector<ll>(26));
  rep(i, 0, 26) cin >> c[i];
  rep(i, 0, D) { rep(j, 0, 26) cin >> s[i][j]; }
  rep(i, 0, D) {
    cin >> t[i];
    t[i]--;
  }
  ll res = 0;
  rep(d, 0, D) {
    res += s[d][t[d]];
    last[t[d]] = d;
    rep(j, 0, 26) { res -= c[j] * (d - last[j]); }
    cout << res << endl;
  }

  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int d;
  cin >> d;
  int c[30], last[30], s[30][30], v = 0;
  rep(i, 26) cin >> c[i];

  rep(i, d) rep(j, 26) cin >> s[i][j];

  rep(i, 26) last[i] = 0;

  rep(i, d) {
    int t;
    cin >> t;
    t--;

    v += s[i][t];
    last[t] = i + 1;

    rep(j, 26) {
      if (j == t)
        continue;
      v -= c[j] * (i + 1 - last[j]);
    }
    cout << v << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int d;
  cin >> d;
  int c[30] = {}, last[30] = {}, s[400][30] = {}, v = 0;
  rep(i, 26) cin >> c[i];

  rep(i, d) rep(j, 26) cin >> s[i][j];

  rep(i, 26) last[i] = 0;

  rep(i, d) {
    int t;
    cin >> t;
    t--;

    v += s[i][t];
    last[t] = i + 1;

    rep(j, 26) {
      if (j == t)
        continue;
      v -= c[j] * (i + 1 - last[j]);
    }
    cout << v << endl;
  }

  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll, ll> P;

ll A(ll x) {
  if (x >= 0)
    return x;
  else
    return -x;
}

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

ll c[27];
ll s[27][27];
ll last[27];
ll score[27];

int main(void) {
  int D;
  cin >> D;
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int i = 1; i <= D; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  for (ll d = 1; d <= D; d++) {
    ll t;
    cin >> t;
    last[t] = d;
    score[t] += s[d][t];
    ll ans = 0;
    for (ll j = 1; j <= 26; j++) {
      score[j] -= c[j] * (d - last[j]);
      ans += score[j];
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define N (1000000000 + 7)
#define M 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll, ll> P;

ll A(ll x) {
  if (x >= 0)
    return x;
  else
    return -x;
}

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

ll c[27];
ll s[400][27];
ll last[27];
ll score[27];

int main(void) {
  int D;
  cin >> D;
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int i = 1; i <= D; i++) {
    for (int j = 1; j <= 26; j++) {
      cin >> s[i][j];
    }
  }
  for (ll d = 1; d <= D; d++) {
    ll t;
    cin >> t;
    last[t] = d;
    score[t] += s[d][t];
    ll ans = 0;
    for (ll j = 1; j <= 26; j++) {
      score[j] -= c[j] * (d - last[j]);
      ans += score[j];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void app() {
  int d;
  cin >> d;

  int n = 26;
  vector<int> c(n);
  rep(j, n) { cin >> c[j]; }
  vector<vector<int>> s(d, vector<int>(n));
  rep(i, d) rep(j, n) cin >> s[i][j];

  vector<int> t(n);
  rep(i, d) {
    cin >> t[i];
    t[i]--;
  }

  lint score = 0;
  vector<int> lastd(n, -1);
  rep(i, d) {
    int j = t[i];
    lastd[j] = i;
    score += s[i][j];
    rep(j, n) score -= c[j] * (i - lastd[j]);
    cout << score << endl;
  }
}

int main() {
  app();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void app() {
  int d;
  cin >> d;

  int n = 26;
  vector<int> c(n);
  rep(j, n) { cin >> c[j]; }
  vector<vector<int>> s(d, vector<int>(n));
  rep(i, d) rep(j, n) cin >> s[i][j];

  vector<int> t(d);
  rep(i, d) {
    cin >> t[i];
    t[i]--;
  }

  lint score = 0;
  vector<int> lastd(n, -1);
  rep(i, d) {
    int j = t[i];
    lastd[j] = i;
    score += s[i][j];
    rep(j, n) score -= c[j] * (i - lastd[j]);
    cout << score << endl;
  }
}

int main() {
  app();
  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct fastio {
  fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} _io;
template <class T, class U> bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

constexpr size_t D = 5;
constexpr size_t type = 26;
constexpr int INF = (1 << 30);

array<int, type> c, last;
array<array<int, type>, D> s;
array<int, D> contest;

void input() {
  int buff;
  cin >> buff;
  for (int i = 0; i < type; i++) {
    cin >> c[i];
    last[i] = 0;
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < type; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < D; i++) {
    cin >> contest[i];
    contest[i]--;
  }
}

int score(int day, int idx) {
  int ans = s[day][idx];
  for (int i = 0; i < type; i++) {
    ans -= c[i] * (day + 1 - last[i]);
  }
  return ans;
}

int main() {
  input();
  int ans = 0;
  for (int i = 0; i < D; i++) {
    const int &id = contest[i];
    last[id] = i + 1;
    ans += score(i, id);
    cout << ans << '\n';
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct fastio {
  fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  }
} _io;
template <class T, class U> bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U> bool chmin(T &a, const U &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

constexpr size_t D = 365;
constexpr size_t type = 26;
constexpr int INF = (1 << 30);

array<int, type> c, last;
array<array<int, type>, D> s;
array<int, D> contest;

void input() {
  int buff;
  cin >> buff;
  for (int i = 0; i < type; i++) {
    cin >> c[i];
    last[i] = 0;
  }
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < type; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < D; i++) {
    cin >> contest[i];
    contest[i]--;
  }
}

int score(int day, int idx) {
  int ans = s[day][idx];
  for (int i = 0; i < type; i++) {
    ans -= c[i] * (day + 1 - last[i]);
  }
  return ans;
}

int main() {
  input();
  int ans = 0;
  for (int i = 0; i < D; i++) {
    const int &id = contest[i];
    last[id] = i + 1;
    ans += score(i, id);
    cout << ans << '\n';
  }

  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  static int last[m];
  fill(begin(last), end(last), -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin.ignore();
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    // cout << type[i] + 1 << '\n';
    cin >> type[i];
    --type[i];
  }
  for (int i = 0; i < n; ++i) {
    cout << score(i + 1) << '\n';
  }
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

constexpr int n = 365, m = 26;
int c[m], s[n][m];

int type[n];
int score(int lim = n) {
  static int last[m];
  fill(begin(last), end(last), -1);
  int res = 0;
  for (int i = 0; i < lim; ++i) {
    res += s[i][type[i]];
    last[type[i]] = i;
    for (int j = 0; j < m; ++j) {
      res -= c[j] * (i - last[j]);
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // cin.ignore();
  int _n;
  cin >> _n;
  assert(_n == n);
  for (int j = 0; j < m; ++j) {
    cin >> c[j];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    // cout << type[i] + 1 << '\n';
    cin >> type[i];
    --type[i];
  }
  for (int i = 0; i < n; ++i) {
    cout << score(i + 1) << '\n';
  }
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#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;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

constexpr int N = 26;
constexpr int D = 365;

signed main() {
  int tt;
  cin >> tt;
  int c[N];
  rep(i, N) { cin >> c[i]; }
  int s[D][N];
  rep(i, D) {
    rep(j, N) { cin >> s[i][j]; }
  }
  int t[D];
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }
  int last[N];
  fill(last, last + N, -1);
  int ans = 0;
  rep(i, D) {
    last[i] = t[i];
    ans += s[i][t[i]];
    rep(j, N) { ans -= c[j] * (i - last[j]); }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#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;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

constexpr int N = 26;
constexpr int D = 365;

signed main() {
  int tt;
  cin >> tt;
  int c[N];
  rep(i, N) { cin >> c[i]; }
  int s[D][N];
  rep(i, D) {
    rep(j, N) { cin >> s[i][j]; }
  }
  int t[D];
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }
  int last[N];
  fill(last, last + N, -1);
  int ans = 0;
  rep(i, D) {
    last[t[i]] = i;
    ans += s[i][t[i]];
    rep(j, N) { ans -= c[j] * (i - last[j]); }
    cout << ans << endl;
  }
  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define N_CONTEST (26)
#define N_DAY (5)

static void get_input(int &D, vector<int> &c, vector<vector<int>> &s) {
  cin >> D;
  assert(D == N_DAY);
  for (int i = 1; i <= N_CONTEST; i++) {
    cin >> c.at(i);
  }
  for (int i = 1; i <= N_DAY; i++) {
    for (int j = 1; j <= N_CONTEST; j++) {
      cin >> s.at(i).at(j);
    }
  }
}

static long long calc_score(vector<int> &c, vector<vector<int>> &s,
                            vector<int> &t) {
  vector<int> last(N_CONTEST + 1, 0);

  long long score = 0;

  for (int d = 1; d <= N_DAY; d++) {
    score += s.at(d).at(t.at(d));
    last.at(t.at(d)) = d;
    for (int con = 1; con <= N_CONTEST; con++) {
      score -= c.at(con) * (d - last.at(con));
    }
    cout << score << endl;
  }

  return score;
}

int main(void) {
  int D;
  vector<int> c(N_CONTEST + 1);
  vector<vector<int>> s(N_DAY + 1, vector<int>(N_CONTEST + 1, 0));

  get_input(D, c, s);

  //    for ( int i = 0; i < N_DAY; i++ ) {
  //        cout << i % 26 + 1 << endl;
  //    }

  vector<int> t(N_DAY + 1, 0);
  for (int i = 1; i <= N_DAY; i++) {
    cin >> t.at(i);
  }

  calc_score(c, s, t);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define N_CONTEST (26)
#define N_DAY (365)

static void get_input(int &D, vector<int> &c, vector<vector<int>> &s) {
  cin >> D;
  assert(D == N_DAY);
  for (int i = 1; i <= N_CONTEST; i++) {
    cin >> c.at(i);
  }
  for (int i = 1; i <= N_DAY; i++) {
    for (int j = 1; j <= N_CONTEST; j++) {
      cin >> s.at(i).at(j);
    }
  }
}

static long long calc_score(vector<int> &c, vector<vector<int>> &s,
                            vector<int> &t) {
  vector<int> last(N_CONTEST + 1, 0);

  long long score = 0;

  for (int d = 1; d <= N_DAY; d++) {
    score += s.at(d).at(t.at(d));
    last.at(t.at(d)) = d;
    for (int con = 1; con <= N_CONTEST; con++) {
      score -= c.at(con) * (d - last.at(con));
    }
    cout << score << endl;
  }

  return score;
}

int main(void) {
  int D;
  vector<int> c(N_CONTEST + 1);
  vector<vector<int>> s(N_DAY + 1, vector<int>(N_CONTEST + 1, 0));

  get_input(D, c, s);

  //    for ( int i = 0; i < N_DAY; i++ ) {
  //        cout << i % 26 + 1 << endl;
  //    }

  vector<int> t(N_DAY + 1, 0);
  for (int i = 1; i <= N_DAY; i++) {
    cin >> t.at(i);
  }

  calc_score(c, s, t);

  return 0;
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int D;
vector<int> c(26 + 1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
  vector<vector<int>> last(D + 1, vector<int>(26 + 1, 0));
  int ans = 0;
  for (int d = 1; d <= D; d++) {
    last[d][t[d]] = d;
    ans += s[d][t[d]];
    for (int i = 1; i <= 26; i++) {
      if (i == t[d])
        continue;
      last[d][i] = last[d - 1][i];
      ans -= c[i] * (d - last[d][i]);
    }
    cout << ans << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin >> D;
  s.assign(D + 1, vector<int>(26 + 1, 0));
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int d = 1; d <= D; d++)
    for (int i = 1; i <= 26; i++)
      cin >> s[d][i];
  vector<int> t(D + 1);
  for (int d = 1; d <= D; d++)
    cin >> t[d];
  compute_score(t);
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int D;
vector<int> c(26 + 1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
  vector<vector<int>> last(D + 1, vector<int>(26 + 1, 0));
  int ans = 0;
  for (int d = 1; d <= D; d++) {
    last[d][t[d]] = d;
    ans += s[d][t[d]];
    for (int i = 1; i <= 26; i++) {
      if (i == t[d])
        continue;
      last[d][i] = last[d - 1][i];
      ans -= c[i] * (d - last[d][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> D;
  s.assign(D + 1, vector<int>(26 + 1, 0));
  for (int i = 1; i <= 26; i++)
    cin >> c[i];
  for (int d = 1; d <= D; d++)
    for (int i = 1; i <= 26; i++)
      cin >> s[d][i];
  vector<int> t(D + 1);
  for (int d = 1; d <= D; d++)
    cin >> t[d];
  compute_score(t);
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++)
    cin >> c.at(i);
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  int ns = 0;
  vector<int> last(26, 0);
  for (int i = 0; i < D; i++) {
    int t;
    cin >> t;
    ns += s.at(i).at(t - 1) - c.at(i);
    //        last.at(t-1) = i + 1;
    //        for (int j = 0; j < 26; j++) {
    //            ns -= c.at(i) * (i + 1 - last.at(j));
    //        }
    cout << ns << endl;
  }
}

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

int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++)
    cin >> c.at(i);
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }

  int ns = 0;
  vector<int> last(26, 0);
  for (int i = 0; i < D; i++) {
    int t;
    cin >> t;
    ns += s.at(i).at(t - 1);
    last.at(t - 1) = i + 1;

    for (int j = 0; j < 26; j++) {
      ns -= c.at(j) * (i + 1 - last.at(j));
    }
    cout << ns << endl;
  }
}
Problem p02619 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9 + 7)
#define INF (1LL << 62) // 1LL<<63でオーバーフロー

int main(int argc, char *argv[]) {
  int d;
  cin >> d; // d=365

  const int contest = 26;
  vector<int> c(contest);
  for (auto &x : c)
    cin >> x;

  vector<vector<int>> s(d, vector<int>(contest, 0));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < contest; j++)
      cin >> s.at(i).at(j);
  }

  vector<int> t(contest);
  for (auto &x : t)
    cin >> x;

  vector<int> last(contest + 1, 0), satisfaction(d + 1);
  satisfaction.at(0) = 0;
  for (int i = 1; i < d + 1; i++) {
    int dissatis = 0;
    int act = t.at(i - 1);
    last.at(act) = i;
    for (int j = 0; j < contest; j++) {
      dissatis += c.at(j) * (i - last.at(j + 1));
    }
    satisfaction.at(i) =
        satisfaction.at(i - 1) + s.at(i - 1).at(act - 1) - dissatis;

    cout << satisfaction.at(i) << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9 + 7)
#define INF (1LL << 62) // 1LL<<63でオーバーフロー

int main(int argc, char *argv[]) {
  int d;
  cin >> d; // d=365

  const int contest = 26;
  vector<int> c(contest);
  for (auto &x : c)
    cin >> x;

  vector<vector<int>> s(d, vector<int>(contest, 0));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < contest; j++)
      cin >> s.at(i).at(j);
  }

  vector<int> t(d);
  for (auto &x : t)
    cin >> x;

  vector<int> last(contest + 1, 0), satisfaction(d + 1);
  satisfaction.at(0) = 0;
  for (int i = 1; i < d + 1; i++) {
    int dissatis = 0;
    int act = t.at(i - 1);
    last.at(act) = i;
    for (int j = 0; j < contest; j++) {
      dissatis += c.at(j) * (i - last.at(j + 1));
    }
    satisfaction.at(i) =
        satisfaction.at(i - 1) + s.at(i - 1).at(act - 1) - dissatis;

    cout << satisfaction.at(i) << endl;
  }

  return 0;
}
Problem p02620 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27]; // 最後の開催日
  int ans = 0;
  int kotae[500];

  cin >> d;
  rep(i, 26) cin >> c[i + 1];
  rep(i, d) {
    rep(j, 26) { cin >> s[i + 1][j + 1]; }
  }

  rep(i, d) { cin >> t[i + 1]; }

  int m;
  cin >> m;
  rep(k, m) {
    int a, b;
    cin >> a >> b;
    t[a] = b;
    // 初期化
    ans = 0;
    rep(i, 26) last[i + 1] = 0;
    for (int i = 1; i <= d; i++) {
      ans += s[i][t[i]];
      last[t[i]] = i;
      for (int j = 1; j <= 26; j++)
        ans -= (i - last[j]) * c[j];
    }
    kotae[k] = ans;
  }

  rep(i, m) cout << kotae[i] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27]; // 最後の開催日
  int ans = 0;
  int kotae[100005];

  cin >> d;
  rep(i, 26) cin >> c[i + 1];
  rep(i, d) {
    rep(j, 26) { cin >> s[i + 1][j + 1]; }
  }

  rep(i, d) { cin >> t[i + 1]; }

  int m;
  cin >> m;
  rep(k, m) {
    int a, b;
    cin >> a >> b;
    t[a] = b;
    // 初期化
    ans = 0;
    rep(i, 26) last[i + 1] = 0;
    for (int i = 1; i <= d; i++) {
      ans += s[i][t[i]];
      last[t[i]] = i;
      for (int j = 1; j <= 26; j++)
        ans -= (i - last[j]) * c[j];
    }
    kotae[k] = ans;
  }

  rep(i, m) cout << kotae[i] << endl;
  return 0;
}
Problem p02620 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

int main() {
  int D;
  std::cin >> D;
  std::vector<int> C(26);
  for (int i = 0; i < 26; i++) {
    std::cin >> C[i];
  }
  std::vector<std::vector<int>> S(D, std::vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      std::cin >> S[i][j];
    }
  }
  std::vector<int> T(D);
  for (int i = 0; i < D; i++) {
    std::cin >> T[i];
  }

  int M;
  std::cin >> M;
  std::vector<int> D_query(M);
  std::vector<int> Q_query(M);
  for (int i = 0; i < M; i++) {
    std::cin >> D_query[i] >> Q_query[i];
  }

  std::vector<int> V(D);
  for (int q = 0; q < M; q++) {
    T[D_query[q] - 1] = Q_query[q];
    long long ans = 0;
    std::vector<int> last(26, 0);
    for (int i = 0; i < D; i++) {
      ans += S[i][T[i] - 1];
      last[T[i] - 1] = i + 1;
      for (int j = 0; j < 26; j++) {
        ans -= (i + 1 - last[j]) * C[j];
      }
    }
    V[q] = ans;
  }

  for (int i = 0; i < M; i++) {
    std::cout << V[i] << std::endl;
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

int main() {
  int D;
  std::cin >> D;
  std::vector<int> C(26);
  for (int i = 0; i < 26; i++) {
    std::cin >> C[i];
  }
  std::vector<std::vector<int>> S(D, std::vector<int>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      std::cin >> S[i][j];
    }
  }
  std::vector<int> T(D);
  for (int i = 0; i < D; i++) {
    std::cin >> T[i];
  }

  int M;
  std::cin >> M;
  std::vector<int> D_query(M);
  std::vector<int> Q_query(M);
  for (int i = 0; i < M; i++) {
    std::cin >> D_query[i] >> Q_query[i];
  }

  std::vector<int> V(M);
  for (int q = 0; q < M; q++) {
    T[D_query[q] - 1] = Q_query[q];
    long long ans = 0;
    std::vector<int> last(26, 0);
    for (int i = 0; i < D; i++) {
      ans += S[i][T[i] - 1];
      last[T[i] - 1] = i + 1;
      for (int j = 0; j < 26; j++) {
        ans -= (i + 1 - last[j]) * C[j];
      }
    }
    V[q] = ans;
  }

  for (int i = 0; i < M; i++) {
    std::cout << V[i] << std::endl;
  }

  return 0;
}
Problem p02620 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int D;
vector<int> C;
vector<vector<int>> S;

struct State {
  vector<int> T;
  vector<set<int>> X;
  long long score;
  State() : T(26, -1), X(26, set<int>{-1, D}) {
    score = 0;
    for (int i = 0; i < 26; i++)
      score -= (long long)C[i] * D * (D + 1) / 2;
  }

  void add(int d, int t) {
    assert(T[d] == -1);
    assert(X[t].count(d) == 0);

    auto p1 = X[t].lower_bound(d);
    auto p0 = p1;
    p0--;
    score += (long long)C[t] * (d - *p0) * (*p1 - d);
    score += S[d][t];
    X[t].insert(d);
    T[d] = t;
  }

  void remove(int d) {
    assert(T[d] != -1);
    assert(X[T[d]].count(d) > 0);

    int t = T[d];
    auto p = X[t].find(d);
    auto p0 = p;
    p0--;
    auto p1 = p;
    p1++;
    score -= (long long)C[t] * (d - *p0) * (*p1 - d);
    score -= S[d][t];
    X[t].erase(d);
    T[d] = -1;
  }
};

int main() {
  cin >> D;
  C = vector<int>(26);
  for (int &c : C)
    cin >> c;
  S = vector<vector<int>>(D, vector<int>(26));
  for (auto &s : S)
    for (auto &x : s)
      cin >> x;

  State state;
  for (int i = 0; i < D; i++) {
    int t;
    cin >> t;
    t--;
    state.add(i, t);
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int d;
    int q;
    cin >> d >> q;
    d--, q--;
    state.remove(d);
    state.add(d, q);
    cout << state.score << endl;
  }
}


Fixed submission:
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int D;
vector<int> C;
vector<vector<int>> S;

struct State {
  vector<int> T;
  vector<set<int>> X;
  long long score;
  State() : T(D, -1), X(26, set<int>{-1, D}) {
    score = 0;
    for (int i = 0; i < 26; i++)
      score -= (long long)C[i] * D * (D + 1) / 2;
  }

  void add(int d, int t) {
    assert(T[d] == -1);
    assert(X[t].count(d) == 0);

    auto p1 = X[t].lower_bound(d);
    auto p0 = p1;
    p0--;
    score += (long long)C[t] * (d - *p0) * (*p1 - d);
    score += S[d][t];
    X[t].insert(d);
    T[d] = t;
  }

  void remove(int d) {
    assert(T[d] != -1);
    assert(X[T[d]].count(d) > 0);

    int t = T[d];
    auto p = X[t].find(d);
    auto p0 = p;
    p0--;
    auto p1 = p;
    p1++;
    score -= (long long)C[t] * (d - *p0) * (*p1 - d);
    score -= S[d][t];
    X[t].erase(d);
    T[d] = -1;
  }
};

int main() {
  cin >> D;
  C = vector<int>(26);
  for (int &c : C)
    cin >> c;
  S = vector<vector<int>>(D, vector<int>(26));
  for (auto &s : S)
    for (auto &x : s)
      cin >> x;

  State state;
  for (int i = 0; i < D; i++) {
    int t;
    cin >> t;
    t--;
    state.add(i, t);
  }
  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int d;
    int q;
    cin >> d >> q;
    d--, q--;
    state.remove(d);
    state.add(d, q);
    cout << state.score << endl;
  }
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int a;
  cin >> a;
  cout << a * (a * a * a - 1) / (a - 1) << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int a;
  cin >> a;
  int temp = 1;
  int ans = 0;
  for (int i = 0; i < 3; i++) {
    temp *= a;
    ans += temp;
  }
  cout << ans << endl;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a;
int main() {
  cin >> a;
  cout << ((a * a * a * a - 1) / (a - 1)) - 1 << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a;
int main() {
  cin >> a;
  if (a == 1)
    cout << "3\n";
  else
    cout << ((a * a * a * a - 1) / (a - 1)) - 1 << "\n";
  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)1000000007
#define pb push_back
#define endl "\n"
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define repo(i, b) for (int i = (int)0; i < b; i++)
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)

signed solve() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
}

signed main() {
  fast;
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    solve();
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)1000000007
#define pb push_back
#define endl "\n"
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define repo(i, b) for (int i = (int)0; i < b; i++)
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)

signed solve() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}

signed main() {
  fast;
  int tests = 1;
  // cin>>tests;
  while (tests--) {
    solve();
  }
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int sum(int a) {
  int Tong = 0;
  while (a >= 1 && a <= 10) {
    for (int i = 1; i <= 3; ++i) {
      Tong += pow(a, i);
    }
    cout << Tong;
    break;
  }
}

int main() {
  int a;
  cin >> a;
  sum(a);
  return 0;
}


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

int sum(int a) {
  int Tong = 0;
  while (a >= 1 && a <= 10) {
    for (int i = 1; i <= 3; ++i) {
      Tong += pow(a, i);
    }
    cout << Tong;
    break;
  }
  return 0;
}

int main() {
  int a;
  cin >> a;
  sum(a);
  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
  int a;
  scanf("%d", a);
  int ans = a + (a * a) + (a * a * a);
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <math.h>
#include <stdio.h>
using namespace std;

int main() {
  int a;
  scanf("%d", &a);
  int ans = a + (a * a) + (a * a * a);
  printf("%d", ans);
  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007

long long int fastexpo(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1)
      ans = (ans * a) % mod;
    b = b / 2;
    a = (a * a) % mod;
  }
  return ans;
}
bool vis[500000000] = {0};
bool child[50000000] = {0};
vector<int> vec[50000000];
int ans = 1;
int bfs(int node) {
  queue<int> qu;
  qu.push(node);
  while (!qu.empty()) {
    int t = qu.front();
    vis[t] = 1;
    qu.pop();
    //  cout << t << "\n";
    for (int i = 0; i < vec[t].size(); i++) {
      if (child[t])
        if (!vis[vec[t][i]]) {
          qu.push(vec[t][i]);
          vis[vec[t][i]] = 1;
          //  child[vec[t][i]] = 1;
          ans++;
        }
      if (!child[t]) {
        if (!vis[vec[t][i]]) {
          qu.push(vec[t][i]);
          vis[vec[t][i]] = 1;
          child[vec[t][i]] = 1;
          // ans++;
        }
      }
    }
  }
  return ans;
}

int main() {
  int a;
  string str;
  cin >> a;
  cout << a + a * a + a * a * a << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007

int main() {
  int a;
  string str;
  cin >> a;
  cout << a + a * a + a * a * a << "\n";

  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {

  ll a;
  cin >> a;
  return a + (a * a) + (a * a * a);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {

  ll a;
  cin >> a;
  cout << a + (a * a) + (a * a * a) << endl;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a;

  return 1;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a;

  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a;
  cin >> a;
  return (a + a * a + a * a * a);
}

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

int main() {
  long long a;
  cin >> a;
  cout << (a + a * a + a * a * a) << endl;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main() {
  int a;
  cin >> a;
  cout << a * (1 - a * a * a) / (1 - a) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, s, n) for (int i = (s); i < (n); i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define REPR(i, s, n) for (int i = (s); i >= (n); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int a;
int main() {
  cin >> a;
  int s = 0;
  for (int i = 0; i < a; i++)
    s = s + a + 1 + a * a;
  return s;
}


Fixed submission:
#include <iostream>

using namespace std;

int a;
int main() {
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  string s, t;
  cin >> s >> t;
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  rep1(i, n) cin >> a[i];
  ll ans = 0;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, k, n) for (ll i = k; i < (n); i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll a;
  cin >> a;
  ll ans = a + a * a + a * a * a;
  cout << ans << endl;
}
Problem p02621 (Python)

Buggy submission (status: Time Limit Exceeded):
N = 10**7


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Fixed submission:
N = 10**6


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)
Problem p02621 (Python)

Buggy submission (status: Time Limit Exceeded):
N = 10**9


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Fixed submission:
N = 5 * 10**8


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)
Problem p02621 (Python)

Buggy submission (status: Runtime Error):
a = input()
print(a + a**2 + a**3)


Fixed submission:
a = int(input())
print(a + a**2 + a**3)
Problem p02621 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a, b, c = 0;
  cin >> a;
  b = a * a;
  c = a * a * a;

  return a + b + c;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c = 0;
  cin >> a;
  b = a * a;
  c = a * a * a;
  cout << a + b + c;
  return 0;
}