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

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

using namespace std;

const int N = 300 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long a[N], r[N], F[N], rF[N];

bool read() {
  if (!(cin >> n))
    return false;

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

  return true;
}

void solve() {
  F[0] = rF[0] = F[1] = rF[1] = r[1] = 1;

  for (int i = 2; i <= n; ++i) {
    r[i] = (MOD - (MOD / i) * r[MOD % i] % MOD) % MOD;
    F[i] = i * F[i - 1] % MOD;
    rF[i] = r[i] * rF[i - 1] % MOD;
  }

  auto ans = 0ll;

  for (int k = (n + 1) / 2; k < n; ++k)
    ans += F[k] * F[k - 1] % MOD * rF[2 * k - n] % MOD;

  cout << (MOD + F[n] - ans % MOD) % MOD << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  while (read())
    solve();

  return 0;
}


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

using namespace std;

const int N = 2000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long a[N], r[N], F[N], rF[N];

bool read() {
  if (!(cin >> n))
    return false;

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

  return true;
}

void solve() {
  F[0] = rF[0] = F[1] = rF[1] = r[1] = 1;

  for (int i = 2; i <= n; ++i) {
    r[i] = (MOD - (MOD / i) * r[MOD % i] % MOD) % MOD;
    F[i] = i * F[i - 1] % MOD;
    rF[i] = r[i] * rF[i - 1] % MOD;
  }

  auto ans = 0ll;

  for (int k = (n + 1) / 2; k < n; ++k)
    ans += F[k] * F[k - 1] % MOD * rF[2 * k - n] % MOD;

  cout << (MOD + F[n] - ans % MOD) % MOD << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  while (read())
    solve();

  return 0;
}
Problem p03365 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define MAXN 1000005
#define PLI pair<long long, int>
#define fi first
#define se second
#define mp make_pair
#define ha 99994711
#define ba 823
#define MOD 1000000007
// #define ivorysi
using namespace std;
typedef long long int64;
int64 fac[MAXN], invfac[MAXN], ans;
int N;
int64 fpow(int64 x, int64 c) {
  int64 res = 1, t = x;
  while (c) {
    if (c & 1)
      res = res * t % MOD;
    t = t * t % MOD;
    c >>= 1;
  }
  return res;
}
int64 C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}
int64 W(int k) {
  int x = N - 2 - k;
  int y = k - x;
  return fac[k] * invfac[y] % MOD * invfac[x] % MOD;
}
void Solve() {
  scanf("%d", &N);
  if (N == 2) {
    puts("1");
    return;
  }
  fac[0] = invfac[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  invfac[N] = fpow(fac[N], MOD - 2);
  for (int i = N - 1; i >= 1; --i) {
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  }
  ans += fac[N - 1];
  for (int i = 1; i < N - 1; ++i) {
    ans += (C(N - 2, i) + C(N - 2, i - 1) + MOD - W(i - 1)) * fac[i] % MOD *
           fac[N - 1 - i] % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#define MAXN 1000005
#define PLI pair<long long, int>
#define fi first
#define se second
#define mp make_pair
#define ha 99994711
#define ba 823
#define MOD 1000000007
// #define ivorysi
using namespace std;
typedef long long int64;
int64 fac[MAXN], invfac[MAXN], ans;
int N;
int64 fpow(int64 x, int64 c) {
  int64 res = 1, t = x;
  while (c) {
    if (c & 1)
      res = res * t % MOD;
    t = t * t % MOD;
    c >>= 1;
  }
  return res;
}
int64 C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * invfac[m] % MOD * invfac[n - m] % MOD;
}
int64 W(int k) {
  int x = N - 2 - k;
  int y = k - x;
  if (x < 0 || y < 0)
    return 0;
  return fac[k] * invfac[y] % MOD * invfac[x] % MOD;
}
void Solve() {
  scanf("%d", &N);
  if (N == 2) {
    puts("1");
    return;
  }
  fac[0] = invfac[0] = 1;
  for (int i = 1; i <= N; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
  }
  invfac[N] = fpow(fac[N], MOD - 2);
  for (int i = N - 1; i >= 1; --i) {
    invfac[i] = invfac[i + 1] * (i + 1) % MOD;
  }
  ans += fac[N - 1];
  for (int i = 1; i < N - 1; ++i) {
    ans += (C(N - 2, i) + C(N - 2, i - 1) + MOD - W(i - 1)) * fac[i] % MOD *
           fac[N - 1 - i] % MOD;
    ans %= MOD;
  }
  printf("%lld\n", ans);
}
int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}
Problem p03365 (C++)

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

const int maxn = 10000;
const int mod = 1e9 + 7;

int step[maxn], inv_step[maxn];

int power(int x, int times) {
  int rt = 1, base = x;
  while (times) {
    if (times & 1)
      rt = (long long)rt * base % mod;
    base = (long long)base * base % mod;
    times >>= 1;
  }
  return rt;
}

int C(int a, int b) {
  if (b < 0 || b > a)
    return 0;
  return (long long)step[a] * inv_step[b] % mod * inv_step[a - b] % mod;
}

int f[maxn];

int main() {
  step[0] = 1;
  for (int i = 1; i < maxn; i++)
    step[i] = (long long)step[i - 1] * i % mod;
  for (int i = 0; i < maxn; i++)
    inv_step[i] = power(step[i], mod - 2);

  int n;
  scanf("%d", &n);
  n--;
  for (int i = 1; i <= n; i++)
    f[i] = C(i - 1, n - i);

  // for (int i = n; i >= 1; i--) f[i] = (f[i] - (long long)f[i - 1] * (n - (i -
  // 1))) % mod;
  //	for (int i = 1; i <= n; i++) cout << f[i] << endl;

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + (long long)f[i] % mod * step[i] % mod * step[n - i]) % mod;
    //		cout << ans << endl;
  }

  ans = ((long long)step[n] * (n + 1) - ans) % mod;
  cout << (ans + mod) % mod << endl;
  return 0;
}

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

