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

Buggy submission (status: Runtime Error):
#include <cstdio>
using namespace std;
int main() {
  int n, scan, i;
  int cnt_max;
  scan = scanf("%d", &n);
  int a[n];
  for (i = 0; i < n && scan; i++) {
    scan = scanf("%d", &a[i]);
  }
  int k;
  int b[9];
  for (i = 0; i < 9; i++) {
    b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    k = a[i] / 400;
    if (k > 8)
      k = k - 1;
    b[k]++;
  }
  int cnt = 0;
  for (i = 0; i < 8; i++) {
    if (b[i] > 0)
      cnt++;
  }
  if (cnt == 0) {
    cnt = 1;
    cnt_max = b[8];
  } else {
    cnt_max = b[8] + cnt;
  }
  printf("%d %d", cnt, cnt_max);
}

Fixed submission:
#include <cstdio>
using namespace std;
int main() {
  int n, scan, i;
  int cnt_max;
  scan = scanf("%d", &n);
  int a[n];
  for (i = 0; i < n && scan; i++) {
    scan = scanf("%d", &a[i]);
  }
  int k;
  int b[9];
  for (i = 0; i < 9; i++) {
    b[i] = 0;
  }
  for (i = 0; i < n; i++) {
    k = a[i] / 400;
    if (k > 8)
      k = 8;
    b[k]++;
  }
  int cnt = 0;
  for (i = 0; i < 8; i++) {
    if (b[i] > 0)
      cnt++;
  }
  if (cnt == 0) {
    cnt = 1;
    cnt_max = b[8];
  } else {
    cnt_max = b[8] + cnt;
  }
  printf("%d %d", cnt, cnt_max);
}
Problem p03695 (C++)

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

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

  int b[8] = {0};

  int a[N];
  int rednum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[a[i] / 400] = 1;
    if (a[i] >= 3200)
      rednum++;
  }

  int colornum = 0;
  for (int i = 0; i < 8; i++) {
    if (b[i])
      colornum++;
  }
  if (colornum == 0) {
    cout << 1 << " " << rednum << endl;
  } else {
    cout << colornum << " " << colornum + rednum << endl;
  }
}

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

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

  int b[13] = {0};

  int a[N];
  int rednum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[a[i] / 400] = 1;
    if (a[i] >= 3200)
      rednum++;
  }

  int colornum = 0;
  for (int i = 0; i < 8; i++) {
    if (b[i])
      colornum++;
  }
  if (colornum == 0) {
    cout << 1 << " " << rednum << endl;
  } else {
    cout << colornum << " " << colornum + rednum << endl;
  }
}
Problem p03695 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> color(9);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    color.at(a / 400)++;
  }

  int minimum = 0, maximum;
  for (int i = 0; i < 8; i++) {
    if (color.at(i) > 0)
      minimum++;
  }

  maximum = minimum + color.at(8);
  if (minimum == 0)
    minimum++;

  cout << minimum << " " << maximum << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> color(9);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a >= 3200)
      color.at(8)++;
    else
      color.at(a / 400)++;
  }

  int minimum = 0, maximum;
  for (int i = 0; i < 8; i++) {
    if (color.at(i) > 0)
      minimum++;
  }

  maximum = minimum + color.at(8);
  if (minimum == 0)
    minimum++;

  cout << minimum << " " << maximum << endl;
}
Problem p03695 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> cnt(9, 0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt[a / 400]++;
  }

  int sum = 0;
  for (int i = 0; i < 8; i++) {
    if (cnt[i] > 0)
      sum++;
  }

  if (cnt[8] == n) {
    cout << 1 << " " << n << endl;
  } else {
    cout << sum << " " << sum + cnt[8] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> cnt(9, 0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int tmp = min(a / 400, 8);
    cnt[tmp]++;
  }

  int sum = 0;
  for (int i = 0; i < 8; i++) {
    if (cnt[i] > 0)
      sum++;
  }

  if (cnt[8] == n) {
    cout << 1 << " " << n << endl;
  } else {
    cout << sum << " " << sum + cnt[8] << endl;
  }
  return 0;
}
Problem p03695 (C++)

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for (int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n, a[101];
int getcolour(int rating) { return rating % 400; }
void minmax() {
  VB used(8, false);

  int grandmaster = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= 3200) {
      ++grandmaster;
      continue;
    }
    int col = getcolour(a[i]);
    used[col] = true;
  }

  int mincolor = count(ALL(used), true);
  cout << max(1, mincolor) << " ";

  int available = 0;
  for (int i = 0; i < n; ++i)
    if (!used[i])
      ++available;

  cout << mincolor + min(grandmaster, available) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  // freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
  cin >> n;

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

  minmax();

  return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for (int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long

int n, a[101];
int getcolour(int rating) { return rating / 400; }
void minmax() {
  VB used(8, false);

  int grandmaster = 0;
  for (int i = 0; i < n; ++i) {
    if (a[i] >= 3200) {
      ++grandmaster;
      continue;
    }
    int col = getcolour(a[i]);
    used[col] = true;
  }

  int mincolor = count(ALL(used), true);
  cout << max(1, mincolor) << " ";

  int available = 0;
  for (int i = 0; i < n; ++i)
    if (!used[i])
      ++available;

  cout << mincolor + min(grandmaster, available) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  // freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
  cin >> n;

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

  minmax();

  return 0;
}
Problem p03695 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, rate, min = 0, max = 0;
  cin >> N;
  vector<int> v(N);
  vector<int> color(9, 0);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < N; i++) {
    rate = v.at(i) / 400;
    color.at(rate) += 1;
  }
  for (int i = 0; i < 9; i++) {
    if (color.at(i)) {
      if (i == 8) {
        if (min == 0) {
          ++min;
        }
        max += color.at(i);
      } else {
        ++min;
        ++max;
      }
    }
  }
  cout << min << " " << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, rate, min = 0, max = 0;
  cin >> N;
  vector<int> v(N);
  vector<int> color(9, 0);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  for (int i = 0; i < N; i++) {
    rate = v.at(i) / 400;
    if (rate >= 9) {
      color.at(8) += 1;
    } else {
      color.at(rate) += 1;
    }
  }
  for (int i = 0; i < 9; i++) {
    if (color.at(i)) {
      if (i == 8) {
        if (min == 0) {
          ++min;
        }
        max += color.at(i);
      } else {
        ++min;
        ++max;
      }
    }
  }
  cout << min << " " << max << endl;
}
Problem p03695 (C++)

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

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;

  set<string> cores;
  int cont3200 = 0;
  vector<string> ratings = {"gray", "brown",  "green",  "cyan",
                            "blue", "yellow", "orange", "red"};
  fo(i, n) {
    int a;
    cin >> a;
    a /= 400;
    if (a >= 3200 / 400)
      cont3200++;
    else
      cores.insert(ratings[a]);
    cout << ratings[a] << endl;
  }

  cout << max(1, (int)cores.size()) << " " << (int)cores.size() + cont3200
       << endl;

  return 0;
}

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

