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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 3005
#define re register
using namespace std;
int n, la[N], lb[N], loca[N], locb[N];
char a[N << 1];
bool dp[N][N];
string ans = "";

string get(bool dp[]) // 对这个存在性的数组求对应的串
{
  string ret = "";
  for (re int i = 0; i < n * 2; ++i) {
    if (a[i] == 'a' && dp[la[i]])
      ret += "a";
    if (a[i] == 'b' && dp[lb[i]])
      ret += "b";
  }
  return ret;
}
int main() {
  scanf("%d%s", &n, a);
  for (int i = 0, ca = 0, cb = 0; i < n * 2; ++i) {
    if (a[i] == 'a')
      la[i] = ++ca, loca[ca] = i;
    else
      lb[i] = ++cb, locb[cb] = i;
  }
  dp[n][n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    int mx = i;
    dp[i][i] = 1;
    if (loca[i] < locb[i]) {
      for (int j = loca[i] + 1; j < locb[i]; ++j)
        if (a[j] == 'a')
          mx = max(mx, la[j]);
      for (int j = mx + 1; j <= n; ++j)
        dp[i][j] = dp[mx + 1][j];
    } else {
      int R = loca[i];
      for (int j = locb[i] + 1; j < R; ++j)
        if (a[j] == 'b') {
          R = max(R, loca[lb[j]]);
          mx = lb[j];
          dp[i][lb[j]] = 1;
        }
      for (int j = mx + 1; j <= n; ++j)
        dp[i][j] = dp[mx + 1][j];
    }
    if (get(dp[i]) < get(dp[i + 1]))
      memcpy(dp[i], dp[i + 1], sizeof(dp[i]));
  }
  cout << get(dp[1]) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define N 3005
#define re register
using namespace std;
int n, la[N << 1], lb[N << 1], loca[N << 1], locb[N << 1];
char a[N << 1];
bool dp[N][N];
string ans = "";

string get(bool dp[]) // 对这个存在性的数组求对应的串
{
  string ret = "";
  for (re int i = 0; i < n * 2; ++i) {
    if (a[i] == 'a' && dp[la[i]])
      ret += "a";
    if (a[i] == 'b' && dp[lb[i]])
      ret += "b";
  }
  return ret;
}
int main() {
  scanf("%d%s", &n, a);
  for (int i = 0, ca = 0, cb = 0; i < n * 2; ++i) {
    if (a[i] == 'a')
      la[i] = ++ca, loca[ca] = i;
    else
      lb[i] = ++cb, locb[cb] = i;
  }
  dp[n][n] = 1;
  for (int i = n - 1; i >= 1; --i) {
    int mx = i;
    dp[i][i] = 1;
    if (loca[i] < locb[i]) {
      for (int j = loca[i] + 1; j < locb[i]; ++j)
        if (a[j] == 'a')
          mx = max(mx, la[j]);
      for (int j = mx + 1; j <= n; ++j)
        dp[i][j] = dp[mx + 1][j];
    } else {
      int R = loca[i];
      for (int j = locb[i] + 1; j < R; ++j)
        if (a[j] == 'b') {
          R = max(R, loca[lb[j]]);
          mx = lb[j];
          dp[i][lb[j]] = 1;
        }
      for (int j = mx + 1; j <= n; ++j)
        dp[i][j] = dp[mx + 1][j];
    }
    if (get(dp[i]) < get(dp[i + 1]))
      memcpy(dp[i], dp[i + 1], sizeof(dp[i]));
  }
  cout << get(dp[1]) << endl;
  return 0;
}
Problem p03300 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105, p = 1000000007;
int read() {
  int f = 1, g = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    g = g * 10 + ch - '0';
  return f * g;
}
int qpow(int x, int k) {
  int t = 1;
  for (; k; k >>= 1) {
    if (k & 1)
      t = (ll)t * x % p;
    x = (ll)x * x % p;
  }
  return t;
}
int n, a[N], b[N], cnt, r[N];
string s, f[N];
string calc(int l, int r) {
  string ans = "";
  if (a[l] < b[l]) {
    int las = a[l] - 1;
    for (int i = l; i <= r; i++)
      if (las < a[i]) {
        ans += "ab";
        las = b[i];
      }
  } else {
    string t;
    for (int i = l; i <= r; i++) {
      t = "";
      int j = i, k = i;
      while ((j <= r) || (k <= r))
        if (a[j] < b[k]) {
          t += 'a';
          j++;
        } else {
          t += 'b';
          k++;
        }
      ans = max(ans, t);
    }
  }
  return ans;
}
int main() {
  cin >> n >> s;
  for (int i = 0; i < n * 2; i++)
    if (s[i] == 'a')
      a[++a[0]] = i + 1;
    else
      b[++b[0]] = i + 1;
  a[n + 1] = b[n + 1] = n * 2 + 1;

  for (int i = 1; i <= n; i++)
    if (max(a[i], b[i]) == i * 2)
      r[++cnt] = i;
  for (int i = 1; i <= cnt; i++)
    f[i] = calc(r[i - 1] + 1, r[i]);
  for (int i = cnt - 1; i; i--)
    f[i] = max(f[i + 1], f[i] + f[i + 1]);
  cout << f[1] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3005, p = 1000000007;
int read() {
  int f = 1, g = 0;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      f = -1;
  for (; isdigit(ch); ch = getchar())
    g = g * 10 + ch - '0';
  return f * g;
}
int qpow(int x, int k) {
  int t = 1;
  for (; k; k >>= 1) {
    if (k & 1)
      t = (ll)t * x % p;
    x = (ll)x * x % p;
  }
  return t;
}
int n, a[N], b[N], cnt, r[N];
string s, f[N];
string calc(int l, int r) {
  string ans = "";
  if (a[l] < b[l]) {
    int las = a[l] - 1;
    for (int i = l; i <= r; i++)
      if (las < a[i]) {
        ans += "ab";
        las = b[i];
      }
  } else {
    string t;
    for (int i = l; i <= r; i++) {
      t = "";
      int j = i, k = i;
      while ((j <= r) || (k <= r))
        if (a[j] < b[k]) {
          t += 'a';
          j++;
        } else {
          t += 'b';
          k++;
        }
      ans = max(ans, t);
    }
  }
  return ans;
}
int main() {
  cin >> n >> s;
  for (int i = 0; i < n * 2; i++)
    if (s[i] == 'a')
      a[++a[0]] = i + 1;
    else
      b[++b[0]] = i + 1;
  a[n + 1] = b[n + 1] = n * 2 + 1;

  for (int i = 1; i <= n; i++)
    if (max(a[i], b[i]) == i * 2)
      r[++cnt] = i;
  for (int i = 1; i <= cnt; i++)
    f[i] = calc(r[i - 1] + 1, r[i]);
  for (int i = cnt - 1; i; i--)
    f[i] = max(f[i + 1], f[i] + f[i + 1]);
  cout << f[1] << endl;
  return 0;
}
Problem p03300 (C++)

Buggy submission (status: Runtime Error):
/*====Corycle====*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3005;
int read() {
  int s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
string S, F[N];
int n, m, id[N], PosA[N], PosB[N], nxt[N];
int main() {
  //	freopen("_.in","r",stdin);
  //	freopen("_.out","w",stdout);
  n = read();
  cin >> S;
  S = " " + S;
  for (int i = 1, n1 = 0, n2 = 0; i <= n * 2; i++) {
    if (S[i] == 'a')
      PosA[id[i] = ++n1] = i;
    if (S[i] == 'b')
      PosB[id[i] = ++n2] = i;
  }
  id[PosA[n + 1] = PosB[n + 1] = n * 2 + 1] = n + 1;
  for (int i = 1, j = 1; i <= n + 1; i++)
    while (j < min(PosA[i], PosB[i])) {
      nxt[j] = i;
      j++;
    }
  for (int i = n; i >= 1; i--) {
    if (PosA[i] < PosB[i])
      F[i] = "ab" + F[nxt[PosB[i]]];
    else {
      int j = PosB[i], k = PosA[i];
      while (j <= k && (id[j] <= i || PosB[id[j]] <= k)) {
        if (id[j] >= i) {
          F[i] += S[j];
          k = max(k, PosA[id[j]]);
        }
        j++;
      }
      F[i] += F[id[j]];
    }
    F[i] = max(F[i], F[i + 1]);
  }
  cout << F[1] << '\n';
  return 0;
}

Fixed submission:
/*====Corycle====*/
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define ll long long
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 6005;
int read() {
  int s = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    s = s * 10 + c - '0';
    c = getchar();
  }
  return s * f;
}
string S, F[N];
int n, m, id[N], PosA[N], PosB[N], nxt[N];
int main() {
  //	freopen("_.in","r",stdin);
  //	freopen("_.out","w",stdout);
  n = read();
  cin >> S;
  S = " " + S;
  for (int i = 1, n1 = 0, n2 = 0; i <= n * 2; i++) {
    if (S[i] == 'a')
      PosA[id[i] = ++n1] = i;
    if (S[i] == 'b')
      PosB[id[i] = ++n2] = i;
  }
  id[PosA[n + 1] = PosB[n + 1] = n * 2 + 1] = n + 1;
  for (int i = 1, j = 1; i <= n + 1; i++)
    while (j < min(PosA[i], PosB[i])) {
      nxt[j] = i;
      j++;
    }
  for (int i = n; i >= 1; i--) {
    if (PosA[i] < PosB[i])
      F[i] = "ab" + F[nxt[PosB[i]]];
    else {
      int j = PosB[i], k = PosA[i];
      while (j <= k && (id[j] <= i || PosB[id[j]] <= k)) {
        if (id[j] >= i) {
          F[i] += S[j];
          k = max(k, PosA[id[j]]);
        }
        j++;
      }
      F[i] += F[id[j]];
    }
    F[i] = max(F[i], F[i + 1]);
  }
  cout << F[1] << '\n';
  return 0;
}
Problem p03301 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 100010
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int a[N], b[N], n;
inline int check(int k) {
  memcpy(b, a, sizeof(a));
  for (rint i = 1; i <= n; i += 2)
    if (i == n)
      return (b[i] >= k);
    else if (!(b[i] >= k && b[i + 1] >= b[i]))
      b[i + 2] += b[i] - b[i + 1];
}
int main() {
  int s0 = 0, s1 = 0;
  cin >> n;
  for (rint i = 1; i <= n; i++)
    scanf("%d", &a[i]), (i & 1) ? s0 += a[i] : s1 += a[i];
  if (n % 2 == 0) {
    cout << max(s0, s1) << " " << min(s0, s1) << endl;
    return 0;
  }
  int l = 0, r = 3e8, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans + s1 << " " << s0 - ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr << #x << "=" << x << endl
#define fgx cerr << "-------------" << endl
#define N 500010
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int a[N], b[N], n;
inline int check(int k) {
  memcpy(b, a, sizeof(a));
  for (rint i = 1; i <= n; i += 2)
    if (i == n)
      return (b[i] >= k);
    else if (!(b[i] >= k && b[i + 1] >= b[i]))
      b[i + 2] += b[i] - b[i + 1];
}
int main() {
  int s0 = 0, s1 = 0;
  cin >> n;
  for (rint i = 1; i <= n; i++)
    scanf("%d", &a[i]), (i & 1) ? s0 += a[i] : s1 += a[i];
  if (n % 2 == 0) {
    cout << max(s0, s1) << " " << min(s0, s1) << endl;
    return 0;
  }
  int l = 0, r = 3e8, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans + s1 << " " << s0 - ans << endl;
  return 0;
}
Problem p03301 (C++)

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

using i64 = long long;

const int N = 300000 + 7;

int n;
i64 a[N], b[N], s[2];
i64 l, r, m, p;

int main() {
  //	freopen("code.in", "r", stdin);
  //	freopen("code.out", "w", stdout);

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", a + i), b[i] = b[i - 1] + (i & 1 ? 1 : -1) * a[i],
                          s[i & 1] += a[i];
  if (n % 2 == 0)
    return printf("%lld %lld", std::max(s[0], s[1]), std::min(s[0], s[1])), 0;

  r = s[0] + s[1];
  while (l < r) {
    m = l + r + 1 >> 1, p = 0;
    for (int i = 1; i < n; i += 2)
      if (b[i] + p >= m)
        p = std::max(p, a[i + 1] - b[i]);
    b[n] + p >= m ? (l = m) : (r = m - 1);
  }
  m = std::max(s[0] + l, s[1]);
  return printf("%lld %lld", m, s[0] + s[1] - m);
}


Fixed submission:
#include <iostream>

using i64 = long long;

const int N = 300000 + 7;

int n;
i64 a[N], b[N], s[2];
i64 l, r, m, p;

int main() {
  //	freopen("code.in", "r", stdin);
  //	freopen("code.out", "w", stdout);

  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lld", a + i), b[i] = b[i - 1] + (i & 1 ? 1 : -1) * a[i],
                          s[i & 1] += a[i];
  if (n % 2 == 0)
    return printf("%lld %lld", std::max(s[0], s[1]), std::min(s[0], s[1])), 0;

  r = s[0] + s[1];
  while (l < r) {
    m = l + r + 1 >> 1, p = 0;
    for (int i = 1; i < n; i += 2)
      if (b[i] + p >= m)
        p = std::max(p, a[i + 1] - b[i]);
    b[n] + p >= m ? (l = m) : (r = m - 1);
  }
  m = std::max(s[0] + l, s[1]);
  return printf("%lld %lld", m, s[0] + s[1] - m), 0;
}
Problem p03301 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define N 100010
using namespace std;
int num[N], sum[N];
int n;
bool check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; i += 2)
    if (ans + x <= sum[i])
      ans = min(ans, sum[i + 1]);
  return x + ans <= sum[n];
}
int main() {
  scanf("%d", &n);
  int a[2] = {0, 0};
  for (int i = 1; i <= n; i++)
    scanf("%d", &num[i]), a[i & 1] += num[i];
  if (n & 1) {
    for (int i = 1; i <= n; i++)
      sum[i] = sum[i - 1] + (i & 1 ? 1 : -1) * num[i];
    int l = 0, r = a[0] + a[1], ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(mid))
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    printf("%d %d\n", a[0] + ans, a[1] - ans);
  } else
    printf("%d %d\n", max(a[0], a[1]), min(a[0], a[1]));
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#define N 300010
using namespace std;
int num[N], sum[N];
int n;
bool check(int x) {
  int ans = 0;
  for (int i = 1; i <= n; i += 2)
    if (ans + x <= sum[i])
      ans = min(ans, sum[i + 1]);
  return x + ans <= sum[n];
}
int main() {
  scanf("%d", &n);
  int a[2] = {0, 0};
  for (int i = 1; i <= n; i++)
    scanf("%d", &num[i]), a[i & 1] += num[i];
  if (n & 1) {
    for (int i = 1; i <= n; i++)
      sum[i] = sum[i - 1] + (i & 1 ? 1 : -1) * num[i];
    int l = 0, r = a[0] + a[1], ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(mid))
        l = mid + 1, ans = mid;
      else
        r = mid - 1;
    }
    printf("%d %d\n", a[0] + ans, a[1] - ans);
  } else
    printf("%d %d\n", max(a[0], a[1]), min(a[0], a[1]));
  return 0;
}
Problem p03301 (C++)