const int maxn = 2000000;
const int mod = 1e9 + 7;

int step[maxn], inv_step[maxn];

int power(int x, int times) {
  int rt = 1, base = x;
  while (times) {
    if (times & 1)
      rt = (long long)rt * base % mod;
    base = (long long)base * base % mod;
    times >>= 1;
  }
  return rt;
}

int C(int a, int b) {
  if (b < 0 || b > a)
    return 0;
  return (long long)step[a] * inv_step[b] % mod * inv_step[a - b] % mod;
}

int f[maxn];

int main() {
  step[0] = 1;
  for (int i = 1; i < maxn; i++)
    step[i] = (long long)step[i - 1] * i % mod;
  for (int i = 0; i < maxn; i++)
    inv_step[i] = power(step[i], mod - 2);

  int n;
  scanf("%d", &n);
  n--;
  for (int i = 1; i <= n; i++)
    f[i] = C(i - 1, n - i);

  // for (int i = n; i >= 1; i--) f[i] = (f[i] - (long long)f[i - 1] * (n - (i -
  // 1))) % mod;
  //	for (int i = 1; i <= n; i++) cout << f[i] << endl;

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = (ans + (long long)f[i] % mod * step[i] % mod * step[n - i]) % mod;
    //		cout << ans << endl;
  }

  ans = ((long long)step[n] * (n + 1) - ans) % mod;
  cout << (ans + mod) % mod << endl;
  return 0;
}
Problem p03366 (C++)

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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair<ll, int> pii;
typedef long double ld;
typedef vector<ll> vi;

const int N = 2e5 + 1;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;

int n, s;
int x[N], a[N];
ll ps[N], ss[N];

int main() {
#ifdef black
  freopen("in", "r", stdin);
#endif // black
  ios_base ::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> s;
  ll sum = 0;
  forn(i, 1, n) {
    cin >> x[i] >> a[i];
    sum += a[i];
  }
  int tl = lower_bound(x + 1, x + 1 + n, s) - x - 1;
  int tr = tl + 1;
  if (x[tr] == s)
    ++tr;

  vi order;
  ll fn = a[1], fp = a[n];
  int l = 1, r = n;
  for (; l <= tl && tr <= r;) {
    if (fn >= fp) {
      fn += fp;
      order.pb(x[r]);
      fp = a[--r];
    } else {
      fp += fn;
      order.pb(x[l]);
      fn = a[++l];
    }
  }
  for (; l <= tl; ++l)
    order.pb(x[l]);
  for (; r >= tr; --l)
    order.pb(x[r]);
  order.pb(s);
  reverse(order.begin(), order.end());
  ll ans = 0;
  forn(i, 1, order.size() - 1) ans += abs(order[i] - order[i - 1]);
  cout << ans << "\n";

  return 0;
}


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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

typedef long long ll;
typedef pair<ll, int> pii;
typedef long double ld;
typedef vector<ll> vi;

const int N = 2e5 + 1;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;

int n, s;
int x[N], a[N];
ll ps[N], ss[N];

int main() {
#ifdef black
  freopen("in", "r", stdin);
#endif // black
  ios_base ::sync_with_stdio(0);
  cin.tie(0);

  cin >> n >> s;
  ll sum = 0;
  forn(i, 1, n) {
    cin >> x[i] >> a[i];
    sum += a[i];
  }
  int tl = lower_bound(x + 1, x + 1 + n, s) - x - 1;
  int tr = tl + 1;
  if (x[tr] == s)
    ++tr;

  vi order;
  ll fn = a[1], fp = a[n];
  int l = 1, r = n;
  for (; l <= tl && tr <= r;) {
    if (fn >= fp) {
      fn += fp;
      order.pb(x[r]);
      fp = a[--r];
    } else {
      fp += fn;
      order.pb(x[l]);
      fn = a[++l];
    }
  }
  for (; l <= tl; ++l)
    order.pb(x[l]);
  for (; r >= tr; --r)
    order.pb(x[r]);
  order.pb(s);
  reverse(order.begin(), order.end());
  ll ans = 0;
  forn(i, 1, order.size() - 1) ans += abs(order[i] - order[i - 1]);
  cout << ans << "\n";

  return 0;
}
Problem p03366 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#define N 100001
int a[N], i, j, k, m, n;
long long b[N], x;
int main() {
  for (scanf("%d%d", &n, &m), i = 1; i <= n; i++)
    scanf("%d%lld", a + i, b + i);
  for (k = 1; k < m && a[k + 1] <= m; k++)
    ;
  for (i = 1, j = n; i <= k && k < j;)
    if (b[i] < b[j])
      for (x += a[j] - a[i]; i <= k && b[i] < b[j]; b[j] += b[i++])
        ;
    else
      for (x += a[j] - a[i]; k < j && b[j] <= b[i]; b[i] += b[j--])
        ;
  return 0 * printf("%lld\n", x + (i <= k ? m - a[i] : a[j] - m));
}

