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

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

const int MAX = 10005;
int counter[MAX];

int main() {
  int n;
  cin >> n;
  ll a[n];
  ll fsum = 0;
  for (int i = 0; i < MAX; ++i) {
    counter[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    counter[a[i]]++;
    fsum += a[i];
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    ll cur = counter[b[i]];
    counter[b[i]] = 0;
    counter[c[i]] += cur;
    fsum += (ll)((c[i] - b[i]) * cur);
    cout << fsum << endl;
  }

  return 0;
}

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

const int MAX = 100005;
int counter[MAX];

int main() {
  int n;
  cin >> n;
  ll a[n];
  ll fsum = 0;
  for (int i = 0; i < MAX; ++i) {
    counter[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    counter[a[i]]++;
    fsum += a[i];
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    ll cur = counter[b[i]];
    counter[b[i]] = 0;
    counter[c[i]] += cur;
    fsum += (ll)((c[i] - b[i]) * cur);
    cout << fsum << endl;
  }

  return 0;
}
Problem p02630 (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;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int q;
  cin >> q;
  int b[n], c[n];
  rep(i, q) cin >> b[i] >> c[i];
  map<int, int> count;
  rep(i, n) count[a[i]]++;
  ll sum = 0;
  for (auto v : count)
    sum += (ll)v.first * v.second;
  rep(i, q) {
    if (count[b[i]] != 0) {
      int tmp = count[b[i]];
      count[c[i]] += tmp;
      count[b[i]] = 0;
      sum += (ll)(c[i] - b[i]) * tmp;
    }
    cout << sum << 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;
typedef pair<int, int> P;

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int q;
  cin >> q;
  int b[q], c[q];
  rep(i, q) cin >> b[i] >> c[i];
  map<int, int> count;
  rep(i, n) count[a[i]]++;
  ll sum = 0;
  for (auto v : count)
    sum += (ll)v.first * v.second;
  rep(i, q) {
    if (count[b[i]] != 0) {
      int tmp = count[b[i]];
      count[c[i]] += tmp;
      count[b[i]] = 0;
      sum += (ll)(c[i] - b[i]) * tmp;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p02630 (C++)

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

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

  vector<ll> vi(100000, 0);

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    vi.at(a)++;
    sum += a;
  }

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    ll from, to;
    cin >> from >> to;

    ll dif = vi.at(from) * (to - from);
    sum = sum + dif;

    vi.at(to) += vi.at(from);
    vi.at(from) -= vi.at(from);

    cout << sum << endl;
  }

  return 0;
}

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

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

  vector<ll> vi(100001, 0);

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    vi.at(a)++;
    sum += a;
  }

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    ll from, to;
    cin >> from >> to;

    ll dif = vi.at(from) * (to - from);
    sum = sum + dif;

    vi.at(to) += vi.at(from);
    vi.at(from) -= vi.at(from);

    cout << sum << endl;
  }

  return 0;
}
Problem p02630 (C++)

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

#define ll long long
#define fr first
#define sec second
#define rep(i, n) for (i = 0; i < n; i++)
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define M 1000000007
#define ios                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define open freopen("input.txt", "r", stdin);
#define close freopen("output.txt", "w", stdout);
#define M_PI 3.14159265358979323846
#define pp pair<int, int>
#define nn 100003

int main() {
  ios;
  ll n, i, q, b, c, sum = 0;
  map<ll, ll> mp;
  cin >> n;
  ll a[n];
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  rep(i, q) {
    ll currsum;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      ll x = mp[b];
      currsum = sum - x * b + x * c;
      sum = currsum;
      replace(a, a + n, b, c);
      mp.erase(b);
      if (mp.find(c) != mp.end())
        mp[c] += x;
      else
        mp[c] = x;
    } else
      currsum = sum;
    cout << currsum << "\n";
  }
  return 0;
}


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

#define ll long long
#define fr first
#define sec second
#define rep(i, n) for (i = 0; i < n; i++)
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define pb push_back
#define M 1000000007
#define ios                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define open freopen("input.txt", "r", stdin);
#define close freopen("output.txt", "w", stdout);
#define M_PI 3.14159265358979323846
#define pp pair<int, int>
#define nn 100003

