prithivMLmods/Coder-Stat huggingface dataset:
Problem p03395 (Python)

Buggy submission (status: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def make_graph(m):
    matrix = np.zeros([m + 1, m + 1, m + 1])
    for k in range(1, m + 1):
        for s in range(k, m + 1):
            matrix[k, s, s % k] = 1
    return matrix


def is_disable(matrix, subset, aaa, bbb):
    sub_matrix = matrix[list(subset)].max(axis=0)
    sp = floyd_warshall(sub_matrix)
    return any(sp[a, b] > 50 for a, b in zip(aaa, bbb))


def solve(aaa, bbb):
    for a, b in zip(aaa, bbb):
        if a < b:
            return -1
    m = max(aaa)
    matrix = make_graph(m)
    subset = set(range(1, m + 1))
    if is_disable(matrix, subset, aaa, bbb):
        return -1

    for k in range(m, 0, -1):
        subset.remove(k)
        if is_disable(matrix, subset, aaa, bbb):
            subset.add(k)
    return sum(1 << k for k in subset)


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(aaa, bbb))


Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def make_graph(m):
    matrix = np.zeros([m + 1, m + 1, m + 1])
    for k in range(1, m + 1):
        for s in range(k, m + 1):
            matrix[k, s, s % k] = 1
    return matrix


def is_disable(matrix, subset, aaa, bbb):
    if subset:
        sub_matrix = matrix[list(subset)].max(axis=0)
    else:
        sub_matrix = matrix[0]
    sp = floyd_warshall(sub_matrix)
    return any(sp[a, b] > 50 for a, b in zip(aaa, bbb))


def solve(aaa, bbb):
    for a, b in zip(aaa, bbb):
        if a < b:
            return -1
    m = max(aaa)
    matrix = make_graph(m)
    subset = set(range(1, m + 1))
    if is_disable(matrix, subset, aaa, bbb):
        return -1

    for k in range(m, 0, -1):
        subset.remove(k)
        if is_disable(matrix, subset, aaa, bbb):
            subset.add(k)
    return sum(1 << k for k in subset)


n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
print(solve(aaa, bbb))
Problem p03396 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int pos[100005];
int main() {
  // freopen("AGC022-D.in", "r", stdin);
  int n, len;
  scanf("%d%d", &n, &len);
  for (int i = 0; i < n; i++)
    scanf("%d", pos + i);
  long long ans = 1, l = 0, r = 0, arb = 0;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    ans += t / (len << 1);
    t %= len << 1;
    if (!t)
      continue;
    bool f = t <= pos[i] << 1, g = t <= (len - pos[i]) << 1;
    if (i == n - 1)
      ans -= g;
    else if (f) {
      l++;
      if (g)
        arb++;
    } else if (g)
      r++;
    while (l - arb < r + arb) {
      if (arb)
        arb--;
      else
        r--;
    }
    ans++;
  }
  printf("%lld\n", (ans - arb - r) * (len << 1));
  return 0;
}