Fixed submission:
#include <cstdio>
#define N 100001
int a[N], i, j, k, m, n;
long long b[N], x;
int main() {
  for (scanf("%d%d", &n, &m), i = 1; i <= n; i++)
    scanf("%d%lld", a + i, b + i);
  for (k = 0; k < n && a[k + 1] <= m; k++)
    ;
  for (i = 1, j = n; i <= k && k < j;)
    if (b[i] < b[j])
      for (x += a[j] - a[i]; i <= k && b[i] < b[j]; b[j] += b[i++])
        ;
    else
      for (x += a[j] - a[i]; k < j && b[j] <= b[i]; b[i] += b[j--])
        ;
  return 0 * printf("%lld\n", x + (i <= k ? m - a[i] : a[j] - m));
}
Problem p03366 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long x['zz'], p['zz'], A, n, s, l = 1, r;
int main() {
  cin >> n >> s;
  r = n;
  for (int i = 1; i <= r; i++)
    cin >> x[i] >> p[i];
  while (l <= r) {
    if (s <= x[l])
      cout << A + x[r] - s, exit(0);
    if (s >= x[r])
      cout << A + s - x[l], exit(0);
    A += x[r] - x[l];
    if (p[l] >= p[r])
      while (p[l] >= p[r] && l < r)
        p[l] += p[r--];
    else
      while (p[l] < p[r] && l < r)
        p[r] += p[l++];
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long x['zzz'], p['zzz'], A, n, s, l = 1, r;
int main() {
  cin >> n >> s;
  r = n;
  for (int i = 1; i <= r; i++)
    cin >> x[i] >> p[i];
  while (l <= r) {
    if (s <= x[l])
      cout << A + x[r] - s, exit(0);
    if (s >= x[r])
      cout << A + s - x[l], exit(0);
    A += x[r] - x[l];
    if (p[l] >= p[r])
      while (p[l] >= p[r] && l < r)
        p[l] += p[r--];
    else
      while (p[l] < p[r] && l < r)
        p[r] += p[l++];
  }
}
Problem p03368 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <queue>
#define LL long long
#define For(i, a, b) for (register int i = a; i <= b; ++i)
using namespace std;
const int maxn = 1e5 + 5;
struct _01 {
  int c0, c1, id;
  bool operator<(const _01 &A) const {
    return 1ll * c0 * A.c1 < 1ll * A.c0 * c1;
  }
};
priority_queue<_01> q;
int fa[maxn], n, a, u, v, cnt[maxn][2];
LL ans;

namespace DSU {
int fa[maxn];
void init(int n) { For(i, 0, n) fa[i] = i; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void combine(int a, int b) { fa[find(a)] = find(b); }
} // namespace DSU

int main() {
  scanf("%d", &n), DSU::init(n);
  For(i, 2, n) scanf("%d", &fa[i]);
  For(i, 1, n) { scanf("%d", &a), u = a == 0, v = a == 1, cnt[i][a] = 1; }
  For(i, 2, n) q.push((_01){cnt[i][0], cnt[i][1], i});
  _01 now;
  while (!q.empty()) {
    now = q.top(), q.pop();
    u = DSU::find(now.id);
    if (cnt[u][0] == now.c0 && cnt[u][1] == now.c1) {
      v = DSU::find(fa[u]);
      ans += 1ll * cnt[v][1] * cnt[u][0];
      cnt[v][1] += cnt[u][1];
      cnt[v][0] += cnt[u][0];
      DSU::combine(u, v);
      if (v != 1)
        q.push((_01){cnt[v][0], cnt[v][1], v});
    }
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <queue>
#define LL long long
#define For(i, a, b) for (register int i = a; i <= b; ++i)
using namespace std;
const int maxn = 2e5 + 5;
struct _01 {
  int c0, c1, id;
  bool operator<(const _01 &A) const {
    return 1ll * c0 * A.c1 < 1ll * A.c0 * c1;
  }
};
priority_queue<_01> q;
int fa[maxn], n, a, u, v, cnt[maxn][2];
LL ans;

namespace DSU {
int fa[maxn];
void init(int n) { For(i, 0, n) fa[i] = i; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void combine(int a, int b) { fa[find(a)] = find(b); }
} // namespace DSU

int main() {
  scanf("%d", &n), DSU::init(n);
  For(i, 2, n) scanf("%d", &fa[i]);
  For(i, 1, n) { scanf("%d", &a), u = a == 0, v = a == 1, cnt[i][a] = 1; }
  For(i, 2, n) q.push((_01){cnt[i][0], cnt[i][1], i});
  _01 now;
  while (!q.empty()) {
    now = q.top(), q.pop();
    u = DSU::find(now.id);
    if (cnt[u][0] == now.c0 && cnt[u][1] == now.c1) {
      v = DSU::find(fa[u]);
      ans += 1ll * cnt[v][1] * cnt[u][0];
      cnt[v][1] += cnt[u][1];
      cnt[v][0] += cnt[u][0];
      DSU::combine(u, v);
      if (v != 1)
        q.push((_01){cnt[v][0], cnt[v][1], v});
    }
  }
  printf("%lld", ans);
  return 0;
}
Problem p03368 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;
int P[maxn], V[maxn], tl[maxn], nxt[maxn];
int c0[maxn], c1[maxn];

struct node {
  int id;
  node(int id = -1) : id(id) {}
  friend bool operator<(node A, node B) {
    if ((LL)c0[A.id] * c1[B.id] != (LL)c0[B.id] * c1[A.id])
      return (LL)c0[A.id] * c1[B.id] > (LL)c0[B.id] * c1[A.id];
    return A.id < B.id;
  }
};
set<node> S;

int fa[maxn];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 2; i <= N; ++i)
    scanf("%d", P + i);
  for (int i = 1; i <= N; ++i) {
    fa[i] = tl[i] = i;
    scanf("%d", V + i);
    if (V[i] == 0)
      c0[i] = 1;
    else
      c1[i] = 1;
    if (i != 1)
      S.insert(node(i));
  }
  for (int i = 1; i < N; ++i) {
    node now = *S.begin();
    S.erase(S.begin());
    int x = now.id, y = Find(P[x]);
    nxt[tl[y]] = x, tl[y] = tl[x], fa[x] = y;
    if (y != 1)
      S.erase(node(y));
    c1[y] += c1[x], c0[y] += c0[x];
    if (y != 1)
      S.insert(node(y));
  }
  LL ans = 0;
  int p = 1, num = V[1];
  for (int i = 1; i < N; ++i) {
    p = nxt[p];
    if (V[p] == 0)
      ans += num;
    else
      num++;
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 10;
int P[maxn], V[maxn], tl[maxn], nxt[maxn];
int c0[maxn], c1[maxn];

struct node {
  int id;
  node(int id = -1) : id(id) {}
  friend bool operator<(node A, node B) {
    if ((LL)c0[A.id] * c1[B.id] != (LL)c0[B.id] * c1[A.id])
      return (LL)c0[A.id] * c1[B.id] > (LL)c0[B.id] * c1[A.id];
    return A.id < B.id;
  }
};
set<node> S;

int fa[maxn];
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 2; i <= N; ++i)
    scanf("%d", P + i);
  for (int i = 1; i <= N; ++i) {
    fa[i] = tl[i] = i;
    scanf("%d", V + i);
    if (V[i] == 0)
      c0[i] = 1;
    else
      c1[i] = 1;
    if (i != 1)
      S.insert(node(i));
  }
  for (int i = 1; i < N; ++i) {
    node now = *S.begin();
    S.erase(S.begin());
    int x = now.id, y = Find(P[x]);
    nxt[tl[y]] = x, tl[y] = tl[x], fa[x] = y;
    if (y != 1)
      S.erase(node(y));
    c1[y] += c1[x], c0[y] += c0[x];
    if (y != 1)
      S.insert(node(y));
  }
  LL ans = 0;
  int p = 1, num = V[1];
  for (int i = 1; i < N; ++i) {
    p = nxt[p];
    if (V[p] == 0)
      ans += num;
    else
      num++;
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03368 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
// #pragma GCC optimize ("O2,unroll-loops")

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MAXN = 200010, LOG = 20;

ll n, m, k, u, v, x, y, t, a, b, ans;
int par[MAXN], dsu[MAXN];
pll A[MAXN];
int seg[MAXN << 1];
/*
struct CMP{
        bool operator ()(int x, int y){
                return pll(A[x].second*A[y].first,
x)<pll(A[y].second*A[x].first, y);
        }
};
set<int, CMP> st;

FUCK C++ 9
FUCK C++ 11
FUCK atcoder
FUCK set
*/
int fuck(int x, int y) {
  if (!x || !y)
    return x ^ y;
  if (A[x].second * A[y].first < A[y].second * A[x].first)
    return x;
  return y;
}
int Set(int pos, int val) {
  seg[pos += n] = val;
  for (; pos > 1; pos >>= 1)
    seg[pos >> 1] = fuck(seg[pos], seg[pos ^ 1]);
}

int getpar(int x) {
  if (dsu[x] == x)
    return x;
  return dsu[x] = getpar(dsu[x]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  iota(dsu, dsu + MAXN, 0);
  cin >> n;
  for (int i = 2; i <= n; i++)
    cin >> par[i];
  for (int i = 1; i <= n; i++) {
    cin >> x;
    A[i] = {x == 0, x == 1};
  }
  for (int i = 2; i <= n; i++)
    Set(i, i);
  for (int i = 1; i < n; i++) {
    int v = seg[1], u = getpar(par[v]);
    assert(v);
    Set(u, 0);
    Set(v, 0);
    ans += A[u].second * A[v].first;
    A[u].first += A[v].first;
    A[u].second += A[v].second;
    if (u > 1)
      Set(u, u);
    dsu[v] = u;
  }
  cout << ans << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #pragma GCC optimize ("O2,unroll-loops")

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MAXN = 200010, LOG = 20;

ll n, m, k, u, v, x, y, t, a, b, ans;
int par[MAXN], dsu[MAXN];
pll A[MAXN];
int seg[MAXN << 1];
/*
struct CMP{
        bool operator ()(int x, int y){
                return pll(A[x].second*A[y].first,
x)<pll(A[y].second*A[x].first, y);
        }
};
set<int, CMP> st;

FUCK C++ 9
FUCK C++ 11
FUCK atcoder
FUCK set
*/
int fuck(int x, int y) {
  if (!x || !y)
    return x ^ y;
  if (A[x].second * A[y].first < A[y].second * A[x].first)
    return x;
  return y;
}
void Set(int pos, int val) {
  seg[pos += n] = val;
  for (; pos > 1; pos >>= 1)
    seg[pos >> 1] = fuck(seg[pos], seg[pos ^ 1]);
}

int getpar(int x) {
  if (dsu[x] == x)
    return x;
  return dsu[x] = getpar(dsu[x]);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  iota(dsu, dsu + MAXN, 0);
  cin >> n;
  for (int i = 2; i <= n; i++)
    cin >> par[i];
  for (int i = 1; i <= n; i++) {
    cin >> x;
    A[i] = {x == 0, x == 1};
  }
  for (int i = 2; i <= n; i++)
    Set(i, i);
  for (int i = 1; i < n; i++) {
    int v = seg[1], u = getpar(par[v]);
    assert(v);
    Set(u, 0);
    Set(v, 0);
    ans += A[u].second * A[v].first;
    A[u].first += A[v].first;
    A[u].second += A[v].second;
    if (u > 1)
      Set(u, u);
    dsu[v] = u;
  }
  cout << ans << "\n";

  return 0;
}
Problem p03369 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

order = input().srtip()

ret = 700
for i in order:
    if i == "o":
        ret += 100

print(ret)


Fixed submission:
# -*- coding: utf-8 -*-

order = input()

ret = 700
for i in order:
    if i == "o":
        ret += 100

print(ret)
Problem p03369 (C++)

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

int topping(char str[]) {
  int i;
  int num = 0;

  for (i = 0; i < 3; i++) {
    if (str[i] == 'o') {
      num++;
    }
  }
  return num * 100;
}

int main() {
  char S[4];
  int ramen = 700;
  cin.getline(S, 4);
  ramen += topping(S);
  cout << ramen << endl;
  return ramen;
}

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

int topping(char str[]) {
  int i;
  int num = 0;

  for (i = 0; i < 3; i++) {
    if (str[i] == 'o') {
      num++;
    }
  }
  return num * 100;
}

int main() {
  char S[4];
  int ramen = 700;
  cin.getline(S, 4);
  ramen += topping(S);
  cout << ramen << endl;
  return 0;
}
Problem p03369 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int n = 0;
  if (S.at(0) == 'o')
    n++;
  if (S.at(1) == 'o')
    n++;
  if (S.at(2) == 'o')
    n++;

  cout << 700 + n * 100 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int n = 0;
  if (S.at(0) == 'o')
    n++;
  if (S.at(1) == 'o')
    n++;
  if (S.at(2) == 'o')
    n++;

  cout << 700 + n * 100 << endl;
  return 0;
}
Problem p03369 (C++)

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

using namespace std;
typedef long long ll;

int main() {

  string s;
  cin >> s;

  ll counter = 0;

  for (ll i = 0; s.size(); i++) {
    if (s[i] == 'o')
      counter++;
  }

  cout << counter * 100 + 700 << endl;
}

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

using namespace std;
typedef long long ll;

int main() {

  string s;
  cin >> s;

  ll counter = 0;

  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'o')
      counter++;
  }

  cout << counter * 100 + 700 << endl;
}
Problem p03369 (C++)

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

int main() {
  string s;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == 'o') {
      count++;
    }
  }
  cout << 700 + count * 100 << endl;

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == 'o') {
      count++;
    }
  }
  cout << 700 + count * 100 << endl;

  return 0;
}
Problem p03369 (C++)

Buggy submission (status: Runtime Error):

#include <cstdio>

int main() {
  char s[3];
  scanf("%s", s);
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') {
      count++;
    }
  }
  printf("%d\n", 700 + 100 * count);

  return 0;
}