#define sws                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;

  set<string> cores;
  int cont3200 = 0;
  vector<string> ratings = {"gray", "brown",  "green",  "cyan",
                            "blue", "yellow", "orange", "red"};
  fo(i, n) {
    int a;
    cin >> a;
    a /= 400;
    if (a >= 3200 / 400)
      cont3200++;
    else
      cores.insert(ratings[a]);
  }

  cout << max(1, (int)cores.size()) << " " << (int)cores.size() + cont3200
       << endl;

  return 0;
}
Problem p03695 (C++)

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

  int N;
  vector<int> A;
  vector<int> color(9, 0);
  cin >> N;
  A.resize(N);
  REP(i, N) {
    cin >> A[i];
    int ind = A[i] / 400;
    color[ind]++;
  }

  int c_min = 0, c_max = 0;

  // 8 のみ
  bool eight = true;
  REP(i, 8) {
    if (color[i] > 0) {
      eight = false;
      break;
    }
  }
  if (eight && color[8] > 0) {
    c_min = 1;
  } else {
    REP(i, 8) {
      if (color[i] > 0) {
        c_min++;
        c_max++;
      }
    }
  }
  c_max += color[8];

  printf("%lld %lld\n", c_min, c_max);

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

  int N;
  vector<int> A;
  vector<int> color(9, 0);
  cin >> N;
  A.resize(N);
  REP(i, N) {
    cin >> A[i];
    int ind = A[i] / 400;
    if (ind > 8) {
      ind = 8;
    }
    color[ind]++;
  }

  int c_min = 0, c_max = 0;

  // 8 のみ
  bool eight = true;
  REP(i, 8) {
    if (color[i] > 0) {
      eight = false;
      break;
    }
  }
  if (eight && color[8] > 0) {
    c_min = 1;
  } else {
    REP(i, 8) {
      if (color[i] > 0) {
        c_min++;
        c_max++;
      }
    }
  }
  c_max += color[8];

  printf("%lld %lld\n", c_min, c_max);

  return 0;
}
Problem p03696 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
S = input()
s = S[:]
while "()" in s:
    s.replace("()", "")
ans = "(" * s.count(")") + S + ")" * s.count("(")
print(ans)


Fixed submission:
N = int(input())
S = input()
s = S[:]
while "()" in s:
    s = s.replace("()", "")
ans = "(" * s.count(")") + S + ")" * s.count("(")
print(ans)
Problem p03696 (C++)

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

