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

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[10005], ans;
bool vis[10005];
inline int get() {
  char c;
  int x = 0, p = 1;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * p;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++)
      if (!vis[j])
        ans++, vis[j] = 1;
  }
  printf("%d", ans);
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[10005], ans;
bool vis[100005];
inline int get() {
  char c;
  int x = 0, p = 1;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * p;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &x, &y);
    for (int j = x; j <= y; j++)
      if (!vis[j])
        ans++, vis[j] = 1;
  }
  printf("%d", ans);
}
Problem p03606 (C++)

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

int main(void) {
  int N;
  cin >> N;
  int l[2], r[2];
  for (int i = 0; i < N; i++)
    cin >> l[i] >> r[i];

  int count = 0;
  for (int i = 0; i < N; i++) {
    count += ((r[i] - l[i]) + 1);
  }

  cout << count;
}


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

int main(void) {
  int N;
  cin >> N;
  int l[1100], r[1100];
  for (int i = 0; i < N; i++)
    cin >> l[i] >> r[i];

  int count = 0;
  for (int i = 0; i < N; i++) {
    count += ((r[i] - l[i]) + 1);
  }

  cout << count;
}
Problem p03606 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int anser = N;
  vector<int> vea;
  vector<int> veb;
  for (int i = 0; i < N; i++) {
    cin >> vea.at(i) >> veb.at(i);
  }
  for (int i = 0; i < N; i++) {
    anser += (veb.at(i) - vea.at(i));
  }
  cout << anser << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int anser = N;
  vector<int> vea(N);
  vector<int> veb(N);
  for (int i = 0; i < N; i++) {
    cin >> vea.at(i) >> veb.at(i);
  }
  for (int i = 0; i < N; i++) {
    anser += (veb.at(i) - vea.at(i));
  }
  cout << anser << endl;
}
Problem p03607 (C++)

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

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (i = (a); i < (b); i++)
#define bitget(a, b) (((a) >> (b)) & 1)

using namespace std;

int i, j, k;