Fixed submission:

#include <cstdio>

int main() {
  char s[4];
  scanf("%s", s);
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') {
      count++;
    }
  }
  printf("%d\n", 700 + 100 * count);

  return 0;
}
Problem p03369 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef long double lld;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define pl pair<ll, ll>
template <class T> T umax(T a, T b) { return (a > b ? a : b); }
template <class T> T umin(T a, T b) { return (a < b ? a : b); }
template <class T, class P> T umax(T a, P b) { return (a > b ? a : b); }
template <class T, class P> T umin(T a, P b) { return (a < b ? a : b); }

const ll mod = 1e9 + 7;

int X[] = {0, 1, 0, -1, -1, -1, 1, 1};
int Y[] = {1, 0, -1, 0, -1, 1, -1, 1};

ll power(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

const int maxn = 10;

int main() {
#ifndef ONLINE_JUDGE
  freopen("qns.txt", "r", stdin);
  freopen("ans.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  // logic
  string s;
  cin >> s;
  int res = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o')
      res += 100;
  }
  cout << res << endl;
#ifndef ONLINE_JUDGE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double ld;
typedef long double lld;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define pl pair<ll, ll>
#define ONLINE_JUDGE
template <class T> T umax(T a, T b) { return (a > b ? a : b); }
template <class T> T umin(T a, T b) { return (a < b ? a : b); }
template <class T, class P> T umax(T a, P b) { return (a > b ? a : b); }
template <class T, class P> T umin(T a, P b) { return (a < b ? a : b); }

const ll mod = 1e9 + 7;

int X[] = {0, 1, 0, -1, -1, -1, 1, 1};
int Y[] = {1, 0, -1, 0, -1, 1, -1, 1};

ll power(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}

const int maxn = 10;

int main() {
#ifndef ONLINE_JUDGE
  freopen("qns.txt", "r", stdin);
  freopen("ans.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  // logic
  string s;
  cin >> s;
  int res = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o')
      res += 100;
  }
  cout << res << endl;
#ifndef ONLINE_JUDGE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
Problem p03369 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int n = 700;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o') {
      n = n + 100;
    }
  }
  cout << n << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int n = 700;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == 'o') {
      n = n + 100;
    }
  }
  cout << n << endl;
}
Problem p03369 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