#define LEFT '('
#define RIGHT ')'

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

  string S;
  cin >> S;

  int cnt = 0;
  vector<int> table(N, 0);
  for (int i = 0; i < N; i++) {
    if (S[i] == LEFT)
      cnt++;
    else
      cnt--;

    table[i] = cnt;
  }

  int cntLeft = -*min_element(table.begin(), table.end());
  int cntRight = table.back() + cntLeft;
  cout << string(cntLeft, LEFT) << S << string(cntRight, RIGHT) << endl;

  return 0;
}


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

#define LEFT '('
#define RIGHT ')'

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

  string S;
  cin >> S;

  int cnt = 0;
  vector<int> table(N, 0);
  for (int i = 0; i < N; i++) {
    if (S[i] == LEFT)
      cnt++;
    else
      cnt--;

    table[i] = cnt;
  }

  int cntLeft = max(0, -*min_element(table.begin(), table.end()));
  int cntRight = table.back() + cntLeft;
  cout << string(cntLeft, LEFT) << S << string(cntRight, RIGHT) << endl;

  return 0;
}
Problem p03696 (C++)

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

int main() {
  int n;
  cin >> n;
  string p;
  cin >> p;
  string copy = p, op = "";
  if (n == 1) {
    cout << "()" << endl;
    return 0;
  }

  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < copy.size() - 1; j++) {
      if (copy.at(j) == '(' && copy.at(j + 1) == ')') {
        copy.at(j) = '@';
        copy.at(j + 1) = '@';
      }
    }
    op = "";
    for (int j = 0; j < copy.size(); j++) {
      if (copy.at(j) != '@') {
        op = op + copy.at(j);
      }
    }
    copy = op;
    if (copy.size() == 1) {
      if (copy == "(") {
        cout << p << ")" << endl;
        return 0;
      }
      cout << "(" << p << endl;
      return 0;
    }
  }

  int h = 0, g = 0;
  for (int i = 0; i < copy.size(); i++) {
    if (copy.at(i) == '(') {
      g++;
      continue;
    }
    if (copy.at(i) == ')') {
      h++;
    }
  }
  for (int i = 0; i < h; i++) {
    cout << "(";
  }
  cout << p;
  for (int i = 0; i < g; i++) {
    cout << ")";
  }
  cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  string p;
  cin >> p;
  string copy = p, op = "";
  if (n == 1) {
    cout << "()" << endl;
    return 0;
  }

  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < copy.size() - 1; j++) {
      if (copy.at(j) == '(' && copy.at(j + 1) == ')') {
        copy.at(j) = '@';
        copy.at(j + 1) = '@';
      }
    }
    op = "";
    for (int j = 0; j < copy.size(); j++) {
      if (copy.at(j) != '@') {
        op = op + copy.at(j);
      }
    }
    copy = op;
    if (copy.size() <= 1) {
      if (copy.size() == 0) {
        cout << p << endl;
        return 0;
      }
      if (copy == "(") {
        cout << p << ")" << endl;
        return 0;
      }
      cout << "(" << p << endl;
      return 0;
    }
  }

  int h = 0, g = 0;
  for (int i = 0; i < copy.size(); i++) {
    if (copy.at(i) == '(') {
      g++;
      continue;
    }
    if (copy.at(i) == ')') {
      h++;
    }
  }
  for (int i = 0; i < h; i++) {
    cout << "(";
  }
  cout << p;
  for (int i = 0; i < g; i++) {
    cout << ")";
  }
  cout << endl;
}
Problem p03696 (C++)

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string Scopy = S;
  bool exist = true;
  while (exist) {
    exist = false;
    if (Scopy.size() == 1)
      break;
    for (int i = 0; i < Scopy.size() - 1; i++) {
      if (Scopy.at(i) == '(' && Scopy.at(i + 1) == ')') {
        Scopy.erase(i, 2);
        exist = true;
        break;
      }
    }
  }
  int insertl = 0;
  int insertr = 0;
  for (int i = 0; i < Scopy.size(); i++) {
    if (Scopy.at(i) == ')')
      insertl++;
    else
      insertr++;
  }
  string l = "";
  string r = "";
  for (int i = 1; i <= insertl; i++)
    l.push_back('(');
  for (int i = 1; i <= insertr; i++)
    r.push_back(')');
  cout << l << S << r << endl;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string Scopy = S;
  bool exist = true;
  while (exist) {
    exist = false;
    if (Scopy.size() <= 1)
      break;
    for (int i = 0; i < Scopy.size() - 1; i++) {
      if (Scopy.at(i) == '(' && Scopy.at(i + 1) == ')') {
        Scopy.erase(i, 2);
        exist = true;
        break;
      }
    }
  }
  int insertl = 0;
  int insertr = 0;
  for (int i = 0; i < Scopy.size(); i++) {
    if (Scopy.at(i) == ')')
      insertl++;
    else
      insertr++;
  }
  string l = "";
  string r = "";
  for (int i = 1; i <= insertl; i++)
    l.push_back('(');
  for (int i = 1; i <= insertr; i++)
    r.push_back(')');
  cout << l << S << r << endl;
}
Problem p03696 (C++)