Buggy submission (status: Time Limit Exceeded):
/**
 *    author:  tourist
 *    created: 23.11.2019 17:41:21
 **/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> s(2);
  for (int i = 0; i < n; i++) {
    s[i % 2] += a[i];
  }
  if (n % 2 == 0) {
    cout << max(s[0], s[1]) << " " << min(s[0], s[1]) << '\n';
    return 0;
  }
  int low = s[0], high = s[0] + s[1];
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    vector<bool> dp(n + 2, false);
    dp[0] = true;
    for (int i = 0; i < n; i += 2) {
      if (dp[i]) {
        int take = s[1];
        for (int j = i; j < n; j++) {
          if (j % 2 == 0)
            take += a[j];
          else
            take -= a[j];
          if (j % 2 == 0 && take >= mid) {
            dp[j + 2] = true;
          }
        }
      }
    }
    if (dp[n + 1]) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << " " << s[0] + s[1] - low << '\n';
  return 0;
}


Fixed submission:
/**
 *    author:  tourist
 *    created: 23.11.2019 17:41:21
 **/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> s(2);
  for (int i = 0; i < n; i++) {
    s[i % 2] += a[i];
  }
  if (n % 2 == 0) {
    cout << max(s[0], s[1]) << " " << min(s[0], s[1]) << '\n';
    return 0;
  }
  int low = s[0], high = s[0] + s[1];
  while (low < high) {
    int mid = (low + high + 1) >> 1;
    vector<bool> dp(n + 2, false);
    dp[0] = true;
    int take = s[1];
    for (int j = 0; j < n; j++) {
      if (dp[j]) {
        take = max(take, s[1]);
      }
      if (j % 2 == 0)
        take += a[j];
      else
        take -= a[j];
      if (j % 2 == 0 && take >= mid) {
        dp[j + 2] = true;
      }
    }
    if (dp[n + 1]) {
      low = mid;
    } else {
      high = mid - 1;
    }
  }
  cout << low << " " << s[0] + s[1] - low << '\n';
  return 0;
}
Problem p03301 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 300010
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int sum[N];
inline int check(int dat, int n) {
  int Min = 0;
  for (int i = 2; i <= n; i += 2)
    if (dat <= sum[i - 1] - Min)
      Min = min(Min, sum[i]);
  return dat <= sum[n] - Min;
}
int main() {
  int n = read(), A = 0, B = 0;
  for (int i = 1; i <= n; i++) {
    int dat = read();
    sum[i] = sum[i - 1];
    if (i & 1)
      A += dat, sum[i] += dat;
    else
      B += dat, sum[i] -= dat;
  }
  if (!(n & 1))
    return printf("%d %d", max(A, B), min(A, B));
  int l = -1e8, r = 1e8, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid, n))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d %d", max(A, B + ans), A + B - max(A, B + ans));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 300010
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch))
    ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int sum[N];
