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

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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> t(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  vector<int> p(n), x(n);
  for (int i = 0; i < m; ++i) {
    cin >> p[i] >> x[i];
  }
  for (int i = 0; i < m; ++i) {
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      if (p[i] == j + 1) {
        sum += x[i];
      } else {
        sum += t[j];
      }
    }
    cout << sum << "\n";
  }
}


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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n;
  cin >> n;
  vector<int> t(n);
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  vector<int> p(m), x(m);
  for (int i = 0; i < m; ++i) {
    cin >> p[i] >> x[i];
  }
  for (int i = 0; i < m; ++i) {
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      if (p[i] == j + 1) {
        sum += x[i];
      } else {
        sum += t[j];
      }
    }
    cout << sum << "\n";
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP2(i, x, n) for (int i = x; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double PI = acos(-1);
static const int INF = 1e9 + 7;
// debug
#ifdef _DEBUG
#define debug(var)                                                             \
  do {                                                                         \
    cout << #var << " :";                                                      \
    view(var);                                                                 \
  } while (0)
#else
#define debug(...)
#endif
template <typename T> void view(T e) { cout << e << endl; }
template <typename T> void view(const vector<T> &v) {
  for (const auto &e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T> void view(const vector<vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  REP(i, n) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(n);
  vector<int> x(n);
  REP(i, m) cin >> p[i] >> x[i];
  REP(i, m) p[i]--;

  ll sum = 0;
  REP(i, n) sum += (ll)t[i];

  REP(i, m) {
    ll ans = sum;
    ans -= (ll)t[p[i]];
    ans += (ll)x[i];
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REP2(i, x, n) for (int i = x; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const double PI = acos(-1);
static const int INF = 1e9 + 7;
// debug
#ifdef _DEBUG
#define debug(var)                                                             \
  do {                                                                         \
    cout << #var << " :";                                                      \
    view(var);                                                                 \
  } while (0)
#else
#define debug(...)
#endif
template <typename T> void view(T e) { cout << e << endl; }
template <typename T> void view(const vector<T> &v) {
  for (const auto &e : v) {
    cout << e << " ";
  }
  cout << endl;
}
template <typename T> void view(const vector<vector<T>> &vv) {
  for (const auto &v : vv) {
    view(v);
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  REP(i, n) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  REP(i, m) cin >> p[i] >> x[i];
  REP(i, m) p[i]--;

  ll sum = 0;
  REP(i, n) sum += (ll)t[i];

  REP(i, m) {
    ll ans = sum;
    ans -= (ll)t[p[i]];
    ans += (ll)x[i];
    cout << ans << endl;
  }

  return 0;
}
Problem p03845 (C++)

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

int main() {
  int n, m, p, x, ans;
  cin >> n;
  vector<int> T(5);
  rep(i, n) cin >> T.at(i);
  int sum = 0;
  cin >> m;
  rep(i, n) sum += T.at(i);
  int tmp = sum;
  rep(i, m) {
    cin >> p >> x;
    tmp = sum - (T.at(p - 1) - x);
    cout << tmp << endl;
  }
}

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

int main() {
  int n, m, p, x, ans;
  cin >> n;
  vector<int> T(n);
  rep(i, n) cin >> T.at(i);
  int sum = 0;
  cin >> m;
  rep(i, n) sum += T.at(i);
  int tmp = sum;
  rep(i, m) {
    cin >> p >> x;
    tmp = sum - (T.at(p - 1) - x);
    cout << tmp << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {

  int n;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  int p, x;
  int ans[n];
  for (int i = 0; i < m; i++) {
    int a = 0;
    cin >> p >> x;
    for (int j = 0; j < n; j++) {
      if (j == (p - 1)) {
        a += x;
      } else {
        a += t[j];
      }
    }
    ans[i] = a;
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {

  int n;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  int p, x;
  int ans[m];
  for (int i = 0; i < m; i++) {
    int a = 0;
    cin >> p >> x;
    for (int j = 0; j < n; j++) {
      if (j == (p - 1)) {
        a += x;
      } else {
        a += t[j];
      }
    }
    ans[i] = a;
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p03845 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  int M;
  cin >> M;
  vector<int> d(M);
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    p.at(i) = make_pair(b, c); // b, a の順でペアにする
  }
  for (int i = 0; i < M; i++) {
    int b, c;
    tie(b, c) = p.at(i);
    d.at(i) = sum - a.at(b) + c;
    cout << d.at(i) << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  int M;
  cin >> M;
  vector<int> d(M);
  vector<pair<int, int>> p(M);
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    p.at(i) = make_pair(b, c); // b, a の順でペアにする
  }
  for (int i = 0; i < M; i++) {
    int b, c;
    tie(b, c) = p.at(i);
    d.at(i) = sum - a.at(b - 1) + c;
    cout << d.at(i) << endl;
  }
}
Problem p03845 (C++)

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

int main() {
  int n, m, i, j, sum = 0;
  cin >> n;
  int t[n];
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  cin >> m;
  int p[m], x[m];
  for (i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }
  for (i = 0; i < n; i++) {
    sum += t[i];
  }
  for (i = 1; i <= m; i++) {
    cout << (sum + (x[i - 1] - p[t[i - 1] - 1]));
  }
}

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

int main() {
  int n, m, i, j, sum = 0;
  cin >> n;
  int t[n];
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  cin >> m;
  int p[m], x[m];
  for (i = 0; i < m; i++) {
    cin >> p[i] >> x[i];
  }
  for (i = 0; i < n; i++) {
    sum += t[i];
  }
  for (i = 0; i < m; i++) {
    cout << (sum + (x[i] - t[p[i] - 1])) << endl;
  }
}
Problem p03845 (C++)

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

typedef long long ll;

int main() {
  int N;
  vector<int> time;
  int M, P, X;
  vector<int> ans;
  int sum;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> time[i];
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P >> X;
    for (int j = 0; j < time.size(); j++) {
      if (j == P - 1) {
        sum += X;
      } else {
        sum += time[j];
      }
    }
    ans.push_back(sum);
    sum = 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


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

typedef long long ll;

int main() {
  int N;
  vector<int> time(N);
  int M, P, X;
  vector<int> ans;
  int sum;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> time[i];
  }
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> P >> X;
    for (int j = 0; j < time.size(); j++) {
      if (j == P - 1) {
        sum += X;
      } else {
        sum += time[j];
      }
    }
    ans.push_back(sum);
    sum = 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
Problem p03845 (C++)

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

int main() {
  int N;
  cin >> N;
  int T[N];

  int sum;

  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  int P[N], X[N];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << sum - T[P[i] - 1] + X[i] << endl;
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int T[N];

  int sum;

  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << sum - T[P[i] - 1] + X[i] << endl;
  }

  return 0;
}
Problem p03845 (C++)

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

using namespace std;

int main() {
  int N;
  int sum = 0;

  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;
  vector<int> P(N);
  vector<int> X(N);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << (sum - T[P[i] - 1] + X[i]) << endl;
  }

  return 0;
}


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

using namespace std;

int main() {
  int N;
  int sum = 0;

  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  for (int i = 0; i < M; i++) {
    cout << (sum - T[P[i] - 1] + X[i]) << endl;
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

int main() {

  int n;
  cin >> n;

  vi a(n);

  int sum = 0;

  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  int m;
  cin >> m;

  vi d(n);

  int b, c;

  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &b, &c);
    d[i] = sum - a[b - 1] + c;
  }

  for (int i = 0; i < m; ++i) {
    cout << d[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

int main() {

  int n;
  cin >> n;

  vi a(n);

  int sum = 0;

  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    sum += a[i];
  }

  int m;
  cin >> m;

  vi d(m);

  int b, c;

  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &b, &c);
    d[i] = sum - a[b - 1] + c;
  }

  for (int i = 0; i < m; ++i) {
    cout << d[i] << endl;
  }

  return 0;
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  rep(i, m) cin >> p[i] >> x[i];

  int sum = 0;
  vector<int> diff(m + 1);

  for (int i = 0; i < n; ++i) {
    sum += t[i];
  }
  for (int i = 0; i < m; ++i) {
    diff[p[i]] = x[p[i]] - t[p[i] - 1];
  }
  for (int i = 1; i <= m; ++i) {
    print(sum + diff[i]);
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  rep(i, n) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  rep(i, m) cin >> p[i] >> x[i];

  int sum = 0;
  vector<int> diff(m + 1);

  for (int i = 0; i < n; ++i) {
    sum += t[i];
  }
  for (int i = 0; i < m; ++i) {
    diff[i] = x[i] - t[p[i] - 1];
    print(sum + diff[i]);
  }
}
Problem p03845 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
(*a0,) = map(int, input().split())
m = int(input())
for _ in range(m):
    k, b = map(int, input().split())
    a = a0[:]
    a[k] = b
    print(sum(a))


Fixed submission:
n = int(input())
(*a0,) = map(int, input().split())
m = int(input())
for _ in range(m):
    k, b = map(int, input().split())
    a = a0[:]
    a[k - 1] = b
    print(sum(a))
Problem p03845 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

PX = []

for i in range(M):
    # 0-indexed
    PX.append([int(j) for j in input().split()])
    PX[i][0] -= 1

ans = sum(T)

for i in range(M):
    print(ans - T[PX[i][0]] + T[PX[i][1]])


Fixed submission:
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())

PX = []

for i in range(M):
    # 0-indexed
    PX.append([int(j) for j in input().split()])
    PX[i][0] -= 1

ans = sum(T)

for i in range(M):
    print(ans - T[PX[i][0]] + PX[i][1])
Problem p03845 (Python)

Buggy submission (status: Runtime Error):
def main(n, t, m, p_x):
    for p, x in p_x:
        _t = t.copy()
        _t[p - 1] = x

        print(sum(_t))


if __name__ == "__main__":
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    p_x = [int(input()) for _ in range(m)]

    main(n, t, m, p_x)


Fixed submission:
def main(n, t, m, p_x):
    for p, x in p_x:
        _t = t.copy()
        _t[p - 1] = x

        print(sum(_t))


if __name__ == "__main__":
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    p_x = [list(map(int, input().split())) for _ in range(m)]

    main(n, t, m, p_x)
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define res(a, b, c) for (int64 a = b; a < c; a++)
#define ress(a, b) for (auto a = b.begin(); a != b.end(); a++)
#define all(con) con.begin(), con.end()
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define MAX numeric_limits<int>::max()
#define MIN numeric_limits<int64>::min()
#define mymin -1000000000000000001
#define mymax 1000000000000000001
#define watch(x) cout << (#x) << " is " << (x) << endl
#define in(x) cin >> (x)
#define inn(x, y) cin >> (x) >> (y)
#define out(x) cout << (x) << "\n"
#define outt(x, y) cout << (x) << " " << (y) << "\n"
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64, int64> pi;
bool doubleSame(double a, double b) {
  const double eps = 1e-15;
  return (abs(a - b) <= eps * abs(a));
}

int main() {
  int64 n;
  cin >> n;

  vi list(n);
  int64 ttime = 0;
  res(i, 0, n) {
    cin >> list[i];
    ttime += list[i];
  }

  int64 m;
  cin >> m;
  vector<pi> d(n);
  res(i, 0, m) { cin >> d[i].f >> d[i].s; }

  res(i, 0, m) { cout << (ttime - list[d[i].f - 1] + d[i].s) << "\n"; }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define res(a, b, c) for (int64 a = b; a < c; a++)
#define ress(a, b) for (auto a = b.begin(); a != b.end(); a++)
#define all(con) con.begin(), con.end()
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define MAX numeric_limits<int>::max()
#define MIN numeric_limits<int64>::min()
#define mymin -1000000000000000001
#define mymax 1000000000000000001
#define watch(x) cout << (#x) << " is " << (x) << endl
#define in(x) cin >> (x)
#define inn(x, y) cin >> (x) >> (y)
#define out(x) cout << (x) << "\n"
#define outt(x, y) cout << (x) << " " << (y) << "\n"
typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64, int64> pi;
bool doubleSame(double a, double b) {
  const double eps = 1e-15;
  return (abs(a - b) <= eps * abs(a));
}

int main() {
  int64 n;
  cin >> n;

  vi list(n);
  int64 ttime = 0;
  res(i, 0, n) {
    cin >> list[i];
    ttime += list[i];
  }

  int64 m;
  cin >> m;
  vector<pi> d(m);
  res(i, 0, m) { cin >> d[i].f >> d[i].s; }

  res(i, 0, m) { cout << (ttime - list[d[i].f - 1] + d[i].s) << "\n"; }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int M, N, i;
  long long int T[N], P, X, sum[M], total = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> T[i];
    total += T[i];
  }
  cin >> M;
  for (i = 0; i < M; i++) {
    cin >> P >> X;
    P--;
    sum[i] = total - T[P] + X;
  }
  for (i = 0; i < M; i++) {
    cout << sum[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int M, N, i;
  long long int T[110], P, X, sum[110], total = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> T[i];
    total += T[i];
  }
  cin >> M;
  for (i = 0; i < M; i++) {
    cin >> P >> X;
    P--;
    sum[i] = total - T[P] + X;
  }
  for (i = 0; i < M; i++) {
    cout << sum[i] << endl;
  }
  return 0;
}
Problem p03845 (C++)

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

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

int main() {
  ll n, m, tot = 0;
  cin >> n;
  vector<ll> t(n), ans(m);
  rep(i, n) {
    cin >> t[i];
    tot += t[i];
  }

  cin >> m;

  ll p1, p2;

  rep(i, m) {
    cin >> p1 >> p2;
    cout << tot - t[p1 - 1] + p2 << endl;
  }

  return 0;
}


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 INF = 1e9;

int main() {
  ll n, m, tot = 0;
  cin >> n;
  vector<ll> t(n);
  rep(i, n) {
    cin >> t[i];
    tot += t[i];
  }

  cin >> m;

  ll p1, p2;

  rep(i, m) {
    cin >> p1 >> p2;
    cout << tot - t[p1 - 1] + p2 << endl;
  }

  return 0;
}
Problem p03845 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> t.at(i);
    ans += t.at(i);
  }

  int m;
  cin >> m;
  vector<int> p(m), x(n);
  for (int i = 0; i < m; i++)
    cin >> p.at(i) >> x.at(i);

  for (int i = 0; i < m; i++)
    cout << ans - t.at(p.at(i) - 1) + x.at(i) << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> t.at(i);
    ans += t.at(i);
  }

  int m;
  cin >> m;
  vector<int> p(m), x(m);
  for (int i = 0; i < m; i++)
    cin >> p.at(i) >> x.at(i);

  for (int i = 0; i < m; i++)
    cout << ans - t.at(p.at(i) - 1) + x.at(i) << endl;
}
Problem p03845 (C++)

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

using namespace std;
// typedef unsigned long long ull;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }

// template<typename T>
// ostream& operator<<(ostream& os, const vector<T>& v) {
//     os << "[";
//     for (const auto i : v) {
//         os << i << " ";
//     }
//     os << "]";
//     return os;
// }

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;
  vector<int> P(N), X(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
    P[i] -= 1;
  }

  for (int i = 0; i < M; i++) {
    cout << sum - T[P[i]] + X[i] << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>
// #include <algorithm>
// #include <map>
// #include <cmath>
// #include <string>

using namespace std;
// typedef unsigned long long ull;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }

// template<typename T>
// ostream& operator<<(ostream& os, const vector<T>& v) {
//     os << "[";
//     for (const auto i : v) {
//         os << i << " ";
//     }
//     os << "]";
//     return os;
// }

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;

  vector<int> T(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i];
    sum += T[i];
  }

  int M;
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
    P[i] -= 1;
  }

  for (int i = 0; i < M; i++) {
    cout << sum - T[P[i]] + X[i] << endl;
  }

  return 0;
}
Problem p03845 (C++)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i];
  ll m;
  cin >> m;
  vector<pair<ll, ll>> px(n);
  for (ll i = 0; i < m; i++) {
    ll p, x;
    cin >> p >> x;
    px[i] = make_pair(p, x);
  }

  for (ll i = 0; i < m; i++) {
    ll sum = px[i].second;
    for (ll j = 0; j < n; j++) {
      if (px[i].first - 1 == j)
        continue;
      sum += t[j];
    }
    cout << sum << endl;
  }
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i];
  ll m;
  cin >> m;
  vector<pair<ll, ll>> px(m);
  for (ll i = 0; i < m; i++) {
    ll p, x;
    cin >> p >> x;
    px[i] = make_pair(p, x);
  }

  for (ll i = 0; i < m; i++) {
    ll sum = px[i].second;
    for (ll j = 0; j < n; j++) {
      if (px[i].first - 1 == j)
        continue;
      sum += t[j];
    }
    cout << sum << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  rep(i, N) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  vector<int> P(N), X(N);
  rep(i, M) cin >> P[i] >> X[i];
  rep(i, M) {
    int ans = sum + X[i] - T[P[i] - 1];
    cout << ans << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int> P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int sum = 0;
  rep(i, N) {
    cin >> T[i];
    sum += T[i];
  }
  int M;
  cin >> M;
  vector<int> P(M), X(M);
  rep(i, M) cin >> P[i] >> X[i];
  rep(i, M) {
    int ans = sum + X[i] - T[P[i] - 1];
    cout << ans << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

int main() {
  int n, t[100], m;
  int p[100], x[100];
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> t[i];
  }
  std::cin >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> p[i] >> x[i];
  }
  for (int i = 0; i < m; i++) {
    int b = t[p[i]];
    t[p[i]] = x[i];
    int nSum = 0;
    for (int j = 1; j <= n; j++) {
      nSum += t[j];
    }
    std::cout << nSum << std::endl;
    t[p[i]] = b;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

int main() {
  int n, t[10000], m;
  int p[10000], x[10000];
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    std::cin >> t[i];
  }
  std::cin >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> p[i] >> x[i];
  }
  for (int i = 0; i < m; i++) {
    int b = t[p[i]];
    t[p[i]] = x[i];
    int nSum = 0;
    for (int j = 1; j <= n; j++) {
      nSum += t[j];
    }
    std::cout << nSum << std::endl;
    t[p[i]] = b;
  }
  return 0;
}
Problem p03845 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  long long K = 0;
  for (int X = 0; X < N; X++) {
    cin >> v[X];
    K += v[X];
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> Q(M);
  vector<int> R(M);
  for (int X = 0; X < M; X++) {
    cin >> P[X] >> Q[X];
    cout << K + (P[X] - v[Q[X] - 1]) << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  long long K = 0;
  for (int X = 0; X < N; X++) {
    cin >> v[X];
    K += v[X];
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> Q(M);
  vector<int> R(M);
  for (int X = 0; X < M; X++) {
    cin >> P[X] >> Q[X];
    cout << K + (Q[X] - v[P[X] - 1]) << endl;
  }
}
Problem p03845 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int Tsum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    Tsum += T.at(i);
  }

  int M;
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++)
    cin >> P.at(i) >> X.at(i);

  for (int i = 0; i < N; i++) {
    int ans = Tsum - T.at(P.at(i) - 1) + X.at(i);
    cout << ans << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  int Tsum = 0;
  for (int i = 0; i < N; i++) {
    cin >> T.at(i);
    Tsum += T.at(i);
  }

  int M;
  cin >> M;
  vector<int> P(M), X(M);
  for (int i = 0; i < M; i++)
    cin >> P.at(i) >> X.at(i);

  for (int i = 0; i < M; i++) {
    int ans = Tsum - T.at(P.at(i) - 1) + X.at(i);
    cout << ans << endl;
  }
}
Problem p03845 (C++)

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

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<ll> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    sum += t[i];
  }
  ll m;
  cin >> m;
  vector<pair<ll, ll>> p(n);
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<ll> ans(m);
  for (int i = 0; i < m; i++) {
    ans[i] = sum - (t[p[i].first - 1] - p[i].second);
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}

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

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<ll> t(n);
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    sum += t[i];
  }
  ll m;
  cin >> m;
  vector<pair<ll, ll>> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  vector<ll> ans(m);
  for (int i = 0; i < m; i++) {
    ans[i] = sum - (t[p[i].first - 1] - p[i].second);
  }

  for (int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e3 + 10;
inline int read() {
  int f = 1, r = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') {
      f = -1;
    }
    c = getchar();
  }
  while (isdigit(c)) {
    r = 10 * r + c - '0';
    c = getchar();
  }
  return f * r;
}
inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int N, arr[maxn], cnt[maxn];
signed main() {
  N = read();
  for (ri i = 1; i <= N; ++i)
    arr[i] = read(), cnt[arr[i]]++;
  int ans = 1;
  for (ri i = 0; i < N; ++i) {
    if (cnt[i] > 2) {
      puts("0");
      return 0;
    } else if (cnt[i]) {
      if ((N - 1 - i) % 2) {
        puts("0");
        return 0;
      }
      if (N % 2 && cnt[0] != 1) {
        puts("0");
        return 0;
      }
      ans *= cnt[i], ans %= MOD;
    }
  }
  writeln(ans);
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define ri register int
#define Max(x, y) (((x) > (y)) ? (x) : (y))
#define Min(x, y) (((x) < (y)) ? (x) : (y))
#define Abs(x) ((x) < 0 ? (-(x)) : (x))
#define int long long
const int maxn = 1e5 + 10;
inline int read() {
  int f = 1, r = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') {
      f = -1;
    }
    c = getchar();
  }
  while (isdigit(c)) {
    r = 10 * r + c - '0';
    c = getchar();
  }
  return f * r;
}
inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) { write(x), puts(""); }
int N, arr[maxn], cnt[maxn];
signed main() {
  N = read();
  for (ri i = 1; i <= N; ++i)
    arr[i] = read(), cnt[arr[i]]++;
  int ans = 1;
  for (ri i = 0; i < N; ++i) {
    if (cnt[i] > 2) {
      puts("0");
      return 0;
    } else if (cnt[i]) {
      if ((N - 1 - i) % 2) {
        puts("0");
        return 0;
      }
      if (N % 2 && cnt[0] != 1) {
        puts("0");
        return 0;
      }
      ans *= cnt[i], ans %= MOD;
    }
  }
  writeln(ans);
  return 0;
}
Problem p03846 (C++)

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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int cnt[200];

