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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}

using P = pair<int, int>;

const int INF = 1 << 30;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<int> A(H), B(H);
  rep(i, 0, H) {
    cin >> A[i] >> B[i];
    --A[i];
  }
  set<P> path;
  multiset<int> dist;
  rep(i, 0, W) {
    path.emplace(i, i);
    dist.insert(0);
  }
  rep(i, 0, H) {
    vector<P> buf;
    for (auto itr = path.lower_bound(P(A[i], 0)); (*itr).first < B[i]; ++itr) {
      buf.push_back(*itr);
    }
    int max_start = -INF;
    P max_path;
    for (auto &p : buf) {
      path.erase(p);
      dist.erase(dist.find(p.first - p.second));
      if (chmax(max_start, p.second)) {
        max_path = p;
      }
    }
    if (max_start > -INF) {
      path.emplace(B[i], max_path.second);
      dist.insert(B[i] == W ? INF : B[i] - max_path.second);
    }
    cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}

using P = pair<int, int>;

const int INF = 1 << 30;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<int> A(H), B(H);
  rep(i, 0, H) {
    cin >> A[i] >> B[i];
    --A[i];
  }
  set<P> path;
  multiset<int> dist;
  rep(i, 0, W) {
    path.emplace(i, i);
    dist.insert(0);
  }
  rep(i, 0, H) {
    vector<P> buf;
    for (auto itr = path.lower_bound(P(A[i], 0));
         itr != path.end() && (*itr).first < B[i]; ++itr) {
      buf.push_back(*itr);
    }
    int max_start = -INF;
    P max_path;
    for (auto &p : buf) {
      path.erase(p);
      dist.erase(dist.find(p.first - p.second));
      if (chmax(max_start, p.second)) {
        max_path = p;
      }
    }
    if (max_start > -INF) {
      path.emplace(B[i], max_path.second);
      dist.insert(B[i] == W ? INF : B[i] - max_path.second);
    }
    cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
  }
  return 0;
}
Problem p02575 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, dis[101010];
set<int> st;
multiset<int> sstt;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    st.insert(i);
    sstt.insert(0);
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    set<int>::iterator it = st.lower_bound(a), it1;
    int mn = 1e9 + 1e5;
    while (it != st.end() && *it <= b) {
      int x = *it;
      mn = min(mn, dis[x] + b - x);
      it1 = it;
      it1++;
      st.erase(it);
      it = it1;
      sstt.erase(sstt.find(dis[x]));
      dis[x] = 1e9 + 1e5;
    }
    if (b != m && mn != 1e9 + 1e5) {
      dis[b] = mn;
      st.insert(b);
      sstt.insert(mn);
    }
    if (st.empty()) {
      cout << "-1\n";
    } else {
      cout << *sstt.begin() + i + 1 << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, dis[202020];
set<int> st;
multiset<int> sstt;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    st.insert(i);
    sstt.insert(0);
  }
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    set<int>::iterator it = st.lower_bound(a), it1;
    int mn = 1e9 + 1e5;
    while (it != st.end() && *it <= b) {
      int x = *it;
      mn = min(mn, dis[x] + b - x);
      it1 = it;
      it1++;
      st.erase(it);
      it = it1;
      sstt.erase(sstt.find(dis[x]));
      dis[x] = 1e9 + 1e5;
    }
    if (b != m && mn != 1e9 + 1e5) {
      dis[b] = mn;
      st.insert(b);
      sstt.insert(mn);
    }
    if (st.empty()) {
      cout << "-1\n";
    } else {
      cout << *sstt.begin() + i + 1 << endl;
    }
  }
  return 0;
}
Problem p02575 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  int h, w;
  cin >> h >> w;
  VI a(h), b(h);
  rep(i, h) {
    cin >> a[i] >> b[i];
    a[i]--;
  }
  multiset<int> num;
  rep(i, w) num.insert(0);
  VI dp(w);
  set<int> alive;
  rep(i, w) alive.insert(i);
  rep(i, h) {
    while (1) {
      auto it = alive.lower_bound(a[i]);
      if (it == alive.end() || *it >= b[i])
        break;
      int k = *it;
      assert(num.find(dp[k]) != num.end());
      alive.erase(k);
      num.erase(num.find(dp[k]));
      if (b[i] == w) {
        ;
      } else if (alive.count(b[i]) == 0) {
        alive.insert(b[i]);
        dp[b[i]] = dp[k] + b[i] - k;
        num.insert(dp[k] + b[i] - k);
      } else {
        if (dp[k] + b[i] - k < dp[b[i]]) {
          num.erase(dp[b[i]]);
          num.insert(dp[k] + b[i] - k);
          dp[b[i]] = dp[k] + b[i] - k;
        }
      }
      a[i] = k + 1;
    }
    if (num.empty())
      cout << -1 << endl;
    else
      cout << *num.begin() + i + 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  int h, w;
  cin >> h >> w;
  VI a(h), b(h);
  rep(i, h) {
    cin >> a[i] >> b[i];
    a[i]--;
  }
  multiset<int> num;
  rep(i, w) num.insert(0);
  VI dp(w);
  set<int> alive;
  rep(i, w) alive.insert(i);
  rep(i, h) {
    while (1) {
      auto it = alive.lower_bound(a[i]);
      if (it == alive.end() || *it >= b[i])
        break;
      int k = *it;
      assert(num.find(dp[k]) != num.end());
      alive.erase(k);
      num.erase(num.find(dp[k]));
      if (b[i] == w) {
        ;
      } else if (alive.count(b[i]) == 0) {
        alive.insert(b[i]);
        dp[b[i]] = dp[k] + b[i] - k;
        num.insert(dp[k] + b[i] - k);
      } else {
        if (dp[k] + b[i] - k < dp[b[i]]) {
          num.erase(num.find(dp[b[i]]));
          num.insert(dp[k] + b[i] - k);
          dp[b[i]] = dp[k] + b[i] - k;
        }
      }
      a[i] = k + 1;
    }
    if (num.empty())
      cout << -1 << endl;
    else
      cout << *num.begin() + i + 1 << endl;
  }
}
Problem p02576 (C++)

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  int count;

  if (N == X) {
    cout << T << endl;
  }

  else if ((N / X) % 0) {
    cout << (N / X) * T << endl;
  }

  else if (X != 1) {

    count = N / X;

    cout << (count + 1) * T << endl;

  }

  else {
    cout << N * T << endl;
  }
}

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  int count;

  if (N == X) {
    cout << T << endl;
  }

  else if (N % X == 0) {
    cout << (N / X) * T << endl;
  }

  else if (X != 1) {

    count = N / X;

    cout << (count + 1) * T << endl;

  }

  else {
    cout << N * T << endl;
  }
}
Problem p02576 (C++)

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define per(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define fastio                                                                 \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define N 1000010
#define MAX 1234567890

ll solve() {
  ll n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << endl;
}

int main() {
  fastio;

  solve();

  return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define per(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define fastio                                                                 \
  {                                                                            \
    ios_base::sync_with_stdio(false);                                          \
    cin.tie(NULL);                                                             \
    cout.tie(NULL);                                                            \
  }
#define N 1000010
#define MAX 1234567890

void solve() {
  ll n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << endl;
}

int main() {
  fastio;

  solve();

  return 0;
}
Problem p02576 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, x, t, c = 0;
  cin >> n >> x >> t;
  while (n > 0) {
    n -= x;
    c++;
  }
  return c * t;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, x, t, c = 0;
  cin >> n >> x >> t;
  while (n > 0) {
    n -= x;
    c++;
  }
  cout << c * t << endl;
  return 0;
}
Problem p02576 (Python)

Buggy submission (status: Runtime Error):
import math

N, X, T = map(int(input().split()))

print(T * math.ceil(N / X))


Fixed submission:
import math

N, X, T = map(int, input().split())

print(T * math.ceil(N / X))
Problem p02576 (C++)

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

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n / (x - 1) * t + t) << endl;
}


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

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int ans = 0;
  ans += n / x * t + !!(n - n / x * x) * t;
  cout << ans << endl;
}
Problem p02577 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[200001];
int n;
int main() {
  scanf("%s", a);
  for (int i = 0; i < strlen(a); i++) {
    n += a[i] - 48;
  }
  // printf("%d\n",n);
  if (n % 9 == 0) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char a[200001];
int n;
int main() {
  scanf("%s", a);
  for (int i = 0; i < 200001; i++) {
    if (a[i] == 0) {
      continue;
    } else {
      n += a[i] - 48;
    }
  }
  // printf("%d\n",n);
  if (n % 9 == 0) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}
Problem p02577 (Python)

Buggy submission (status: Runtime Error):
N = input()
tmp = 0
while N > 0:
    tmp += N % 10
    N /= 10
if tmp % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
print("No" if int(input()) % 9 else "Yes")
Problem p02577 (Python)

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

input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())