int main() {
  int n;
  int a[100000];
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  unsigned int b[31000000] = {};
  int ans = 0;
  rep(i, 0, n) {
    if (bitget(b[a[i] / 32], a[i] % 32) == 0) {
      b[a[i] / 32] = b[a[i] / 32] + (1 << (a[i]) % 32);
      ans++;
    } else {
      b[a[i] / 32] = b[a[i] / 32] - (1 << (a[i]) % 32);
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <array>
#include <iostream>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (i = (a); i < (b); i++)
#define bitget(a, b) (((a) >> (b)) & 1)

using namespace std;

int i, j, k;

int main() {
  int n;
  int a[100000];
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  unsigned int b[40000000] = {};
  int ans = 0;
  rep(i, 0, n) {
    if (bitget(b[a[i] / 32], a[i] % 32) == 0) {
      b[a[i] / 32] = b[a[i] / 32] + (1 << (a[i]) % 32);
      ans++;
    } else {
      b[a[i] / 32] = b[a[i] / 32] - (1 << (a[i]) % 32);
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, m;
  cin >> N;
  m = N;
  vector<int> a;
  int Max = 0;
  while (N--) {
    int x;
    scanf("%d", &x);

    // if(find(a.begin(),a.end(),x) == a.end() || (Max < x)){
    a.push_back(x);
    // Max = max(x,Max);
    //}else{
    // a.erase(find(a.begin(),a.end(),x));
    //}
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < a.end() - a.begin(); i++) {
    if (a[i] == a[i + 1]) {
      a.erase(a.begin() + i);
      a.erase(a.begin() + i);
      i--;
      m -= 2;
    }
  }
  cout << m << endl;
  return 0;
}


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, m;
  cin >> N;
  m = N;
  vector<int> a;
  int Max = 0;
  while (N--) {
    int x;
    scanf("%d", &x);

    // if(find(a.begin(),a.end(),x) == a.end() || (Max < x)){
    a.push_back(x);
    // Max = max(x,Max);
    //}else{
    // a.erase(find(a.begin(),a.end(),x));
    //}
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < a.end() - a.begin() - 1; i++) {
    if (a[i] == a[i + 1]) {
      a.erase(a.begin() + i);
      a.erase(a.begin() + i);
      i--;
      m -= 2;
    }
  }
  cout << m << endl;
  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp __builtin_popcount
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
const double EPS = 1e-14;
const int MOD = 1e9 + 7;
ll fact(int c) {
  if (c == 1 || c == 0)
    return 1;
  else
    return c * fact(c - 1);
}
ll npr(int a, int b) { return (fact(a) / fact(a - b)); }
ll ncr(int a, int b) { return (fact(a) / (fact(b) * fact(a - b))); }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (s.count(x))
      s.erase(x);
    else
      s.insert(x);
  }
  cout << (int)s.size();
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp __builtin_popcount
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
const double EPS = 1e-14;
const int MOD = 1e9 + 7;
ll fact(int c) {
  if (c == 1 || c == 0)
    return 1;
  else
    return c * fact(c - 1);
}
ll npr(int a, int b) { return (fact(a) / fact(a - b)); }
ll ncr(int a, int b) { return (fact(a) / (fact(b) * fact(a - b))); }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  /*#ifndef ONLINE_JUDGE
      freopen("in.txt", "r", stdin);
  #endif*/
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    if (s.count(x))
      s.erase(x);
    else
      s.insert(x);
  }
  cout << (int)s.size();
}
Problem p03607 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> mp;
  REP(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ll ans = 0;
  REP(i, mp.size()) {
    if (mp[i] % 2)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  SORT(a, n);

  ll ans = 0, cnt = 1;

  REP(i, n - 1) {
    if (a[i + 1] == a[i])
      cnt++;
    else {
      if (cnt % 2)
        ans++;
      cnt = 1;
    }
    if (i == n - 2 && cnt % 2)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long int> A;
  for (int i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    A.push_back(a);
  }

  map<long long int, int> m;
  for (int i = 0; i < N; i++) {
    m[A[i]] = 0;
  }
  for (int i = 0; i < N; i++) {
    m[A[i]]++;
  }
  vector<long long int> S;
  sort(A.begin(), A.end());
  S.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    if (A[i] != A[i - 1])
      S.push_back(A[i]);
  }
  int cnt = 0;
  for (int i = 0; i < A.size(); i++) {
    if (m[S[i]] % 2 != 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long int> A;
  for (int i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    A.push_back(a);
  }

  map<long long int, int> m;
  for (int i = 0; i < N; i++) {
    m[A[i]] = 0;
  }
  for (int i = 0; i < N; i++) {
    m[A[i]]++;
  }
  vector<long long int> S;
  sort(A.begin(), A.end());
  S.push_back(A[0]);
  for (int i = 1; i < N; i++) {
    if (A[i] != A[i - 1])
      S.push_back(A[i]);
  }
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (m[S[i]] % 2 != 0)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}
Problem p03607 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
ans = 0
A_list = [int(input()) for i in range(N)]
A_set = set(A_list)
for i in A_set:
    if A_list.count(i) % 2 == 1:
        ans += 1
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
from itertools import permutations, combinations
from fractions import gcd
from collections import Counter
from math import sqrt
import sys

input = sys.stdin.readline


def lcm(x, y):
    return x * y // gcd(x, y)


def small_letters():
    return [chr(i) for i in range(97, 97 + 26)]


def capital_letters():
    return [chr(i) for i in range(65, 65 + 26)]


def main():
    """ここに書いてね"""
    N = int(input())
    A_list = [int(input()) for i in range(N)]
    ans = 0
    counter = Counter(A_list)
    for i in counter.values():
        if i % 2 == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()
Problem p03607 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans: int = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()


Fixed submission:
from collections import Counter


def main():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    counter = Counter(a)
    ans = 0
    for key, value in counter.items():
        if value % 2 == 1:
            ans += 1
    print(ans)


main()
Problem p03607 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
print(len(m))


Fixed submission:
n = int(input())
m = set()
while n:
    x = int(input())
    if x in m:
        m.remove(x)
    else:
        m.add(x)
    n -= 1
print(len(m))
Problem p03607 (Python)

Buggy submission (status: Time Limit Exceeded):
import collections

N = int(input())
A = [int(input()) for i in range(N)]

Adic = collections.Counter(A)

B = [n % 2 for n in Adic.values()]

while 0 in B:
    B.remove(0)

print(len(B))


Fixed submission:
import collections

N = int(input())
A = [int(input()) for i in range(N)]

Adic = collections.Counter(A)

B = [n % 2 for n in Adic.values()]

print(B.count(1))
Problem p03607 (Python)

Buggy submission (status: Runtime Error):
from collections import Counter

N = int(input())
A = [int(input()) for _ in range(N)]
c = Counter(A)
print(len([i for i in c if c.values(i) % 2 == 1]))


Fixed submission:
from collections import Counter

N = int(input())
A = [int(input()) for _ in range(N)]
c = Counter(A).values()

print(len([i for i in c if i % 2 == 1]))
Problem p03607 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    if a in A:
        A[a] += 1
    else:
        A[a] = 1
ans = 0
for val in A.values:
    ans += val % 2
print(ans)


Fixed submission:
N = int(input())
A = {}
for i in range(N):
    a = int(input())
    if a in A:
        A[a] += 1
    else:
        A[a] = 1
ans = 0
for val in A.values():
    ans += val % 2
print(ans)
Problem p03607 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
s = set()

for i in range(n):
    s = {input()} ^ s

print(len(s))


Fixed submission:
n = int(input())
s = set()

for i in range(n):
    s ^= {int(input())}

print(len(s))
Problem p03607 (C++)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A)) / (sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
  fastio;

  int n;
  cin >> n;
  set<ll> A;
  FOR(i, 0, n) {
    int x;
    cin >> x;
    if (count(A.begin(), A.end(), x)) {
      A.erase(x);
    } else {
      A.insert(x);
    }
  }
  cout << A.size() << "\n";
  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A)) / (sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
const ll MOD = 1e9 + 7;

int main() {
  fastio;

  int n;
  cin >> n;
  set<ll> A;
  FOR(i, 0, n) {
    int x;
    cin >> x;
    if (A.count(x)) {
      A.erase(x);
    } else {
      A.insert(x);
    }
  }
  cout << A.size() << "\n";
  return 0;
}
Problem p03607 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (vec.at(i) == vec.at(j)) {
        vec.at(i) = 0;
        vec.at(j) = 0;
        break;
      }
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) != 0) {
      count++;
    }
  }
  cout << count << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < n - 1; i++) {
    if (vec.at(i) == vec.at(i + 1)) {
      vec.at(i) = 0;
      vec.at(i + 1) = 0;
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (vec.at(i) != 0) {
      count++;
    }
  }
  cout << count << endl;
}
Problem p03607 (C++)

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