int main(void) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);

  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.pb(t);
    cnt[t]++;
  }

  ll ans = 1;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (cnt[i] == 2) {
        ans *= 2;
        ans %= MOD;
      } else if (cnt[i] > 0) {
        ans = 0;
        break;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i == 0 && cnt[i] == 1) {
        ans *= 1;
      } else if (i == 0) {
        ans = 0;
        break;
      } else if (cnt[i] == 2) {
        ans *= 2;
        ans %= MOD;
      } else if (cnt[i] > 0) {
        ans = 0;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define pb push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int cnt[100003];

int main(void) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);

  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.pb(t);
    cnt[t]++;
  }

  ll ans = 1;
  if (n % 2 == 0) {
    for (int i = 0; i < n; i++) {
      if (cnt[i] == 2) {
        ans *= 2;
        ans %= MOD;
      } else if (cnt[i] > 0) {
        ans = 0;
        break;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (i == 0 && cnt[i] == 1) {
        ans *= 1;
      } else if (i == 0) {
        ans = 0;
        break;
      } else if (cnt[i] == 2) {
        ans *= 2;
        ans %= MOD;
      } else if (cnt[i] > 0) {
        ans = 0;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9) + 7)

ll pow_2(ll n) {
  if (n == 1)
    return 2;
  else if (n % 2 == 0)
    return pow_2(n / 2) * pow_2(n / 2) % mod;
  else
    return 2 * pow_2(n - 1);
}

int main() {
  ll n;
  cin >> n;
  ll cnt[n];
  ll r = n % 2;
  for (ll i = 0; i < n; i++)
    cnt[i] = 0;
  bool flg = true;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a % 2 == r)
      flg = false;
    cnt[a]++;
  }

  if (r == 1 && cnt[0] != 1)
    flg = false;
  for (ll i = 1; i <= n - r; i++) {
    if (i % 2 != r && cnt[i] != 2)
      flg = false;
  }

  if (flg)
    cout << pow_2((n - r) / 2) << endl;
  else
    cout << 0 << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9) + 7)