Buggy submission (status: Runtime Error):
#include <deque>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  deque<char> s, t;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    s.push_back(c);
    t.push_back(c);
  }
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == '(' && s[i + 1] == ')') {
      s.erase(s.begin() + i, s.begin() + i + 2);
      i = -1;
    }
  }
  int l = 0, r = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ')')
      l++;
    else
      r++;
  }
  for (int i = 0; i < l; i++)
    t.push_front('(');
  for (int i = 0; i < r; i++)
    t.push_back(')');
  for (int i = 0; i < t.size(); i++)
    cout << t[i];
  cout << endl;
}


Fixed submission:
#include <deque>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  deque<char> s, t;
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    s.push_back(c);
    t.push_back(c);
  }
  for (int i = 0; i < s.size() - 1; i++) {
    if (s[i] == '(' && s[i + 1] == ')') {
      s.erase(s.begin() + i, s.begin() + i + 2);
      i = -1;
    }
    if (s.size() == 0)
      break;
  }
  int l = 0, r = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ')')
      l++;
    else
      r++;
  }
  for (int i = 0; i < l; i++)
    t.push_front('(');
  for (int i = 0; i < r; i++)
    t.push_back(')');
  for (int i = 0; i < t.size(); i++)
    cout << t[i];
  cout << endl;
}
Problem p03696 (C++)

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

int main() {
  int N;
  string s;
  cin >> N >> s;
  vector<char> S(N);
  for (int i = 0; i < N; i++)
    S.at(i) = s.at(i);

  bool fin = false;
  while (!fin) {
    fin = true;
    for (int i = 0; i < S.size() - 1; i++) {
      if (S.at(i) == '(' && S.at(i + 1) == ')') {
        S.erase(S.begin() + (i + 1));
        S.erase(S.begin() + i);
        fin = false;
      }
    }
  }

  string L, R;

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == ')')
      L += '(';
    else if (S.at(i) == '(')
      R += ')';
  }

  cout << L << s << R << endl;
}

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

int main() {
  int N;
  string s;
  cin >> N >> s;
  vector<char> S(N);
  for (int i = 0; i < N; i++)
    S.at(i) = s.at(i);

  bool fin = false;
  while (!fin) {
    fin = true;
    for (int i = 0; i < S.size() - 1; i++) {
      if (S.at(i) == '(' && S.at(i + 1) == ')') {
        S.erase(S.begin() + (i + 1));
        S.erase(S.begin() + i);
        if (S.size() > 0)
          fin = false;
        break;
      }
    }
  }

  string L, R;

  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == ')')
      L += '(';
    else if (S.at(i) == '(')
      R += ')';
  }

  cout << L << s << R << endl;
}
Problem p03696 (C++)

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#define showvv(v)
#endif

using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)), v.end())
#define SUM(a) accumulate(all(a), 0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

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

  int d = 0, x = 1 << 29;
  rep(i, n) {
    if (s[i] == '(')
      d++;
    else
      d--;
    x = min(x, d);
  }

  s.insert(0, -x, '(');
  rep(i, d - x) s.pb(')');

  cout << s << endl;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#define showvv(v)
#endif

using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)), v.end())
#define SUM(a) accumulate(all(a), 0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

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

  int d = 0, x = 1 << 29;
  rep(i, n) {
    if (s[i] == '(')
      d++;
    else
      d--;
    x = min(x, d);
  }

  if (x < 0) {
    s.insert(0, -x, '(');
    rep(i, d - x) s.pb(')');
  } else
    rep(i, d) s.pb(')');
  cout << s << endl;
}
Problem p03696 (C++)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

#define X first
#define Y second

const int MAXN = 110;

int n;
char s[MAXN];

pair<int, string> operator+(pair<int, string> a, pair<int, string> b) {
  return make_pair(a.X + b.X, a.Y + b.Y);
}

int b[MAXN][MAXN];
pair<int, string> F[MAXN][MAXN];

int main() {

  scanf("%d", &n);
  scanf("%s", s + 1);

  for (int i = 1; i <= n; ++i) {
    int cur = 0;
    for (int j = i; j <= n; ++j) {
      if (s[j] == '(')
        cur++;
      if (s[j] == ')')
        cur--;
      if (cur < 0)
        break;
      if (cur == 0)
        b[i][j] = 1;
    }
  }

  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i) {
      int j = i + k - 1;
      string ss;
      for (int p = i; p <= j; ++p)
        ss += s[p];
      F[i][j] = b[i][j] ? make_pair(j - i + 1, ss) : make_pair(201, "");
      for (int p = i; p < j; ++p)
        F[i][j] = min(F[i][j], F[i][p] + F[p + 1][j]);
      if (s[j] == ')')
        F[i][j] =
            min(F[i][j], make_pair(1, "(") + F[i][j - 1] + make_pair(1, ")"));
      if (s[i] == '(')
        F[i][j] =
            min(F[i][j], make_pair(1, "(") + F[i + 1][j] + make_pair(1, ")"));
    }
  cout << F[1][n].Y << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;

