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

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

int main() {
  int n, m;
  cin >> n >> m;
  char s[100010];
  cin >> s;

  int r = 0, idx = 0;
  while (idx < n) {
    for (int i = m; i >= 0; i--) {
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (s[idx + i] == '0') {
        idx += i;
        r++;
        break;
      }
    }
  }

  int ans[100010] = {};
  int r2 = 0;
  idx = n;
  while (idx > 0) {
    for (int i = m; i >= 0; i--) {
      if (idx - i >= 0 && s[idx - i] == '0') {
        idx -= i;
        ans[r2++] = i;
        break;
      }
    }
  }
  for (int i = r2 - 1; i >= 0; i--) {
    if (i != r2 - 1)
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  char s[100010];
  cin >> s;

  int r = 0, idx = 0;
  while (idx < n) {
    for (int i = m; i >= 0; i--) {
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
      if (idx + i <= n && s[idx + i] == '0') {
        idx += i;
        r++;
        break;
      }
    }
  }

  int ans[100010] = {};
  int r2 = 0;
  idx = n;
  while (idx > 0) {
    for (int i = m; i >= 0; i--) {
      if (idx - i >= 0 && s[idx - i] == '0') {
        idx -= i;
        ans[r2++] = i;
        break;
      }
    }
  }
  for (int i = r2 - 1; i >= 0; i--) {
    if (i != r2 - 1)
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
}
Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int now = n;
  vector<int> ans;
  while (now) {
    for (int i = k; i >= 0; i--) {
      if (now - i >= 0 && s[now - i] == '0') {
        ans.push_back(i);
        now -= i;
        break;
      }
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  for (int p : ans) {
    cout << p << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int now = n;
  vector<int> ans;
  while (now) {
    for (int i = k; i >= 0; i--) {
      if (now - i >= 0 && s[now - i] == '0' && i) {
        ans.push_back(i);
        now -= i;
        break;
      }
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  for (int p : ans) {
    cout << p << endl;
  }
}
Problem p02852 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> ans;
  int t = n;
  while (t != 0) {
    int i = m;
    for (i = m; i >= 0; i--) {
      if (s[t - i] == '0') {
        ans.push_back(i);
        t -= i;
        break;
      }
    }
    if (i == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> ans;
  int t = n;
  while (t != 0) {
    int i = m;
    for (i = min(t, m); i >= 0; i--) {
      if (s[t - i] == '0') {
        ans.push_back(i);
        t -= i;
        break;
      }
    }
    if (i == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
Problem p02852 (C++)

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

int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> ans(n);
  deque<pair<int, int>> d;
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
  }
  ans[n] = 0;
  d.push_back({0, n});
  for (int i = n - 1; i >= 0; i--) {
    if (!d.empty() && d[0].second > i + m) {
      d.pop_front();
    }
    if (!d.empty() && s[i] == '0') {
      ans[i] = d[0].first + 1;
      d.push_back({ans[i], i});
    }
  }
  if (ans[0] == -1) {
    cout << -1 << endl;
  } else {
    int p = 0;
    for (int i = 0; i <= n; i++) {
      if (ans[i] == ans[p] - 1) {
        cout << i - p << " ";
        p = i;
      }
    }
    cout << endl;
  }
}

Fixed submission:
#include <deque>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n, m;
  string s;
  cin >> n >> m >> s;
  vector<int> ans(n + 1);
  deque<pair<int, int>> d;
  for (int i = 0; i < n; i++) {
    ans[i] = -1;
  }
  ans[n] = 0;
  d.push_back({0, n});
  for (int i = n - 1; i >= 0; i--) {
    if (!d.empty() && d[0].second > i + m) {
      d.pop_front();
    }
    if (!d.empty() && s[i] == '0') {
      ans[i] = d[0].first + 1;
      d.push_back({ans[i], i});
    }
  }
  if (ans[0] == -1) {
    cout << -1 << endl;
  } else {
    int p = 0;
    for (int i = 0; i <= n; i++) {
      if (ans[i] == ans[p] - 1) {
        cout << i - p << " ";
        p = i;
      }
    }
    cout << endl;
  }
}
Problem p02852 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline bool CHMAX(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool CHMIN(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
constexpr long long INF = 1e18;

signed main() {
  int N, M;
  cin >> N >> M;
  string s;
  cin >> s;
  vector<int> ans;
  int now = N;
  while (now != 0) {
    int flg = 1;
    FOR(j, now - M, now) {
      if (s[j] == '0') {
        ans.push_back(now - j);
        now = j;
        flg = 0;
        break;
      }
      if (j == now - 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  RREP(i, ans.size()) {
    if (i + 1 != ans.size())
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template <class T> inline bool CHMAX(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool CHMIN(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
constexpr long long INF = 1e18;

signed main() {
  int N, M;
  cin >> N >> M;
  string s;
  cin >> s;
  vector<int> ans;
  int now = N;
  while (now != 0) {
    int flg = 1;
    FOR(j, now - M, now) {
      if (j < 0)
        continue;
      if (s[j] == '0') {
        ans.push_back(now - j);
        now = j;
        flg = 0;
        break;
      }
      if (j == now - 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  RREP(i, ans.size()) {
    if (i + 1 != ans.size())
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
}
Problem p02852 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

  int n, m, i, j, k, p, last;
  string s;
  cin >> n >> m >> s;

  vector<int> dp(n + 1, -1);
  vector<bool> reached(n + 1, false);
  last = -1;
  p = n - 1;
  reached[n] = true;
  for (i = n; i >= 1; i--) {
    if (s[i] == '1')
      continue;

    while ((p >= i - m) && (p >= 0)) {
      if (s[p] == '0')
        last = p;
      p--;
    }

    dp[i] = last;
    if (reached[i])
      reached[last] = true;
  }

  if (!reached[0])
    cout << "-1\n";
  else {
    vector<int> ans;
    ans.push_back(n);
    p = n;
    while (dp[p] != -1) {
      p = dp[p];
      ans.push_back(p);
    }
    reverse(ans.begin(), ans.end());
    for (i = 1; i < ans.size(); i++)
      cout << ans[i] - ans[i - 1] << " ";
    cout << "\n";
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

  int n, m, i, j, k, p, last;
  string s;
  cin >> n >> m >> s;

  vector<int> dp(n + 1, -1);
  vector<bool> reached(n + 1, false);
  last = -1;
  p = n - 1;
  reached[n] = true;
  for (i = n; i >= 1; i--) {
    if (s[i] == '1')
      continue;

    while ((p >= i - m) && (p >= 0)) {
      if (s[p] == '0')
        last = p;
      p--;
    }

    dp[i] = last;
    if ((last != -1) && (reached[i]))
      reached[last] = true;
  }

  if (!reached[0])
    cout << "-1\n";
  else {
    vector<int> ans;
    ans.push_back(n);
    p = n;
    while (dp[p] != -1) {
      p = dp[p];
      ans.push_back(p);
    }
    reverse(ans.begin(), ans.end());
    for (i = 1; i < ans.size(); i++)
      cout << ans[i] - ans[i - 1] << " ";
    cout << "\n";
  }

  return 0;
}
Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
#define sz(s) (int)(s.size())
#define vecprint(v)                                                            \
  rep(i, 0, v.size() - 1) cout << v[i] << " ";                                 \
  cout << endl;
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

string s;
vector<int> ans;
int m;

bool dfs(int start) {
  if (s[start] == '1')
    return false;
  if (start == 0)
    return true;
  drep(i, m, 1) {
    if (start - i < 0)
      continue;
    if (dfs(start - i)) {
      ans.push_back(i);
      return true;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n >> m;
  cin >> s;
  int now = n;

  if (dfs(n)) {
    vecprint(ans);
    return 0;
  } else {
    puts("-1");
    return 0;
  }

  // cout << ans << endl;
  //  printf("%.10f\n",ans);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
#define sz(s) (int)(s.size())
#define vecprint(v)                                                            \
  rep(i, 0, v.size() - 1) cout << v[i] << " ";                                 \
  cout << endl;
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

string s;
vector<int> ans;
int m;

bool dfs(int start) {
  if (s[start] == '1')
    return false;
  if (start == 0)
    return true;
  drep(i, m, 1) {
    if (start - i < 0)
      continue;
    if (dfs(start - i)) {
      ans.push_back(i);
      return true;
    }
  }
  return false;
}

int main() {
  int n;
  cin >> n >> m;
  cin >> s;
  int now = n;
  int cnt = 0;
  rep(i, 0, n) {
    if (s[i] == '0')
      cnt = 0;
    else
      cnt++;
    if (cnt == m) {
      puts("-1");
      return 0;
    }
  }

  if (dfs(n)) {
    vecprint(ans);
    return 0;
  } else {
    puts("-1");
    return 0;
  }

  // cout << ans << endl;
  //  printf("%.10f\n",ans);

  return 0;
}
Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m, res[100001], cnt = 0;
int book[100001], jud = 1;
string s;

void dfs(int x) {
  if (x == 0) {
    for (int i = cnt - 1; i >= 0; i--) {
      if (i != cnt - 1)
        cout << " ";
      cout << res[i];
    }
    jud = 0;
    return;
  }
  for (int i = m; i > 0; i--) {
    if (x - i >= 0 && s[x - i] == '0') {
      res[cnt++] = i;
      dfs(x - i);
      if (!jud)
        return;
      cnt--;
    }
  }
}
int main() {
  cin >> n >> m >> s;
  if (s[0] == '1') {
    cout << "-1";
    return 0;
  }
  dfs(n);
  if (jud)
    cout << "-1";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m, res[100001], cnt = 0;
int book[100001], jud = 1;
string s;

void dfs(int x) {
  if (x == 0) {
    for (int i = cnt - 1; i >= 0; i--) {
      if (i != cnt - 1)
        cout << " ";
      cout << res[i];
    }
    jud = 0;
    return;
  }
  for (int i = m; i > 0; i--) {
    if (x - i >= 0 && s[x - i] == '0') {
      res[cnt++] = i;
      dfs(x - i);
      return;
    }
  }
}
int main() {
  cin >> n >> m >> s;
  if (s[0] == '1') {
    cout << "-1";
    return 0;
  }
  dfs(n);
  if (jud)
    cout << "-1";
  return 0;
}
Problem p02852 (C++)

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

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

const int N = 2e5 + 10, mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  int cur = n, lst = -1, ch = n - 1;
  vector<int> ans;
  while (cur != 0) {
    for (int i = ch; i >= max(0, cur - m); i--) {
      if (s[i] == '0')
        lst = i;
      ch = i - 1;
    }
    if (lst == -1)
      return cout << -1, 0;
    ans.push_back(cur - lst);
    cur = lst;
  }
  reverse(ans.begin(), ans.end());
  for (int x : ans)
    cout << x << " ";
  return 0;
}


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

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

const int N = 2e5 + 10, mod = 1e9 + 7;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  int cur = n, lst = -1, ch = n - 1;
  vector<int> ans;
  while (cur != 0) {
    for (int i = ch; i >= max(0, cur - m); i--) {
      if (s[i] == '0')
        lst = i;
      ch = i - 1;
    }
    if (lst == -1)
      return cout << -1, 0;
    ans.push_back(cur - lst);
    cur = lst;
    lst = -1;
  }
  reverse(ans.begin(), ans.end());
  for (int x : ans)
    cout << x << " ";
  return 0;
}
Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  string str;
  set<int> canmove;
  cin >> n >> m;
  cin >> str;
  if (str.find(string(m, '1')) != string::npos) {
    cout << "-1\n";
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    if (str[i] == '1')
      continue;
    canmove.insert(i);
  }
  map<int, int> tomove;
  auto ep = end(canmove);
  list<int> ans;
  int p = n;
  while (p > 0) {
    auto bp = canmove.lower_bound(p - m);
    ans.push_front(p - *bp);
    p = *bp;
    canmove.erase(bp, canmove.end());
  }
  while (ans.size() > 1) {
    cout << ans.front() << " ";
    ans.pop_front();
  }
  cout << ans.back() << "\n";
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  string str;
  set<int> canmove;
  cin >> n >> m;
  cin >> str;
  if (str.find(string(m, '1')) != string::npos) {
    cout << "-1\n";
    return 0;
  }
  if (m == 1) {
    string ans = "1";
    for (int i = 1; i < n; i++) {
      ans += " 1";
    }
    cout << ans << "\n";
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    if (str[i] == '1')
      continue;
    canmove.insert(i);
  }
  map<int, int> tomove;
  auto ep = end(canmove);
  list<int> ans;
  int p = n;
  while (p > 0) {
    auto bp = canmove.lower_bound(p - m);
    ans.push_front(p - *bp);
    p = *bp;
    canmove.erase(bp, canmove.end());
  }
  while (ans.size() > 1) {
    cout << ans.front() << " ";
    ans.pop_front();
  }
  cout << ans.back() << "\n";
}
Problem p02852 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

int n, m;
vector<int> ans;
char s[maxn];

int main() {
  n = read();
  m = read();
  scanf("%s", s);
  int nw = n;
  while (nw != 0) {
    int f = 0;
    for (int i = max(0, nw - m); i <= nw; i++) {
      if (s[i] == '0') {
        ans.push_back(nw - i);
        nw = i, f = 1;
        break;
      }
    }
    if (f == 0) {
      puts("-1");
      return 0;
    }
  }
  for (int i = ans.size() - 1; i >= 0; i--)
    printf("%d ", ans[i]);
  return 0;
}

Fixed submission:
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      w = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  return w == 1 ? x : -x;
}

int n, m;
vector<int> ans;
char s[maxn];

int main() {
  n = read();
  m = read();
  scanf("%s", s);
  int nw = n;
  while (nw != 0) {
    int f = 0;
    for (int i = max(0, nw - m); i < nw; i++) {
      if (s[i] == '0') {
        ans.push_back(nw - i);
        nw = i, f = 1;
        break;
      }
    }
    if (f == 0) {
      puts("-1");
      return 0;
    }
  }
  for (int i = ans.size() - 1; i >= 0; i--)
    printf("%d ", ans[i]);
  return 0;
}
Problem p02853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> a = {300000, 200000, 100000};
  int ans = 0;
  ans += a.at(x - 1);
  ans += a.at(y - 1);
  if (x == 1 && y == 1)
    ans += 400000;
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);

int main() {
  int x, y;
  cin >> x >> y;
  vector<int> a = {300000, 200000, 100000};
  int ans = 0;
  if (x <= 3)
    ans += a.at(x - 1);
  if (y <= 3)
    ans += a.at(y - 1);
  if (x == 1 && y == 1)
    ans += 400000;
  cout << ans << endl;
}
Problem p02853 (C++)

Buggy submission (status: Runtime Error):
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("INPUT.txt", "r", stdin);
  freopen("OUTPUT.txt", "w", stdout);
#endif

  // -------------------------------------Code starts
  // here---------------------------------------------------------------------

  int a[400] = {0};
  a[1] = 300000;
  a[2] = 200000;
  a[3] = 100000;

  int x, y;
  cin >> x >> y;
  int s = 0;
  s += a[x] + a[y];
  if (x == y && x == 1) {
    s += 400000;
  }
  cout << s;

  // -------------------------------------Code ends
  // here------------------------------------------------------
  clock_t clk;
  clk = clock();

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}

Fixed submission:
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //  #ifndef ONLINE_JUDGE
  //     freopen ("INPUT.txt" , "r" , stdin);
  //     freopen ("OUTPUT.txt" , "w" , stdout);
  //  #endif

  // -------------------------------------Code starts
  // here---------------------------------------------------------------------

  int a[400] = {0};
  a[1] = 300000;
  a[2] = 200000;
  a[3] = 100000;

  int x, y;
  cin >> x >> y;
  int s = 0;
  s += a[x] + a[y];
  if (x == y && x == 1) {
    s += 400000;
  }
  cout << s;

  // -------------------------------------Code ends
  // here------------------------------------------------------
  clock_t clk;
  clk = clock();

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}
Problem p02853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  zoom;
  ll X, Y;
  cin >> X >> Y;
  ll look[3] = {300000, 200000, 100000};
  ll ans = 0;
  if (X <= 3)
    ans += look[X - 1];
  if (Y <= 3)
    ans += look[Y - 1];
  if (X == 1 && Y == 1)
    ans += 400000;
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
using namespace std;

int main() {

  zoom;
  ll X, Y;
  cin >> X >> Y;
  ll look[3] = {300000, 200000, 100000};
  ll ans = 0;
  if (X <= 3)
    ans += look[X - 1];
  if (Y <= 3)
    ans += look[Y - 1];
  if (X == 1 && Y == 1)
    ans += 400000;
  cout << ans;
  return 0;
}
Problem p02853 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int x, y;
  cin >> x >> y;
  long long ans = 0;
  int a[3] = {300000, 200000, 100000};
  if (x <= 3)
    ans += a[x - 1];
  if (y <= 3)
    ans += a[y - 1];
  if (x == 1 && y == 1)
    ans += 400000;
  cout << ans;
  return 0;
}

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

int main() {

  int x, y;
  cin >> x >> y;
  long long ans = 0;
  int a[3] = {300000, 200000, 100000};
  if (x <= 3)
    ans += a[x - 1];
  if (y <= 3)
    ans += a[y - 1];
  if (x == 1 && y == 1)
    ans += 400000;
  cout << ans;
  return 0;
}
Problem p02853 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
#else
#endif
}

int main() {
  run();
  int x, y;
  cin >> x >> y;
  vector<int> v = {300000, 200000, 100000, 0};
  ll sum = v[min(x - 1, 3)] + v[min(y - 1, 3)];
  if (x == y && x == 1)
    sum += 400000;
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}

int main() {
  run();
  int x, y;
  cin >> x >> y;
  vector<int> v = {300000, 200000, 100000, 0};
  ll sum = v[min(x - 1, 3)] + v[min(y - 1, 3)];
  if (x == y && x == 1)
    sum += 400000;
  cout << sum;
}
Problem p02854 (C++)

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

using namespace std;

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

  vector<size_t> A;
  for (size_t i = 0; i < N; i++) {
    size_t a;
    cin >> a;
    A.emplace_back(a);
  }

  size_t sumA = A[0];
  size_t idxA = 1;
  size_t sumB = 0;
  size_t idxB = N - 1;

  while (true) {
    if (sumA <= sumB) {
      sumA += A[idxA];
      idxA++;
    } else {
      sumB += A[idxB];
      idxB--;
    }

    if (idxA == idxB) {
      if (sumA <= sumB) {
        sumA += A[idxA];
      } else {
        sumB += A[idxA];
      }
      break;
    }
  }

  if (sumA <= sumB) {
    cout << sumB - sumA << endl;
  } else {
    cout << sumA - sumB << endl;
  }

  return 0;
}


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

using namespace std;

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

  vector<size_t> A;
  for (size_t i = 0; i < N; i++) {
    size_t a;
    cin >> a;
    A.emplace_back(a);
  }

  if (A.size() == 2) {
    if (A[0] < A[1]) {
      cout << A[1] - A[0] << endl;
    } else {
      cout << A[0] - A[1] << endl;
    }
    return 0;
  }

  size_t sumA = A[0];
  size_t idxA = 1;
  size_t sumB = 0;
  size_t idxB = N - 1;

  while (true) {
    if (sumA <= sumB) {
      sumA += A[idxA];
      idxA++;
    } else {
      sumB += A[idxB];
      idxB--;
    }

    if (idxA == idxB) {
      if (sumA <= sumB) {
        sumA += A[idxA];
      } else {
        sumB += A[idxA];
      }
      break;
    }
  }

  if (sumA <= sumB) {
    cout << sumB - sumA << endl;
  } else {
    cout << sumA - sumB << endl;
  }

  return 0;
}
Problem p02854 (C++)

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

int main() {
  ll N;
  cin >> N;
  ll L = 0; // 全長
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    L += a;
    A[i] = a;
  }
  vector<vector<ll>> B(2, vector<ll>(N - 1));
  priority_queue<ll, vector<ll>, greater<ll>> ans;
  B[0][0] = A[0];
  B[1][0] = L - A[0];
  ans.push(abs(B[1][0] - B[0][0]));
  for (int i = 1; i <= N - 1; i++) {
    B[0][i] = B[0][i - 1] + A[i];
    B[1][i] = L - B[0][i];
    ans.push(abs(B[1][i] - B[0][i]));
  }
  cout << ans.top() << endl;
}


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

int main() {
  ll N;
  cin >> N;
  ll L = 0; // 全長
  vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    L += a;
    A[i] = a;
  }
  vector<vector<ll>> B(2, vector<ll>(N - 1));
  priority_queue<ll, vector<ll>, greater<ll>> ans;
  B[0][0] = A[0];
  B[1][0] = L - A[0];
  ans.push(abs(B[1][0] - B[0][0]));
  for (int i = 1; i <= N - 2; i++) {
    B[0][i] = B[0][i - 1] + A[i];
    B[1][i] = L - B[0][i];
    ans.push(abs(B[1][i] - B[0][i]));
  }
  cout << ans.top() << endl;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <cstring>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> S(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }

  int ret = INF;

  for (int i = 0; i < N - 1; i++) {
    int left = S[i + 1];
    int right = S[N] - left;
    ret = min(ret, abs(left - right));
  }
  cout << ret << endl;
  return 0;
}

Fixed submission:
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <cstring>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> S(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }

  int ret = INF;

  for (int i = 0; i < N - 1; i++) {
    int left = S[i + 1];
    int right = S[N] - left;
    ret = min(ret, abs(left - right));
  }
  cout << ret << endl;
  return 0;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010];
int main() {
  int n;
  while (cin >> n) {
    ll ans = 0, tmp = 0, sm = 0, tmp1;
    for (int i = 0; i < n; ++i) {
      scanf("%lld", a + i);
      sm += a[i];
    }
    ans = sm;
    for (int i = 0; i < n; ++i) {
      tmp += a[i];
      tmp1 = sm - tmp;
      ans = min(ans, abs(tmp1 - tmp));
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[2020010];
int main() {
  int n;
  while (cin >> n) {
    ll ans = 0, tmp = 0, sm = 0, tmp1;
    for (int i = 0; i < n; ++i) {
      scanf("%lld", a + i);
      sm += a[i];
    }
    ans = sm;
    for (int i = 0; i < n; ++i) {
      tmp += a[i];
      tmp1 = sm - tmp;
      ans = min(ans, abs(tmp1 - tmp));
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, n) for (int i = n; i >= 1; i--)
#define mrep(i, from, n) for (int i = from; i < n; i++)
#define mreps(i, from, n) for (int i = from; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x, val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll mod = 1000000007;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), s(n + 1, 0);
  rep(i, n) cin >> a[i];
  rep(i, n + 1) s[i + 1] = s[i] + a[i];
  ll ans = 2e15;
  rep(i, n + 1) {
    ll x = s[i];
    ll y = s[n] - x;
    chmin(ans, abs(x - y));
  }
  cout << ans << endl;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, n) for (int i = n; i >= 1; i--)
#define mrep(i, from, n) for (int i = from; i < n; i++)
#define mreps(i, from, n) for (int i = from; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x, val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll mod = 1000000007;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), s(n + 1, 0);
  rep(i, n) cin >> a[i];
  rep(i, n) s[i + 1] = s[i] + a[i];
  ll ans = 2e16;
  rep(i, n + 1) {
    ll x = s[i];
    ll y = s[n] - x;
    chmin(ans, abs(x - y));
  }
  cout << ans << endl;
  return;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main() {
  int N;
  cin >> N;
  ll A[100010];
  ll sum1 = 0, sum2 = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum2 += A[i];
  }
  ll ans = INF;
  for (int i = 0; i < N; i++) {
    sum1 += A[i];
    sum2 -= A[i];
    // cout << sum1 << " " << sum2 << endl;
    ans = min(ans, abs(sum1 - sum2));
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main() {
  int N;
  cin >> N;
  ll A[200010];
  ll sum1 = 0, sum2 = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum2 += A[i];
  }
  ll ans = INF;
  for (int i = 0; i < N; i++) {
    sum1 += A[i];
    sum2 -= A[i];
    // cout << sum1 << " " << sum2 << endl;
    ans = min(ans, abs(sum1 - sum2));
  }
  cout << ans << endl;
}
Problem p02854 (C++)

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

int main() {
  // 制約見て！！！デカかったらlong longにすること！
  int n;
  cin >> n;
  vector<long> a(n);
  rep(i, n) cin >> a[i];
  long m = INT64_MAX;
  rep(i, n) {
    long left = 0;
    rep(j, i + 1) { left += a[j]; }
    long right = 0;
    for (int j = i + 1; j < n; j++) {
      right += a[j];
    }
    m = min(m, abs(right - left));
  }
  cout << m << endl;
}

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

int main() {
  // 制約見て！！！デカかったらlong longにすること！
  int n;
  cin >> n;
  vector<long> a(n);
  rep(i, n) cin >> a[i];
  long m = INT64_MAX;
  long sum = 0;
  rep(i, n) sum += a[i];
  long left = a[0];
  long right = sum - left;
  m = abs(right - left);
  for (int i = 1; i < n; i++) {
    left += a[i];
    right -= a[i];
    m = min(m, abs(left - right));
  }
  cout << m << endl;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int test[123456];
int main() {
  long long n, k, sum = 0, num = 1234567891230, a = 0;
  cin >> n;
  for (int h = 0; h < n; h++) {
    cin >> k;
    sum += k;
    test[h] = k;
  }
  for (int h = 0; h < n; h++) {
    num = min(abs(a - (sum - a)), num);
    a += test[h];
  }
  cout << num << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int test[213456];
int main() {
  long long n, k, sum = 0, num = 1234567891230, a = 0;
  cin >> n;
  for (int h = 0; h < n; h++) {
    cin >> k;
    sum += k;
    test[h] = k;
  }
  for (int h = 0; h < n; h++) {
    num = min(abs(a - (sum - a)), num);
    a += test[h];
  }
  cout << num << endl;
  return 0;
}
Problem p02854 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
arr = list(map(int, input().split()))
min_delta = sum(arr)
for i in range(1, N):
    min_delta = min(abs(sum(arr[:i]) - sum(arr[i:])), min_delta)

print(min_delta)


Fixed submission:
N = int(input())
arr = list(map(int, input().split()))
first = 0
second = sum(arr)
min_delta = second - first
for i in range(N):
    first += arr[i]
    second -= arr[i]
    min_delta = min(abs(second - first), min_delta)

print(min_delta)
Problem p02854 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L += (1,)
        df += A[L]
    else:
        R -= 1
        df -= A[R]
print(abs(df))


Fixed submission:
N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]

while R - L > 1:
    if df < 0:
        L += 1
        df += A[L]
    else:
        R -= 1
        df -= A[R]
print(abs(df))
Problem p02854 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 10**10
for i in range(1, len(a)):
    ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
    l += a[i]
    i += 1
print(min(abs(sum(a[: i - 1]) - sum(a[i - 1 :])), abs(sum(a[:i]) - sum(a[i:]))))
Problem p02854 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = sum(a)
r = [sum(a[: i + 1]) for i in range(n)]
print(min(abs(2 * i - s) for i in r))


Fixed submission:
#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = sum(a)
r = [a[0]]
for i in range(1, n):
    r.append(r[i - 1] + a[i])
print(min(abs(2 * i - s) for i in r))
Problem p02854 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
x = 2020202020
for i in range(1, n):
    x = min(x, abs(sum(a[:i]) - sum(a[i:])))
print(x)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
x = 0
y = sum(a)
ans = 2020202020
for i in range(n - 1):
    x += a[i]
    y -= a[i]
    ans = min(ans, abs(x - y))
print(ans)
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, mid, i, a[100], sum = 0, l = 0, ta, ans;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ans = sum;
  for (i = 0; i < n; i++) {
    l += a[i];
    sum -= a[i];
    ta = abs(sum - l);
    if (ta < ans)
      ans = ta;
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, mid, i, a[500000], sum = 0, l = 0, ta, ans;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  ans = sum;
  for (i = 0; i < n; i++) {
    l += a[i];
    sum -= a[i];
    ta = abs(sum - l);
    if (ta < ans)
      ans = ta;
  }
  cout << ans;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  int N;
  cin >> N;
  vec<ll> A(N), S(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }
  ll ans = 1e18;
  for (int i = 0; i < N - 1; i++) {
    ll l = S[i + 1], r = S[N] - S[i + 1];
    ans = min(ans, abs(l - r));
  }
  cout << ans << endl;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  int N;
  cin >> N;
  vec<ll> A(N), S(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }
  ll ans = 1e18;
  for (int i = 0; i < N - 1; i++) {
    ll l = S[i + 1], r = S[N] - S[i + 1];
    ans = min(ans, abs(l - r));
  }
  cout << ans << endl;
}
Problem p02854 (C++)

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

using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N;

int main() {
  cin >> N;

  vi A(N - 1);
  ll S = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }

  ll ans = 1e11, R = 0;
  for (int i = 0; i < N - 1; i++) {
    R += A[i];
    ans = min(ans, abs(S - R * 2));
  }

  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N;

int main() {
  cin >> N;

  vi A(N);
  ll S = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    S += A[i];
  }

  ll ans = 1e11, R = 0;
  for (int i = 0; i < N - 1; i++) {
    R += A[i];
    ans = min(ans, abs(S - R * 2));
  }

  cout << ans << endl;
  return 0;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x, y) (max(x, y) - min(x, y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100005];
lol sum[100005];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol a, b, c = 0, d = 0;
  lol ans = INF;
  cin >> a;
  cin >> b, sum[0] = b;
  for (int n = 1; n < a; n++) {
    cin >> b;
    sum[n] = sum[n - 1] + b;
  }
  c = sum[a - 1];
  for (int n = 0; n < a - 1; n++) {
    ans = min(ans, abs(c - sum[n], sum[n]));
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x, y) (max(x, y) - min(x, y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100005];
lol sum[200005];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol a, b, c = 0, d = 0;
  lol ans = INF;
  cin >> a;
  cin >> b, sum[0] = b;
  for (int n = 1; n < a; n++) {
    cin >> b;
    sum[n] = sum[n - 1] + b;
  }
  c = sum[a - 1];
  for (int n = 0; n < a - 1; n++) {
    ans = min(ans, abs(c - sum[n], sum[n]));
  }
  cout << ans << '\n';
  return 0;
}
Problem p02854 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
long long int a[20005], sum = 0;
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long b = sum / 2, c = 0, ans = 1e18;
  for (int i = 0; i < n; i++) {
    c += a[i];
    ans = min(ans, abs(b - c) + abs(sum - c - b));
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
long long int a[200005], sum = 0;
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long b = sum / 2, c = 0, ans = 1e18;
  for (int i = 0; i < n; i++) {
    c += a[i];
    ans = min(ans, abs(b - c) + abs(sum - c - b));
  }
  cout << ans << endl;
}
Problem p02854 (C++)

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

int main() {
  int n;
  ll ans = 404040404000000, dif;
  ll sum = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  for (int i = 1; i < n; ++i) {
    ll left = 0, right = 0;
    for (int j = 0; j < i; ++j) {
      if (j < i)
        left += a.at(j);
    }
    right = sum - left;
    dif = left - right;
    if (dif < 0)
      dif *= -1;
    ans = min(dif, ans);
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  ll ans = 404040404000000, dif;
  ll sum = 0;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  ll left = 0, right;
  for (int i = 0; i < n; ++i) {
    left += a.at(i);
    right = sum - left;
    dif = left - right;
    if (dif < 0)
      dif *= -1;
    ans = min(dif, ans);
  }

  cout << ans << endl;

  return 0;
}