total = 0
while n:
    total += n % 10
    n //= 10

if total % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())

if n % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())

s = 0

for i in range(len(str(n))):
    s += n % 10
    n //= 10
    s %= 9

print("Yes" if s == 0 else "No")


Fixed submission:
n = int(input())

print("Yes" if n % 9 == 0 else "No")
Problem p02577 (Python)

Buggy submission (status: Runtime Error):
def main():
    num = input()
    if num % 9 == 0:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    ans = main()
    print(ans)


Fixed submission:
def main():
    num = int(input())
    if num % 9 == 0:
        return "Yes"
    else:
        return "No"


if __name__ == "__main__":
    ans = main()
    print(ans)
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
s = 0

while N != 0:
    s = s + N % 10
    N = N // 10

if s % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = int(input())
s = 0

s = sum(list(map(int, str(N))))

if s % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main() {
  char s[100000];
  long long int i, j, p = 0, a, k;
  scanf("%s", s);
  a = strlen(s); // printf("%d",a);
  for (i = 0; i < a; i++) {
    p = p + (s[i] - '0');
    p = p % 9;
  }
  if (p % 9 == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Fixed submission:
#include <stdio.h>
#include <string.h>
int main() {
  char s[1000000];
  long long int i, j, p = 0, a, k;
  scanf("%s", s);
  a = strlen(s); // printf("%d",a);
  for (i = 0; i < a; i++) {
    p = p + (s[i] - '0');
    p = p % 9;
  }
  if (p % 9 == 0)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define IOS                                                                    \
  ios::sync_with_stdio();                                                      \
  cin.tie(0);
#define tc()                                                                   \
  int tc;                                                                      \
  scanf("%d", &tc);                                                            \
  while (tc--)
#define endl "\n"
#define FLOAT_COM(a, b) if (abs(a - b) == 1e-9)
#define LOOP(a, b) for (i = a; i < b; i++)
#define VI vector<int>
#define VLL vector<long long>
#define PB push_back
#define MP make_pair

using namespace std;

// int i,j,k,l,temp;

void shomoy() {
#ifndef ONLINE_JUDGE
  cerr << "\nTime  :" << 1.0 * clock() / CLOCKS_PER_SEC << "  s\n";
#endif
}

bool isprime(int n) {
  int f;
  for (f = 2; f * f <= n; f++) {
    if (n % f == 0)
      return false;
  }
  return true;
}

/*Driver Code Startes Here*/
int main() {
  IOS int n, i, j, count = 0;
  char line[100000];
  cin >> line;
  n = strlen(line);
  for (i = 0; i < n; i++) {
    count += (line[i] - '0');
  }
  if (count % 9) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  // shomoy();
  return 0;
}

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define IOS                                                                    \
  ios::sync_with_stdio();                                                      \
  cin.tie(0);
#define tc()                                                                   \
  int tc;                                                                      \
  scanf("%d", &tc);                                                            \
  while (tc--)
#define endl "\n"
#define FLOAT_COM(a, b) if (abs(a - b) == 1e-9)
#define LOOP(a, b) for (i = a; i < b; i++)
#define VI vector<int>
#define VLL vector<long long>
#define PB push_back
#define MP make_pair

using namespace std;

// int i,j,k,l,temp;

void shomoy() {
#ifndef ONLINE_JUDGE
  cerr << "\nTime  :" << 1.0 * clock() / CLOCKS_PER_SEC << "  s\n";
#endif
}

bool isprime(int n) {
  int f;
  for (f = 2; f * f <= n; f++) {
    if (n % f == 0)
      return false;
  }
  return true;
}

/*Driver Code Startes Here*/
int main() {
  IOS int i, n, count = 0;
  char line[10000000];
  cin >> line;
  n = strlen(line);
  for (i = 0; i < n; i++) {
    count += (line[i] - '0');
  }
  if (count % 9) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  // shomoy();
  return 0;
}
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
sum = 0
while n > 0:
    sum += n % 10
    n = n // 10
if sum % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
n = int(input())
if n % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
sum = 0
while N > 0:
    sum += N % 10
    N = N // 10
if sum % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()
s = [char for char in N]
sum_ = 0
for char in s:
    sum_ += int(char)
if sum_ % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
using namespace std;
char s[100009];
int main() {
  cin >> s;
  long long sum = 0;
  for (int i = 0; i < strlen(s); i++)
    sum += int(s[i] - '0');
  if (sum % 9 == 0)
    cout << "Yes";
  else {
    cout << "No";
  }
  system("pause");
}

Fixed submission:
#include <cstring>
#include <iostream>
using namespace std;
char s[10000009];
int main() {
  cin >> s;
  long long sum = 0;
  for (int i = 0; i < strlen(s); i++)
    sum += int(s[i] - '0');
  if (sum % 9 == 0)
    cout << "Yes";
  else {
    cout << "No";
  }
  system("pause");
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  char c[200005];
  int sum = 1;
  while (cin >> c[sum])
    sum++;
  int ans = 0;
  for (int i = 1; i <= sum; i++) {
    int num = (int)(c[i] - '0');
    sum += num;
  }
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n.length(); i++) {
    sum += (n[i] - '0');
  }
  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  char s[100000];
  unsigned long long int n = 0;
  cin >> s;
  for (int i = 0; s[i] != '\0'; i++) {
    n += s[i] - '0';
    n %= 9;
  }
  if (n)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  char s[300000];
  unsigned long long int n = 0;
  cin >> s;
  for (int i = 0; s[i] != '\0'; i++) {
    n += s[i] - '0';
    n %= 9;
  }
  if (n)
    cout << "No";
  else
    cout << "Yes";
  return 0;
}
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
N = input()

cnt = 0
for s in N:
    cnt += int(N)

if cnt % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()

cnt = 0
for s in N:
    cnt += int(s)

if cnt % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (Python)

Buggy submission (status: Runtime Error):
N = input()
ans = 0
while N:
    ans += int(N[:-1])
    ans = ans % 9
    N = N[:-1]
if ans == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()
ans = 0
while N:
    ans += int(N[-1])
    ans = ans % 9
    N = N[:-1]
if ans == 0:
    print("Yes")
else:
    print("No")
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main() {
  int i, sm = 0;
  char s[100000];
  scanf("%s", s);
  for (i = 0; i < strlen(s); i++)
    sm += s[i] - '0';
  if (sm % 9 == 0)
    printf("Yes\n");
  else
    printf("No\n");
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main() {
  int i, sm = 0;
  char s[2000009];
  scanf("%s", s);
  for (i = 0; i < strlen(s); i++)
    sm += s[i] - '0';
  if (sm % 9 == 0)
    printf("Yes\n");
  else
    printf("No\n");
}
Problem p02577 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <cstring>
using namespace std;
int sum;
char ch[200005];
int main() {
  scanf("%s", ch);
  for (int i = 0; i < (int)strlen(ch); ++i)
    sum += ch[i] - '0';
  if (sum % 9)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;
int sum;
char ch[200005];
int main() {
  scanf("%s", ch);
  int t = (int)strlen(ch);
  for (int i = 0; i < t; ++i)
    sum += ch[i] - '0';
  if (sum % 9)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int m, a;
  m = 0;
  for (int i = 0; i < len; i++) {
    a = s[i] - '0';
    m += a;
  }
  if (m % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
char s[100000005];
int main() {
  scanf("%s", s);
  int len = strlen(s);
  int m, a;
  m = 0;
  for (int i = 0; i < len; i++) {
    a = s[i] - '0';
    m += a;
  }
  if (m % 9 == 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frb(i, a, b) for (ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll, ll>
#define v vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define mod 1000000007
#define max 1000001
bool prime[max];
void seive() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i <= max; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= max; j += i) {
        prime[j] = false;
      }
    }
  }
}
void solve() {
  string s;
  cin >> s;
  ll n = s.size();
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += (s[i - '0']);
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
int main() {
  Bahut_tej;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t;
  // cin>>t;
  // while(t--){
  solve();
  //}
  return 0;
}


Fixed submission:
//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frb(i, a, b) for (ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll, ll>
#define v vector<ll>
#define srt(v) sort(v.begin(), v.end())
#define mod 1000000007
#define max 1000001
bool prime[max];
void seive() {
  memset(prime, true, sizeof(prime));
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i * i <= max; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= max; j += i) {
        prime[j] = false;
      }
    }
  }
}
void solve() {
  string s;
  cin >> s;
  ll n = s.size();
  ll sum = 0;
  for (ll i = 0; i < n; i++) {
    sum += (s[i] - '0');
  }
  if (sum % 9 == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
int main() {
  Bahut_tej;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  // int t;
  // cin>>t;
  // while(t--){
  solve();
  //}
  return 0;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
#define charToInt(c) (c - '0')
int main() {
  ll a, b, c = 0, d, i, j;
  char s[1000];
  in >> s;
  for (i = 0; s[i]; i++) {
    s[i] = s[i] - 48;
    c += s[i];
  }
  if (c % 9 == 0) {
    cout << "Yes" << nl;
  } else {
    cout << "No" << nl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define nl endl
#define in cin
#define out cout
#define ll long long
#define charToInt(c) (c - '0')
int main() {
  ll a, b, c = 0, d, i, j;
  string s;
  in >> s;
  for (i = 0; s[i]; i++) {
    s[i] = s[i] - 48;
    c += s[i];
  }
  if (c % 9 == 0) {
    cout << "Yes" << nl;
  } else {
    cout << "No" << nl;
  }
}
Problem p02577 (C++)

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

char S[20010];
int main() {
  cin >> S;
  int len = strlen(S);
  long long sum = 0;
  for (int i = 0; i < len; i++) {
    sum += S[i] - '0';
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  ;
}

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

char S[200100];
int main() {
  cin >> S;
  int len = strlen(S);
  long long sum = 0;
  for (int i = 0; i < len; i++) {
    sum += S[i] - '0';
  }
  if (sum % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  ;
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long int ll;
int main() {
  char s[100000];
  scanf("%s", s);
  ll sum = 0;
  rep(i, strlen(s)) sum += s[i] - '0';
  if (sum % 9 == 0)
    printf("Yes");
  else
    printf("No");
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long int ll;
int main() {
  char s[200000];
  scanf("%s", s);
  ll sum = 0;
  rep(i, strlen(s)) sum += s[i] - '0';
  if (sum % 9 == 0)
    printf("Yes");
  else
    printf("No");
}
Problem p02577 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define FUP(i, x, y) for (int i = (x); i <= (y); i++)
#define FDW(i, x, y) for (int i = (x); i >= (y); i--)
#define MAXN 100010
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read() {
  int w = 0, flg = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flg = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    w = w * 10 - '0' + ch, ch = getchar();
  }
  return w * flg;
}
int sum;
char s[20010];
int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  FUP(i, 1, len) sum += s[i] - '0';
  sum % 9 == 0 ? puts("Yes") : puts("No");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#define FUP(i, x, y) for (int i = (x); i <= (y); i++)
#define FDW(i, x, y) for (int i = (x); i >= (y); i--)
#define MAXN 100010
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define ll long long
#define db double
using namespace std;
int read() {
  int w = 0, flg = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      flg = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    w = w * 10 - '0' + ch, ch = getchar();
  }
  return w * flg;
}
int sum;
char s[200010];
int main() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  FUP(i, 1, len) sum += s[i] - '0';
  sum % 9 == 0 ? puts("Yes") : puts("No");
  return 0;
}
Problem p02577 (C++)

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

int main() {
  char S[100100];
  scanf("%s", S);
  int s = 0;
  for (int i = 0; S[i]; i++)
    s += S[i] - '0';
  puts(s % 9 == 0 ? "Yes" : "No");
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  char S[200100];
  scanf("%s", S);
  int s = 0;
  for (int i = 0; S[i]; i++)
    s += S[i] - '0';
  puts(s % 9 == 0 ? "Yes" : "No");
  return 0;
}
Problem p02577 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
summer = 0

while N > 0:
    digit = N % 10
    summer += digit
    N = N // 10
if summer % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = int(input())
if N % 9 == 0:
    print("Yes")
else:
    print("No")
Problem p02578 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, a[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = n - 2; i >= 0; i++) {
    long long up = max(0, a[i + 1] - a[i]);
    a[i] += up, ans += up;
  }
  cout << ans << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, a[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    long long up = max(0, a[i - 1] - a[i]);
    a[i] += up, ans += up;
  }
  cout << ans << '\n';
  return 0;
}
Problem p02578 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
long long int n, x[2000001], t, ans;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> x[i];
  for (int i = 1; i < n; i++) {
    for (int j = i - 1; j >= 0; j--)
      if (t < x[j])
        t = x[j];
    if (x[i] < t) {
      ans += t - x[i];
      x[i] += t - x[i];
    }
  }
  cout << ans;
}

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

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

using namespace std;
using ll = long long;
ll a[101010], n, ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) {
      if (a[i] < a[i - 1]) {
        ans += a[i - 1] - a[i];
        a[i] = a[i - 1];
      }
    }
  }
  cout << ans << '\n';
}


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

using namespace std;
using ll = long long;
ll a[202020], n, ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) {
      if (a[i] < a[i - 1]) {
        ans += a[i - 1] - a[i];
        a[i] = a[i - 1];
      }
    }
  }
  cout << ans << '\n';
}
Problem p02578 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pis pair<ll, string>
#define F first
#define S second
#define LCM(a, b) ((a * b) / __gcd(a, b))
#define inf 1e15
#define test                                                                   \
  ll cse;                                                                      \
  cin >> cse;                                                                  \
  for (ll _i = 1; _i <= cse; _i++)
#define PI 3.14159265
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const double EPS = 1E-9;
typedef vector<vector<double>> matrix;
typedef vector<int> vi;

ll ar[N];
int main() {
  fast;

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

  ll sum = 0, m = ar[0];

  for (int i = 1; i < n; i++) {
    m = max(m, ar[i]);
    sum += (m - ar[i]);
  }
  cout << sum << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pis pair<ll, string>
#define F first
#define S second
#define LCM(a, b) ((a * b) / __gcd(a, b))
#define inf 1e15
#define test                                                                   \
  ll cse;                                                                      \
  cin >> cse;                                                                  \
  for (ll _i = 1; _i <= cse; _i++)
#define PI 3.14159265
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
const double EPS = 1E-9;
typedef vector<vector<double>> matrix;
typedef vector<int> vi;

ll ar[N];
int main() {
  fast;

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

  ll sum = 0, m = ar[0];

  for (int i = 1; i < n; i++) {
    m = max(m, ar[i]);
    sum += (m - ar[i]);
  }
  cout << sum << "\n";
  return 0;
}
Problem p02578 (C++)

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

typedef long long ll;

ll a[100005];

int main(void) {
  ll n, mx = 0, sum = 0;

  scanf("%lld", &n);
  for (ll i = 1; i <= n; i++)
    scanf("%lld", &a[i]);

  mx = a[1];

  for (ll i = 2; i <= n; i++) {
    if (mx < a[i])
      mx = a[i];

    sum += mx - a[i];
  }

  printf("%lld", sum);

  return 0;
}

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

typedef long long ll;

ll a[200005];

int main(void) {
  ll n, mx = 0, sum = 0;

  scanf("%lld", &n);
  for (ll i = 1; i <= n; i++)
    scanf("%lld", &a[i]);

  mx = a[1];

  for (ll i = 2; i <= n; i++) {
    if (mx < a[i])
      mx = a[i];

    sum += mx - a[i];
  }

  printf("%lld", sum);

  return 0;
}
Problem p02578 (Python)

Buggy submission (status: Runtime Error):
N = input()
tmp = 0
while N > 0:
    tmp += N % 10
    N /= 10
if tmp % 9 == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np


def input():
    return sys.stdin.readline().strip()


def INT():
    return int(input())


def MAP():
    return map(int, input().split())


def LIST():
    return list(map(int, input().split()))


def ZIP(n):
    return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7

N = INT()
A = MAP()
prev = -INF
ans = 0
for a in A:
    if a < prev:
        ans += prev - a
    else:
        prev = a
print(ans)
Problem p02578 (C++)

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

int main(void) {
  int n, ans;
  int h[100010];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  ans = 0;
  for (int i = 1; i < n; i++) {
    if (h[i - 1] > h[i]) {
      ans += h[i - 1] - h[i];
      h[i] = h[i - 1];
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main(void) {
  int n;
  long long ans;
  int h[200010];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  ans = 0;
  for (int i = 1; i < n; i++) {
    if (h[i - 1] > h[i]) {
      ans += h[i - 1] - h[i];
      h[i] = h[i - 1];
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02578 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int sum = 0;
  for (int i = 1; i < N + 1; i++) {
    if (vec.at(i - 1) > vec.at(i)) {
      sum += (vec.at(i - 1) - vec.at(i));
      vec.at(i) = vec.at(i - 1);
    }
  }
  cout << sum << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int64_t sum = 0;
  for (int i = 1; i < N; i++) {
    if (vec.at(i - 1) > vec.at(i)) {
      sum += (vec.at(i - 1) - vec.at(i));
      vec.at(i) = vec.at(i - 1);
    }
  }
  cout << sum << endl;
}
Problem p02578 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, a[100005], sum = 0;
signed main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << sum;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
int n, a[200005], sum = 0;
signed main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      sum += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << sum;
  return 0;
}
Problem p02578 (C++)

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

long long a[2 * 10 ^ 5 + 5];

int main() {
  long long n, min_sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      min_sum += a[i] - a[i + 1];
      a[i + 1] += a[i] - a[i + 1];
    }
  }
  cout << min_sum << endl;
}

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

long long a[2 * 100000 + 5];

int main() {
  long long n, min_sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      min_sum += a[i] - a[i + 1];
      a[i + 1] += a[i] - a[i + 1];
    }
  }
  cout << min_sum << endl;
}
Problem p02578 (C++)

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

int main() {

  int N;
  long int A[20000], ans = 0;
  cin >> N;
  rep(i, N) cin >> A[i];

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

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

Fixed submission:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {

  int N;
  long int A[200001], ans = 0;
  cin >> N;
  rep(i, N) cin >> A[i];

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

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  ll ans = 0;
  rep(i, N) cin >> A.at(i);
  B.at(1) = A.at(0);
  ans += B.at(1) - A.at(1);
  for (int i = 1; i < N - 1; i++) {
    int maxtmp = 0;
    maxtmp = max(A.at(i + 1), B.at(i));
    B.at(i + 1) = maxtmp;
    ans += B.at(i + 1) - A.at(i + 1);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  ll ans = 0;
  rep(i, N) cin >> A.at(i);
  int maxtmp = 0;
  rep(i, N) {
    maxtmp = max(maxtmp, A.at(i));
    ans += maxtmp - A.at(i);
  }
  cout << ans << endl;
  return 0;
}
Problem p02578 (C++)

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

int a[100005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      ans += (a[i - 1] - a[i]);
      a[i] = a[i - 1];
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int a[200005];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      ans += (a[i - 1] - a[i]);
      a[i] = a[i - 1];
    }
  }
  cout << ans << '\n';
  return 0;
}
Problem p02578 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int64_t u;
  int64_t sum = 0;
  int A[200010];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (N == 1) {
    cout << sum << endl;
  } else {
    for (int i = 0; i < N - 1; i++) {
      int s = i + 1;
      // cout<<A[i]<<A[s]<<endl;
      if (A[i] > A[s]) {
        u = A[i] - A[s];
        A[s] = A[i];
        sum += u;
        // cout << u <<endl;
      }
    }
    cout << sum << endl;
  }
}
Problem p02578 (C++)

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

int main() {
  ll N;
  ll sum = 0, mx;
  vi A(30000);
  cin >> N;
  rep(i, N) cin >> A[i];
  mx = A[0];
  rep(i, N) {
    if (mx > A[i])
      sum += mx - A[i];
    if (A[i] > mx)
      mx = A[i];
  }
  cout << sum << endl;
}


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

int main() {
  ll N;
  ll sum = 0, mx;
  vi A(300000);
  cin >> N;
  rep(i, N) cin >> A[i];
  mx = A[0];
  rep(i, N) {
    if (mx > A[i])
      sum += mx - A[i];
    if (A[i] > mx)
      mx = A[i];
  }
  cout << sum << endl;
}
Problem p02578 (C++)

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

int _;

int n, a[100050], maxn;
long long ans;

int main() {
  // for(scanf("%d",&_);_;_--)
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    maxn = max(maxn, a[i]);
    ans += max(maxn - a[i], 0);
  }
  printf("%lld", ans);
  return 0;
}

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