Fixed submission:
#include <cstdio>
int pos[300005];
int main() {
  // freopen("AGC022-D.in", "r", stdin);
  int n, len;
  scanf("%d%d", &n, &len);
  for (int i = 0; i < n; i++)
    scanf("%d", pos + i);
  long long ans = 1, l = 0, r = 0, arb = 0;
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    ans += t / (len << 1);
    t %= len << 1;
    if (!t)
      continue;
    bool f = t <= pos[i] << 1, g = t <= (len - pos[i]) << 1;
    if (i == n - 1)
      ans -= g;
    else if (f) {
      l++;
      if (g)
        arb++;
    } else if (g)
      r++;
    while (l - arb < r + arb) {
      if (arb)
        arb--;
      else
        r--;
    }
    ans++;
  }
  printf("%lld\n", (ans - arb - r) * (len << 1));
  return 0;
}
Problem p03396 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
const int N = 100100;
inline int read() {
  int x = 0, f = 0, c = getchar();
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
inline void write(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
struct cqz {
  int l, r;
} a[N];
ll ans;
int n, m, i, sl, sm, x[N], t[N];
int main() {
  // freopen("1.out","w",stdout);
  n = read();
  m = read();
  m = m + m;
  ans = m;
  for (i = 1; i <= n; i++)
    x[i] = read();
  for (i = 1; i <= n; i++) {
    t[i] = read();
    ans += (t[i] / m) * m;
    t[i] = t[i] % m;
    if (t[i] == 0)
      continue;
    a[i].l = (t[i] <= x[i] + x[i]);
    a[i].r = (t[i] <= m - x[i] - x[i]);
    ans += m;
  }
  for (i = 1; i < n; i++) {
    if (sl && a[i].r) {
      if (a[i].l)
        sm++;
      sl--;
      ans -= m;
    } else if (!a[i].l && a[i].r) {
      if (sm)
        sm--, sl++;
    } else if (a[i].l)
      ++sl;
  }
  if (a[n].r)
    ans -= m;
  write(ans);
  puts("");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;
const int N = 500100;
inline int read() {
  int x = 0, f = 0, c = getchar();
  for (; c > '9' || c < '0'; f = c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  return f ? -x : x;
}
inline void write(ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
struct cqz {
  int l, r;
} a[N];
ll ans;
int n, m, i, sl, sm, x[N], t[N];
int main() {
  // freopen("1.out","w",stdout);
  n = read();
  m = read();
  m = m + m;
  ans = m;
  for (i = 1; i <= n; i++)
    x[i] = read();
  for (i = 1; i <= n; i++) {
    t[i] = read();
    ans += (t[i] / m) * m;
    t[i] = t[i] % m;
    if (t[i] == 0)
      continue;
    a[i].l = (t[i] <= x[i] + x[i]);
    a[i].r = (t[i] <= m - x[i] - x[i]);
    ans += m;
  }
  for (i = 1; i < n; i++) {
    if (sl && a[i].r) {
      if (a[i].l)
        sm++;
      sl--;
      ans -= m;
    } else if (!a[i].l && a[i].r) {
      if (sm)
        sm--, sl++;
    } else if (a[i].l)
      ++sl;
  }
  if (a[n].r)
    ans -= m;
  write(ans);
  puts("");
  return 0;
}
Problem p03397 (C++)

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

const int _ = 3e5 + 7, MOD = 1e9 + 7;
int N, dp[_][4][3];
char str[_];

int main() {
  scanf("%s", str + 1);
  N = strlen(str + 1);
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    if (str[i] != '1')
      for (int j = 0; j <= 3; ++j)
        for (int k = 0; k < 3; ++k) {
          if (dp[i - 1][j][k])
            dp[i][j][k == 2 ? 1 : k + 1] =
                (dp[i][j][k == 2 ? 1 : k + 1] + dp[i - 1][j][k]) % MOD;
        }
    if (str[i] != '0')
      for (int j = 0; j <= 3; ++j)
        for (int k = 0; k < 3; ++k)
          if (dp[i - 1][j][k])
            dp[i][min(j + (k == 0), 3)][max(k - 1, 0)] =
                (dp[i][min(j + (k == 0), 3)][max(k - 1, 0)] + dp[i - 1][j][k]) %
                MOD;
  }
  int sum = 0;
  for (int i = 0; i <= 3; ++i)
    for (int j = 0; j <= i; ++j)
      sum = (sum + dp[N][i][j]) % MOD;
  cout << sum;
  return 0;
}

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

const int _ = 3e5 + 7, MOD = 1e9 + 7;
int N, dp[_][4][3];
char str[_];

int main() {
  scanf("%s", str + 1);
  N = strlen(str + 1);
  dp[0][0][0] = 1;
  for (int i = 1; i <= N; ++i) {
    if (str[i] != '1')
      for (int j = 0; j <= 3; ++j)
        for (int k = 0; k < 3; ++k) {
          if (dp[i - 1][j][k])
            dp[i][j][k == 2 ? 1 : k + 1] =
                (dp[i][j][k == 2 ? 1 : k + 1] + dp[i - 1][j][k]) % MOD;
        }
    if (str[i] != '0')
      for (int j = 0; j <= 3; ++j)
        for (int k = 0; k < 3; ++k)
          if (dp[i - 1][j][k])
            dp[i][min(j + (k == 0), 3)][max(k - 1, 0)] =
                (dp[i][min(j + (k == 0), 3)][max(k - 1, 0)] + dp[i - 1][j][k]) %
                MOD;
  }
  int sum = 0;
  for (int i = 0; i <= 3; ++i)
    for (int j = 0; j < i; ++j)
      sum = (sum + dp[N][i][j]) % MOD;
  cout << sum;
  return 0;
}
Problem p03397 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(a, b, c) for (int a = b; a <= c; a++)
#define per(a, b, c) for (int a = b; a >= c; a--)
#define go(u) for (int o = ft[u], v; v = E[o].t, o; o = E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> par;
typedef double dob;
/*
0:
1:0
2:00
3:1
4:10
5:100
6:11
*/
const int N = 300010, P = 1000000007;
int n, g[N], f[N], h[N];
char s[N];
void add(int &x, int y) { x = (x + y) % P; }
void tran(int k) {
  memset(g, 0, sizeof(g));
  memset(h, 0, sizeof(h));
  add(g[1], f[0]);
  add(g[2], f[1]);
  add(g[1], f[2]);
  add(g[4], f[3]);
  add(g[5], f[4]);
  add(g[4], f[5]);
  add(g[6], f[6]);

  add(h[3], f[0]);
  add(h[0], f[1]);
  add(h[1], f[2]);
  add(h[6], f[3]);
  add(h[3], f[4]);
  add(h[4], f[5]);
  add(h[6], f[6]);
  if (k == 0)
    swap(f, g);
  else if (k == 1)
    swap(f, h);
  else {
    rep(i, 0, 6) add(g[i], h[i]);
    swap(f, g);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0] = 1;
  rep(i, 1, n) tran(s[i] == '?' ? 2 : s[i] - '0');
  LL ans = f[6] + f[3];
  ans = (ans % P + P) % P;
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define rep(a, b, c) for (int a = b; a <= c; a++)
#define per(a, b, c) for (int a = b; a >= c; a--)
#define go(u) for (int o = ft[u], v; v = E[o].t, o; o = E[o].n)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> par;
typedef double dob;
/*
0:
1:0
2:00
3:1
4:10
5:100
6:11
*/
const int N = 300010, P = 1000000007;
int n, g[7], f[7], h[7];
char s[N];
void add(int &x, int y) { x = (x + y) % P; }
void tran(int k) {
  memset(g, 0, sizeof(g));
  memset(h, 0, sizeof(h));
  add(g[1], f[0]);
  add(g[2], f[1]);
  add(g[1], f[2]);
  add(g[4], f[3]);
  add(g[5], f[4]);
  add(g[4], f[5]);
  add(g[6], f[6]);

  add(h[3], f[0]);
  add(h[0], f[1]);
  add(h[1], f[2]);
  add(h[6], f[3]);
  add(h[3], f[4]);
  add(h[4], f[5]);
  add(h[6], f[6]);
  if (k == 0)
    swap(f, g);
  else if (k == 1)
    swap(f, h);
  else {
    rep(i, 0, 6) add(g[i], h[i]);
    swap(f, g);
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0] = 1;
  rep(i, 1, n) tran(s[i] == '?' ? 2 : s[i] - '0');
  LL ans = f[6] + f[3];
  ans = (ans % P + P) % P;
  printf("%lld\n", ans);
  return 0;
}
Problem p03397 (C++)

Buggy submission (status: Runtime Error):
/*
        考虑入栈的顺序和删除的优先级
        插入 0
        1  : 直接插入
        0  : 直接插入
        00 : 变成 1 个 0
        插入 1
        1  : 直接插入
        11 : 不插入
        0  : 抵消掉一个 0
*/
#include <bits/stdc++.h>
#define N 30005

using namespace std;

const int mod = 1e9 + 7;

int n, m;
char s[N];

int f[N][3][3];

void Inc(int &u, int v) {
  if ((u += v) >= mod)
    u -= mod;
}

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i + 1] == '0' || s[i + 1] == '?') {
      for (int c1 = 0; c1 < 3; ++c1) {
        Inc(f[i + 1][c1][1], f[i][c1][0]);
        Inc(f[i + 1][c1][2], f[i][c1][1]);
        Inc(f[i + 1][c1][1], f[i][c1][2]);
      }
    }
    if (s[i + 1] == '1' || s[i + 1] == '?') {
      for (int c1 = 0; c1 < 3; ++c1) {
        Inc(f[i + 1][min(c1 + 1, 2)][0], f[i][c1][0]);
        Inc(f[i + 1][c1][0], f[i][c1][1]);
        Inc(f[i + 1][c1][1], f[i][c1][2]);
      }
    }
  }
  int ans = 0;
  for (int c0 = 0; c0 < 3; ++c0)
    for (int c1 = c0; c1 < 3; ++c1)
      Inc(ans, f[n][c1][c0]);
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
/*
        考虑入栈的顺序和删除的优先级
        插入 0
        1  : 直接插入
        0  : 直接插入
        00 : 变成 1 个 0
        插入 1
        1  : 直接插入
        11 : 不插入
        0  : 抵消掉一个 0
*/
#include <bits/stdc++.h>
#define N 300005

using namespace std;

const int mod = 1e9 + 7;

int n, m;
char s[N];

int f[N][3][3];

void Inc(int &u, int v) {
  if ((u += v) >= mod)
    u -= mod;
}

int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  f[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    if (s[i + 1] == '0' || s[i + 1] == '?') {
      for (int c1 = 0; c1 < 3; ++c1) {
        Inc(f[i + 1][c1][1], f[i][c1][0]);
        Inc(f[i + 1][c1][2], f[i][c1][1]);
        Inc(f[i + 1][c1][1], f[i][c1][2]);
      }
    }
    if (s[i + 1] == '1' || s[i + 1] == '?') {
      for (int c1 = 0; c1 < 3; ++c1) {
        Inc(f[i + 1][min(c1 + 1, 2)][0], f[i][c1][0]);
        Inc(f[i + 1][c1][0], f[i][c1][1]);
        Inc(f[i + 1][c1][1], f[i][c1][2]);
      }
    }
  }
  int ans = 0;
  for (int c0 = 0; c0 < 3; ++c0)
    for (int c1 = c0; c1 < 3; ++c1)
      Inc(ans, f[n][c1][c0]);
  printf("%d\n", ans);
  return 0;
}
Problem p03398 (C++)

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

using namespace std;

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f ? x : -x;
}