int main() {
  long long int a, b[a], c, d, e, f, g, h, i;
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  d = 0;
  g = 0;
  while (i < a) {
    c = b[i], e = 0;
    while (i < a && c == b[i])
      e++, i++;
    g += e % 2;
  }
  cout << g << endl;

  return 0;
}


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

int main() {
  long long int a, b[1000010], c, d, e, f, g, h, i;
  cin >> a;

  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  d = 0;
  g = 0;
  while (i < a) {
    c = b[i], e = 0;
    while (i < a && c == b[i])
      e++, i++;
    g += e % 2;
  }
  cout << g << endl;

  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int ans = 0;
  for (auto i = 0; i < mp.size(); i++) {
    if (mp[i] % 2)
      ans++;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for ((i) = 0; (i) < (int)(n); (i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int ans = 0;
  for (auto i : mp) {
    if (i.second % 2)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  int sum = n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j])
        sum -= 2;
    }
  }
  printf("%d\n", sum);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  int sum = n;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  /*	for(int i=1;i<n;i++){
                  for(int j=i+1;j<=n;j++){
                          if (a[i]==a[j])
                                  sum-=2;
                  }
          }*/
  sort(a + 1, a + 1 + n);
  for (int i = n; i >= 2; i--) {
    if (a[i] == a[i - 1]) {
      sum -= 2;
      i--;
    }
  }
  printf("%d\n", sum);
  return 0;
}
Problem p03607 (C++)

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

int main(void) {
  int n, a, b;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
    auto itr = find(v.begin(), v.end(), a);
    if (itr == v.end()) {
      v.push_back(a);
    } else {
      v.erase(itr);
    }
  }
  sort(v.begin(), v.end());
  a = b = 0;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] == v[i + 1]) {
      a++;
    } else {
      if (a % 2) {
      } else {
        b++;
      }
      a = 0;
    }
  }
  if (a % 2) {
  } else {
    b++;
  }
  cout << b << endl;
  return 0;
}

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

