alexjercan/bugnet huggingface dataset:
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string s;
  cin >> s;
  int sum = 0, i;

  for (i = 0; i < s.size(); i++) {
    sum += s[i] - '0';
  }

  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}

Error: 9

Fixed submission:

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

int main() {
  string s;
  cin >> s;
  int sum = 0, i;

  for (i = 0; i < s.size(); i++) {
    sum += s[i] - 48;
  }

  if (sum % 9 == 0)
    cout << "Yes";
  else
    cout << "No";

  return 9;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: WA

Fixed submission:

#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;
}
Problem p02577 (C++) — buggy submission, verdict: 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 < 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;
}


Error: TLE

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 < strlen(a); i++) {
    n += a[i] - 48;
  }
  // printf("%d\\n",n);
  if (n % 9 == 0) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
  string str;
  cin >> str;
  ll c = 0;
  ll n = str.length();
  for (ll i = 0; i < n; i++) {
    c += (str[i] - '0');
  }
  if (c % 9)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
#define ll long long int
int main() {
  cpp_int n;
  cin >> n;
  cpp_int count = 0;
  while (n > 0) {
    cpp_int k = (n % 10);
    n /= 10;
    if (k > 0)
      count = count + k;
  }
  if (count % 9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02577 (C++) — buggy submission, verdict: 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[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;
}

Error: 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[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;
}
Problem p02577 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
int ans;
char s[200005];
void Read() {
  int i;
  scanf("%s", s);
  int SIZ = strlen(s);
  for (i = 0; i < SIZ; i++) {
    ans += s[i] - '0';
    ans %= 9;
  }
  if (ans == 0)
    printf("Yes");
  else
    printf("No");
}
int main() {
  Read();
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
int ans;
char s[200005];
void Read() {
  int i;
  scanf("%s", s);
  for (i = 0; i < strlen(s); i++)
    ans += s[i] - '0';
  if (ans % 9 == 0)
    printf("Yes");
  else
    printf("No");
}
int main() {
  Read();
  return 0;
}
Problem p02577 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string n;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n.length(); i++) {
    res += (int)(n[i] - '0');
  }
  cout << ((res % 9 == 0) ? "Yes" : "No") << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  char *n;
  cin >> n;
  int res = 0;
  for (int i = 0; i++;) {
    if (n[i] == '\\0')
      break;
    res += n[i] - '0';
  }
  cout << ((res % 9 == 0) ? "Yes" : "No") << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test()                                                                 \\
  ull t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pll pair<ll, ll>
#define puu pair<ull, ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout << endl
#define sp cout << " "
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int main() {
  // ios::sync_with_stdio(0);
  // cin.tie(0);
  // cout.tie(0);
  ll n;
  cin >> n;

  vector<ll> v(n);

  loop(i, 0, n) cin >> v[i];

  ull result = 0;
  ll mx = 0;
  loop(i, 0, n) {
    mx = max(v[i], mx);

    result += mx - v[i];
  }

  cout << result;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio()                                                               \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define loope(i, a, b) for (ll i = a; i <= b; i++)
#define test()                                                                 \\
  ull t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define pll pair<ll, ll>
#define puu pair<ull, ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout << endl
#define sp cout << " "
#define MOD 1000000007
#define all(x) x.begin(), x.end()

int main() {
  // ios::sync_with_stdio(0);
  // cin.tie(0);
  // cout.tie(0);
  ll n;
  vector<ll> v(n);

  cin >> n;

  loop(i, 0, n) cin >> v[i];

  ull result = 0;
  ll mx = 0;
  loop(i, 0, n) {
    mx = max(v[i], mx);

    result += mx - v[i];
  }

  cout << result;
}
Problem p02578 (C++) — buggy submission, verdict: 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 = 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;
}

Error: TLE

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 = 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;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<int> A;

  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  /*
  N = 5;
  A[0] = 2;
  A[1] = 1;
  A[2] = 5;
  A[3] = 4;
  A[4] = 3;
  */

  long long s = 0;
  int max = 0;
  int dif;

  for (int i = 0; i < N; i++) {
    dif = max - A[i];
    s += dif > 0 ? dif : 0;
    max = dif > 0 ? max : A[i];
    // cout << "max = " << max << endl;
  }
  cout << s << endl;
  return (0);
}


Error: -11

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<int> A;

  cin >> N;
  /*
  N = 5;
  A.resize(N);
  A[0] = 2;
  A[1] = 1;
  A[2] = 5;
  A[3] = 4;
  A[4] = 3;
  */

  int s = 0;
  int max = 0;
  int dif;

  for (int i = 0; i < N; i++) {
    dif = max - A[i];
    s += dif > 0 ? dif : 0;
    max = dif > 0 ? max : A[i];
    // cout << "max = " << max << endl;
  }
  cout << s << endl;
  return (0);
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  long N;
  cin >> N;
  long long A[N], t, count = 0;
  for (long i = 0; i < N; i++) {
    cin >> t;
    A[i] = t;
  }

  for (long i = 1; i < N; i++) {
    if (A[i - 1] > A[i]) {
      long long dif = abs(A[i - 1] - A[i]);
      A[i] += dif;
      count += dif;
    }
  }

  cout << count << endl;

  return 0;
}