typedef long long LL;
const int maxn = 60, mod = 1e9 + 7;
int inv[maxn], fac[maxn], ifac[maxn], f[maxn][maxn];

int C(int N, int M) { return (LL)fac[N] * ifac[M] % mod * ifac[N - M] % mod; }

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

  int n = read();

  inv[0] = inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fac[i] = (LL)fac[i - 1] * i % mod;
    inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
    ifac[i] = (LL)ifac[i - 1] * inv[i] % mod;
  }

  f[1][0] = f[1][1] = 1;
  for (int i = 1; i < n; ++i)
    for (int j = 0; j <= i; ++j)
      if (f[i][j])
        for (int x = 0; x + i <= n; ++x)
          for (int y = 0; y + x + i <= n; ++y)
            if ((x + y) && (x + y >= j) && (!((x + y - j) & 1)))
              (f[i + x + y][abs((x + y - j) / 2 + j - x)] +=
               (LL)f[i][j] * C(i + x + y, x + y) % mod * C(x + y, x) % mod) %=
                  mod;

  cout << f[n][0] << endl;

  return 0;
}

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

using namespace std;

int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = 0;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f ? x : -x;
}

typedef long long LL;
const int maxn = 60, mod = 1e9 + 7;
int inv[maxn], fac[maxn], ifac[maxn], f[maxn][maxn];

int C(int N, int M) { return (LL)fac[N] * ifac[M] % mod * ifac[N - M] % mod; }