inline int check(int dat, int n) {
  int Min = 0;
  for (int i = 2; i <= n; i += 2)
    if (dat <= sum[i - 1] - Min)
      Min = min(Min, sum[i]);
  return dat <= sum[n] - Min;
}
int main() {
  int n = read(), A = 0, B = 0;
  for (int i = 1; i <= n; i++) {
    int dat = read();
    sum[i] = sum[i - 1];
    if (i & 1)
      A += dat, sum[i] += dat;
    else
      B += dat, sum[i] -= dat;
  }
  if (!(n & 1))
    return printf("%d %d", max(A, B), min(A, B)), 0;
  int l = -1e8, r = 1e8, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid, n))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%d %d", max(A, B + ans), A + B - max(A, B + ans));
  return 0;
}
Problem p03301 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[300010], sum[300010], n;
inline int check(int x) {
  int _min = 0;
  for (int i = 1; i <= n; i += 2) {
    if (sum[i] - _min >= x) {
      _min = min(_min, sum[i + 1]);
      if (i == n)
        return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (i % 2 == 0)
      a[i] = -a[i], sum1 -= a[i];
    else
      sum2 += a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if (n % 2 == 0)
    return printf("%d %d\n", max(sum1, sum2), min(sum1, sum2));
  int ans, l = -1.5e9, r = 1.5e9;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  return printf("%d %d\n", sum1 + ans, sum2 - ans), 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[300010], sum[300010], n;
inline int check(int x) {
  int _min = 0;
  for (int i = 1; i <= n; i += 2) {
    if (sum[i] - _min >= x) {
      _min = min(_min, sum[i + 1]);
      if (i == n)
        return 1;
    }
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  int sum1 = 0, sum2 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    if (i % 2 == 0)
      a[i] = -a[i], sum1 -= a[i];
    else
      sum2 += a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  if (n % 2 == 0)
    return printf("%d %d\n", max(sum1, sum2), min(sum1, sum2)), 0;
  int ans, l = -1.5e9, r = 1.5e9;
  while (l <= r) {
    int mid = l + r >> 1;
    if (check(mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  return printf("%d %d\n", sum1 + ans, sum2 - ans), 0;
}
Problem p03302 (Python)

Buggy submission (status: Runtime Error):
a, b = input().split()

if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")


Fixed submission:
a, b = map(int, input().split())

if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")
Problem p03302 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input())
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")


Fixed submission:
a, b = map(int, input().split())
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")
Problem p03302 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())

if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")


Fixed submission:
N = input().split(" ")
a = int(N[0])
b = int(N[1])
if a + b == 15:
    print("+")
elif a * b == 15:
    print("*")
else:
    print("x")
Problem p03302 (C++)

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

int main(void) {

  int a, b;

  scanf("%d %d", a, b);

  if (a * b == 15) {
    printf("*");
  } else if (a + b == 15) {
    printf("+");
  } else {
    printf("x");
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {

  int a, b;

  scanf("%d %d", &a, &b);

  if (a * b == 15) {
    printf("*");
  } else if (a + b == 15) {
    printf("+");
  } else {
    printf("x");
  }

  return 0;
}
Problem p03303 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define all(a) a.begin(), a.end()
#define VV(T) vector<vector<T>>
#define rep(i, N) for (int i = 0; i < N; i++)
#define repsg(i, s, g) for (int i = s; i < g; i++)
#define name(x) #x

using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL << 40;
const double PI = atan(1) * 4;
const long long MOD = pow(10, 9) + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

typedef long long ll, LL;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;

// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

int main() {
  string s;
  cin >> s;
  int w;
  cin >> w;
  int j = 0;
  while (j < s.size()) {
    cout << s[j * w];
    j++;
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <locale>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define all(a) a.begin(), a.end()
#define VV(T) vector<vector<T>>
#define rep(i, N) for (int i = 0; i < N; i++)
#define repsg(i, s, g) for (int i = s; i < g; i++)
#define name(x) #x

using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL << 40;
const double PI = atan(1) * 4;
const long long MOD = pow(10, 9) + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

typedef long long ll, LL;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;

// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

int main() {
  string s;
  cin >> s;
  int w;
  cin >> w;
  int j = 0;
  while (j * w < s.size()) {
    cout << s[j * w];
    j++;
  }
  cout << endl;
  return 0;
}
Problem p03303 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s;
  cin >> s;
  int w;
  cin >> w;
  rep(i, s.size() - 1 / w + 2) { cout << s[i * w]; }
  cout << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string s;
  cin >> s;
  int w;
  cin >> w;
  rep(i, s.size()) {
    if (i % w == 0) {
      cout << s[i];
    }
  }
  cout << endl;

  return 0;
}
Problem p03303 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <vector>
typedef long long unsigned int ll;
using namespace std;

int main() {
  string s;
  int w;
  cin >> s;
  cin >> w;
  for (int i = 0; i < s.length(); i++) {
    cout << s[i * w];
  }
  cout << endl;
  return 0;
}

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

int main() {
  string s;
  int w;
  cin >> s;
  cin >> w;
  for (int i = 0; i * w < s.length(); i++) {
    cout << s[i * w];
  }
  cout << endl;
  return 0;
}
Problem p03303 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a, b) memset((a), (b), sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash {
  size_t operator()(const string &str) const {
    return __stl_hash_string(str.c_str());
  }
};
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-4;
const int MAX = 2e5 + 10;
const ll mod = 1e9 + 7;
/***************************************  head
 * **********************************************/
int main() {
  string s;
  while (cin >> s) {
    int x;
    string ans = "";
    for (int i = 0; i < s.length(); i++) {
      if (i % x == 0)
        ans += s[i];
    }
    cout << ans << "\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a, b) memset((a), (b), sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash {
  size_t operator()(const string &str) const {
    return __stl_hash_string(str.c_str());
  }
};
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-4;
const int MAX = 2e5 + 10;
const ll mod = 1e9 + 7;
/***************************************  head
 * **********************************************/
int main() {
  string s;
  while (cin >> s) {
    int x;
    cin >> x;
    string ans = "";
    for (int i = 0; i < s.length(); i++) {
      if (i % x == 0)
        ans += s[i];
    }
    cout << ans << "\n";
  }
  return 0;
}
Problem p03303 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int w;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i += w) {
    cout << s[i];
  }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int w;
  string s;
  cin >> s >> w;
  for (int i = 0; i < s.size(); i += w) {
    cout << s[i];
  }
  cout << endl;
}
Problem p03303 (C++)

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

int main() {
  string a;
  int b;
  cin >> a >> b;
  if (a.size() / b == 0) {
    for (int i = 0; i <= a.size() / b; i++) {
      cout << a.at(i * b);
    }
  } else {
    for (int i = 0; i < a.size() / b + 1; i++) {
      cout << a.at(i * b);
    }
  }
  cout << endl;
}

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

int main() {
  string a;
  int b;
  cin >> a >> b;
  for (int i = 0; i < a.size(); i += b) {
    cout << a.at(i);
  }
  cout << endl;
}
Problem p03303 (C++)

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

using namespace std;
int main() {
  int w, i, j;
  char S[5000];
  cin >> S;
  cin >> w;
  for (i = 0; S[i] != '\0'; i++) {
  }
  if (i % j == 0) {
    for (j = 0; j < i / w; j++) {
      cout << S[w * j];
    }
  } else
    for (j = 0; j <= i / w; j++) {
      cout << S[w * j];
    }

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;
int main() {
  int w, i, j;
  char S[5000];
  cin >> S;
  cin >> w;
  for (i = 0; S[i] != '\0'; i++) {
  }
  if (i % w == 0) {
    for (j = 0; j < i / w; j++) {
      cout << S[w * j];
    }
  } else
    for (j = 0; j <= i / w; j++) {
      cout << S[w * j];
    }

  return 0;
}
Problem p03303 (C++)

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

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

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

int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  for (int i = 0; i < s.size(); i++)
    if (i % n == 0)
      cout << s[i];
  cout << endl;
}
Problem p03303 (C++)

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

int main() {
  string S;
  int w;
  cin >> S >> w;
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    cout << S[cnt];
    cnt += w;
  }
}

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

int main() {
  string S;
  int w;
  cin >> S >> w;
  int cnt = 0;
  for (int i = 0; i < S.size(); i++) {
    if (cnt >= S.size())
      return 0;
    cout << S[cnt];
    cnt += w;
  }
}
Problem p03303 (C++)

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

int main() {
  int w;
  string s;
  cin >> s >> w;
  int n = s.size() * w;
  string ans;
  for (int i = 0; i < n; i += w) {
    ans += s.at(i);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  int w;
  string s;
  cin >> s >> w;
  int n = s.size();
  string ans;
  for (int i = 0; i < n; i += w) {
    ans += s.at(i);
  }
  cout << ans << endl;

  return 0;
}
Problem p03303 (C++)

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

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

  int n;
  cin >> n;

  string ans;
  for (int i = 0; i < (S.size() / n) + 1; i++) {
    ans += S.at(i * n);
  }
  cout << ans << endl;
}

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

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

  int n;
  cin >> n;

  string ans;
  int tmp;

  if (S.size() % n == 0) {
    tmp = S.size() / n;
  } else {
    tmp = (S.size() / n) + 1;
  }

  for (int i = 0; i < tmp; i++) {
    ans += S.at(i * n);
  }
  cout << ans << endl;
}
Problem p03303 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
  string s, ans;
  int k;
  cin >> s;
  for (int i = 0; i < s.size(); i++)
    if (i % k == 0)
      ans += s[i];
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
  string s, ans;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++)
    if (i % k == 0)
      ans += s[i];
  cout << ans << endl;
  return 0;
}
Problem p03304 (C++)

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

// #define int long long
// #define ll int long long
#define REP(i, n) for (int i = 0; i < n; i++)
// #define ALL(vec) (vec).begin(),(vec).end()
// #define vint vector<int>
// #define pint pair<int,int>
// #define vpint vector<pint>
/*
int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int
y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
*/

long double n, m, d;

signed main() {
  cin >> n >> m >> d;
  long double ans = (m - 1) / n;
  if (d > 0)
    ans *= 2 * (n - d) / n;
  if (m == 2)
    throw;
  // if(n>1e8)for(;;);
  cout << ans << endl;
}


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

// #define int long long
// #define ll int long long
#define REP(i, n) for (int i = 0; i < n; i++)
// #define ALL(vec) (vec).begin(),(vec).end()
// #define vint vector<int>
// #define pint pair<int,int>
// #define vpint vector<pint>
/*
int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int
y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
*/

long double n, m, d;

signed main() {
  cin >> n >> m >> d;
  long double ans = (m - 1) / n;
  if (d > 0)
    ans *= 2 * (n - d) / n;
  cout << fixed << ans << endl;
}
Problem p03304 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 998244353;
const LL LINF = 1LL << 62;

int main() {
  double n, m, d;
  cin >> n >> m >> d;
  assert(d != 0);
  cout << fixed << setprecision(10) << (m - 1) / n << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<LL, LL> P;
const LL mod = 998244353;
const LL LINF = 1LL << 62;

int main() {
  double n, m, d;
  cin >> n >> m >> d;
  if (d == 0)
    cout << fixed << setprecision(10) << (m - 1) / n << endl;
  else
    cout << fixed << setprecision(10) << (m - 1) * 2 * (n - d) / (n * n)
         << endl;
  return 0;
}
Problem p03304 (Python)

Buggy submission (status: Time Limit Exceeded):
n, m, d = list(map(int, input().split()))

s = 1 if d == 0 else 2
ans = (n - d) * s * (n) ** (m - 2) * (m - 1) / n**m
print(ans)


Fixed submission:
n, m, d = list(map(int, input().split()))

s = 1 if d == 0 else 2
# ans = (n - d) * s * (n)**(m - 2) * (m - 1) / n**m
ans = (n - d) * s * (m - 1) / n**2
print(ans)
Problem p03304 (Python)

Buggy submission (status: Time Limit Exceeded):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M, D = list(map(int, sys.stdin.readline().split()))


# 数列の 1 つ目の要素が決まれば数も決まりそう
# 差が D となる数が上にだけある・下にだけある・上にも下にもある・どっちにもない
# 1 <= a <= N-D までは上にある
# D < a <= N までは下にある


def solve(n, m, d):
    arr = list(itertools.product(range(n), repeat=m))
    ans = 0
    for a in arr:
        for i in range(m - 1):
            if abs(a[i] - a[i + 1]) == d:
                ans += 1
    return ans


# 隣り合う要素を 2 つ決めたときに差が D となる組み合わせの数
if D == 0:
    c = N
else:
    c = (N - D) * 2

# 全部の合計
# pow(N, M - 2): ある 2 つの要素を決めたときにその位置にそれらを使う数列の数
s = c * pow(N, M - 2) * (M - 1)
# 個々の美しさがわからなくても合計がわかれば組み合わせ数で割れば平均になる
ans = s / pow(N, M)
print(ans)


Fixed submission:
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M, D = list(map(int, sys.stdin.readline().split()))


# 数列の 1 つ目の要素が決まれば数も決まりそう
# 差が D となる数が上にだけある・下にだけある・上にも下にもある・どっちにもない
# 1 <= a <= N-D までは上にある
# D < a <= N までは下にある


def solve(n, m, d):
    arr = list(itertools.product(range(n), repeat=m))
    ans = 0
    for a in arr:
        for i in range(m - 1):
            if abs(a[i] - a[i + 1]) == d:
                ans += 1
    return ans


# 隣り合う要素を 2 つ決めたときに差が D となる組み合わせの数
if D == 0:
    c = N
else:
    c = (N - D) * 2

# # 全部の合計
# # pow(N, M - 2): ある 2 つの要素を決めたときにその位置にそれらを使う数列の数
# s = c * pow(N, M - 2) * (M - 1)
# # 個々の美しさがわからなくても合計がわかれば組み合わせ数で割れば平均になる
# ans = s / pow(N, M)

# ans = c * (M - 1) * pow(N, M - 2) / pow(N, M)
ans = c * (M - 1) / N**2
print(ans)
Problem p03305 (C++)

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

#define MAX_V 10000

struct edge {
  int to;
  ll cost;
};

int V; // 頂点数

// 始点sから各頂点への最短距離を求める
void dijkstra(int s, vector<edge> G[], ll d[]) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int m, s, t;
  cin >> V >> m >> s >> t;
  s--;
  t--;
  int u, v;
  ll a, b;
  vector<edge> G1[MAX_V],
      G2[MAX_V]; // 辺の張り方 : G[from].push_back((edge){to, cost});
  REP(i, m) {
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G1[u].push_back((edge){v, a});
    G1[v].push_back((edge){u, a});
    G2[u].push_back((edge){v, b});
    G2[v].push_back((edge){u, b});
  }
  ll d1[MAX_V], d2[MAX_V];
  dijkstra(s, G1, d1);
  dijkstra(t, G2, d2);
  ll mx = 0;
  ll ans[V];
  for (int i = V - 1; i >= 0; i--) {
    mx = max(mx, 1000000000000000 - (d1[i] + d2[i]));
    ans[i] = mx;
  }
  REP(i, V) { cout << ans[i] << endl; }
}

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

#define MAX_V 100000

struct edge {
  int to;
  ll cost;
};

int V; // 頂点数

// 始点sから各頂点への最短距離を求める
void dijkstra(int s, vector<edge> G[], ll d[]) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int m, s, t;
  cin >> V >> m >> s >> t;
  s--;
  t--;
  int u, v;
  ll a, b;
  vector<edge> G1[MAX_V],
      G2[MAX_V]; // 辺の張り方 : G[from].push_back((edge){to, cost});
  REP(i, m) {
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G1[u].push_back((edge){v, a});
    G1[v].push_back((edge){u, a});
    G2[u].push_back((edge){v, b});
    G2[v].push_back((edge){u, b});
  }
  ll d1[MAX_V], d2[MAX_V];
  dijkstra(s, G1, d1);
  dijkstra(t, G2, d2);
  ll mx = 0;
  ll ans[V];
  for (int i = V - 1; i >= 0; i--) {
    mx = max(mx, 1000000000000000 - (d1[i] + d2[i]));
    ans[i] = mx;
  }
  REP(i, V) { cout << ans[i] << endl; }
}
Problem p03305 (C++)

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, int> pr;

#define MAX 10000
#define INF (1ll << 60)

struct edge {
  int to;
  ll cost;
};

int n, m;
vector<edge> yen[MAX + 1], snk[MAX + 1];
ll cost_y[MAX + 1], cost_s[MAX + 1];

void dijkstra(int s, vector<edge> g[], ll d[]) {
  priority_queue<pr, vector<pr>, greater<pr>> que;
  fill(d, d + n + 1, INF);
  d[s] = 0;
  que.push(pr(0, s));

  while (!que.empty()) {
    pr p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pr(d[e.to], e.to));
      }
    }
  }
  return;
}