int main() {
  ios;
  ll n, i, q, b, c, sum = 0;
  map<ll, ll> mp;
  cin >> n;
  ll a[n];
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  rep(i, q) {
    ll currsum;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      ll x = mp[b];
      currsum = sum - x * b + x * c;
      sum = currsum;
      mp.erase(b);
      if (mp.find(c) != mp.end())
        mp[c] += x;
      else
        mp[c] = x;
    } else
      currsum = sum;
    cout << currsum << "\n";
  }
  return 0;
}
Problem p02630 (C++)

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

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

  vector<int> num(100000, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    ans += A;
    num.at(A)++;
  }

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;

    ans += (C - B) * num.at(B);
    num.at(C) += num.at(B);
    num.at(B) = 0;

    cout << ans << endl;
  }
}

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

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

  vector<int> num(100001, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    ans += A;
    num.at(A)++;
  }

  int Q;
  cin >> Q;

  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;

    ans += (C - B) * num.at(B);
    num.at(C) += num.at(B);
    num.at(B) = 0;

    cout << ans << endl;
  }
}
Problem p02630 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long MAX = 100005;

int main(void) {
  long long N;
  cin >> N;
  vector<long long> bucket(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    sum += tmp;
    bucket[tmp]++;
  }

  long long Q;
  cin >> Q;

  long long B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    long long diff = C - B;
    sum += bucket[B] * diff;
    bucket[C] += bucket[B];
    bucket[B] = 0;
    cout << sum << "\n";
  } // for

} // main


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long MAX = 100005;

int main(void) {
  long long N;
  cin >> N;
  vector<long long> bucket(MAX);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    sum += tmp;
    bucket[tmp]++;
  }

  long long Q;
  cin >> Q;

  long long B, C;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    long long diff = C - B;
    sum += bucket[B] * diff;
    bucket[C] += bucket[B];
    bucket[B] = 0;
    cout << sum << "\n";
  } // for

} // main
Problem p02630 (C++)

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; // ↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w) {
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n;
  cin >> n;
  vi a(n, 0);
  ll s = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t - 1]++;
    s += t;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    s += (c - b) * a[b - 1];
    a[c - 1] += a[b - 1];
    a[b - 1] = 0;
    cout << s << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctime>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; // ↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w) {
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n;
  cin >> n;
  vi a(100000, 0);
  ll s = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t - 1]++;
    s += t;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    s += (c - b) * a[b - 1];
    a[c - 1] += a[b - 1];
    a[b - 1] = 0;
    cout << s << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}
Problem p02630 (Python)

Buggy submission (status: Runtime Error):
from sys import stdin

readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

t = [0] * (N + 1)
s = sum(A)
for a in A:
    t[a] += 1

for _ in range(Q):
    B, C = map(int, readline().split())
    s -= B * t[B]
    s += C * t[B]
    t[C] += t[B]
    t[B] = 0
    print(s)


Fixed submission:
from sys import stdin

readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

t = [0] * (10**5 + 1)
s = sum(A)
for a in A:
    t[a] += 1

for _ in range(Q):
    B, C = map(int, readline().split())
    s -= B * t[B]
    s += C * t[B]
    t[C] += t[B]
    t[B] = 0
    print(s)
Problem p02630 (C++)

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

int main() {
  int N;
  cin >> N;
  map<int, ll> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    auto it = A.find(a);
    if (it == A.end()) {
      A.emplace(a, 1);
    } else {
      (it->second)++;
    }
  }
  ll S = 0;
  for (auto p : A) {
    S += p.first * p.second;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    if (A.find(B) != A.end()) {
      S += (C - B) * A.at(B);
      A.at(C) += A.at(B);
      A.erase(B);
    }
    cout << S << endl;
  }
  return 0;
}