int main() {
  int n = read();

  inv[0] = inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fac[i] = (LL)fac[i - 1] * i % mod;
    inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
    ifac[i] = (LL)ifac[i - 1] * inv[i] % mod;
  }

  f[1][0] = f[1][1] = 1;
  for (int i = 1; i < n; ++i)
    for (int j = 0; j <= i; ++j)
      if (f[i][j])
        for (int x = 0; x + i <= n; ++x)
          for (int y = 0; y + x + i <= n; ++y)
            if ((x + y) && (x + y >= j) && (!((x + y - j) & 1)))
              (f[i + x + y][abs((x + y - j) / 2 + j - x)] +=
               (LL)f[i][j] * C(i + x + y, x + y) % mod * C(x + y, x) % mod) %=
                  mod;

  cout << f[n][0] << endl;

  return 0;
}
Problem p03398 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define re
int f[510][510], gg[510][1020], *g[510], c[510][510];
inline int abss(re int a) { return a > 0 ? a : -a; }
int main() {
  re int n, mod;
  scanf("%d%d", &n, &mod);
  for (re int i = 1; i <= n; i++) {
    g[i] = gg[i] + 510;
  }
  f[1][0] = f[1][1] = n;
  c[0][0] = 1;
  for (re int i = 1; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    for (re int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
  for (re int i = 1; i <= n; i++) {
    for (re int j = -i; j <= i; j++)
      if (g[i][j]) {
        { // printf("*%d %d %d\n",i,j,g[i][j]);
          for (re int x = (j <= 0 ? (-j) % 2 : j); i + x <= n; x += 2)
            f[i + x][abss((j + x) / 2)] = (f[i + x][abss((j + x) / 2)] +
                                           (long long)g[i][j] * c[n - i][x]) %
                                          mod;
        }
      }
    for (re int j = 0; j <= i; j++)
      if (f[i][j]) {
        for (re int x = 1; i + x <= n; x++) {
          if (x >= j && (!((j + x) % 2)))
            f[i + x][(j + x) / 2] =
                (f[i + x][(j + x) / 2] + (long long)f[i][j] * c[n - i][x]) %
                mod;
          g[i + x][j - x] =
              (g[i + x][j - x] + (long long)f[i][j] * c[n - i][x]) % mod;
        }
      }
  }
  printf("%d\n", f[n][0]);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define re
int f[510][510], gg[510][1020], *g[510], c[510][510];
inline int abss(re int a) { return a > 0 ? a : -a; }
int main() {
  re int n, mod = 1e9 + 7;
  scanf("%d", &n);
  for (re int i = 1; i <= n; i++) {
    g[i] = gg[i] + 510;
  }
  f[1][0] = f[1][1] = n;
  c[0][0] = 1;
  for (re int i = 1; i <= n; i++) {
    c[i][0] = c[i][i] = 1;
    for (re int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
    }
  }
  for (re int i = 1; i <= n; i++) {
    for (re int j = -i; j <= i; j++)
      if (g[i][j]) {
        { // printf("*%d %d %d\n",i,j,g[i][j]);
          for (re int x = (j <= 0 ? (-j) % 2 : j); i + x <= n; x += 2)
            f[i + x][abss((j + x) / 2)] = (f[i + x][abss((j + x) / 2)] +
                                           (long long)g[i][j] * c[n - i][x]) %
                                          mod;
        }
      }
    for (re int j = 0; j <= i; j++)
      if (f[i][j]) {
        for (re int x = 1; i + x <= n; x++) {
          if (x >= j && (!((j + x) % 2)))
            f[i + x][(j + x) / 2] =
                (f[i + x][(j + x) / 2] + (long long)f[i][j] * c[n - i][x]) %
                mod;
          g[i + x][j - x] =
              (g[i + x][j - x] + (long long)f[i][j] * c[n - i][x]) % mod;
        }
      }
  }
  printf("%d\n", f[n][0]);
}
Problem p03399 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int a, b, c, d;
  int x, y;
  scanf("%d %d %d %d");

  if (a > b) {
    x = b;
  } else if (a < b) {
    x = a;
  } else if (a = b) {
    x = a;
  }

  if (c > d) {
    y = d;
  } else if (c < d) {
    y = c;
  } else if (c = d) {
    y = c;
  }
  printf("%d\n", x + y);

  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int a, b, c, d;
  int x, y;
  scanf("%d %d %d %d", &a, &b, &c, &d);

  if (a > b) {
    x = b;
  } else if (a < b) {
    x = a;
  } else if (a = b) {
    x = a;
  }

  if (c > d) {
    y = d;
  } else if (c < d) {
    y = c;
  } else if (c = d) {
    y = c;
  }
  printf("%d\n", x + y);

  return 0;
}
Problem p03399 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) {
  li res = 1;
  while (b) {
    if (b % 2)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) {
  li cnt = 0;
  while (n) {
    n &= (n - 1);
    cnt++;
  }
  return cnt;
}

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d);
}

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define li long long int
#define ld long double
const int MX1 = 1e5 + 5;
const int MX2 = 1e6 + 5;
const li inf = 4e18;
const li mod = 1e9 + 7;

li power(li a, li b) {
  li res = 1;
  while (b) {
    if (b % 2)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}

li mmi(li a) { return power(a, mod - 2); }

li cntbit(li n) {
  li cnt = 0;
  while (n) {
    n &= (n - 1);
    cnt++;
  }
  return cnt;
}

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d);
}

int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
a, b, c, d = map(int, input().split())

print(min(a, b) + min(c, d))


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())

print(min(a, b) + min(c, d))
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    a, b, c, d = map(int, string.split())
    return str(min(a, b) + min(c, d))


if __name__ == "__main__":
    n = 4
    print(solve("n".join([input() for _ in range(n)])))


Fixed submission:
def solve(string):
    a, b, c, d = map(int, string.split())
    return str(min(a, b) + min(c, d))


if __name__ == "__main__":
    n = 4
    print(solve("\n".join([input() for _ in range(n)])))
Problem p03399 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
int max(int x, int y) {
  if (x <= y) {
    return x;
  }

  else {
    return y;
  }
}
int main() {
  int a, b, c, d;

  while (scanf("%d%d%d%d", &a, &b, &c, &d)) {
    printf("%d", max(a, b) + max(c, d));
  }

  return 0;
}

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