#define X first
#define Y second

const int MAXN = 110;

int n;
char s[MAXN];

pair<int, string> operator+(pair<int, string> a, pair<int, string> b) {
  return make_pair(a.X + b.X, a.Y + b.Y);
}

int b[MAXN][MAXN];
pair<int, string> F[MAXN][MAXN];

int main() {

  scanf("%d", &n);
  scanf("%s", s + 1);

  for (int i = 1; i <= n; ++i) {
    int cur = 0;
    for (int j = i; j <= n; ++j) {
      if (s[j] == '(')
        cur++;
      if (s[j] == ')')
        cur--;
      if (cur < 0)
        break;
      if (cur == 0)
        b[i][j] = 1;
    }
  }

  for (int k = 1; k <= n; ++k)
    for (int i = 1; i <= n; ++i) {
      int j = i + k - 1;
      if (j > n)
        continue;
      string ss;
      for (int p = i; p <= j; ++p)
        ss += s[p];
      F[i][j] = b[i][j] ? make_pair(j - i + 1, ss) : make_pair(201, "");
      for (int p = i; p < j; ++p)
        F[i][j] = min(F[i][j], F[i][p] + F[p + 1][j]);
      if (s[j] == ')')
        F[i][j] =
            min(F[i][j], make_pair(1, "(") + F[i][j - 1] + make_pair(1, ")"));
      if (s[i] == '(')
        F[i][j] =
            min(F[i][j], make_pair(1, "(") + F[i + 1][j] + make_pair(1, ")"));
    }
  cout << F[1][n].Y << endl;

  return 0;
}
Problem p03696 (C++)

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

using namespace std;

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

  string ans;
  int l = 0, r = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == ')') {
      r++;
    } else if (r - l < 0) {
      l++;
      S += ')';
      r++;
    } else {
      l++;
    }
  }

  string start(r - l, '(');
  cout << start << S << endl;
  return 0;
}


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

using namespace std;

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

  string ans;
  int l = 0, r = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == ')') {
      r++;
    } else if (r - l <= 0) {
      l++;
      S += ')';
      r++;
    } else {
      l++;
    }
  }

  string start(r - l, '(');
  cout << start << S << endl;
  return 0;
}
Problem p03696 (C++)

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

#define MOD 1000000007ll
#define pb push_back
#define mp make_pair
#define MAX 100005
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int n;
string s;
stack<char> st;

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);

#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  cin >> n;
  cin >> s;
  int fr = 0, ls = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '(')
      st.push('(');
    else {
      if (!st.empty())
        st.pop();
      else
        fr++;
    }
  }

  while (!st.empty()) {
    st.pop();
    ls++;
  }

  string sa, sb;

  for (int i = 0; i < fr; i++)
    sa.pb('(');

  for (int j = 0; j < ls; j++)
    sb.pb(')');

  s = sa + s + sb;
  cout << s;

  return 0;
}


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

#define MOD 1000000007ll
#define pb push_back
#define mp make_pair
#define MAX 100005
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int n;
string s;
stack<char> st;