int main() {
  int s, t;
  cin >> n >> m >> s >> t;
  for (int i = 0; i < m; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    yen[u].push_back(edge{v, a});
    yen[v].push_back(edge{u, a});
    snk[u].push_back(edge{v, b});
    snk[v].push_back(edge{u, b});
  }

  dijkstra(s, yen, cost_y);
  dijkstra(t, snk, cost_s);

  vector<ll> ans(n + 1);
  ll m_cost = INF;
  for (int i = n; i > 0; i--) {
    m_cost = min(m_cost, cost_y[i] + cost_s[i]);
    ans[i] = m_cost;
  }
  for (int i = 1; i <= n; i++)
    cout << 1000000000000000 - ans[i] << endl;
  return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, int> pr;

#define MAX 100000
#define INF (1ll << 60)

struct edge {
  int to;
  ll cost;
};

int n, m;
vector<edge> yen[MAX + 1], snk[MAX + 1];
ll cost_y[MAX + 1], cost_s[MAX + 1];

void dijkstra(int s, vector<edge> g[], ll d[]) {
  priority_queue<pr, vector<pr>, greater<pr>> que;
  fill(d, d + n + 1, INF);
  d[s] = 0;
  que.push(pr(0, s));

  while (!que.empty()) {
    pr p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < g[v].size(); i++) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pr(d[e.to], e.to));
      }
    }
  }
  return;
}