using namespace std;
int max(int x, int y) {
  if (x <= y) {
    return x;
  }

  else {
    return y;
  }
}
int main() {
  int a, b, c, d;

  while (scanf("%d%d%d%d", &a, &b, &c, &d) == 4) {
    printf("%d\n", max(a, b) + max(c, d));
  }

  return 0;
}
Problem p03399 (C++)

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

int main() {
  int n, d, k, count;
  cin >> n >> d >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(n);
    for (int j = 1; j <= d; j += a.at(i)) {
      count++;
    }
  }
  cout << count + k << endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a = min(a, b);
  c = min(c, d);
  cout << a + c << endl;
}
Problem p03399 (C++)

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) != s.at(1) && s.at(1) != s.at(2) && s.at(2) != s.at(0))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
  return 0;
}
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
a, b, c, d = map(int, input().split())
print(min(a + c, a + d, b + c, b + d))


Fixed submission:
a, b, c, d = [int(input()) for _ in range(4)]
print(min(a + c, a + d, b + c, b + d))
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
def main():
    A, B, C, D = map(int, input().split())
    print(min(A, B) + min(C, D))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    A, B, C, D = [int(input()) for _ in range(4)]
    print(min(A, B) + min(C, D))


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

Buggy submission (status: Runtime Error):
ABCD = []
for i in range(4):
    ticket = int(input())
    hodai = int(input())
    ABCD.append(min(ticket, hodai))

print(sum(ABCD))


Fixed submission:
ABCD = []
for i in range(2):
    ticket = int(input())
    hodai = int(input())
    ABCD.append(min(ticket, hodai))

print(sum(ABCD))
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
def main(A: int, B: int, C: int, D: int):
    train, bus = 0, 0
    if A <= B:
        train += A
    else:
        train += B

    if C <= D:
        bus += C
    else:
        bus += D

    return train + bus


if __name__ == "__main__":
    A, B, C, D = map(int, input().split(" "))
    print(main(A, B, C, D))


Fixed submission:
def main(A: int, B: int, C: int, D: int):
    train, bus = 0, 0
    if A <= B:
        train += A
    else:
        train += B

    if C <= D:
        bus += C
    else:
        bus += D

    return train + bus


if __name__ == "__main__":
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    print(main(A, B, C, D))
Problem p03399 (C++)

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

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

using namespace std;

int main() {
  valarray<int> ab, cd;
  cin >> ab[0];
  cin >> ab[1];
  cin >> cd[0];
  cin >> cd[1];

  cout << ab.min() + cd.min();

  return 0;
}


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

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

using namespace std;

int main() {
  valarray<int> ab(2), cd(2);
  cin >> ab[0];
  cin >> ab[1];
  cin >> cd[0];
  cin >> cd[1];

  cout << ab.min() + cd.min();

  return 0;
}
Problem p03399 (Python)

Buggy submission (status: Runtime Error):
A, B, C, D = map(int, input().split())
print(min(A, B) + min(C, D))


Fixed submission:
A, B, C, D = [int(input()) for _ in range(4)]
print(min(A, B) + min(C, D))
Problem p03400 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int N, D, X, eaten_n;

  int A[110];

  cin >> N >> D >> X;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  eaten_n = N;

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < D; ++i) {
      if (j * A[i] + 1 <= D) {
        eaten_n = eaten_n + 1;
      }
    }
  }

  cout << eaten_n + X << endl;
}

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

int main() {
  int N, D, X, eaten_n;

  int A[110];

  cin >> N >> D >> X;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  eaten_n = N;

  for (int i = 0; i < N; ++i) {
    for (int j = 1; j <= D; ++j) {
      if (j * A[i] + 1 <= D) {
        eaten_n = eaten_n + 1;
      }
    }
  }

  cout << eaten_n + X << endl;
}
Problem p03400 (C++)

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

int main() {
  int N;
  cin >> N;
  int D;
  int X;
  cin >> D >> X;
  int a[X];

  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  int total = 0;
  int taberu = 0;
  for (int i = 0; i < N; ++i) {

    int tabeta = 0;
    for (int j = 0; j < D; ++j) {

      taberu = a[i] * tabeta + 1;
      if (j == taberu - 1) {
        total++;
        tabeta++;
      }
    }
  }

  total += X;

  cout << total << endl;
}


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

int main() {
  int N;
  cin >> N;
  int D;
  int X;
  cin >> D >> X;
  int a[N];

  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  int total = 0;
  int taberu = 0;
  for (int i = 0; i < N; ++i) {

    int tabeta = 0;
    for (int j = 0; j < D; ++j) {

      taberu = a[i] * tabeta + 1;
      if (j == taberu - 1) {
        total++;
        tabeta++;
      }
    }
  }

  total += X;

  cout << total << endl;
}
Problem p03400 (C++)

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, d) {
    rep(j, n) {
      if (i %= a[j] == 0)
        ++x;
    }
  }
  cout << x << endl;
  return 0;
}

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(i, d) {
    rep(j, n) {
      if (i % a[j] == 0)
        ++x;
    }
  }
  cout << x << endl;
  return 0;
}
Problem p03400 (C++)

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

int main() {
  int N;
  int D, X;
  int result = 0;
  cin >> N >> D >> X;
  result += X;

  for (int i = 0; i < N; i++) {
    int A;
    result++;
    result += (int)((D - 1) / A);
  }

  cout << result << endl;

  return 0;
}


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

int main() {
  int N;
  int D, X;
  int result = 0;
  cin >> N >> D >> X;
  result += X;

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    result++;
    result += (int)((D - 1) / A);
  }

  cout << result << endl;

  return 0;
}
Problem p03400 (C++)

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

int main() {
  int n, d, k, count;
  cin >> n >> d >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(n);
    for (int j = 1; j <= d; j += a.at(i)) {
      count++;
    }
  }
  cout << count + k << endl;
}


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