Error: -11

Fixed submission:

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

int main(void) {
  int N, count = 0;
  int A[N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

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

  printf("%d", count);

  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp, -1, sizeof(dp))
const ll mod = 1e9 + 7;
void _IOS() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
}
#define PI 3.14159265359
int sx, sy, tx, ty;
struct threeElements {
  int _1st, _2nd, _3rd;
};
int main() {
  // freopen ("jumping.in","r",stdin);
  _IOS();
  int n;
  cin >> n;
  int a[200009];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll ans = 0;
  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;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp, -1, sizeof(dp))
const ll mod = 1e9 + 7;
void _IOS() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
}
#define PI 3.14159265359
int sx, sy, tx, ty;
struct threeElements {
  int _1st, _2nd, _3rd;
};
int main() {
  // freopen ("jumping.in","r",stdin);
  _IOS();
  int n;
  cin >> n;
  int a[100009];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int ans = 0;
  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;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define A 100000000
int main() {
  long long n;
  long long ans = 0;
  cin >> n;
  static int a[A];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0 && a[i - 1] > a[i]) {
      ans = ans + a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int n;
  int ans = 0;
  int a[n];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0 && a[i - 1] > a[i]) {
      ans = ans + a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }

  cout << ans << endl;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, a[i]);
    sum += mx - a[i];
  }
  cout << sum << endl;
}
int main() {
  fast();
  solve();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
void solve() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    ll k = *max_element(a.begin(), a.begin() + i + 1);
    sum += k - a[i];
  }
  cout << sum << endl;
}
int main() {
  fast();
  solve();

  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN = 2e5;

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mx = a[0];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, a[i]);
    ans += mx - a[i];
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>
const int mxN = 2e5;

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll c = 0;
  for (int i = n - 1; i > 0; i--) {
    int mx = a[i];
    for (int j = i - 1; j >= 0; j--) {
      mx = max(a[j], mx);
    }
    c += mx - a[i];
  }
  cout << c;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: WA

Fixed submission:

#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;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

int main() {
  ll N;
  cin >> N;
  ll su = 0;
  ll p = 0;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll p2 = A[0];
  for (ll i = 0; i < N; ++i) {
    if (p2 > A[i]) {
      su += p2 - A[i];
    } else
      p2 = A[i];
  }
  cout << su << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x % y) : x; }

int main() {
  ll N;
  cin >> N;
  ll su = 0;
  ll p = 0;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  for (int i = 0; i < N; ++i) {
    if (A[p] > A[i]) {
      su += A[p] - A[i];
    } else
      p = A[i];
  }
  cout << su << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  ll S = 0;
  REP(i, N) {
    cin >> A.at(i);
    S += A.at(i);
  }

  REP(i, N - 1) {
    if (A.at(i + 1) < A.at(i))
      A.at(i + 1) = A.at(i);
  }
  ll _S = 0;
  REP(i, N) { _S += A.at(i); }
  cout << (_S - S) << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A.at(i);
  int Ans = 0;
  REP(i, N - 1) {
    while (A.at(i) > A.at(i + 1)) {
      Ans++;
      A.at(i + 1)++;
    }
  }
  cout << Ans << endl;
  return 0;
}
Problem p02578 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  for (ll i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << ans;

  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;

void solve() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n;
  vector<ll> a(n);
  cin >> n;
  rep(i, n) cin >> a[i];
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      ans += a[i - 1] - a[i];
      a[i] = a[i - 1];
    }
  }
  cout << ans;

  return 0;
}