int main(void) {
  int n, a, b;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  a = b = 0;
  for (int i = 0; i < n - 1; i++) {
    if (v[i] == v[i + 1]) {
      a++;
    } else {
      if (a % 2) {
      } else {
        b++;
      }
      a = 0;
    }
  }
  if (a % 2) {
  } else {
    b++;
  }
  cout << b << endl;
  return 0;
}
Problem p03607 (C++)

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

using namespace std;

#define max_n 10000

int main() {
  int n;
  int a[max_n];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  int index = 0;
  int ret = 0;
  while (index < n) {
    int num = 0;
    int tmp = a[index];
    while (index < n && a[index] == tmp) {
      num++;
      index++;
    }
    ret += num % 2;
  }
  cout << ret << endl;

  return 0;
}


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

using namespace std;

#define max_n 100000

int main() {
  int n;
  int a[max_n];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);

  int index = 0;
  int ret = 0;
  while (index < n) {
    int num = 0;
    int tmp = a[index];
    while (index < n && a[index] == tmp) {
      num++;
      index++;
    }
    ret += num % 2;
  }
  cout << ret << endl;

  return 0;
}
Problem p03607 (C++)

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

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

  bitset<1000000000> a(0);
  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if (a[tmp] == 1) {
      a.reset(tmp);
    } else {
      a.set(tmp);
    }
  }
  cout << a.count() << endl;
}


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

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

  bitset<1000000001> a(0);
  for (ll i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    if (a[tmp] == 1) {
      a.reset(tmp);
    } else {
      a.set(tmp);
    }
  }
  cout << a.count() << endl;
}
Problem p03607 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
bool num[1000000005];
int main() {
  long long n, a, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (num[a] == 0) {
      ans++;
      num[a] = 1;
    } else {
      ans--;
      num[a] = 0;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
map<int, int> num;
int main() {
  long long n, a, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (num[a] == 0) {
      ans++;
      num[a] = 1;
    } else {
      ans--;
      num[a] = 0;
    }
  }
  cout << ans;
  return 0;
}
Problem p03607 (C++)

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main() {
  int N;
  scanf("%d", &N);
  vector<int> v(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &v[i]);
  }
  sort(v.begin(), v.end());
  int ans = 0, i = 0;
  while (i < N) {
    int pos = find_if_not(v.begin() + i, v.end(),
                          [v, i](int val) -> bool { return v[i] == val; }) -
              v.begin();
    ans += (pos - i) % 2;
    i = pos;
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main() {
  int N;
  scanf("%d", &N);
  vector<int> v(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &v[i]);
  }
  sort(v.begin(), v.end());
  int ans = 0, i = 0;
  while (i < N) {
    int j = i + 1;
    while (v[j] == v[i] and j < N) {
      ++j;
    }
    ans += (j - i) % 2;
    i = j;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03607 (C++)

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

using namespace std;

int main(void) {
  int N = 0, temp = 0;
  cin >> N;
  unordered_set<int> myset;
  std::unordered_set<int>::iterator it;

  for (int i = 0; i < N; i++) {
    cin >> temp;
    it = myset.find(temp);
    if (it != myset.end()) {
      myset.insert(temp);
    } else {
      myset.erase(it);
    }
  }
  cout << myset.size();

  return 0;
}

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

using namespace std;

int main(void) {
  int N = 0, temp = 0;
  cin >> N;
  unordered_set<int> myset;
  std::unordered_set<int>::iterator it;

  for (int i = 0; i < N; i++) {
    cin >> temp;
    it = myset.find(temp);
    if (it == myset.end()) {
      myset.insert(temp);
    } else {
      myset.erase(it);
    }
  }
  cout << myset.size();

  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
int n, a[100000], ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0, j = 0; i < n; i + j) {
    while (a[i] == a[j] && j < n)
      j++;
    if ((j - i) % 2)
      ans++;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int n, a[100000], ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0, j = 0; i < n; i = j) {
    while (a[i] == a[j] && j < n)
      j++;
    if ((j - i) % 2)
      ans++;
  }
  cout << ans;
  return 0;
}
Problem p03607 (C++)

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

using namespace std;

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

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

  int a;
  vi value;
  int it;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (value.size() == 0) {
      value.push_back(a);
      continue;
    }
    it = lower_bound(value.begin(), value.end(), a) - value.begin();
    if (value[it] == a)
      value.erase(value.begin() + it);
    else
      value.insert(value.begin() + it, a);
  }

  cout << value.size() << endl;

  return 0;
}

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