int main() {
  int n, d, k, count;
  cin >> n >> d >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    for (int j = 1; j <= d; j += a.at(i)) {
      count++;
    }
  }
  cout << count + k << endl;
}
Problem p03400 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
D, X = map(int, input().split())
A = list(input() for i in range(N))
sum = 0
for i in range(N):
    B = 0
    while B * A[i] + 1 <= D:
        B += 1
        sum += 1
print(X + sum)


Fixed submission:
N = int(input())
D, X = map(int, input().split())
A = list(int(input()) for i in range(N))
sum = 0
for i in range(N):
    B = 0
    while B * A[i] + 1 <= D:
        B += 1
        sum += 1
print(X + sum)
Problem p03400 (C++)

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  vector<int> b(n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(n);
    b.at(i) = (d - 1 + a.at(i)) / a.at(i);
    total += b.at(i);
  }
  cout << x + total << endl;
}

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

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  vector<int> b(n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    b.at(i) = (d - 1 + a.at(i)) / a.at(i);
    total += b.at(i);
  }
  cout << x + total << endl;
}
Problem p03400 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using ll = long long;

int main() {
  ll n, d, x;
  std::cin >> n >> d >> x;
  std::vector<ll> a;
  for (int i = 0; i < n; i++) {
    ll b;
    std::cin >> b;
    a.push_back(b);
  }

  std::vector<ll> ch(d + 1, 0);
  for (auto &ai : a) {
    for (int i = 0; i <= d; i++) {
      ch[i * ai + 1]++;
    }
  }

  std::cout << x + std::accumulate(ch.begin(), ch.end(), 0LL);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using ll = long long;

int main() {
  ll n, d, x;
  std::cin >> n >> d >> x;
  std::vector<ll> a;
  for (int i = 0; i < n; i++) {
    ll b;
    std::cin >> b;
    a.push_back(b);
  }

  std::vector<ll> ch(d + 1, 0);
  for (auto &ai : a) {
    for (int i = 0; i * ai + 1 <= d; i++) {
      ch[i * ai + 1]++;
    }
  }

  std::cout << x + std::accumulate(ch.begin(), ch.end(), 0LL);
  return 0;
}
Problem p03400 (C++)

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

int main(void) {
  int N, D, i, A[N], X, j, s = 0;

  scanf("%d%d%d", &N, &D, &X);

  for (i = 0; i < N; i++)
    scanf("%d", &A[i]);

  for (i = 0; i < N; i++) {
    for (j = 1; j <= D; j = j + A[i])
      s++;
  }

  printf("%d\n", s + X);

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int N, D, i, A[100], X, j, s = 0;

  scanf("%d%d%d", &N, &D, &X);

  for (i = 0; i < N; i++)
    scanf("%d", &A[i]);

  for (i = 0; i < N; i++) {
    for (j = 1; j <= D; j = j + A[i])
      s++;
  }

  printf("%d\n", s + X);

  return 0;
}
Problem p03400 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, d, x, a[110];
  cin >> n >> d >> x;
  int re = 0;
  for (int i = 0; i < n; i++) {
    if (d % a[i] != 0)
      re += d / a[i] + 1;
    else {
      re += d / a[i];
    }
  }
  re += x;
  cout << re << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, d, x, a[110];
  cin >> n >> d >> x;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int re = 0;
  for (int i = 0; i < n; i++) {
    if (d % a[i] != 0)
      re += d / a[i] + 1;
    else {
      re += d / a[i];
    }
  }
  re += x;
  cout << re << endl;
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A[10000], s = 0;
  cin >> N;
  A[-1] == 0;
  A[N + 1] == 0;
  for (int i = 1; i <= N + 1; i++) {
    cin >> A[i];
    s += abs(A[i] - A[i - 1]);
  }
  for (int i = 1; i <= N; i++) {
    cout << s - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A[100000], s = 0;
  cin >> N;
  A[-1] == 0;
  A[N + 1] == 0;
  for (int i = 1; i <= N + 1; i++) {
    cin >> A[i];
    s += abs(A[i] - A[i - 1]);
  }
  for (int i = 1; i <= N; i++) {
    cout << s - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1])) +
                abs(A[i + 1] - A[i - 1])
         << endl;
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
  int n, a[10000], dist[10000], sum = 0;
  cin >> n;
  a[0] = 0;
  a[n + 1] = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i <= n; i++) {
    dist[i] = abs(a[i] - a[i + 1]);
    sum += dist[i];
  }
  for (int i = 0; i < n; i++)
    cout << sum - (dist[i] + dist[i + 1]) + abs(a[i + 2] - a[i]) << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
  int n, a[100010], dist[100010], sum = 0;
  cin >> n;
  a[0] = 0;
  a[n + 1] = 0;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 0; i <= n; i++) {
    dist[i] = abs(a[i] - a[i + 1]);
    sum += dist[i];
  }
  for (int i = 0; i < n; i++)
    cout << sum - (dist[i] + dist[i + 1]) + abs(a[i + 2] - a[i]) << endl;
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N, a[10000], i, sum = 0;
  ;
  cin >> N;
  a[0] = 0;
  a[N] = 0;
  for (i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (i = 0; i <= N + 1; i++) {
    sum += abs(a[i + 1] - a[i]);
  }
  for (i = 1; i <= N; i++) {
    int s;
    s = sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
        abs(a[i + 1] - a[i - 1]);
    cout << s << endl;
  }
  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int N, a[1000010], i, sum = 0;
  ;
  cin >> N;
  a[0] = 0;
  a[N] = 0;
  for (i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (i = 0; i <= N + 1; i++) {
    sum += abs(a[i + 1] - a[i]);
  }
  for (i = 1; i <= N; i++) {
    int s;
    s = sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
        abs(a[i + 1] - a[i - 1]);
    cout << s << endl;
  }
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < (0) ? -(a) : (a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for (typeof(n) i = (a); i < (n); i++)

int N;
int a[100010];

int main() {
  cin >> N;
  rep(i, N) cin >> a[i];
  rep(i, N) {
    ll ans = 0;
    int prev = 0;
    rep(j, N) {
      if (i == j)
        continue;
      ans += abs(a[j] - prev);
      prev = a[j];
    }
    cout << ans + abs(prev - 0) << endl;
  }
}


Fixed submission:
#include <iostream>

using namespace std;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < (0) ? -(a) : (a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for (typeof(n) i = (a); i < (n); i++)

int N;
int a[100010];

int main() {
  cin >> N;
  int mini = 0, maxi = 0;
  ll total = 0;
  REP(i, 1, N + 1) {
    cin >> a[i];
    mini = a[i] < a[mini] ? i : mini;
    maxi = a[i] > a[maxi] ? i : maxi;
    total += abs(a[i - 1] - a[i]);
  }
  total += abs(a[N]);
  REP(i, 1, N + 1) {
    cout << total - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]) -
                     abs(a[i - 1] - a[i + 1]))
         << endl;
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include "stdio.h"
#include "stdlib.h"

int main() {
  int N;           // スポットの数
  int spot[10002]; // スポットの座標
  int j, i, k;
  int sum = 0; // 全体の金額
  int sum_i;

  scanf("%d", &N);

  spot[0] = 0;
  spot[N + 1] = 0;

  for (i = 1; i <= N; i++) {
    scanf("%d", &spot[i]);
  }

  for (j = 1; j <= N + 1; j++) {
    sum += abs(spot[j] - spot[j - 1]);
  }

  for (k = 1; k <= N; k++) {
    sum_i = sum + abs(spot[k - 1] - spot[k + 1]) - abs(spot[k - 1] - spot[k]) -
            abs(spot[k] - spot[k + 1]);
    printf("%d\n", sum_i);
  }
  return 0;
}


Fixed submission:
#include "stdio.h"
#include "stdlib.h"

int main() {
  int N;            // スポットの数
  int spot[100002]; // スポットの座標
  int j, i, k;
  int sum = 0; // 全体の金額
  int sum_i;

  scanf("%d", &N);

  spot[0] = 0;
  spot[N + 1] = 0;

  for (i = 1; i <= N; i++) {
    scanf("%d", &spot[i]);
  }

  for (j = 1; j <= N + 1; j++) {
    sum += abs(spot[j] - spot[j - 1]);
  }

  for (k = 1; k <= N; k++) {
    sum_i = sum + abs(spot[k - 1] - spot[k + 1]) - abs(spot[k - 1] - spot[k]) -
            abs(spot[k] - spot[k + 1]);
    printf("%d\n", sum_i);
  }
  return 0;
}
Problem p03401 (C++)

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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
// typedef vector<ll> vec;
// typedef vector<vec> mat;

const ll mod = 1000000007ll;
const ll inf = 1000000000000000ll;

const ll MAX_N = 100;

ll N, a[MAX_N];

int main() {
  cin >> N;
  a[0] = 0;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  a[N + 1] = 0;
  ll asum = 0;
  for (ll i = 0; i <= N; i++) {
    asum += abs(a[i + 1] - a[i]);
  }
  for (ll i = 1; i <= N; i++) {
    cout << (asum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
             abs(a[i + 1] - a[i - 1]))
         << endl;
  }
  return 0;
}


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

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
// typedef vector<ll> vec;
// typedef vector<vec> mat;

const ll mod = 1000000007ll;
const ll inf = 1000000000000000ll;

const ll MAX_N = 1000000;

ll N, a[MAX_N];

int main() {
  cin >> N;
  a[0] = 0;
  for (ll i = 1; i <= N; i++)
    cin >> a[i];
  a[N + 1] = 0;
  ll asum = 0;
  for (ll i = 0; i <= N; i++) {
    asum += abs(a[i + 1] - a[i]);
  }
  for (ll i = 1; i <= N; i++) {
    cout << (asum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) +
             abs(a[i + 1] - a[i - 1]))
         << endl;
  }
  return 0;
}
Problem p03401 (C++)

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

using namespace std;

int n;
vector<int> a(n + 2);
int s;

int main() {
  cin >> n;
  a[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    s += abs(a[i] - a[i - 1]);
  }
  a[n + 1] = 0;
  s += abs(a[n + 1] - a[n]);

  for (int i = 1; i <= n; i++) {
    cout << s - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << endl;
  }

  return 0;
}


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

using namespace std;

int n;
vector<int> a(100001);
int s;

int main() {
  cin >> n;
  a[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    s += abs(a[i] - a[i - 1]);
  }
  a[n + 1] = 0;
  s += abs(a[n + 1] - a[n]);

  for (int i = 1; i <= n; i++) {
    cout << s - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << endl;
  }

  return 0;
}
Problem p03401 (C++)

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

using namespace std;
int main() {
  int n;
  int a[10010] = {0};

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i + 1];
  a[n + 1] = 0;

  int all_price = 0;
  for (int i = 0; i <= n; i++) {
    all_price += abs(a[i] - a[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    int diff_price = all_price + abs(a[i + 1] - a[i - 1]) -
                     (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]));
    cout << diff_price << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>

using namespace std;
int main() {
  int n;
  int a[100100] = {0};

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i + 1];
  a[n + 1] = 0;

  int all_price = 0;
  for (int i = 0; i <= n; i++) {
    all_price += abs(a[i] - a[i + 1]);
  }

  for (int i = 1; i <= n; i++) {
    int diff_price = all_price + abs(a[i + 1] - a[i - 1]) -
                     (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]));
    cout << diff_price << endl;
  }
  return 0;
}
Problem p03401 (C++)

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