a = input().split("")
sum = 700
for i in a:
    if i == "o":
        sum += 100

print(sum)


Fixed submission:
# -*- coding: utf-8 -*-

a = list(input())
sum = 700
for i in a:
    if i == "o":
        sum += 100

print(sum)
Problem p03370 (Python)

Buggy submission (status: Runtime Error):
N, X = map(int, input().split())
M = [int(input()) for _ in range(N)]
ans = 0
for m in range(M):
    X -= m
    ans += 1
ans += X // min(M)
print(ans)


Fixed submission:
N, X = map(int, input().split())
M = [int(input()) for _ in range(N)]
ans = 0
for m in M:
    X -= m
    ans += 1
ans += X // min(M)
print(ans)
Problem p03370 (C++)

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  int sum = 0, cnt = n;
  for (auto &&u : v) {
    cin >> u;
    sum += u;
  }
  sort(begin(v), end(v));
  int rem = x - sum;
  while (rem > 0) {
    rem - v.front();
    if (rem >= 0)
      cnt++;
  }
  cout << cnt << endl;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  int sum = 0, cnt = n;
  for (auto &&u : v) {
    cin >> u;
    sum += u;
  }
  sort(begin(v), end(v));
  int rem = x - sum, mn = v.front();
  cnt += rem / mn;
  cout << cnt << endl;
}
Problem p03370 (C++)

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