using namespace std;

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

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

  int a;
  vi value;
  int it;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (value.size() == 0) {
      value.push_back(a);
      continue;
    }
    it = lower_bound(value.begin(), value.end(), a) - value.begin();
    if (it == value.size()) {
      value.push_back(a);
      continue;
    }
    if (value[it] == a)
      value.erase(value.begin() + it);
    else
      value.insert(value.begin() + it, a);
  }

  cout << value.size() << endl;

  return 0;
}
Problem p03607 (C++)

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

int main() {
  int a, c, d, e;
  c = 0;
  cin >> a;
  vector<int> b(a);
  for (int i = 0; i < a; i++) {
    cin >> b.at(i);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < a; i = i) {
    e = b.at(i);
    d = 0;
    for (int j = 0; i < a && b.at(i) == e; j = j) {
      d++;
    }
    c += d % 2;
  }
  cout << c << endl;
}

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

int main() {
  int a, c, d, e;
  c = 0;
  cin >> a;
  vector<int> b(a);
  for (int i = 0; i < a; i++) {
    cin >> b.at(i);
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < a; i = i) {
    e = b.at(i);
    d = 0;
    for (int j = 0; i < a && b.at(i) == e; j = j) {
      d++;
      i++;
    }
    c += d % 2;
  }
  cout << c << endl;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
signed main() {
  int N;
  cin >> N;
  bitset<1000000000> A;
  rep(i, 0, N) {
    int X;
    cin >> X;
    A.flip(X);
  }
  cout << A.count();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
signed main() {
  int N;
  cin >> N;
  bitset<1000000000> A;
  rep(i, 0, N) {
    int X;
    cin >> X;
    A.flip(X - 1);
  }
  cout << A.count();
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[10005], ans;
bool vis[100005];
inline int get() {
  char c;
  int x = 0, p = 1;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * p;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  ans = 1;
  int flag = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1] && flag == 0)
      ans--, flag = 1;
    else if (a[i] != a[i - 1] || flag == 1)
      ans++, flag = 0;
  }
  printf("%d", ans);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a[100005], ans;
bool vis[100005];
inline int get() {
  char c;
  int x = 0, p = 1;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * p;
}
int main() {
  int n, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a + 1, a + n + 1);
  ans = 1;
  int flag = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] == a[i - 1] && flag == 0)
      ans--, flag = 1;
    else if (a[i] != a[i - 1] || flag == 1)
      ans++, flag = 0;
  }
  printf("%d", ans);
}
Problem p03607 (C++)

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

#define MAX 1000000000

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[MAX];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  int currCount = 1;
  for (int i = 1; i < n; ++i)
    if (a[i] == a[i - 1])
      ++currCount;
    else {
      if (currCount % 2 == 1)
        ++ans;
      currCount = 1;
    }
  if (currCount % 2 == 1)
    ++ans;
  cout << ans;
  return 0;
}

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

#define MAX 100000

using namespace std;

int main() {
  int n;
  cin >> n;
  int a[MAX];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  int currCount = 1;
  for (int i = 1; i < n; ++i)
    if (a[i] == a[i - 1])
      ++currCount;
    else {
      if (currCount % 2 == 1)
        ++ans;
      currCount = 1;
    }
  if (currCount % 2 == 1)
    ++ans;
  cout << ans;
  return 0;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  v[n] = 1000000001;
  ll ans = 0;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (v[i] == v[i + 1])
      cnt++;
    else {
      ans += cnt % 2;
      cnt = 1;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> v(n + 1);
  v[n] = 1000000001;
  ll ans = 0;
  for (int i = 0; i < n; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (v[i] == v[i + 1])
      cnt++;
    else {
      ans += cnt % 2;
      cnt = 1;
    }
  }
  cout << ans << endl;
}
Problem p03607 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1e-10;

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

  vector<bool> number(100000);
  int num;
  for (int i = 0; i < N; i++) {
    cin >> num;
    if (number[num] == false) {
      number[num] = true;
    } else {
      number[num] = false;
    }
  }

  int ans = 0;
  for (int i = 1; i < number.size(); i++) {
    if (number[i] == true) {
      ans++;
    }
  }
  cout << ans << endl;
  return (0);
}

Fixed submission:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1e-10;

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

  vector<bool> number(1000000000 + 1);
  int num;
  for (int i = 0; i < N; i++) {
    cin >> num;
    if (number[num] == false) {
      number[num] = true;
    } else {
      number[num] = false;
    }
  }

  int ans = 0;
  for (int i = 1; i < number.size(); i++) {
    if (number[i] == true) {
      ans++;
    }
  }
  cout << ans << endl;
  return (0);
}
Problem p03607 (C++)

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