using namespace std;

int main() {
  int N;
  int a[10000];
  int res;
  int total;
  cin >> N;
  cin >> a[0];
  total = abs(a[0]);
  for (int i = 1; i < N; i++) {
    cin >> a[i];
    total += abs(a[i] - a[i - 1]);
  }
  total += abs(a[N - 1]);

  res = total - abs(a[0]) - abs(a[1] - a[0]) + abs(a[1]);
  cout << res << endl;
  for (int i = 1; i < N - 1; i++) {
    res = total - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
          abs(a[i - 1] - a[i + 1]);
    cout << res << endl;
  }
  res = total - abs(a[N - 1]) - abs(a[N - 1] - a[N - 2]) + abs(a[N - 2]);
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N;
  int a[100000];
  int res;
  int total;
  cin >> N;
  cin >> a[0];
  total = abs(a[0]);
  for (int i = 1; i < N; i++) {
    cin >> a[i];
    total += abs(a[i] - a[i - 1]);
  }
  total += abs(a[N - 1]);

  res = total - abs(a[0]) - abs(a[1] - a[0]) + abs(a[1]);
  cout << res << endl;
  for (int i = 1; i < N - 1; i++) {
    res = total - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
          abs(a[i - 1] - a[i + 1]);
    cout << res << endl;
  }
  res = total - abs(a[N - 1]) - abs(a[N - 1] - a[N - 2]) + abs(a[N - 2]);
  cout << res << endl;
  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include "iostream"
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
#include <string.h>

using namespace std;

int main() {
  int n, x, a[200];
  long long int d = 0, dd, in[200];
  int i, j = 2, k = 0;
  cin >> n;
  a[0] = 0;

  for (i = 1; i <= n; i++) {
    cin >> a[i];
    in[i] = (long long int)(fabs(a[i] - a[i - 1]));
    d += in[i];
  }
  a[n + 1] = 0;
  in[n + 1] = (long long int)(fabs(a[n]));
  d += in[n + 1];

  for (i = 1; i <= n; i++) {
    dd = d - in[i] - in[i + 1] + (long long int)(fabs(a[i + 1] - a[i - 1]));

    printf("%lld\n", dd);
  }

  return 0;
}


Fixed submission:
#include "iostream"
#include "math.h"
#include "stdio.h"
#include "stdlib.h"
#include <string.h>

using namespace std;

int main() {
  int n, x, a[200000];
  long long int d = 0, dd, in[200000];
  int i, j = 2, k = 0;
  cin >> n;
  a[0] = 0;

  for (i = 1; i <= n; i++) {
    cin >> a[i];
    in[i] = (long long int)(fabs(a[i] - a[i - 1]));
    d += in[i];
  }
  a[n + 1] = 0;
  in[n + 1] = (long long int)(fabs(a[n]));
  d += in[n + 1];

  for (i = 1; i <= n; i++) {
    dd = d - in[i] - in[i + 1] + (long long int)(fabs(a[i + 1] - a[i - 1]));

    printf("%lld\n", dd);
  }

  return 0;
}
Problem p03401 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  int A[N + 10];
  A[0] = 0;
  A[N + 1] = 0;
  for (int i = 1; i <= N; ++i)
    cin >> A[i];
  for (int i = 1; i <= N; ++i) {
    int len = 0;
    for (int j = 1; j <= N + 1; ++j) {
      if (j == i && j <= N) {
        len += abs(A[j + 1] - A[j - 1]);
        ++j;
      } else
        len += abs(A[j] - A[j - 1]);
    }
    cout << len << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  int A[N + 10];
  A[0] = 0;
  A[N + 1] = 0;
  for (int i = 1; i <= N; ++i)
    cin >> A[i];
  int len = 0;
  for (int i = 1; i <= N + 1; ++i) {
    len += abs(A[i] - A[i - 1]);
  }
  for (int j = 1; j <= N; ++j) {
    int tr_len = 0;
    tr_len = len - abs(A[j] - A[j - 1]) - abs(A[j + 1] - A[j]) +
             abs(A[j + 1] - A[j - 1]);
    cout << tr_len << endl;
  }
}
Problem p03401 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rFOR(i, a, b) for (int i = a - 1; i >= b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define rREP(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define MAXNUM 10
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int p[MAXNUM], sum = 0;
  p[0] = 0;
  p[n + 1] = 0;
  REP(i, n) { cin >> p[i + 1]; }
  FOR(i, 1, n + 2) sum += abs(p[i] - p[i - 1]);
  FOR(i, 1, n + 1) {
    cout << sum + abs(p[i + 1] - p[i - 1]) -
                (abs(p[i + 1] - p[i]) + abs(p[i] - p[i - 1]))
         << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rFOR(i, a, b) for (int i = a - 1; i >= b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define rREP(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define MAXNUM 100000
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  int p[MAXNUM], sum = 0;
  p[0] = 0;
  p[n + 1] = 0;
  REP(i, n) { cin >> p[i + 1]; }
  FOR(i, 1, n + 2) sum += abs(p[i] - p[i - 1]);
  FOR(i, 1, n + 1) {
    cout << sum + abs(p[i + 1] - p[i - 1]) -
                (abs(p[i + 1] - p[i]) + abs(p[i] - p[i - 1]))
         << endl;
  }
  return 0;
}