Fixed submission:
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  map<int, ll> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    auto it = A.find(a);
    if (it == A.end()) {
      A.emplace(a, 1);
    } else {
      (it->second)++;
    }
  }
  ll S = 0;
  for (auto p : A) {
    S += p.first * p.second;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    if (A.find(B) != A.end()) {
      S += (C - B) * A.at(B);
      if (A.find(C) == A.end()) {
        A.emplace(C, A.at(B));
      } else {
        A.at(C) += A.at(B);
      }
      A.erase(B);
    }
    cout << S << endl;
  }
  return 0;
}
Problem p02630 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  vector<int> d(q);
  for (int i = 0; i < q; i++) {
    d[i] = c[i] - b[i];
  }

  sort(a.begin(), a.end());
  vector<int> k(a[n - 1]);
  for (int i = 0; i < n; i++) {
    k[a[i] - 1]++;
  }

  long long s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  }

  for (int i = 0; i < q; i++) {
    s += k[b[i] - 1] * d[i];
    cout << s << endl;
    k[c[i] - 1] += k[b[i] - 1];
    k[b[i] - 1] = 0;
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  vector<int> d(q);
  for (int i = 0; i < q; i++) {
    d[i] = c[i] - b[i];
  }

  sort(a.begin(), a.end());
  vector<int> k(100000);
  for (int i = 0; i < n; i++) {
    k[a[i] - 1]++;
  }

  long long s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
  }

  for (int i = 0; i < q; i++) {
    s += k[b[i] - 1] * d[i];
    cout << s << endl;
    k[c[i] - 1] += k[b[i] - 1];
    k[b[i] - 1] = 0;
  }
}
Problem p02630 (C++)

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(n);
  ll ans = 0;
  ll b[100010], c[100010];
  ll q;
  rep(i, n) {
    cin >> a[i];
    ans += a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  cin >> q;
  rep(i, q) cin >> b[i] >> c[i];

  rep(i, q) {
    ans += (c[i] - b[i]) * cnt[b[i] - 1];
    cnt[c[i] - 1] += cnt[b[i] - 1];
    cnt[b[i] - 1] = 0;
    cout << ans << endl;
  }
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> cnt(100010);
  ll ans = 0;
  ll b[100010], c[100010];
  ll q;
  rep(i, n) {
    cin >> a[i];
    ans += a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  cin >> q;
  rep(i, q) cin >> b[i] >> c[i];

  rep(i, q) {
    ans += (c[i] - b[i]) * cnt[b[i] - 1];
    cnt[c[i] - 1] += cnt[b[i] - 1];
    cnt[b[i] - 1] = 0;
    cout << ans << endl;
  }
}
Problem p02630 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define read(n) scanf("%d", &n)
#define f(i, a, b) for (int i = a; i <= b; ++i)
#define N 100005
ll num[N];
int main() {
  ll n, q, sum = 0;
  read(n);
  f(i, 1, n) {
    ll x;
    read(x);
    ++num[x];
    sum += x;
  }
  read(q);
  f(i, 1, q) {
    ll x, y;
    read(x);
    read(y);
    sum += (y - x) * (num[x]);
    num[y] += num[x];
    num[x] = 0;
    cout << sum << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
#define ll long long
#define read(n) scanf("%lld", &n)
#define f(i, a, b) for (int i = a; i <= b; ++i)
#define N 100005
ll num[N];
int main() {
  ll n, q, sum = 0;
  read(n);
  f(i, 1, n) {
    ll x;
    read(x);
    ++num[x];
    sum += x;
  }
  read(q);
  f(i, 1, q) {
    ll x, y;
    read(x);
    read(y);
    sum += (y - x) * (num[x]);
    num[y] += num[x];
    num[x] = 0;
    cout << sum << endl;
  }
  return 0;
}
Problem p02630 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[10005];
  long long ans = 0;
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
    ans += a[i];
  }
  int q, be, af;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> be >> af;
    ans += (af - be) * b[be];
    b[af] += b[be];
    b[be] = 0;
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  int b[100005];
  long long ans = 0;
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[a[i]]++;
    ans += a[i];
  }
  int q, be, af;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> be >> af;
    ans += (af - be) * b[be];
    b[af] += b[be];
    b[be] = 0;
    cout << ans << endl;
  }
  return 0;
}
Problem p02630 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, n) for (int i = 1; i <= (int)n; i++) // i=1からi=nまで
#define RREP(i, n) for (int i = n; i >= 1; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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() {
  int N, Q;
  cin >> N;
  vector<int> A(N + 1);
  ll ans = 0;
  map<int, int> cnt;
  REP(i, N) {
    cin >> A[i];
    ans += A[i];
    cnt[A[i]]++;
  }
  cin >> Q;
  vector<int> B(N + 1);
  vector<int> C(N + 1);
  REP(i, Q) { cin >> B[i] >> C[i]; }
  REP(i, Q) {
    if (cnt[B[i]] != 0) {
      ans += (C[i] - B[i]) * cnt[B[i]];
      cnt[C[i]] += cnt[B[i]];
      cnt[B[i]] = 0;
      cout << ans << endl;

    } else {
      cout << ans << endl;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, n) for (int i = 1; i <= (int)n; i++) // i=1からi=nまで
#define RREP(i, n) for (int i = n; i >= 1; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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() {
  int N, Q;
  cin >> N;
  vector<int> A(N + 1);
  ll ans = 0;
  map<int, int> cnt;
  REP(i, N) {
    cin >> A[i];
    ans += A[i];
    cnt[A[i]]++;
  }
  cin >> Q;
  vector<int> B(Q + 1);
  vector<int> C(Q + 1);
  REP(i, Q) { cin >> B[i] >> C[i]; }
  REP(i, Q) {
    if (cnt[B[i]] != 0) {
      ans += (C[i] - B[i]) * cnt[B[i]];
      cnt[C[i]] += cnt[B[i]];
      cnt[B[i]] = 0;
      cout << ans << endl;

    } else {
      cout << ans << endl;
    }
  }
}
Problem p02630 (C++)

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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