int main() {
  int s, t;
  cin >> n >> m >> s >> t;
  for (int i = 0; i < m; i++) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    yen[u].push_back(edge{v, a});
    yen[v].push_back(edge{u, a});
    snk[u].push_back(edge{v, b});
    snk[v].push_back(edge{u, b});
  }

  dijkstra(s, yen, cost_y);
  dijkstra(t, snk, cost_s);

  vector<ll> ans(n + 1);
  ll m_cost = INF;
  for (int i = n; i > 0; i--) {
    m_cost = min(m_cost, cost_y[i] + cost_s[i]);
    ans[i] = m_cost;
  }
  for (int i = 1; i <= n; i++)
    cout << 1000000000000000 - ans[i] << endl;
  return 0;
}
Problem p03305 (C++)

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF (1LL << 62)

auto dijkstra(vector<vector<pair<int, ll>>> const &graph, int start) {
  vector<ll> dist(graph.size(), INF);
  priority_queue<pair<ll, int>> que;
  que.push({0, start});
  while (!que.empty()) {
    ll d;
    int crr;
    tie(d, crr) = que.top();
    que.pop();
    if (dist[crr] <= d)
      continue;
    dist[crr] = d;
    for (auto pair : graph[crr]) {
      ll cost;
      int nxt;
      tie(nxt, cost) = pair;
      if (dist[nxt] - d <= cost)
        continue;
      que.push({d + cost, nxt});
    }
  }
  return dist;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  vector<vector<pair<int, ll>>> graph_yen(n), graph_s(n);
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    graph_yen[u].push_back({v, a});
    graph_yen[v].push_back({u, a});
    graph_s[u].push_back({v, b});
    graph_s[v].push_back({u, b});
  }
  vector<ll> dist_yen, dist_s;
  dist_yen = dijkstra(graph_yen, s);
  dist_s = dijkstra(graph_s, t);
  vector<ll> ans(n, 0);
  ll cost = INF;
  REPR(i, n - 1) {
    cost = min(cost, dist_yen[i] + dist_s[i]);
    ans[i] = cost;
  }
  REP(i, n) { cout << ll(1e15 - ans[i]) << endl; }
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