ll pow_2(ll n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return pow_2(n / 2) * pow_2(n / 2) % mod;
  else
    return 2 * pow_2(n - 1);
}

int main() {
  ll n;
  cin >> n;
  ll cnt[n];
  ll r = n % 2;
  for (ll i = 0; i < n; i++)
    cnt[i] = 0;
  bool flg = true;
  for (ll i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a % 2 == r)
      flg = false;
    cnt[a]++;
  }

  if (r == 1 && cnt[0] != 1)
    flg = false;
  for (ll i = 1; i <= n - r; i++) {
    if (i % 2 != r && cnt[i] != 2)
      flg = false;
  }

  if (flg)
    cout << pow_2((n - r) / 2) << endl;
  else
    cout << 0 << endl;
  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int n[10001] = {0};
  for (int i = 0; i < N; i++) {
    int in;
    cin >> in;
    if ((N % 2) == 0 && (in % 2) == 0) {
      printf("0\n");
      return 0;
    } else if ((N % 2) == 1 && (in % 2) == 1) {
      printf("0\n");
      return 0;
    }
    n[in]++;
    if (in == 0 && n[0] == 2) {
      printf("0\n");
      return 0;
    }
    if (n[in] == 3) {
      printf("0\n");
      return 0;
    }
  }

  long ret = 1;
  for (int i = 0; i < (N / 2); i++) {
    ret = ret * 2;
    if (ret > pow(10, 9) + 7) {
      ret = ret - (pow(10, 9) + 7);
    }
  }
  printf("%ld\n", ret);

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int n[100001] = {0};
  for (int i = 0; i < N; i++) {
    int in;
    cin >> in;
    if ((N % 2) == 0 && (in % 2) == 0) {
      printf("0\n");
      return 0;
    } else if ((N % 2) == 1 && (in % 2) == 1) {
      printf("0\n");
      return 0;
    }
    n[in]++;
    if (in == 0 && n[0] == 2) {
      printf("0\n");
      return 0;
    }
    if (n[in] == 3) {
      printf("0\n");
      return 0;
    }
  }

  long ret = 1;
  for (int i = 0; i < (N / 2); i++) {
    ret = ret * 2;
    if (ret > pow(10, 9) + 7) {
      ret = ret - (pow(10, 9) + 7);
    }
  }
  printf("%ld\n", ret);

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  if (n % 2 == 0) {
    for (auto &c : mp) {
      if (c.second != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    ll ans = modPow(2, n / 2, mod);
    cout << ans << endl;
  } else {
    for (auto &c : mp) {
      if (c.second != 2) {
        if (!(c.second == 1 && c.first == 0)) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    ll ans = modPow(2, (n - 1) / 2, mod);
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n) {
    int a;
    cin >> a;
    mp[a]++;
  }
  if (n == 1) {
    for (auto &c : mp) {
      if (c.first == 0) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
    return 0;
  }
  if (n % 2 == 0) {
    for (auto &c : mp) {
      if (c.second != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
    ll ans = modPow(2, n / 2, mod);
    cout << ans << endl;
  } else {
    for (auto &c : mp) {
      if (c.second != 2) {
        if (!(c.second == 1 && c.first == 0)) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    ll ans = modPow(2, (n - 1) / 2, mod);
    cout << ans << endl;
  }
  return 0;
}
Problem p03846 (C++)

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

using namespace std;
int a[10005];
long long int fun(int n) {
  long long int a, b = 1, c;
  a = 2;
  c = 1000000007;
  while (n) {
    if (n % 2 == 1)
      b = b * a % c;
    a = a * a % c;
    n /= 2;
  }
  return b;
}
int main() {
  int i, j, m, n, flag = 1;
  long long int x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> m;
    a[m]++;
  }
  if (n % 2 == 0) {
    for (i = 1; i <= n - 1; i += 2) {
      if (a[i] != 2) {
        flag = 0;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
    } else {
      x = fun(n / 2);
      cout << x << endl;
    }
  } else if (a[0] == 1) {
    for (i = 2; i <= n - 1; i += 2) {
      if (a[i] != 2) {
        flag = 0;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
    } else {
      x = fun(n / 2);
      cout << x << endl;
    }
  } else {
    cout << 0 << endl;
  }
  return 0;
}


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

using namespace std;
int a[100005];
long long int fun(int n) {
  long long int a, b = 1, c;
  a = 2;
  c = 1000000007;
  while (n) {
    if (n % 2 == 1)
      b = b * a % c;
    a = a * a % c;
    n /= 2;
  }
  return b;
}
int main() {
  int i, j, m, n, flag = 1;
  long long int x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> m;
    a[m]++;
  }
  if (n % 2 == 0) {
    for (i = 1; i <= n - 1; i += 2) {
      if (a[i] != 2) {
        flag = 0;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
    } else {
      x = fun(n / 2);
      cout << x << endl;
    }
  } else if (a[0] == 1) {
    for (i = 2; i <= n - 1; i += 2) {
      if (a[i] != 2) {
        flag = 0;
      }
    }
    if (flag == 0) {
      cout << 0 << endl;
    } else {
      x = fun(n / 2);
      cout << x << endl;
    }
  } else {
    cout << 0 << endl;
  }
  return 0;
}
Problem p03846 (C++)

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

using namespace std;

int seen[11111];

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

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    seen[x]++;
  }

  long long ans = 1;
  bool valid = true;
  for (int i = n - 1; i >= 0; i -= 2) {
    if (i == 0) {
      valid &= (seen[i] == 1);
    } else {
      ans *= 2;
      ans %= 1000000007;
      valid &= (seen[i] == 2);
    }
  }

  if (!valid) {
    cout << 0;
    return 0;
  }

  cout << ans;
}

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

using namespace std;

int seen[111111];

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

  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    seen[x]++;
  }

  long long ans = 1;
  bool valid = true;
  for (int i = n - 1; i >= 0; i -= 2) {
    if (i == 0) {
      valid &= (seen[i] == 1);
    } else {
      ans *= 2;
      ans %= 1000000007;
      valid &= (seen[i] == 2);
    }
  }

  if (!valid) {
    cout << 0;
    return 0;
  }

  cout << ans;
}
Problem p03846 (C++)

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

const ll mod = 1000000007;

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

  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  vector<ll> num(10010, 0);
  for (ll i = 0; i < n; i++)
    num[a[i]]++;

  bool can = true;

  if (n % 2 == 0) {

    for (ll i = 0; i < n; i++) {

      if (i == 0) {
        if (num[i] == 0)
          continue;
        else {
          can = false;
          break;
        }
      } else { // 1 <= i
        if (i % 2 == 1) {
          if (num[i] == 2)
            continue;
          else {
            can = false;
            break;
          }
        } else {
          if (num[i] == 0)
            continue;
          else {
            can = false;
            break;
          }
        }
      }
    }

  } else { // n % 2 == 1

    for (ll i = 0; i < n; i++) {

      if (i == 0) {
        if (num[i] == 1)
          continue;
        else {
          can = false;
          break;
        }
      } else {
        if (i % 2 == 1) {
          if (num[i] == 0)
            continue;
          else {
            can = false;
            break;
          }
        } else {
          if (num[i] == 2)
            continue;
          else {
            can = false;
            break;
          }
        }
      }
    }
  }

  ll ans = 1;
  for (ll i = 1; i <= n / 2; i++) {
    ans *= 2LL;
    ans %= mod;
  }

  if (can)
    cout << ans << endl;
  else
    cout << 0 << endl;

  return 0;
}

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

const ll mod = 1000000007;

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

  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];

  vector<ll> num(n, 0);
  for (ll i = 0; i < n; i++)
    num[a[i]]++;

  bool can = true;

  if (n % 2 == 0) {

    for (ll i = 0; i < n; i++) {

      if (i == 0) {
        if (num[i] == 0)
          continue;
        else {
          can = false;
          break;
        }
      } else { // 1 <= i
        if (i % 2 == 1) {
          if (num[i] == 2)
            continue;
          else {
            can = false;
            break;
          }
        } else {
          if (num[i] == 0)
            continue;
          else {
            can = false;
            break;
          }
        }
      }
    }

  } else { // n % 2 == 1

    for (ll i = 0; i < n; i++) {

      if (i == 0) {
        if (num[i] == 1)
          continue;
        else {
          can = false;
          break;
        }
      } else {
        if (i % 2 == 1) {
          if (num[i] == 0)
            continue;
          else {
            can = false;
            break;
          }
        } else {
          if (num[i] == 2)
            continue;
          else {
            can = false;
            break;
          }
        }
      }
    }
  }

  ll ans = 1;
  for (ll i = 1; i <= n / 2; i++) {
    ans *= 2LL;
    ans %= mod;
  }

  if (can)
    cout << ans << endl;
  else
    cout << 0 << endl;

  return 0;
}
Problem p03846 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <math.h>
int main() {
  int N;
  std::cin >> N;
  int a[11000];
  for (auto &x : a)
    x = 0;
  for (int n = 0; n < N; n++) {
    int tmp;
    std::cin >> tmp;
    a[tmp]++;
  }

  if (N % 2 == 0) {
    for (int i = 1; i <= N - 1; i += 2) {
      if (a[i] != 2) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
  } else {
    if (a[0] != 1) {
      std::cout << 0 << std::endl;
      return 0;
    } else {
      for (int i = 2; i <= N - 1; i += 2) {
        if (a[i] != 2) {
          std::cout << 0 << std::endl;
          return 0;
        }
      }
    }
  }
  // double tmp = pow(2,N/2);
  long long ans = 1;
  for (int i = 0; i < N / 2; i++) {
    ans *= 2;
    ans %= 1000000007;
  }
  std::cout << ans << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
int main() {
  int N;
  std::cin >> N;
  int a[110000];
  for (auto &x : a)
    x = 0;
  for (int n = 0; n < N; n++) {
    int tmp;
    std::cin >> tmp;
    a[tmp]++;
  }

  if (N % 2 == 0) {
    for (int i = 1; i <= N - 1; i += 2) {
      if (a[i] != 2) {
        std::cout << 0 << std::endl;
        return 0;
      }
    }
  } else {
    if (a[0] != 1) {
      std::cout << 0 << std::endl;
      return 0;
    } else {
      for (int i = 2; i <= N - 1; i += 2) {
        if (a[i] != 2) {
          std::cout << 0 << std::endl;
          return 0;
        }
      }
    }
  }
  // double tmp = pow(2,N/2);
  long long ans = 1;
  for (int i = 0; i < N / 2; i++) {
    ans *= 2;
    ans %= 1000000007;
  }
  std::cout << ans << std::endl;
  return 0;
}