int _;

int n, a[200050], maxn;
long long ans;

int main() {
  // for(scanf("%d",&_);_;_--)
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    maxn = max(maxn, a[i]);
    ans += max(maxn - a[i], 0);
  }
  printf("%lld", ans);
  return 0;
}
Problem p02578 (C++)

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

int N;
int A[100005];
long long ans;

int main() {
  cin >> N;

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

  long long mn = 1LL * A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] < mn) {
      ans += mn - 1LL * A[i];
    } else {
      mn = 1LL * A[i];
    }
  }

  cout << ans;

  return 0;
}

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

int N;
int A[200005];
long long ans;

int main() {
  cin >> N;

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

  long long mn = 1LL * A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] < mn) {
      ans += mn - 1LL * A[i];
    } else {
      mn = 1LL * A[i];
    }
  }

  cout << ans;

  return 0;
}
Problem p02578 (C++)

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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 100010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i] < a[i - 1])
      cnt += (ll)a[i - 1] - (ll)a[i], a[i] += (ll)a[i - 1] - (ll)a[i];
  cout << cnt << "\n";
}


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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(a) a.begin(), a.end()

const int maxn = 200010;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
int n, m, a[maxn];
string s, ss;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll cnt = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 1; i < n; i++)
    if (a[i] < a[i - 1])
      cnt += (ll)a[i - 1] - (ll)a[i], a[i] += (ll)a[i - 1] - (ll)a[i];
  cout << cnt << "\n";
}
Problem p02578 (C++)

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