lint P(lint n, lint k) {
  if (k == 1) {
    return n;
  }
  return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007);
}

int main() {
  lint n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  lint q;
  cin >> q;
  vector<lint> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }

  lint sum = 0;
  vector<lint> d(n, 0);
  for (int i = 0; i < n; i++) {
    sum += a[i];
    d[a[i] - 1]++;
  }

  for (int i = 0; i < q; i++) {
    sum += (c[i] - b[i]) * d[b[i] - 1];
    d[c[i] - 1] += d[b[i] - 1];
    d[b[i] - 1] = 0;
    cout << sum << endl;
  }
  return 0;
}


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

lint gcd(lint x, lint y) {
  if (x == 0) {
    return y;
  } else {
    return gcd(y % x, x);
  }
}

lint lcm(lint x, lint y) { return x / gcd(x, y) * y; }

lint C(lint n, lint k) {
  if (n == k) {
    return 1;
  } else if (n < k) {
    return 0;
  } else if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else
    return C(n - 1, k - 1) + C(n - 1, k);
}

lint P(lint n, lint k) {
  if (k == 1) {
    return n;
  }
  return (n * (P(n - 1, k - 1) % 1000000007) % 1000000007);
}

int main() {
  lint n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  lint q;
  cin >> q;
  vector<lint> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }

  lint sum = 0;
  vector<lint> d(100000, 0);
  for (int i = 0; i < n; i++) {
    sum += a[i];
    d[a[i] - 1]++;
  }

  for (int i = 0; i < q; i++) {
    sum += (c[i] - b[i]) * d[b[i] - 1];
    d[c[i] - 1] += d[b[i] - 1];
    d[b[i] - 1] = 0;
    cout << sum << endl;
  }
  return 0;
}
Problem p02630 (C++)

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

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(n + 1);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<ll> bc(q + 1);
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    bc[i] = (c - b) * cnt[b];
    // cout << (c - b) * cnt[b] << '/';
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  // cout << endl;
  vector<ll> ans(q);
  ans[0] = bc[1] + sum;
  for (int i = 1; i < q; i++) {
    ans[i] = ans[i - 1] + bc[i + 1];
  }
  rep(i, q) cout << ans[i] << endl;
}


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