int main() {
  int N, X;
  cin >> N >> X;
  int m[N];

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> m[i];
    ans += m[i];
  }
  X = X - ans;

  int min = 100000;
  for (int i = 0; i < N; i++) {
    if (min > m[N])
      min = m[N];
  }

  cout << N + X / min << endl;

  return 0;
}


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

int main() {
  int N, X;
  cin >> N >> X;
  int m[N];

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> m[i];
    ans += m[i];
  }
  X = X - ans;

  int min = 100000;
  for (int i = 0; i < N; i++) {
    if (min > m[i])
      min = m[i];
  }

  cout << N + X / min << endl;

  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, cnt = 0, val, sum = 0, tmp = 0, tmp2 = 0;
  cin >> N >> val;
  cnt += N;
  int arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];
  for (int i = 0; i < N; i++)
    sum += arr[i];
  tmp = val - sum;
  for (int i = 0; i < N; i++) {
    if (tmp2 > arr[i])
      tmp2 = arr[i];
  }
  tmp = tmp / tmp2;
  cnt += tmp;
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, cnt = 0, val, sum = 0, tmp = 0, tmp2 = 100000;
  cin >> N >> val;
  cnt += N;
  int arr[N];
  for (int i = 0; i < N; i++)
    cin >> arr[i];
  for (int i = 0; i < N; i++)
    sum += arr[i];
  tmp = val - sum;
  for (int i = 0; i < N; i++) {
    if (tmp2 > arr[i])
      tmp2 = arr[i];
  }
  tmp = tmp / tmp2;
  cnt += tmp;
  cout << cnt << endl;
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
// ConsoleApplication2.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

int main() {
  int variant, amount, production;
  production = 0;
  int min = 0;
  std::cin >> variant >> amount;
  for (int i = 0; i < variant; i++) {
    int mi;
    std::cin >> mi;
    if (mi < min) {
      min = mi;
    }
    amount = amount - mi;
    production++;
  }
  production += amount / min;
  std::cout << production;
}


Fixed submission:
// ConsoleApplication2.cpp : このファイルには 'main'
// 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

int main() {
  int variant, amount, production;
  production = 0;
  int min = 0;
  std::cin >> variant >> amount;
  for (int i = 0; i < variant; i++) {
    int mi;
    std::cin >> mi;
    if (i == 0) {
      min = mi;
    }
    if (mi < min) {
      min = mi;
    }
    amount = amount - mi;
    production++;
  }
  production += amount / min;
  std::cout << production;
}
Problem p03370 (C++)

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

int main() {
  int n, x;
  cin >> n >> x;
  int sum, l;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    sum += m;
    l = min(l, m);
  }
  cout << n + (x - sum) / l << endl;
}


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

int main() {
  int n, x;
  cin >> n >> x;
  int sum = 0, l = 1001;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    sum += m;
    l = min(l, m);
  }
  cout << n + (x - sum) / l << endl;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> m[i];
  }
  sort(m.begin(), m.end());
  int Y = 0;
  for (int j = 0; j < N; j++) {
    Y += m[j];
  }
  cout << N + (X - Y) / m[0] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    cin >> m[i];
  }
  sort(m.begin(), m.end());
  int Y = 0;
  for (int j = 0; j < N; j++) {
    Y += m[j];
  }
  cout << N + (X - Y) / m[0] << endl;
}
Problem p03370 (C++)

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

int main() {
  // int flag=1;
  int n, x, m;
  int MIN = 1001;
  int ans = 0;

  cin >> n >> x;

  for (int i = 0; i < n; i++) {
    cin >> m;

    ans++;
    x -= m;

    MIN = min(MIN, m);
  }

  while (1) {
    x -= MIN;
    if (x < 0)
      ans++;
  }

  cout << ans << endl;
  // cout <<fixed<<setprecision(16)<< ans <<endl;
  // if(flag==1)cout << "Yes" <<endl;
  // else cout << "No" <<endl;

  return 0;
}


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

int main() {
  // int flag=1;
  int n, x, m;
  int MIN = 1001;
  int ans = 0;

  cin >> n >> x;

  for (int i = 0; i < n; i++) {
    cin >> m;

    ans++;
    x -= m;

    MIN = min(MIN, m);
  }

  while (1) {
    x -= MIN;
    if (x < 0)
      break;
    ans++;
  }

  cout << ans << endl;
  // cout <<fixed<<setprecision(16)<< ans <<endl;
  // if(flag==1)cout << "Yes" <<endl;
  // else cout << "No" <<endl;

  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
char line[100];
int X;
int N;
int m[10000];
int min;
int sum = 0;
int number = 0;
int main() {
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d %d", &X, &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &m[i]);
  }
  min = m[0];
  for (int i = 0; i < N; ++i) {
    if (min > m[i])
      min = m[i];
    sum += m[i];
  }
  number = (X - sum) / min + N;
  printf("%d\n", number);
  return 0;
}

Fixed submission:
#include <stdio.h>
char line[100];
int X;
int N;
int m[10000];
int min;
int sum = 0;
int number = 0;
int main() {
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d %d", &N, &X);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &m[i]);
  }
  min = m[0];
  for (int i = 0; i < N; ++i) {
    if (min > m[i])
      min = m[i];
    sum += m[i];
  }
  number = (X - sum) / min + N;
  printf("%d\n", number);
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, mind;
  cin >> n >> x;
  int ans = x;
  for (int i = 0; i < n; i++) {
    int m[i];
    cin >> m[i];
    ans -= m[i];
    mind = min(mind, m[i]);
  }
  cout << ans / mind + n << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x, mind = 1000000;
  cin >> n >> x;
  int ans = x;
  for (int i = 0; i < n; i++) {
    int m[i];
    cin >> m[i];
    ans -= m[i];
    mind = min(mind, m[i]);
  }
  cout << ans / mind + n << endl;
}
Problem p03370 (C++)

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