using namespace std;

int main() {
  int n, s = 0, a, b, ck[100000];
  memset(ck, 0, sizeof(ck));
  cin >> n;
  while (n--) {
    cin >> a;
    if (ck[a] == 0) {
      ck[a] = 1;
      s++;
    } else {
      ck[a] = 0;
      s--;
    }
  }
  cout << s << endl;
  return 0;
}


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

using namespace std;

int main() {
  map<long long, int> ck;
  int n, s = 0, a, b;
  cin >> n;
  while (n--) {
    cin >> a;
    if (ck[a] == 0) {
      ck[a] = 1;
      s++;
    } else {
      ck[a] = 0;
      s--;
    }
  }
  cout << s << endl;
  return 0;
}
Problem p03608 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int node[10];
int route[200][200];
int dp[1 << 10][10];
int main(void) {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < k; i++)
    scanf("%d", &node[i]);
  memset(route, 0x3f, sizeof(route));
  while (m--) {
    int x, y, cost;
    scanf("%d %d %d", &x, &y, &cost);
    route[y][x] = route[x][y] = cost;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int s = 1; s <= n; s++) {
        route[j][s] = min(route[j][s], route[j][i] + route[i][s]);
      }
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  int maxx = dp[0][0];
  for (int i = 0; i < k; i++) {
    dp[(1 << i)][i] = 0;
  }
  for (int i = 1; i < 1 << k; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = 0; s < k; s++) {
        if (j != s && !(i & (1 << s))) {
          dp[i | (1 << s)][s] =
              min(dp[i | (1 << s)][s], dp[i][j] + route[node[j]][node[s]]);
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    maxx = min(dp[(1 << k) - 1][i], maxx);
  }
  printf("%d\n", maxx);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int node[10];
int route[205][205];
int dp[1 << 10][10];
int main(void) {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < k; i++)
    scanf("%d", &node[i]);
  memset(route, 0x3f, sizeof(route));
  while (m--) {
    int x, y, cost;
    scanf("%d %d %d", &x, &y, &cost);
    route[y][x] = route[x][y] = cost;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int s = 1; s <= n; s++) {
        route[j][s] = min(route[j][s], route[j][i] + route[i][s]);
      }
    }
  }
  memset(dp, 0x3f, sizeof(dp));
  int maxx = dp[0][0];
  for (int i = 0; i < k; i++) {
    dp[(1 << i)][i] = 0;
  }
  for (int i = 1; i < 1 << k; i++) {
    for (int j = 0; j < k; j++) {
      for (int s = 0; s < k; s++) {
        if (j != s && !(i & (1 << s))) {
          dp[i | (1 << s)][s] =
              min(dp[i | (1 << s)][s], dp[i][j] + route[node[j]][node[s]]);
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    maxx = min(dp[(1 << k) - 1][i], maxx);
  }
  printf("%d\n", maxx);
  return 0;
}
Problem p03608 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, a) for (int i = 0; i < (a); i++)
using namespace std;
#define INF 1e9

int dist[200][200];
int N, M, R;

void warshall_floyd() {
  REP(k, N)
  REP(i, N)
  REP(j, N)
  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main() {
  cin >> N >> M >> R;
  int r[R];
  REP(i, R) {
    cin >> r[i];
    r[i]--;
  }
  int a[M], b[M], c[M];
  REP(i, M) cin >> a[i] >> b[i] >> c[i];
  REP(i, M) {
    REP(j, M) { dist[i][j] = INF; }
  }
  REP(i, M) {
    dist[a[i] - 1][b[i] - 1] = c[i];
    dist[b[i] - 1][a[i] - 1] = c[i];
  }
  warshall_floyd();
  sort(r, r + R);
  int ans = INF;
  do {
    int num = 0;
    REP(i, R - 1) num += dist[r[i]][r[i + 1]];
    ans = min(ans, num);
  } while (next_permutation(r, r + R));
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, a) for (int i = 0; i < (a); i++)
using namespace std;
#define INF 1e9

int dist[200][200];
int N, M, R;

void warshall_floyd() {
  REP(k, N)
  REP(i, N)
  REP(j, N)
  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
}

int main() {
  cin >> N >> M >> R;
  int r[R];
  REP(i, R) {
    cin >> r[i];
    r[i]--;
  }
  int a[M], b[M], c[M];
  REP(i, M) cin >> a[i] >> b[i] >> c[i];
  REP(i, N) {
    REP(j, N) { dist[i][j] = INF; }
  }
  REP(i, M) {
    dist[a[i] - 1][b[i] - 1] = c[i];
    dist[b[i] - 1][a[i] - 1] = c[i];
  }
  warshall_floyd();
  sort(r, r + R);
  int ans = INF;
  do {
    int num = 0;
    REP(i, R - 1) num += dist[r[i]][r[i + 1]];
    ans = min(ans, num);
  } while (next_permutation(r, r + R));
  cout << ans << endl;
}
Problem p03608 (C++)

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

using namespace std;

int main(void) {
  int n, m, rmax;
  cin >> n >> m >> rmax;
  int r[8];
  for (int i = 0; i < rmax; i++) {
    cin >> r[i];
    r[i]--;
  }
  int dist[200][200];
  for (int i = 0; i < 200; i++) {
    for (int j = 0; j < 200; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = 1e8;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a - 1][b - 1] = c;
    dist[b - 1][a - 1] = c;
  }

  for (int k = 0; k < m; k++) {
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < m; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  /*
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cout << dist[i][j] << " ";
    }
    cout << endl;
  }
  cout << "---------------" << endl;
  */

  sort(r, r + rmax);
  int ans = 1e8;
  do {
    int progress = 0;
    for (int i = 0; i + 1 < rmax; i++) {
      int from = r[i];
      int to = r[i + 1];
      int d = dist[from][to];
      progress += d;
    }
    ans = min(ans, progress);
  } while (next_permutation(r, r + rmax));
  cout << ans << endl;
  return EXIT_SUCCESS;
}


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

using namespace std;

int main(void) {
  int n, m, rmax;
  cin >> n >> m >> rmax;
  int r[8];
  for (int i = 0; i < rmax; i++) {
    cin >> r[i];
    r[i]--;
  }
  int dist[200][200];
  for (int i = 0; i < 200; i++) {
    for (int j = 0; j < 200; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = 1e8;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    dist[a - 1][b - 1] = c;
    dist[b - 1][a - 1] = c;
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  /*
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cout << dist[i][j] << " ";
    }
    cout << endl;
  }
  cout << "---------------" << endl;
  */

  sort(r, r + rmax);
  int ans = 1e8;
  do {
    int progress = 0;
    for (int i = 0; i + 1 < rmax; i++) {
      int from = r[i];
      int to = r[i + 1];
      int d = dist[from][to];
      progress += d;
    }
    ans = min(ans, progress);
  } while (next_permutation(r, r + rmax));
  cout << ans << endl;
  return EXIT_SUCCESS;
}
Problem p03608 (C++)

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

#define INF 1e8

int a[222][222], r[11], R, ans = INF;

void update(void) {
  int i, sum = 0;

  for (i = 1; i < R; i++)
    sum += a[r[i]][r[i + 1]];

  ans = min(ans, sum);
}

int main(void) {
  freopen("input.txt", "r", stdin);

  int N, M, i, j, k;

  scanf("%d %d %d", &N, &M, &R);
  for (i = 1; i <= R; i++)
    scanf("%d", &r[i]);

  for (i = 1; i <= N; i++)
    for (j = 1; j <= N; j++)
      if (i != j)
        a[i][j] = INF;

  while (M--) {
    int x, y, z;

    scanf("%d %d %d", &x, &y, &z);

    a[x][y] = a[y][x] = min(a[x][y], z);
  }

  for (k = 1; k <= N; k++)
    for (i = 1; i <= N; i++)
      for (j = 1; j <= N; j++)
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);

  sort(r + 1, r + R + 1);
  do {
    update();
  } while (next_permutation(r + 1, r + R + 1));

  printf("%d", ans);
  return 0;
}

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

#define INF 1e8

int a[222][222], r[11], R, ans = INF;

void update(void) {
  int i, sum = 0;

  for (i = 1; i < R; i++)
    sum += a[r[i]][r[i + 1]];

  ans = min(ans, sum);
}

int main(void) {
  // freopen("input.txt", "r", stdin);

  int N, M, i, j, k;

  scanf("%d %d %d", &N, &M, &R);
  for (i = 1; i <= R; i++)
    scanf("%d", &r[i]);

  for (i = 1; i <= N; i++)
    for (j = 1; j <= N; j++)
      if (i != j)
        a[i][j] = INF;

  while (M--) {
    int x, y, z;

    scanf("%d %d %d", &x, &y, &z);

    a[x][y] = a[y][x] = min(a[x][y], z);
  }

  for (k = 1; k <= N; k++)
    for (i = 1; i <= N; i++)
      for (j = 1; j <= N; j++)
        a[i][j] = min(a[i][j], a[i][k] + a[k][j]);

  sort(r + 1, r + R + 1);
  do {
    update();
  } while (next_permutation(r + 1, r + R + 1));

  printf("%d", ans);
  return 0;
}
Problem p03608 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll R[8], c[201][201], r, ans = inf;
bool ch[8];
void dep(ll now, ll cnt, ll sum) {
  //	cout << cnt<<endl;
  if (cnt == r) {
    ans = min(sum, ans);
    return;
  }
  for (ll i = 0; i < r; i++) {
    ll next = R[i];
    if (ch[next]) {
      continue;
    }
    ch[next] = true;
    dep(next, cnt + 1, sum + c[now][next]);
    ch[next] = false;
  }
}

int main() {
  ll n, m;
  cin >> n >> m >> r;
  for (ll i = 0; i < r; i++) {
    ll x;
    cin >> x;
    x--;
    R[i] = x;
  }
  for (ll i = 0; i < 201; i++) {
    for (ll j = 0; j < 201; j++) {
      c[i][j] = inf;
    }
  }
  for (ll i = 0; i < m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    c[x][y] = z;
    c[y][x] = z;
  }
  for (ll k = 0; k < n; k++) {
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < n; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  for (ll i = 0; i < r; i++) {
    ch[R[i]] = true;
    dep(R[i], 1, 0);
    ch[R[i]] = false;
  }
  cout << ans;
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll R[8], c[201][201], r, ans = inf;
bool ch[201];
void dep(ll now, ll cnt, ll sum) {
  //	cout << cnt<<endl;
  if (cnt == r) {
    ans = min(sum, ans);
    return;
  }
  for (ll i = 0; i < r; i++) {
    ll next = R[i];
    if (ch[next]) {
      continue;
    }
    ch[next] = true;
    dep(next, cnt + 1, sum + c[now][next]);
    ch[next] = false;
  }
}

int main() {
  ll n, m;
  cin >> n >> m >> r;
  for (ll i = 0; i < r; i++) {
    ll x;
    cin >> x;
    x--;
    R[i] = x;
  }
  for (ll i = 0; i < 201; i++) {
    for (ll j = 0; j < 201; j++) {
      c[i][j] = inf;
    }
  }
  for (ll i = 0; i < m; i++) {
    ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    c[x][y] = z;
    c[y][x] = z;
  }
  for (ll k = 0; k < n; k++) {
    for (ll i = 0; i < n; i++) {
      for (ll j = 0; j < n; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  for (ll i = 0; i < r; i++) {
    ch[R[i]] = true;
    dep(R[i], 1, 0);
    ch[R[i]] = false;
  }
  cout << ans;
  // your code goes here
  return 0;
}
Problem p03608 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, R;
  cin >> N >> M >> R;

  int c[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        c[i][j] = 0;
      else
        c[i][j] = 1e9;
    }
  }

  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }

  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    c[A][B] = C;
    c[B][A] = C;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
      }
    }
  }

  sort(r.begin(), r.end());

  int ans = 1e9;
  do {
    int tmp, cost = 0;
    for (int i = 0; i < N; i++) {
      if (i > 0) {
        cost += c[tmp][r[i]];
      }
      tmp = r[i];
    }
    ans = min(ans, cost);
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;

  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M, R;
  cin >> N >> M >> R;

  int c[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j)
        c[i][j] = 0;
      else
        c[i][j] = 1e9;
    }
  }

  vector<int> r(R);
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }

  for (int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    c[A][B] = C;
    c[B][A] = C;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
      }
    }
  }

  sort(r.begin(), r.end());

  int ans = 1e9;
  do {
    int tmp, cost = 0;
    for (int i = 0; i < R; i++) {
      if (i > 0) {
        cost += c[tmp][r[i]];
      }
      tmp = r[i];
    }
    ans = min(ans, cost);
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;

  return 0;
}