typedef pair<int, int> p;
typedef long long ll;

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(100005);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<ll> bc(q + 1);
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    bc[i] = (c - b) * cnt[b];
    // cout << (c - b) * cnt[b] << '/';
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
  // cout << endl;
  vector<ll> ans(q);
  ans[0] = bc[1] + sum;
  for (int i = 1; i < q; i++) {
    ans[i] = ans[i - 1] + bc[i + 1];
  }
  rep(i, q) cout << ans[i] << endl;
}
Problem p02631 (C++)

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

typedef long long int ll;
typedef long double ld;

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pll pair<ll, ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i, start, end) for (ll i = start; i <= end; i++)
#define deb1(a) cout << #a << " = " << (a) << endl;
#define deb2(a, b)                                                             \
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl;
#define deb3(a, b, c)                                                          \
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \
       << " = " << (c) << endl;

ll modu(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return ans;
}

int main() {
  fastio ll n;
  ll a[n];
  ll al;
  cin >> a[0] >> a[1];
  al = a[0] ^ a[1];
  lp(i, 2, n - 1) {
    cin >> a[i];
    al = al ^ a[i];
  }
  for (ll i = 0; i < n; i++)
    cout << (al ^ a[i]) << " ";
  cout << endl;

  return 0;
}


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

typedef long long int ll;
typedef long double ld;

#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pll pair<ll, ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i, start, end) for (ll i = start; i <= end; i++)
#define deb1(a) cout << #a << " = " << (a) << endl;
#define deb2(a, b)                                                             \
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl;
#define deb3(a, b, c)                                                          \
  cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c       \
       << " = " << (c) << endl;

ll modu(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = (ans * a) % mod;
    b /= 2;
    a = (a * a) % mod;
  }
  return ans;
}

int main() {
  fastio ll n;
  cin >> n;
  ll a[n];
  ll al;
  cin >> a[0] >> a[1];
  al = a[0] ^ a[1];
  lp(i, 2, n - 1) {
    cin >> a[i];
    al = al ^ a[i];
  }
  for (ll i = 0; i < n; i++)
    cout << (al ^ a[i]) << " ";
  cout << endl;

  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN = 301;
const int MAXK = 19;
const int INF = 1e9;
const ll MOD = 998244353;

ll N, a, b, c, d, e, f;
ll A[MAXN];
ll B[MAXN];

int main() {
  cin >> N;
  ll T = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    T ^= A[i];
  }
  for (int i = 1; i <= N; ++i)
    cout << (T ^ A[i]) << ' ';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MAXN = 200100;
const int MAXK = 19;
const int INF = 1e9;
const ll MOD = 998244353;

ll N, a, b, c, d, e, f;
ll A[MAXN];
ll B[MAXN];

int main() {
  cin >> N;
  ll T = 0;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    T ^= A[i];
  }
  for (int i = 1; i <= N; ++i)
    cout << (T ^ A[i]) << ' ';
}
Problem p02631 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]


ans = []
for i in range(n):
    temp = 0
    for j, aa in enumerate(a):
        if j == i:
            continue
        temp = temp ^ aa
    ans.append(temp)

ans = [str(i) for i in ans]
print(" ".join(ans))


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]


ans = []
alld = 0

for aa in a:
    alld = alld ^ aa

for aa in a:
    ans.append(alld ^ aa)

ans = [str(i) for i in ans]
print(" ".join(ans))
Problem p02631 (C++)

Buggy submission (status: Runtime Error):

// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x)                                                                \
  freopen(x ".in", "r", stdin);                                                \
  freopen(x ".out", "w", stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

inline int gi() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return f * x;
}