int main() {
  int N, X;
  cin >> N >> X;
  int M[N];
  sort(M, M + N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += M[i];
  }
  cout << ((X - sum) / M[0]) + N << endl;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  int M[N];
  for (int i = 0; i < N; i++) {
    cin >> M[i];
  }
  sort(M, M + N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += M[i];
  }
  cout << ((X - sum) / M[0]) + N << endl;
}
Problem p03370 (C++)

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

int main() {
  int m, n, x, mab;
  cin >> n;
  cin >> x;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    x = x - m;
    if (mab > m)
      mab = m;
  }

  cout << (x / mab) + n << endl;
  return 0;
}

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

int main() {
  int m, n, x, mab = 1000;
  cin >> n;
  cin >> x;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    x = x - m;
    if (mab > m)
      mab = m;
  }

  cout << (x / mab) + n << endl;
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define r(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main(void) {
  int n, k;
  int m;
  cin >> n >> k;
  int minm;
  int ans = n;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    k -= m;
    minm = min(minm, m);
  }

  ans += k / minm;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define r(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main(void) {
  int n, k;
  int m;
  cin >> n >> k;
  int minm = 100000000;
  int ans = n;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    k -= m;
    minm = min(minm, m);
  }

  ans += k / minm;
  cout << ans << endl;
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int m[n];
  int ans = n;
  for (int i = 0; i < n; i++)
    x -= m[i];
  sort(m, m + n);
  ans += x / m[0];
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int m[n];
  int ans = n;
  for (int i = 0; i < n; i++)
    cin >> m[i];
  for (int i = 0; i < n; i++)
    x -= m[i];
  sort(m, m + n);
  ans += x / m[0];
  cout << ans << endl;
}
Problem p03370 (C++)

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

int main() {
  int N, X, X_shin;
  int m[110];
  int i, j, c, d, counter;

  cin >> N >> X;

  for (i = 0; i < N; i++) {
    cin >> m[i];
    X = X - m[i];
  }

  counter = N;
  X_shin = X;

  for (i = 0; i < N; i++) {
    for (j = 0; j < N - 1; j++) {
      c = m[j];
      d = m[j + 1];
      if (m[j] > m[j + 1]) {
        m[j] = d;
        m[j + 1] = c;
      }
    }
  }
  for (i = 0; X_shin > 0; i++) {
    while (X_shin - m[i] > 0) {
      X_shin = X_shin - m[i];
      counter++;
    }
  }
  cout << counter << endl;
}


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

int main() {
  int N, X, X_shin;
  int m[110];
  int i, j, c, d, counter;

  cin >> N >> X;

  for (i = 0; i < N; i++) {
    cin >> m[i];
    X = X - m[i];
  }

  counter = N;
  X_shin = X;

  for (i = 0; i < N; i++) {
    for (j = 0; j < N - 1; j++) {
      c = m[j];
      d = m[j + 1];
      if (m[j] > m[j + 1]) {
        m[j] = d;
        m[j + 1] = c;
      }
    }
  }
  for (i = 0; X_shin > 0; i++) {
    if (X_shin - m[i] < 0) {
      break;
    }
    while (1) {
      if (X_shin - m[i] < 0) {
        break;
      }
      X_shin = X_shin - m[i];
      counter++;
    }
  }
  cout << counter << endl;
}
Problem p03370 (C++)

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

int main(void) {
  int N, X, mi;
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    mi = min(mi, m);
    X -= m;
  }
  cout << N + X / mi << endl;
  return 0;
}

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

int main(void) {
  int N, X, mi = 10000;
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    mi = min(mi, m);
    X -= m;
  }
  cout << N + X / mi << endl;
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)

int main() {
  ll N, X;
  cin >> N >> X;
  ll m, minV;
  rep(i, 0, N) {
    cin >> m;
    X -= m;
    minV = min(minV, m);
  }
  cout << N + X / minV << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)

int main() {
  ll N, X;
  cin >> N >> X;
  ll m, minV = 1 << 21;
  rep(i, 0, N) {
    cin >> m;
    X -= m;
    minV = min(minV, m);
  }
  cout << N + X / minV << endl;
  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X, m[200];
  cin >> N >> X;
  int sum = 0, min;
  for (int i = 0; i < N; i++) {

    cin >> m[i];
    sum += m[i];

    if (min > m[i]) {
      min = m[i];
    }
  }
  int ans = N + (X - sum) / min;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, X, m[200];
  cin >> N >> X;
  int sum = 0, min;
  for (int i = 0; i < N; i++) {

    cin >> m[i];
    sum += m[i];
  }
  min = m[0];
  for (size_t i = 0; i < N; i++) {

    if (min > m[i]) {
      min = m[i];
    }
  }
  int ans = N + (X - sum) / min;
  cout << ans << endl;
}
Problem p03370 (C++)

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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main() {
  int n, x, _min = 0, ret = 0;
  int m[100];
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> m[i];
    x -= m[i];
    ret++;
  }
  sort(m, m + 100);
  _min = m[0];
  ret += x / _min;
  cout << ret << endl;
  return 0;
}

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

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

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795;

int main() {
  int n, x, _min = 0, ret = 0;
  int m[100];
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> m[i];
    x -= m[i];
    ret++;
  }
  sort(m, m + n);
  _min = m[0];
  ret += x / _min;
  cout << ret << endl;
  return 0;
}
Problem p03370 (C++)

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

using namespace std;