int main(int argc, char const *argv[]) {
  cin >> n;
  cin >> s;
  int fr = 0, ls = 0;

  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == '(')
      st.push('(');
    else {
      if (!st.empty())
        st.pop();
      else
        fr++;
    }
  }

  while (!st.empty()) {
    st.pop();
    ls++;
  }

  string sa, sb;

  for (int i = 0; i < fr; i++)
    sa.pb('(');

  for (int j = 0; j < ls; j++)
    sb.pb(')');

  s = sa + s + sb;
  cout << s;

  return 0;
}
Problem p03696 (C++)

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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int left = 0;
  int right = 0;

  string s_temp = s;
  string temp;

  if (s.length() == 1) {
    cout << "()" << endl;
    return 0;
  }

  while (1) {
    temp = s_temp;
    string new_str = "";
    for (int i = 0; i < temp.length() - 1; i++) {
      if (temp[i] == '(' && temp[i + 1] == ')') {
        temp[i] = '#';
        temp[i + 1] = '#';
      }
    }
    for (int i = 0; i < temp.length(); i++) {
      if (temp[i] != '#') {
        new_str += temp[i];
      }
    }
    if (s_temp == new_str) {
      break;
    } else {
      s_temp = new_str;
    }
  }

  for (int i = 0; i < s_temp.length(); i++) {
    if (s_temp[i] == '(') {
      left++;
    } else {
      right++;
    }
  }

  for (int i = 0; i < right; i++) {
    cout << '(';
  }
  cout << s;
  for (int i = 0; i < left; i++) {
    cout << ')';
  }
  cout << endl;

  return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  int left = 0;
  int right = 0;

  string s_temp = s;
  string temp;

  if (s.length() == 1) {
    cout << "()" << endl;
    return 0;
  }

  while (1) {
    if (s_temp == "") {
      break;
    }
    temp = s_temp;
    string new_str = "";
    for (int i = 0; i < temp.length() - 1; i++) {
      if (temp[i] == '(' && temp[i + 1] == ')') {
        temp[i] = '#';
        temp[i + 1] = '#';
      }
    }
    for (int i = 0; i < temp.length(); i++) {
      if (temp[i] != '#') {
        new_str += temp[i];
      }
    }
    if (s_temp == new_str) {
      break;
    } else {
      s_temp = new_str;
    }
  }

  for (int i = 0; i < s_temp.length(); i++) {
    if (s_temp[i] == '(') {
      left++;
    } else {
      right++;
    }
  }

  for (int i = 0; i < right; i++) {
    cout << '(';
  }
  cout << s;
  for (int i = 0; i < left; i++) {
    cout << ')';
  }
  cout << endl;

  return 0;
}
Problem p03697 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d%d", &a, &b)) {
    if (a + b >= 10)
      printf("error\n");
    else
      printf("%d\n", a + b);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  if (a + b >= 10)
    printf("error\n");
  else
    printf("%d\n", a + b);

  return 0;
}
Problem p03697 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int A, B;
  scanf("%d%d", A, B);
  if (A + B >= 10) {
    printf("error");
  } else {
    printf("%d", A + B);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int A, B;
  scanf("%d%d", &A, &B);
  if (A + B >= 10) {
    printf("error");
  } else {
    printf("%d", A + B);
  }
  return 0;
}
Problem p03698 (C++)

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ans = "yes";
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; i++) {
      if (s[i] == s[j]) {
        ans = "no";
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ans = "yes";
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        ans = "no";
      }
    }
  }
  cout << ans << endl;
}
Problem p03698 (Python)

Buggy submission (status: Runtime Error):
s = input()
s2 = [*s]
s3 = list(set(s2))
print("yes" if len(s2) == len(s3) else "no")


Fixed submission:
s = input()
s2 = list(s)
s3 = list(set(s2))
print("yes" if len(s2) == len(s3) else "no")
Problem p03698 (C++)

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

int main() {
  std::string s, t;

  std::cin >> s;

  std::sort(s.begin(), s.end());

  t = s;

  s.erase(std::unique(s.begin(), s.end()));

  if (s == t) {
    std::cout << "yes" << std::endl;
  } else {
    std::cout << "no" << std::endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>

int main() {
  std::string s, t;

  std::cin >> s;

  std::sort(s.begin(), s.end());

  t = s;

  s.erase(std::unique(s.begin(), s.end()) - s.begin());

  if (s == t) {
    std::cout << "yes" << std::endl;
  } else {
    std::cout << "no" << std::endl;
  }

  return 0;
}
Problem p03698 (C++)

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

int main() {

  string a;
  cin >> a;

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

  for (int i = 0; i < a.size(); i++) {

    if (a.at(i) == a.at(i + 1)) {

      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;
}


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

int main() {

  string a;
  cin >> a;

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

  for (int i = 0; i < a.size() - 1; i++) {

    if (a.at(i) == a.at(i + 1)) {

      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;
}
Problem p03698 (C++)

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

int main() {
  char *str;
  int n, count = 0;

  cin >> str;
  n = strlen(str);

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (str[i] == str[j]) {
        ++count;
      }
    }
  }

  if (count > 0) {
    cout << "no\n";
  } else {
    cout << "yes\n";
  }

  return 0;
}


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

int main() {
  char str[32];
  int n, count = 0;

  cin >> str;
  n = strlen(str);

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (str[i] == str[j]) {
        ++count;
      }
    }
  }

  if (count > 0) {
    cout << "no\n";
  } else {
    cout << "yes\n";
  }

  return 0;
}
Problem p03698 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string a;
bool u[30];
int main() {
  cin >> a;
  for (int s = 0; s < a.size(); s++) {
    if (u[a[s] - 'A'] == 0)
      u[a[s] - 'A'] = 1;
    else {
      cout << "no" << endl;
      exit(0);
    }
  }
  cout << "yes" << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string a;
bool u[30];
int main() {
  cin >> a;
  for (int s = 0; s < a.size(); s++) {
    if (u[a[s] - 'a'] == 0)
      u[a[s] - 'a'] = 1;
    else {
      cout << "no" << endl;
      exit(0);
    }
  }
  cout << "yes" << endl;
}
Problem p03698 (C++)

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

int main() {
  string s;
  cin >> s;
  int a = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i + 1; j < s.size(); j++) {
      j++;
      if (s.at(i) == s.at(j)) {
        a++;
        break;
      }
    }
  }
  if (a == 0) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
}


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

int main() {
  string s;
  cin >> s;
  int a = 0;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i + 1; j < s.size(); j++) {
      if (s.at(i) == s.at(j)) {
        a++;
        break;
      }
    }
  }
  if (a == 0) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
}
Problem p03698 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  bool b = true;
  cin >> S;
  for (int i = 0; i < (S.size() - 1); i++) {
    for (int j = i + 1; j < S.size(); i++) {
      if (S.at(i) != S.at(j)) {
        b = false;
      }
    }
  }
  if (b) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  bool b = true;
  cin >> S;
  for (int i = 0; i < (S.size() - 1); i++) {
    for (int j = i + 1; j < S.size(); j++) {
      if (S.at(i) == S.at(j)) {
        b = false;
      }
    }
  }
  if (b) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
}
Problem p03698 (C++)

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