inline LL gl() {
  LL f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, m;
int a[N];

signed main() {
  // File("");
  n = gi();
  int sum = 0;
  for (int i = 1; i <= n; i += 1)
    a[i] = gi(), sum ^= a[i];
  for (int i = 1; i <= n; i += 1)
    cout << (sum ^ a[i]) << ' ';
  return 0;
}

Fixed submission:

// Problem : E - Red Scarf
// Contest : AtCoder - AtCoder Beginner Contest 171
// URL : https://atcoder.jp/contests/abc171/tasks/abc171_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x)                                                                \
  freopen(x ".in", "r", stdin);                                                \
  freopen(x ".out", "w", stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

inline int gi() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return f * x;
}

inline LL gl() {
  LL f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return f * x;
}

const int INF = 0x3f3f3f3f, N = 1000003, M = N << 1;

int n, m;
int a[N];

signed main() {
  // File("");
  n = gi();
  int sum = 0;
  for (int i = 1; i <= n; i += 1)
    a[i] = gi(), sum ^= a[i];
  for (int i = 1; i <= n; i += 1)
    cout << (sum ^ a[i]) << ' ';
  return 0;
}
Problem p02631 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
# b = np.bitwise_xor.reduce(a)
# c = np.bitwise_xor(a, b)
# print(*c, sep=" ")
for n in range(N):
    print(np.bitwise_xor.reduce(a) ^ a[n])


Fixed submission:
import numpy as np

N = int(input())
a = np.fromstring(input(), sep=" ", dtype=np.int64)
b = np.bitwise_xor.reduce(a)
c = np.bitwise_xor(a, b)
print(*c, sep=" ")
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
// Apparat : drobucs, aleonov, vit_72
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

// #pragma warning(disable : 4996)
// #pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cout.tie(0);                                                                 \
  cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef long long ll;

const int maxn = (int)1e5 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7,
         MOD2 = 998244353; // 1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;

int a[maxn];
int main() {
  drobucs;

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int xr = 0;
  for (int i = 1; i <= n; ++i)
    xr ^= a[i];
  for (int i = 1; i <= n; ++i)
    cout << (xr ^ a[i]) << " ";
  return 0;
}

Fixed submission:
// Apparat : drobucs, aleonov, vit_72
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

// #pragma warning(disable : 4996)
// #pragma GCC optimize("O3")

using namespace std;

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cout.tie(0);                                                                 \
  cin.tie(0);
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)(x).size()

typedef long long ll;

const int maxn = (int)2e5 + 13;
const ll INFL = 9223372036854775807;
const ll INF = 2147483647;
const ll MOD = (int)1e9 + 7,
         MOD2 = 998244353; // 1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;

int a[maxn];
int main() {
  drobucs;

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  int xr = 0;
  for (int i = 1; i <= n; ++i)
    xr ^= a[i];
  for (int i = 1; i <= n; ++i)
    cout << (xr ^ a[i]) << " ";
  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <vector>
#define ll long long
#define N 100005
#define inf 1000000000
using namespace std;
int n;
int a[N], c[N];
int q;
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), sum ^= a[i];
  for (int i = 1; i <= n; ++i)
    printf("%d ", a[i] ^ sum);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <vector>
#define ll long long
#define N 200005
#define inf 1000000000
using namespace std;
int n;
int a[N], c[N];
int q;
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), sum ^= a[i];
  for (int i = 1; i <= n; ++i)
    printf("%d ", a[i] ^ sum);
  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  int a[100000];
  int s = 0;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    s ^= a[i];
  }
  rep(i, n) {
    cout << (s ^ a[i]);
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}