int main() {
  long int N;
  cin >> N;
  if (N > 0) {
    vector<long int> vec(N, 0);
    for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
    }
    vector<long int> dai(N - 1, 0);
    if (vec.at(0) > vec.at(1)) {
      dai.at(0) = vec.at(0) - vec.at(1);
    }
    for (int j = 0; j < N - 2; j++) {
      if (vec.at(j + 1) + dai.at(j) > vec.at(j + 2)) {
        dai.at(j + 1) = vec.at(j + 1) + dai.at(j) - vec.at(j + 2);
      }
    }
    long int s = 0;
    for (int k = 0; k < N - 1; k++) {
      s += dai.at(k);
    }
    cout << s << endl;
  } else {
    cout << 0 << endl;
  }
}

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

int main() {
  long int N;
  cin >> N;
  if (N > 1) {
    vector<long int> vec(N, 0);
    for (int i = 0; i < N; i++) {
      cin >> vec.at(i);
    }
    vector<long int> dai(N - 1, 0);
    if (vec.at(0) > vec.at(1)) {
      dai.at(0) = vec.at(0) - vec.at(1);
    }
    for (int j = 0; j < N - 2; j++) {
      if (vec.at(j + 1) + dai.at(j) > vec.at(j + 2)) {
        dai.at(j + 1) = vec.at(j + 1) + dai.at(j) - vec.at(j + 2);
      }
    }
    long int s = 0;
    for (int k = 0; k < N - 1; k++) {
      s += dai.at(k);
    }
    cout << s << endl;
  } else {
    cout << 0 << endl;
  }
}