int main() {
  string s;
  cin >> s;

  vector<int> c(26, 0);
  for (int i = 0; i < 26; i++) {
    c.at((int)(s.at(i) - 'a')) += 1;
  }

  int c_max = 0;
  for (int i : c) {
    c_max = max(c_max, i);
  }
  if (c_max > 1)
    cout << "no" << endl;
  else
    cout << "yes" << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;

  vector<int> c(26, 0);
  for (int i = 0; i < s.size(); i++) {
    c.at((int)(s.at(i) - 'a')) += 1;
  }

  int c_max = 0;
  for (int i : c) {
    c_max = max(c_max, i);
  }
  if (c_max > 1)
    cout << "no" << endl;
  else
    cout << "yes" << endl;

  return 0;
}
Problem p03699 (C++)

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

int memo[100][10010] = {};

int n;
int s[110];

int dp(int i, int num) {
  if (i == n) {
    return memo[i][num] = (num % 10 == 0 ? 0 : num);
  }
  if (memo[i][num] != -1)
    return memo[i][num];
  return memo[i][num] = max(dp(i + 1, num), dp(i + 1, num + s[i]));
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];

  memset(memo, -1, sizeof(memo));

  cout << dp(0, 0) << endl;

  return 0;
}


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

int memo[110][10010] = {};

int n;
int s[110];

int dp(int i, int num) {
  if (i == n) {
    return memo[i][num] = (num % 10 == 0 ? 0 : num);
  }
  if (memo[i][num] != -1)
    return memo[i][num];
  return memo[i][num] = max(dp(i + 1, num), dp(i + 1, num + s[i]));
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> s[i];

  memset(memo, -1, sizeof(memo));

  cout << dp(0, 0) << endl;

  return 0;
}
Problem p03699 (C++)

Buggy submission (status: Runtime Error):
#define ll long long
#define ffor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
bool dp[101][10001];

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

  int s[101];
  int sum = 0;
  rep(i, n) {
    cin >> s[i];
    sum += s[i];
  }

  rep(i, n + 2) { rep(j, sum + 1) dp[i][j] = false; }
  dp[0][0] = true;

  rep(i, n) {
    rep(j, sum) {
      if (dp[i][j] == true) {
        dp[i + 1][j] = true;
        dp[i + 1][j + s[i]] = true;
      }
    }
  }

  for (int i = sum; i >= 0; i--) {
    if (dp[n][i] == true && i % 10 != 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}


Fixed submission:
#define ll long long
#define ffor(i, a, b) for (int i = (a); i < (b); i++)
#define rfor(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
bool dp[101][10001];

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

  int s[101];
  int sum = 0;
  rep(i, n) {
    cin >> s[i];
    sum += s[i];
  }

  rep(i, n + 1) { rep(j, sum + 1) dp[i][j] = false; }
  dp[0][0] = true;

  rep(i, n) {
    rep(j, sum) {
      if (dp[i][j] == true) {
        dp[i + 1][j] = true;
        dp[i + 1][j + s[i]] = true;
      }
    }
  }

  for (int i = sum; i >= 0; i--) {
    if (dp[n][i] == true && i % 10 != 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}
Problem p03699 (C++)

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

int n;
int sum = 0;
vector<int> v;
int main() {
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    if (x % 10)
      v.push_back(x);
    sum += x;
  }
  sort(v.begin(), v.end(), greater<int>());
  while (sum % 10 == 0) {
    int u = v.back();
    sum -= u;
    v.pop_back();
  }
  printf("%d", sum);
}

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

int n;
int sum = 0;
vector<int> v;
int main() {
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    if (x % 10)
      v.push_back(x);
    sum += x;
  }
  if (v.size() == 0) {
    printf("0");
    return 0;
  }
  sort(v.begin(), v.end(), greater<int>());
  while (sum % 10 == 0) {
    int u = v.back();
    sum -= u;
    v.pop_back();
  }
  printf("%d", sum);
}
Problem p03699 (C++)

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