using ll = long long;
#define INF (1LL << 62)

auto dijkstra(vector<vector<pair<int, ll>>> const &graph, int start) {
  vector<ll> dist(graph.size(), INF);
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      que;
  que.push({0, start});
  while (!que.empty()) {
    ll d;
    int crr;
    tie(d, crr) = que.top();
    que.pop();
    if (dist[crr] <= d)
      continue;
    dist[crr] = d;
    for (auto pair : graph[crr]) {
      ll cost;
      int nxt;
      tie(nxt, cost) = pair;
      if (dist[nxt] - d <= cost)
        continue;
      que.push({d + cost, nxt});
    }
  }
  return dist;
}

int main() {
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  vector<vector<pair<int, ll>>> graph_yen(n), graph_s(n);
  REP(i, m) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    graph_yen[u].push_back({v, a});
    graph_yen[v].push_back({u, a});
    graph_s[u].push_back({v, b});
    graph_s[v].push_back({u, b});
  }
  vector<ll> dist_yen, dist_s;
  dist_yen = dijkstra(graph_yen, s);
  dist_s = dijkstra(graph_s, t);
  vector<ll> ans(n, 0);
  ll cost = INF;
  REPR(i, n - 1) {
    cost = min(cost, dist_yen[i] + dist_s[i]);
    ans[i] = cost;
  }
  REP(i, n) { cout << ll(1e15 - ans[i]) << endl; }
  return 0;
}