Fixed submission:
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  int a[200000];
  int s = 0;
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    s ^= a[i];
  }
  rep(i, n) {
    cout << (s ^ a[i]);
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
#define mod 1000000007

int solve(int A[], int n) {
  int i;
  int B[n];
  int x = 0;
  for (i = 0; i < n; i++)
    x = x ^ A[i];

  for (i = 0; i < n; i++) {
    B[i] = x ^ A[i];
  }

  for (i = 0; i < n; i++)
    cout << B[i] << " ";
  cout << endl;
}

int32_t main() {
  // code
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t, n, w, k, x, i;
  // cin>>t;
  t = 1;
  while (t--) {
    cin >> n;
    int A[n];

    for (i = 0; i < n; i++)
      cin >> A[i];

    solve(A, n);
  }

  return 0;
}

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

void solve(int A[], int n) {
  int i;
  int B[n];
  int x = 0;
  for (i = 0; i < n; i++)
    x = x ^ A[i];

  for (i = 0; i < n; i++) {
    B[i] = x ^ A[i];
  }

  for (i = 0; i < n; i++)
    cout << B[i] << " ";
  cout << endl;
}

int32_t main() {
  // code
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int t, n, w, k, x, i;
  // cin>>t;
  t = 1;
  while (t--) {
    cin >> n;
    int A[n];

    for (i = 0; i < n; i++)
      cin >> A[i];

    solve(A, n);
  }

  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n;
vll a;

void input() {
  cin >> n;
  rep(i, n) {
    ll A;
    cin >> A;
    a.push_back(A);
  }
}

void solve() {
  ll M = 0;
  rep(i, n) { M = max(M, a[i]); }
  ll m = (ll)floor(log2((ld)M)) + 1;
  vvll b(n, vll(m));
  rep(i, n) {
    for (ll j = m - 1; j >= 0; j--) {
      b[i][j] = a[i] % 2;
      a[i] /= 2;
    }
  }
  /*
  rep(i,n){
    rep(j,m){
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
  */
  vll c(m, 0);
  rep(j, m) {
    rep(i, n) { c[j] += b[i][j]; }
    // cout << c[j] << " ";
  }
  rep(j, m) {
    if (c[j] % 2 == 1) {
      rep(i, n) { b[i][j] = (b[i][j] + 1) % 2; }
    }
  }
  rep(i, n) {
    ll s = 0;
    rep(j, m) { s += (ll)pow(2, m - j - 1) * b[i][j]; }
    cout << s;
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}

int main() {
  input();
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define pll pair<long long, long long>
using namespace std;
using ll = long long;
using ld = long double;

// グローバル変数（入力）
ll n;
vll a;

void input() {
  cin >> n;
  rep(i, n) {
    ll A;
    cin >> A;
    a.push_back(A);
  }
}

void solve() {
  ll M = 0;
  rep(i, n) { M = max(M, a[i]); }
  ll m;
  if (M != 0) {
    m = (ll)floor(log2((ld)M)) + 1;
  } else {
    m = 0;
  }
  // cout << "m:" << m << endl;
  vvll b(n, vll(m));
  rep(i, n) {
    for (ll j = m - 1; j >= 0; j--) {
      b[i][j] = a[i] % 2;
      a[i] /= 2;
    }
  }
  /*
  rep(i,n){
    rep(j,m){
      cout << b[i][j] << " ";
    }
    cout << endl;
  }
  */
  vll c(m, 0);
  rep(j, m) {
    rep(i, n) { c[j] += b[i][j]; }
    // cout << c[j] << " ";
  }
  rep(j, m) {
    if (c[j] % 2 == 1) {
      rep(i, n) { b[i][j] = (b[i][j] + 1) % 2; }
    }
  }
  rep(i, n) {
    ll s = 0;
    rep(j, m) { s += (ll)pow(2, m - j - 1) * b[i][j]; }
    cout << s;
    if (i != n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}

int main() {
  input();
  solve();
  return 0;
}
Problem p02631 (C++)

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

#define FAST                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define ll long long int
ll mod = 1000000007;
ll a[MAXX], b[MAXX];
char str[MAXX];

int main() {
  FAST;
  ll n, k, ans = 0;
  cin >> n;
  cin >> a[0];
  k = a[0];
  for (ll i = 1; i < n; i++) {
    cin >> a[i];
    k ^= a[i];
  }
  for (ll i = 0; i < n; i++) {
    ll t = k;
    t ^= a[i];
    cout << t << " ";
  }
}

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

#define FAST                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie();                                                                   \
  cout.tie();

#define MAXX 200020

#define PI 3.14159265358979323846264338327950

#define ll long long int
ll mod = 1000000007;
ll a[MAXX], b[MAXX];
char str[MAXX];

int main() {
  FAST;
  ll n, k, ans = 0;
  cin >> n;
  cin >> a[0];
  k = a[0];
  for (ll i = 1; i < n; i++) {
    cin >> a[i];
    k ^= a[i];
  }
  for (ll i = 0; i < n; i++) {
    ll t = k;
    t ^= a[i];
    cout << t << " ";
  }
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read() {
  ll a = 0, b = getchar(), c = 1;
  while (!isdigit(b))
    c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b))
    a = a * 10 + b - '0', b = getchar();
  return a * c;
}
ll n, ans, a[100005];
int main() {
  n = read();
  for (int i = 0; i < n; i++)
    a[i] = read(), ans ^= a[i];
  for (int i = 0; i < n; i++)
    printf("%lld ", ans ^ a[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read() {
  ll a = 0, b = getchar(), c = 1;
  while (!isdigit(b))
    c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b))
    a = a * 10 + b - '0', b = getchar();
  return a * c;
}
ll n, ans, a[200005];
int main() {
  n = read();
  for (int i = 0; i < n; i++)
    a[i] = read(), ans ^= a[i];
  for (int i = 0; i < n; i++)
    printf("%lld ", ans ^ a[i]);
  return 0;
}
Problem p02631 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mp make_pair
#define mm(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repn(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k, m) for (auto k : m)
#define in_edges(m)                                                            \
  repp(i, 1, m) {                                                              \
    ll a, b;                                                                   \
    cin >> a >> b;                                                             \
    adj[a].pb(b), adj[b].pb(a);                                                \
  }
#define debug(this) cerr << "> " << #this << " : " << this << "\n"
#define MOD 1000000007
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define quick                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
// stoll(s);
int main() {
  quick ll t;
  t = 1;
  // cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) { cin >> a[i]; }
    ll k = 0;
    vector<ll> ans;
    rep(i, 0, n) {
      k = 0;
      rep(j, 0, n) {
        if (j == i)
          continue;
        k ^= a[j];
      }
      ans.pb(k);
    }
    fto(j, ans) cout << j << " ";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mp make_pair
#define mm(a) memset(a, 0, sizeof(a))
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repn(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define fto(k, m) for (auto k : m)
#define in_edges(m)                                                            \
  repp(i, 1, m) {                                                              \
    ll a, b;                                                                   \
    cin >> a >> b;                                                             \
    adj[a].pb(b), adj[b].pb(a);                                                \
  }
#define debug(this) cerr << "> " << #this << " : " << this << "\n"
#define MOD 1000000007
#define sz(a) ll((a).size())
#define pii 3.1415926535897
#define quick                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
// stoll(s);
int main() {
  quick ll t;
  t = 1;
  // cin >> t;
  while (t--) {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, 0, n) { cin >> a[i]; }
    ll k = 0;
    vector<ll> ans;
    rep(i, 0, n) { k ^= a[i]; }
    rep(i, 0, n) { ans.pb(k ^ a[i]); }
    fto(k, ans) cout << k << " ";
  }
}
Problem p02631 (C++)

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

int main() {
  int N;
  int i, j;
  cin >> N;
  vector<int> a(N);
  for (i = 0; i < N; i++)
    cin >> a[i];
  for (i = 0; i < N; i++) {
    bitset<32> ans;
    for (j = 0; j < N; j++)
      if (i != j)
        ans ^= a[j];
    cout << ans.to_ullong() << " ";
  }
  cout << endl;
}


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

int main() {
  int N;
  int i, j;
  cin >> N;
  vector<int> a(N);
  for (i = 0; i < N; i++)
    cin >> a[i];
  bitset<32> ans;
  for (i = 1; i < N; i++)
    ans ^= a[i];
  cout << ans.to_ullong() << " ";
  for (i = 1; i < N; i++) {
    ans ^= a[i];
    ans ^= a[i - 1];
    cout << ans.to_ullong() << " ";
  }
  cout << endl;
}
Problem p02631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n, a[100005], q, sum = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum ^ a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (a[i] ^ sum);
    cout << " ";
  }

  cout << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
  ll n, a[200005], q, sum = 0;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum ^ a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (a[i] ^ sum);
    cout << " ";
  }

  cout << "\n";
  return 0;
}