int main() {
  int N, X, sum = 0, min_kona;
  cin >> N >> X;
  vector<int> kona(N);
  for (int i = 0; i < N; i++) {
    cin >> kona.at(i);

    if (min_kona > kona.at(i)) {
      min_kona = kona.at(i);
    }

    sum += kona.at(i);
  }

  int total = X - sum;
  int ans = N;
  bool unko = true;
  while (unko) {
    total = X - min_kona;
    if (total >= 0) {
      ans += 1;
    } else {
      unko = false;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int N, X, sum = 0, min_kona;
  cin >> N >> X;
  vector<int> kona(N);
  for (int i = 0; i < N; i++) {
    cin >> kona.at(i);

    if (min_kona > kona.at(i)) {
      min_kona = kona.at(i);
    }

    sum += kona.at(i);
  }

  int total = X - sum;
  int ans = N + total / min_kona;
  cout << ans << endl;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
/*
 * cpp_filepath
 */

// C++ 14
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring> // memset
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++)
template <class T> ostream &operator<<(ostream &out, vector<T> const &v) {
  for (auto &&a : v)
    out << a << " ";
  out << endl;
  return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() {
  solve();
  return 0;
}

void solve() {
  int n, x;
  cin >> n >> x;
  vector<int> M(n);
  loop(i, 0, n) cin >> M[i];
  loop(i, 0, n) x -= M[i];
  int min_ = M[0];
  loop(i, 1, x) if (min_ > M[i]) min_ = M[i];
  cout << n + (x / min_) << endl;
}


Fixed submission:
/*
 * cpp_filepath
 */

// C++ 14
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring> // memset
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for (int __x = __start; __x < __end; __x++)
template <class T> ostream &operator<<(ostream &out, vector<T> const &v) {
  for (auto &&a : v)
    out << a << " ";
  out << endl;
  return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() {
  solve();
  return 0;
}

void solve() {
  int n, x;
  cin >> n >> x;
  vector<int> M(n);
  loop(i, 0, n) cin >> M[i];
  loop(i, 0, n) x -= M[i];
  int min_ = M[0];
  loop(i, 1, n) if (min_ > M[i]) min_ = M[i];
  cout << n + (x / min_) << endl;
}
Problem p03370 (C++)

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

int main() {
  int N, X;
  cin >> N >> X;
  int m[N];

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> m[i];
    ans += m[i];
  }
  X = X - ans;

  int min = 100000;
  for (int i = 0; i < N; i++) {
    if (min > m[N])
      min = m[N];
  }

  cout << N + X / min << endl;

  return 0;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  int m[N];

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> m[i];
    ans += m[i];
  }
  X = X - ans;

  int min = 100000;
  for (int i = 0; i < N; i++) {
    if (min > m[i])
      min = m[i];
  }

  cout << N + X / min << endl;

  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int mi = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mi = min(mi, a);
    x -= a;
  }
  cout << n + (x / mi);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n >> x;
  int mi = 1001;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mi = min(mi, a);
    x -= a;
  }
  cout << n + (x / mi);
}
Problem p03370 (C++)

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

using namespace std;

int main() {
  std::vector<long long> v = {0};
  long long a, b, ans = 0, min = 10000;
  cin >> a >> b;
  for (long long i = 0; i < a; i++) {
    cin >> v[i];
  }

  for (long long i = 0; i < a; i++) {
    b -= v[i];
    if (v[i] < min) {
      min = v[i];
    }
    ans++;
  }

  cout << ans + (b / min);

  return 0;
}


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

using namespace std;

int main() {
  array<int, 1000> v = {0};
  long long a, b, ans = 0, min = 10000;
  cin >> a >> b;
  for (long long i = 0; i < a; i++) {
    cin >> v[i];
  }

  for (long long i = 0; i < a; i++) {
    b -= v[i];
    if (v[i] < min) {
      min = v[i];
    }
    ans++;
  }

  cout << ans + (b / min);

  return 0;
}
Problem p03370 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, x, s, m, t;
int main() {
  m = 0;
  t = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> s;
    m = min(m, s);
    t += s;
  }
  int out;
  out = (int)((x - t) / m) + n;
  cout << out;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int n, x, s, m, t;
int main() {
  m = 100000000;
  t = 0;
  cin >> n >> x;
  for (int i = 0; i < n; i++) {
    cin >> s;
    m = min(m, s);
    t += s;
  }
  int out;
  out = (int)((x - t) / m) + n;
  cout << out;
  return 0;
}
Problem p03370 (C++)

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

int N, X;
int m[1000];

int A, B;
int MIN;
int ans;

int main() {

  cin >> N >> X;

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

  for (int i = 1; i <= N; i++) {
    A = A + m[i];
  }

  sort(m, m + N, greater<int>());

  MIN = m[1];

  B = (X - A) / MIN;

  ans = N + B;
  cout << ans << endl;

  return 0;
}


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

int N, X;
int m[1000];

int A, B;
int MIN;
int ans;

int main() {

  cin >> N >> X;

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

  for (int i = 1; i <= N; i++) {
    A = A + m[i];
  }

  sort(m, m + N + 1);

  MIN = m[1];

  B = (X - A) / MIN;

  ans = N + B;
  cout << ans << endl;

  return 0;
}
Problem p03370 (C++)

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

int main() {
  int n, x, sum = 0, min, m[101], rest;
  cin >> n >> x;
  for (int i = 0; i < 101; i++)
    m[i] = 0;
  for (int i = 0; i < n; i++)
    cin >> m[i];
  sort(m, m + n);
  for (int i = 0; i < n; i++)
    sum += m[i];
  rest = x - sum;
  min = 101 - (n - 1);
  cout << (n + rest / m[min]) << endl;

  return 0;
}

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

int main() {
  int n, x, sum = 0, min, m[101], rest;
  cin >> n >> x;
  for (int i = 0; i < 101; i++)
    m[i] = 0;
  for (int i = 0; i < n; i++)
    cin >> m[i];
  sort(m, m + n);
  for (int i = 0; i < n; i++)
    sum += m[i];
  rest = x - sum;
  min = 101 - (n - 1);
  cout << (n + rest / m[0]) << endl;

  return 0;
}