int main() {
  int n, i, sum;
  cin >> n;
  int s[i];
  for (i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  if (sum % 10 != 0) {
    cout << sum;
  } else {
    sort(s, s + n);
    i = 0;
    while (i < n && s[i] % 10 == 0)
      i++;
    if (i == n) {
      cout << 0;
    } else {
      cout << sum - s[i];
    }
  }
  return 0;
}

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

int main() {
  int n, i, sum;
  cin >> n;
  int s[n];
  for (i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  if (sum % 10 != 0) {
    cout << sum;
  } else {
    sort(s, s + n);
    i = 0;
    while (i < n && s[i] % 10 == 0)
      i++;
    if (i == n) {
      cout << 0;
    } else {
      cout << sum - s[i];
    }
  }
  return 0;
}
Problem p03699 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  rep(i, n) {
    cin >> v.at(i);
    ans += v.at(i);
    if (v.at(i) % 10 == 0) {
      v.at(i) = 0;
    }
  }
  sort(v.begin(), v.end());
  while (v.at(0) == 0) {
    v.erase(v.begin());
  }

  if (ans % 10 != 0) {
    cout << ans;
  } else if (v.size() == 0)
    cout << 0;
  else {
    cout << ans - v.at(0);
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  rep(i, n) {
    cin >> v.at(i);
    ans += v.at(i);
    if (v.at(i) % 10 == 0) {
      v.at(i) = 0;
    }
  }
  sort(v.begin(), v.end());
  while (v.at(0) == 0) {
    v.erase(v.begin());
    if (v.size() == 0)
      break;
  }

  if (ans % 10 != 0) {
    cout << ans;
  } else if (v.size() == 0)
    cout << 0;
  else {
    cout << ans - v.at(0);
  }
}
Problem p03699 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = [int(input()) for _ in range(n)]

dp = [set() for _ in range(n + 1)]
for i in range(n):
    dp[i + 1].update(dp[i])
    for x in dp[i]:
        dp[i + 1].add(x + s[i])
    dp[i + 1].add(s[i])


ans = max((x for x in dp[i + 1] if x % 10 != 0), default=0)
print(ans)


Fixed submission:
n = int(input())
s = [int(input()) for _ in range(n)]

dp = [set() for _ in range(n + 1)]
for i in range(n):
    dp[i + 1].update(dp[i])
    for x in dp[i]:
        dp[i + 1].add(x + s[i])
    dp[i + 1].add(s[i])


ans = 0
for x in dp[i + 1]:
    if x % 10 != 0:
        ans = max(ans, x)
print(ans)
Problem p03699 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;

ll func(ll a, ll b, ll c) {
  ll smax, smin;
  smax = max(a, b);
  smax = max(smax, c);
  smin = min(a, b);
  smin = min(smin, c);
  return smax - smin;
}
bool dp[100][10000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, s[110], ans = 0;
  scanf("%d", &N);
  REP(i, N) scanf("%d", &s[i]);
  dp[0][0] = true;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 10000; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j >= s[i - 1]) {
        dp[i][j] |= dp[i - 1][j - s[i - 1]];
      } else {
        //				if(j<=30)cout << j << "<" << s[i - 1] <<
        //endl;
      }
      //		if(j<=30)cout << "dp[" << i << "][" << j << "]=" <<
      //dp[i][j] << endl;
      if (i == N && dp[i][j] && j % 10 != 0)
        ans = j;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;

ll func(ll a, ll b, ll c) {
  ll smax, smin;
  smax = max(a, b);
  smax = max(smax, c);
  smin = min(a, b);
  smin = min(smin, c);
  return smax - smin;
}
bool dp[101][10001];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, s[110], ans = 0;
  scanf("%d", &N);
  REP(i, N) scanf("%d", &s[i]);
  dp[0][0] = true;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < 10000; j++) {
      dp[i][j] = dp[i - 1][j];
      if (j >= s[i - 1]) {
        dp[i][j] |= dp[i - 1][j - s[i - 1]];
      } else {
        //				if(j<=30)cout << j << "<" << s[i - 1] <<
        //endl;
      }
      //		if(j<=30)cout << "dp[" << i << "][" << j << "]=" <<
      //dp[i][j] << endl;
      if (i == N && dp[i][j] && j % 10 != 0)
        ans = j;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03699 (Python)

Buggy submission (status: Runtime Error):
import sys

N = int(input())
S = [int(input()) for _ in range(N)]
S.sort()
t = sum(S)
if t % 10 != 0:
    print(t)
    sys.exit()

for s in range(S):
    if (t - s) % 10 != 0:
        print(t - s)
        sys.exit()
print(0)


Fixed submission:
import sys

N = int(input())
S = [int(input()) for _ in range(N)]
S.sort()
t = sum(S)
if t % 10 != 0:
    print(t)
    sys.exit()

for s in S:
    if (t - s) % 10 != 0:
        print(t - s)
        sys.exit()
print(0)