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

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  char f;
  f = s[0];
  int ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != f) {
      for (int j = i; j >= 0; j--) {
        s[j] = s[i];
      }
      ans++;
    }
    f = s[i];
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s;
  cin >> s;
  char f;
  f = s[0];
  int ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != f) {
      ans++;
    }
    f = s[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[10000];
  cin >> a;
  int s = 0;
  for (int i = 0; i < strlen(a) - 1; i++)
    if (a[i] != a[i + 1])
      s++;
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  char a[100000];
  cin >> a;
  int s = 0;
  for (int i = 0; i < strlen(a) - 1; i++)
    if (a[i] != a[i + 1])
      s++;
  cout << s << endl;
}
Problem p03945 (C++)

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

string s;
char t[100000];
int l;

int main() {
  scanf("%s", t);
  s = t;
  l = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1])
      l++;
  }
  printf("%d\n", l - 1);
  return 0;
}

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

string s;
char t[1000000];
int l;

int main() {
  scanf("%s", t);
  s = t;
  l = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1])
      l++;
  }
  printf("%d\n", l - 1);
  return 0;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int res = 1;
  bool flag;
  cin >> s;
  int len = s.size();
  if (s[0] == 'B')
    flag = 0;
  else
    flag = 1;
  for (int i = 1; i < len; ++i) {
    if ((s[i] == 'B') && (!flag))
      continue;
    else if ((s[i] == 'W') && (flag))
      continue;
    else {
      res++;
      flag = (s[i] == 'B') ? 0 : 1;
    }
  }
  return res - 1;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int res = 1;
  bool flag;
  cin >> s;
  int len = s.size();
  if (s[0] == 'B')
    flag = 0;
  else
    flag = 1;
  for (int i = 1; i < len; ++i) {
    if ((s[i] == 'B') && (!flag))
      continue;
    else if ((s[i] == 'W') && (flag))
      continue;
    else {
      res++;
      flag = (s[i] == 'B') ? 0 : 1;
    }
  }
  cout << res - 1;
  return 0;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i <= s.length() - 2; i++) {
    char a = s[i];
    char b = s[i + 1];
    if (a != b) {
      ans++;
    }
  }
  cout << ans;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s.length() <= 1) {
    cout << 0;
    return 0;
  }
  for (int i = 0; i <= s.length() - 2; i++) {
    char a = s[i];
    char b = s[i + 1];
    if (a != b) {
      ans++;
    }
  }
  cout << ans;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep0(i, n) for (int i = 0; i <= (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define REP(a, b) for (int i = a; i <= (b); ++i)
#define mREP(a, b) for (int i = a; i == (b); --i)
typedef long long ll;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  /*
  　　　  　 ,ﾍ／L──- 、
  　　　   　Lﾆ)r_」=＝= ｲ
  　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
  　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
  　　 .i　　 >〈(つ,i!と)　　i
  　　  vﾍγk´_/___i,ゝﾍノ
  　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
  */
  string s;
  cin >> s;
  ll ans = 0;
  rep0(i, s.length() - 2) {
    if (s[i] != s[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep0(i, n) for (int i = 0; i <= (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define REP(a, b) for (int i = a; i <= (b); ++i)
#define mREP(a, b) for (int i = a; i == (b); --i)
typedef long long ll;
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  /*
  　　　  　 ,ﾍ／L──- 、
  　　　   　Lﾆ)r_」=＝= ｲ
  　　 　,ﾍ、i ﾉノλﾉﾊﾉﾍ
  　　   ,'　｀(ﾊﾘ ﾟ ヮﾟﾉi)　',
  　　 .i　　 >〈(つ,i!と)　　i
  　　  vﾍγk´_/___i,ゝﾍノ
  　　　　　 ｀ﾞr_,ｨ_ｧﾞ´
  */
  string s;
  cin >> s;
  ll ans = 0;
  if (s.length() == 1) {
    cout << 0 << endl;
    return 0;
  }
  rep0(i, s.length() - 2) {
    if (s[i] != s[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03945 (C++)

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

int main() {
  // input
  string s;
  cin >> s;
  int n;
  n = s.size();
  int counter = 0;

  // compute
  for (int i = 0; i < n; i++) {
    if (s.at(i) = s.at(i + 1)) {
      counter += 1;
    }
  }

  // output
  cout << counter << endl;
}

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

int main() {
  // input
  string s;
  cin >> s;
  int n;
  n = s.size();
  int counter = 0;

  // compute
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) != s.at(i + 1)) {
      counter += 1;
    }
  }

  // output
  cout << counter << endl;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
int main() {
  char a[10004];
  scanf("%s", a);
  int l = strlen(a);
  int ant = 0;
  for (int i = 1; i < l; i++) {
    if (a[i] != a[i - 1])
      ant++;
  }
  printf("%d\n", ant);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
int main() {
  char a[100004];
  scanf("%s", a);
  int l = strlen(a);
  int ant = 0;
  for (int i = 1; i < l; i++) {
    if (a[i] != a[i - 1])
      ant++;
  }
  printf("%d\n", ant);
  return 0;
}
Problem p03945 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
int main() {
  char s[10005];
  int l, flag;
  scanf("%s", &s);
  l = strlen(s);
  flag = 0;
  for (int i = l - 1; i >= 0; i--) {
    if (s[i] != s[i - 1])
      flag++;
  }
  printf("%d\n", flag - 1);

  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
int main() {
  char s[100005];
  int l, flag;
  scanf("%s", &s);
  l = strlen(s);
  flag = 0;
  for (int i = l - 1; i >= 0; i--) {
    if (s[i] != s[i - 1])
      flag++;
  }
  printf("%d\n", flag - 1);

  return 0;
}
Problem p03945 (C++)

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

using namespace std;

int main() {
  int lcount = 0;
  int rcount = 0;
  char s[10000];

  scanf("%s", s);

  char now;

  // 左から
  now = s[0];
  for (int n = 0; s[n] != '\0'; n++) {
    if (s[n] != now) {
      lcount++;
      now = s[n];
    }
  }

  // 右から
  int len = strlen(s);
  now = s[len - 1];
  for (int n = len - 1; n >= 0; n--) {
    if (s[n] != now) {
      rcount++;
      now = s[n];
    }
  }

  //    printf("lcount=%d, rcount=%d\n", lcount, rcount);

  printf("%d\n", (lcount < rcount) ? lcount : rcount);

  return 0;
}


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

using namespace std;

int main() {
  int lcount = 0;
  int rcount = 0;
  char s[100001];

  scanf("%s", s);

  char now;

  // 左から
  now = s[0];
  for (int n = 0; s[n] != '\0'; n++) {
    if (s[n] != now) {
      lcount++;
      now = s[n];
    }
  }

  // 右から
  int len = strlen(s);
  now = s[len - 1];
  for (int n = len - 1; n >= 0; n--) {
    if (s[n] != now) {
      rcount++;
      now = s[n];
    }
  }

  //    printf("lcount=%d, rcount=%d\n", lcount, rcount);

  printf("%d\n", (lcount < rcount) ? lcount : rcount);

  return 0;
}
Problem p03946 (C++)

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, start, end) for (int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

void solve() {
  int n, t;
  cin >> n >> t;
  vi a(n);
  REP(i, n) cin >> a[i];
  vi b(n);
  REP(i, n - 1) {
    vi::iterator itr = max_element(a.begin() + i + 1, a.end());
    b[i] = *itr - a[i];
  }
  int m = -INF;
  int count = 0;
  REP(i, n) {
    if (m < b[i]) {
      m = b[i];
      count = 1;
    } else if (m == b[i])
      count++;
  }
  cout << count << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();

  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, start, end) for (int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

void solve() {
  int n, t;
  cin >> n >> t;
  vi a(n);
  REP(i, n) cin >> a[i];
  vi b(n);
  int min = a[0];
  b[0] = -INF;
  FOR(i, 1, n) {
    if (min > a[i - 1])
      min = a[i - 1];
    b[i] = a[i] - min;
  }
  int m = -INF;
  int count = 0;
  REP(i, n) {
    if (m < b[i]) {
      m = b[i];
      count = 1;
    } else if (m == b[i])
      count++;
  }
  cout << count << endl;
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();

  return 0;
}
Problem p03946 (C++)

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

int main() {
  int N;
  int64_t T;
  cin >> N >> T;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  map<int64_t, int> diff;
  int64_t max_key = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      // max_key = max(max_key, A.at(j) - A.at(i));
      // cout << A.at(j) - A.at(i) << endl;
      if (diff.count(A.at(j) - A.at(i))) {
        diff[A.at(j) - A.at(i)] += 1;
      } else {
        diff[A.at(j) - A.at(i)] = 1;
      }
    }
  }
  cout << diff.rbegin()->second << endl;
  // cout << diff[10] << endl;

  return 0;
}


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

int main() {
  int N;
  int64_t T;
  cin >> N >> T;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  map<int64_t, int> diff;
  int64_t min_key = A.at(0);
  // for (int i = 0; i < N; i++) {
  //     for (int j = i + 1; j < N; j++) {
  //         // max_key = max(max_key, A.at(j) - A.at(i));
  //         // cout << A.at(j) - A.at(i) << endl;
  //         if (diff.count(A.at(j) - A.at(i))) {
  //             diff[A.at(j) - A.at(i)] += 1;
  //         }
  //         else {
  //             diff[A.at(j) - A.at(i)] = 1;
  //         }
  //     }
  // }
  for (int i = 1; i < N; i++) {
    min_key = min(min_key, A.at(i));
    if (diff.count(A.at(i) - min_key)) {
      diff[A.at(i) - min_key] += 1;
    } else {
      diff[A.at(i) - min_key] = 1;
    }
  }
  cout << diff.rbegin()->second << endl;
  // cout << diff[10] << endl;

  return 0;
}
Problem p03946 (C++)

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

using namespace std;

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

  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
  }

  int ans = 0;
  int g = 0;
  vector<int> ga;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] >= a[j])
        break;
      if (g <= a[j] - a[i]) {
        g = a[j] - a[i];
        ga.push_back(g);
        ans++;
      }
    }
  }

  for (auto i : ga) {
    if (i != g)
      ans--;
    else
      break;
  }
  cout << ans << endl;
}


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

using namespace std;

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

  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (auto &i : a) {
    cin >> i;
  }

  int ans = 0;
  int g = 0;
  vector<int> ga;
  int root = a[0];
  for (int i = 1; i < n; i++) {
    if (root >= a[i]) {
      root = a[i];
      continue;
    }
    if (g <= a[i] - root) {
      g = a[i] - root;
      ga.push_back(g);
      ans++;
    }
  }

  for (auto i : ga) {
    if (i != g)
      ans--;
    else
      break;
  }
  cout << ans << endl;
}
Problem p03946 (C++)

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

#define MAX_N 10000
int n;
int a[MAX_N] = {0};
int diff[MAX_N] = {0};
int mins[MAX_N] = {0};
int t;

void solve() {
  int tmp_min = a[0];

  for (int i = 0; i < n - 1; i++) {
    mins[i] = min(tmp_min, a[i]);
    tmp_min = mins[i];
  }

  diff[0] = 0;
  int max_diff = 0;

  for (int i = 1; i < n; i++) {
    diff[i] = a[i] - mins[i - 1];
    max_diff = max(max_diff, diff[i]);
  }

  int count = 0;
  for (int i = 1; i < n; i++) {
    if (diff[i] == max_diff)
      count++;
  }
  cout << count << endl;
  return;
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve();
  return 0;
}


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

#define MAX_N 100000

int n;
int a[MAX_N] = {0};
int diff[MAX_N] = {0};
int mins[MAX_N] = {0};
int t;

void solve() {
  int tmp_min = a[0];

  for (int i = 0; i < n - 1; i++) {
    mins[i] = min(tmp_min, a[i]);
    tmp_min = mins[i];
  }

  diff[0] = 0;
  int max_diff = 0;

  for (int i = 1; i < n; i++) {
    diff[i] = a[i] - mins[i - 1];
    max_diff = max(max_diff, diff[i]);
  }

  int count = 0;
  for (int i = 1; i < n; i++) {
    if (diff[i] == max_diff)
      count++;
  }
  cout << count << endl;
  return;
}

int main() {
  cin >> n >> t;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  solve();
  return 0;
}
Problem p03946 (C++)

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

using namespace std;

int main() {
  int n, t;
  cin >> n >> t;

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

  int maxDiff = 0, minPrice = a[0], ans = 0;
  for (int i = 1; i < n; i++) {
    minPrice = min(minPrice, a[i]);

    if (maxDiff == a[i] - minPrice) {
      ans++;
    } else if (maxDiff < a[i] - minPrice) {
      maxDiff = a[i] - minPrice;
      ans = 1;
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int n, t;
  cin >> n >> t;

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

  int maxDiff = 0, minPrice = a[0], ans = 0;
  for (int i = 1; i < n; i++) {
    minPrice = min(minPrice, a[i]);

    if (maxDiff == a[i] - minPrice) {
      ans++;
    } else if (maxDiff < a[i] - minPrice) {
      maxDiff = a[i] - minPrice;
      ans = 1;
    }
  }

  cout << ans << endl;
}
Problem p03946 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
long long a[10001], f[10001], d[10001];
int main() {
  long long n, t, k = 0, g = 0;
  cin >> n >> t;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  f[0] = a[1];
  for (int i = 1; i <= n; i++)
    f[i] = min(f[i - 1], a[i]);
  for (int i = 1; i <= n; i++)
    d[i] = a[i] - f[i];
  for (int i = 1; i <= n; i++)
    if (d[i] > k)
      k = d[i];
  for (int i = 1; i <= n; i++)
    if (d[i] == k)
      g++;
  cout << g << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long a[1000001], f[1000001], d[1000001];
int main() {
  long long n, t, k = 0, g = 0;
  cin >> n >> t;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  f[0] = a[1];
  for (int i = 1; i <= n; i++)
    f[i] = min(f[i - 1], a[i]);
  for (int i = 1; i <= n; i++)
    d[i] = a[i] - f[i];
  for (int i = 1; i <= n; i++)
    if (d[i] > k)
      k = d[i];
  for (int i = 1; i <= n; i++)
    if (d[i] == k)
      g++;
  cout << g << endl;
  return 0;
}
Problem p03946 (C++)

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

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int res = 1;
  int mpr = INT_MIN;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int diff = a[j] - a[i];
      if (diff > mpr) {
        mpr = diff;
        res = 1;
      } else if (diff == mpr) {
        res++;
      }
    }
  }
  cout << res << '\n';

  return 0;
}


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

using namespace std;

int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);

  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int res = 1;
  int mpr = INT_MIN;
  int ma = INT_MAX;
  for (int i = 0; i < n; i++) {
    ma = min(ma, a[i]);
    int diff = a[i] - ma;
    if (diff > mpr) {
      mpr = diff;
      res = 1;
    } else if (diff == mpr) {
      res++;
    }
  }
  cout << res << '\n';

  return 0;
}
Problem p03946 (C++)

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

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  int diffmax = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      diffmax = max(diffmax, A[j] - A[i]);
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      ans += diffmax == (A[j] - A[i]);
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N, T;
  cin >> N >> T;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  int max_diff = 0, max_value = A[N - 1], ans = 0;
  for (int i = N - 2; i >= 0; i--) {
    if (A[i] > max_value) {
      max_value = A[i];
    } else if (max_value - A[i] == max_diff)
      ans++;
    else if (max_value - A[i] > max_diff) {
      ans = 1;
      max_diff = max_value - A[i];
    }
  }
  cout << ans << endl;
}
Problem p03946 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int N, T;
  cin >> N >> T;
  int A[N];
  rep(i, N) cin >> A[i];
  int mx = -1;
  int cnt = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      int cost = abs(A[j] - A[i]);
      if (mx < cost && A[j] > A[i]) {
        mx = cost;
        cnt = 0;
      }
      if (mx == cost && A[j] > A[i])
        cnt++;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int N, T;
  cin >> N >> T;
  int A[N];
  rep(i, N) cin >> A[i];

  long int r[N - 1];
  rep(i, N - 1) r[i] = A[i + 1] - A[i];
  vector<long int> dp(N, -10e9);
  long int mx = -10e9;
  int cnt = 1;
  int tmp = 0;
  rep(i, N - 1) dp[i + 1] = max(r[i], dp[i] + r[i]);
  for (int i = 1; i < N; i++) {
    // cout << dp[i] << " " << mx << endl;
    if (dp[i] > mx) {
      mx = dp[i];
      cnt = 1;
    } else if (dp[i] == mx)
      cnt++;
  }
  cout << cnt << endl;
}
Problem p03947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
typedef unsigned long long ull;

string str;
set<string> se;

int solve(string s) {
  if (s.length() > str.length()) {
    return 9999999;
  }
  if (se.count(s)) {
    return 9999999;
  }
  se.insert(s);
  bool b = true;
  char c = s[0];
  for (int i = 1; i < s.length(); i++) {
    if (s[i] != c) {
      b = false;
      break;
    }
  }
  if (b) {
    return 0;
  }
  int mi = 9999999;
  string ns = 'B' + s;

  while (ns.length() && ns[0] == 'B') {
    ns = ns.substr(1);
  }
  mi = min(mi, solve(ns));
  ns = 'W' + s;
  while (ns.length() && ns[0] == 'W') {
    ns = ns.substr(1);
  }
  mi = min(mi, solve(ns));
  ns = s + 'B';
  while (ns.length() && ns[ns.length() - 1] == 'B') {
    ns = ns.substr(0, ns.length() - 1);
  }
  mi = min(mi, solve(ns));
  ns = s + 'W';
  while (ns.length() && ns[ns.length() - 1] == 'W') {
    ns = ns.substr(0, ns.length() - 1);
  }
  mi = min(mi, solve(ns));
  return 1 + mi;
}
bool dfs() { return false; }
int main() {

  cin >> str;
  cout << solve(str) << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
typedef unsigned long long ull;

string str;
set<string> se;

int solve(string s) {
  if (s.length() > str.length()) {
    return 9999999;
  }
  if (se.count(s)) {
    return 9999999;
  }
  se.insert(s);
  bool b = true;
  char c = s[0];
  for (int i = 1; i < s.length(); i++) {
    if (s[i] != c) {
      b = false;
      break;
    }
  }
  if (b) {
    return 0;
  }
  int mi = 9999999;
  string ns = 'B' + s;

  while (ns.length() && ns[0] == 'B') {
    ns = ns.substr(1);
  }
  mi = min(mi, solve(ns));
  ns = 'W' + s;
  while (ns.length() && ns[0] == 'W') {
    ns = ns.substr(1);
  }
  mi = min(mi, solve(ns));
  ns = s + 'B';
  while (ns.length() && ns[ns.length() - 1] == 'B') {
    ns = ns.substr(0, ns.length() - 1);
  }
  mi = min(mi, solve(ns));
  ns = s + 'W';
  while (ns.length() && ns[ns.length() - 1] == 'W') {
    ns = ns.substr(0, ns.length() - 1);
  }
  mi = min(mi, solve(ns));
  return 1 + mi;
}
bool dfs() { return false; }
int main() {

  cin >> str;
  int ans = 0;
  char last = str[0];
  int a1 = 0, a2 = 0;
  for (int i = 1; i < str.length(); i++) {
    if (str[i] != last) {
      last = str[i];
      a1++;
    }
  }
  last = str[str.length() - 1];
  for (int i = str.length() - 2; i >= 0; i--) {
    if (str[i] != last) {
      last = str[i];
      a2++;
    }
  }
  cout << min(a1, a2) << endl;
}
Problem p03947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main() {
  char s[10001];
  scanf("%s", s);
  int l = strlen(s);
  int black = 0, white = 0;
  for (int i = 0; i < l; i++) {
    if (i == 0) {
      if (s[i] == 'B')
        black++;
      else
        white++;
    } else {
      if (s[i] != s[i - 1]) {
        if (s[i] == 'B')
          black++;
        else
          white++;
      }
    }
  }
  printf("%d\n", black + white - 1);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main() {
  char s[100001];
  scanf("%s", s);
  int l = strlen(s);
  int black = 0, white = 0;
  for (int i = 0; i < l; i++) {
    if (i == 0) {
      if (s[i] == 'B')
        black++;
      else
        white++;
    } else {
      if (s[i] != s[i - 1]) {
        if (s[i] == 'B')
          black++;
        else
          white++;
      }
    }
  }
  printf("%d\n", black + white - 1);
  return 0;
}
Problem p03947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  string S;
  cin >> S;
  int l = S.length();
  int cnt = 0, i = 0;
  if (S[0] == 'B') {
    i++;
    while (i < l && S[i] != 'W') {
      i++;
    }
    cnt++;
  }
  int j = l - 1;
  if (S[j] == 'B') {
    j--;
    while (S[j] != 'W') {
      j--;
    }
    cnt++;
  }
  int s = 0;
  while (++i <= j) {
    if (s == 0 && S[i] == 'B') {
      s = 1;
    } else if (s == 1 && S[i] == 'W') {
      s = 0;
      cnt += 2;
    }
  }
  cout << cnt << endl;
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  string S;
  cin >> S;
  int l = S.length();
  int cnt = 0, i = 0;
  if (S[0] == 'B') {
    i++;
    while (i < l && S[i] != 'W') {
      i++;
    }
    cnt++;
  }
  if (i == l) {
    cout << 0 << endl;
    return 0;
  }
  int j = l - 1;
  if (S[j] == 'B') {
    j--;
    while (S[j] != 'W') {
      j--;
    }
    cnt++;
  }
  int s = 0;
  while (++i <= j) {
    if (s == 0 && S[i] == 'B') {
      s = 1;
    } else if (s == 1 && S[i] == 'W') {
      s = 0;
      cnt += 2;
    }
  }
  cout << cnt << endl;
}
Problem p03947 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  char s[100008] = {0};
  int i, j, n, t = 0, x = 0;
  scanf("%s", s);
  int l = strlen(s);
  while (777) {
    bool b = 0, w = 0;
    for (i = x; i < l; i++) {
      if (s[i] == 'B')
        b = 1;
      if (s[i] == 'W')
        w = 1;
    }
    if (b == 0 || w == 0)
      break;
    t++;
    for (i = x; i < l; i++) {
      if (s[i] != s[x]) {
        x = i;
        break;
      }
    }
  }
  printf("%d\n", t);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  char s[100008] = {0};
  int i, j, n, t = 0, x = 0;
  scanf("%s", s);
  int l = strlen(s);
  for (i = 0; i < l - 1; i++) {
    if (s[i] != s[i + 1])
      t++;
  }
  printf("%d\n", t);
  return 0;
}
Problem p03947 (C++)

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

using namespace std;

int main() {
  string s;
  int cnt = 0;
  cin >> s;
  for (int i = s.size() - 2; i >= 0; ++i) {
    if (s[i] != s[i + 1]) {
      cnt++;
    }
    s[i + 1] = s[i];
  }
  cout << cnt;
}


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

using namespace std;

int main() {
  string s;
  int cnt = 0;
  cin >> s;
  for (int i = s.size() - 2; i >= 0; --i) {
    if (s[i] != s[i + 1]) {
      cnt++;
    }
    s[i + 1] = s[i];
  }
  cout << cnt;
}
Problem p03947 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef pair<int, int> P2;
typedef pair<pair<int, int>, int> P3;
typedef pair<pair<int, int>, pair<int, int>> P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a, b) make_pair((a), (b))
#define M3P(a, b, c) make_pair(make_pair((a), (b)), (c))
#define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d)))
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repv(t, it, v)                                                         \
  for (vector<t>::iterator it = v.begin(); it != v.end(); ++it)

char s[10010];
int a;

int main() {
  scanf("%s", s);
  for (int i = 1; s[i] != 0; ++i) {
    if (s[i - 1] != s[i])
      ++a;
  }
  printf("%d\n", a);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef pair<int, int> P2;
typedef pair<pair<int, int>, int> P3;
typedef pair<pair<int, int>, pair<int, int>> P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a, b) make_pair((a), (b))
#define M3P(a, b, c) make_pair(make_pair((a), (b)), (c))
#define M4P(a, b, c, d) make_pair(make_pair((a), (b)), make_pair((c), (d)))
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define repm(i, a, b) for (int i = (int)(a); i > (int)(b); --i)
#define repv(t, it, v)                                                         \
  for (vector<t>::iterator it = v.begin(); it != v.end(); ++it)

char s[100010];
int a;

int main() {
  scanf("%s", s);
  for (int i = 1; s[i] != 0; ++i) {
    if (s[i - 1] != s[i])
      ++a;
  }
  printf("%d\n", a);
  return 0;
}
Problem p03947 (C++)

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

int main() {
  char s[10000];
  int count = 0;
  cin >> s;

  for (int i = 0; s[i] != '\0'; i++) {
    if (s[i] != s[i + 1]) {
      count += 1;
    }
  }

  cout << count - 1 << endl;
  return 0;
}

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

int main() {
  char s[100000];
  int count = 0;
  cin >> s;

  for (int i = 0; s[i] != '\0'; i++) {
    if (s[i] != s[i + 1]) {
      count += 1;
    }
  }

  cout << count - 1 << endl;
  return 0;
}
Problem p03948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep0(i, N) for (int i = 0; i < N; i++)
#define rep1(i, a, N) for (int i = 0 + a; i < N; i++)
#define lint long long int
#define SIZE 10005

using namespace std;

int main() {
  lint n, t, a[SIZE], mina[SIZE] = {}, maxa[SIZE] = {}, minnum = 1, now = 0,
                      rest = 0, ans = 1;
  cin >> n >> t;
  cin >> a[0];
  mina[0] = a[0];
  maxa[0] = a[0];
  rep1(i, 1, n) {
    cin >> a[i];
    if (mina[i - 1] > a[i])
      mina[i] = a[i];
    else
      mina[i] = mina[i - 1];
    if (maxa[i - 1] < a[i])
      maxa[i] = a[i];
    else
      maxa[i] = maxa[i - 1];
    rest = a[i] - mina[i];
    if (now == rest) {
      ans++;
    } else if (now < rest) {
      now = rest;
      ans = 1;
    }
  }
  cout << ans;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define rep0(i, N) for (int i = 0; i < N; i++)
#define rep1(i, a, N) for (int i = 0 + a; i < N; i++)
#define lint long long int
#define SIZE 100005

using namespace std;

int main() {
  lint n, t, a[SIZE], mina[SIZE] = {}, maxa[SIZE] = {}, minnum = 1, now = 0,
                      rest = 0, ans = 1;
  cin >> n >> t;
  cin >> a[0];
  mina[0] = a[0];
  maxa[0] = a[0];
  rep1(i, 1, n) {
    cin >> a[i];
    if (mina[i - 1] > a[i])
      mina[i] = a[i];
    else
      mina[i] = mina[i - 1];
    if (maxa[i - 1] < a[i])
      maxa[i] = a[i];
    else
      maxa[i] = maxa[i - 1];
    rest = a[i] - mina[i];
    if (now == rest) {
      ans++;
    } else if (now < rest) {
      now = rest;
      ans = 1;
    }
  }
  cout << ans;

  return 0;
}
Problem p03948 (C++)

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

#define F first
#define S second
#define pb push_back
#define ld double
#define ll long long
#define int long long

using namespace std;

const int MAXN = 1111, MOD = 1e9 + 7;

int n, t;

int a[MAXN];

int ans = 0;

int get(int x, int k) {
  ans = max(ans, k * x - 2LL * k * k);
  return k * x - 2LL * k * k;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> t;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int mx = -1;
  for (int i = n - 1; i > -1; i--) {
    mx = max(mx, a[i]);
    ans = max(ans, (t / 2) * (mx - a[i]));
  }

  int mn = 0;

  pair<int, int> mxx = {-1, 1};
  for (int i = n - 1; i > -1; i--) {
    if (a[i] > mxx.F)
      mxx.F = a[i], mxx.S = 0;
    if (a[i] == mxx.F)
      mxx.S++;
    if ((t / 2) * (mxx.F - a[i]) == ans)
      mn += mxx.S;
  }
  cout << mn;
}


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

#define F first
#define S second
#define pb push_back
#define ld double
#define ll long long
#define int long long

using namespace std;

const int MAXN = 101 * 1001, MOD = 1e9 + 7;

int n, t;

int a[MAXN];

int ans = 0;

int get(int x, int k) {
  ans = max(ans, k * x - 2LL * k * k);
  return k * x - 2LL * k * k;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> t;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int mx = -1;
  for (int i = n - 1; i > -1; i--) {
    mx = max(mx, a[i]);
    ans = max(ans, (t / 2) * (mx - a[i]));
  }

  int mn = 0;

  pair<int, int> mxx = {-1, 1};
  for (int i = n - 1; i > -1; i--) {
    if (a[i] > mxx.F)
      mxx.F = a[i], mxx.S = 0;
    if (a[i] == mxx.F)
      mxx.S++;
    if ((t / 2) * (mxx.F - a[i]) == ans)
      mn += mxx.S;
  }
  cout << mn;
}
Problem p03948 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define It iterator
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 100003;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

ll n, t, a[10000], m = 10000000000, cnt = 0;

int main() {
  cin >> n >> t;
  rep(i, 0, n) {
    int cur;
    cin >> cur;
    if (cur < m)
      m = cur;
    a[i] = cur - m;
  }
  m = 0;
  rep(i, 0, n) if (a[i] > m) m = a[i];
  rep(i, 0, n) if (a[i] == m) cnt++;
  cout << cnt;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define It iterator
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 100003;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}

ll n, t, a[100000], m = 10000000000, cnt = 0;

int main() {
  cin >> n >> t;
  rep(i, 0, n) {
    int cur;
    cin >> cur;
    if (cur < m)
      m = cur;
    a[i] = cur - m;
  }
  m = 0;
  rep(i, 0, n) if (a[i] > m) m = a[i];
  rep(i, 0, n) if (a[i] == m) cnt++;
  cout << cnt;

  return 0;
}
Problem p03948 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> a;
  vector<int> b;
  REP(i, n) {
    int c;
    cin >> c;
    a.pb(c);
  }
  int mn = a[0], pos = 0;
  for (int i = 1; i < a.size(); i++) {
    b.pb(a[i] - mn);
    mn = min(mn, a[i]);
  }
  REP(i, b.size())
  // cout << b[i] << endl;
  sort(b.begin(), b.end(), greater<int>());
  int mx = b[0], num = 0;
  REP(i, b.size()) {
    if (b[i] == mx)
      num++;
    else
      break;
  }
  cout << num << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> a;
  vector<int> b;
  REP(i, n) {
    int c;
    cin >> c;
    a.pb(c);
  }
  int mn = a[0], pos = 0;
  for (int i = 1; i < a.size(); i++) {
    b.pb(a[i] - mn);
    mn = min(mn, a[i]);
  }
  /*
  REP(i,b.size())
  cout << b[i] << endl;*/
  sort(b.begin(), b.end(), greater<int>());
  int mx = b[0], num = 0;
  REP(i, b.size()) {
    if (b[i] == mx)
      num++;
    else
      break;
  }
  cout << num << endl;

  return 0;
}
Problem p03948 (C++)

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

int n, t, a[100010], mx1, mx2, ans;

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

  for (int i = n - 1; i >= 0; i++) {
    mx1 = max(mx1, a[i]);
    a[i] = mx1 - a[i];
    mx2 = max(mx2, a[i]);
  }
  for (int i = 0; i < n; i++)
    ans += (a[i] == mx2);
  cout << ans;

  return 0;
}

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

int n, t, a[100010], mx1, mx2, ans;

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

  for (int i = n - 1; i >= 0; i--) {
    mx1 = max(mx1, a[i]);
    a[i] = mx1 - a[i];
    mx2 = max(mx2, a[i]);
  }
  for (int i = 0; i < n; i++)
    ans += (a[i] == mx2);
  cout << ans;

  return 0;
}
Problem p03948 (C++)

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

#define pb push_back
#define ins insert
#define ers erase
#define all(x) x.begin(), x.end()
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef string str;
typedef long double ld;

const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll MOD = 1e9 + 10;

ll Cnt, n, a[N], Max, Cnt_Max[N], t;
map<ll, vector<ll>> koj;
map<ll, ll> joons;

int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    koj[a[i]].pb(i);
  }
  ll ans = 0;
  for (int i = n; i > 0; i--) {
    ans = max(ans, Max - a[i]);
    Max = max(Max, a[i]);
  }
  Max = 0;
  ll cnMax = 0;
  for (int i = n; i > 0; i--) {
    if (Max - a[i] == ans) {
      joons[a[i]]++;
      Cnt_Max[a[i]] = cnMax;
    }
    if (Max == a[i]) {
      cnMax++;
    } else if (Max < a[i]) {
      cnMax = 1;
      Max = a[i];
    }
  }
  for (auto u : joons) {
    Cnt += min(Cnt_Max[u.F], u.S);
  }
  cout << Cnt;

  return 0;
}

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

#define pb push_back
#define ins insert
#define ers erase
#define all(x) x.begin(), x.end()
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef string str;
typedef long double ld;

const ll N = 2e5 + 10;
const ll INF = 1e18;
const ll MOD = 1e9 + 10;

ll Cnt, n, a[N], Max, t;
map<ll, ll> Cnt_Max;
map<ll, vector<ll>> koj;
map<ll, ll> joons;

int main() {
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    koj[a[i]].pb(i);
  }
  ll ans = 0;
  for (int i = n; i > 0; i--) {
    ans = max(ans, Max - a[i]);
    Max = max(Max, a[i]);
  }
  Max = 0;
  ll cnMax = 0;
  for (int i = n; i > 0; i--) {
    if (Max - a[i] == ans) {
      joons[a[i]]++;
      Cnt_Max[a[i]] = cnMax;
    }
    if (Max == a[i]) {
      cnMax++;
    } else if (Max < a[i]) {
      cnMax = 1;
      Max = a[i];
    }
  }
  for (auto u : joons) {
    Cnt += min(Cnt_Max[u.F], u.S);
  }
  cout << Cnt;

  return 0;
}
Problem p03948 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)

int main() {
  int n, t;
  cin >> n >> t;
  int a[n];
  rep(i, n) cin >> a[i];
  int cur = a[0];
  multiset<int> ms;
  rep(i, n - 1) {
    if (a[i] > a[i - 1])
      continue;
    ms.insert(a[i - 1] - cur);
    if (cur > a[i])
      cur = a[i];
  }
  int ans = 1;
  auto it = ms.end();
  --it;
  int mval = (*it);
  while (it != ms.begin()) {
    if (*(--it) != mval)
      break;
    else
      ++ans;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)

int main() {
  int n, t;
  cin >> n >> t;
  int a[n];
  rep(i, n) cin >> a[i];
  int cur = a[0];
  multiset<int> ms;
  rep(i, n - 1) {
    if (a[i] > a[i - 1])
      continue;
    ms.insert(a[i - 1] - cur);
    if (cur > a[i])
      cur = a[i];
  }
  ms.insert(a[n - 1] - cur);
  int ans = 1;
  auto it = ms.end();
  --it;
  int mval = (*it);
  while (it != ms.begin()) {
    if (*(--it) != mval)
      break;
    else
      ++ans;
  }
  cout << ans << endl;
}
Problem p03948 (C++)

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

int main() {
  unsigned long n, t;
  std::cin >> n >> t;
  std::vector<unsigned long> prices(n);
  for (unsigned long i = 0; i != n; ++i) {
    std::cin >> prices[i];
  }

  unsigned long maxProfit = 0;
  unsigned long counter;
  for (auto it = prices.begin(); it != prices.end(); ++it) {
    unsigned long profit = *std::max_element(it, prices.end()) - *it;
    if (profit > maxProfit) {
      maxProfit = profit;
      counter = 1;
    } else if (profit == maxProfit) {
      ++counter;
    }
  }
  std::cout << counter << std::endl;
}


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

int main() {
  unsigned long n, t;
  std::cin >> n >> t;
  std::vector<unsigned long> prices(n);
  for (unsigned long i = 0; i != n; ++i) {
    std::cin >> prices[i];
  }

  unsigned long maxProfit = 0;
  unsigned long counter;

  std::vector<unsigned long> max(n);
  max[n - 1] = prices[n - 1];
  for (unsigned long i = n - 1; i != 0; --i) {
    max[i - 1] = std::max(max[i], prices[i - 1]);
  }
  for (unsigned long i = 0; i != n; ++i) {
    if (i != 0 && prices[i - 1] < prices[i])
      continue;
    unsigned long profit = max[i] - prices[i];
    if (profit > maxProfit) {
      maxProfit = profit;
      counter = 1;
    } else if (profit == maxProfit) {
      ++counter;
    }
  }
  std::cout << counter << std::endl;
}
Problem p03949 (C++)

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

typedef pair<int, int> P;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> graph(n);
  for (int i = 0, a, b; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int k;
  cin >> k;
  vector<int> num(k, -1);
  for (int i = 0, v, p; i < k; i++) {
    cin >> v >> p;
    num[v - 1] = p;
  }

  vector<int> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < n; i++)
    if (num[i] >= 0) {
      dist[i] = num[i];
      que.push({dist[i], i});
    }
  while (que.size()) {
    int v = que.top().second;
    que.pop();
    for (int u : graph[v])
      if (dist[u] > dist[v] + 1) {
        dist[u] = dist[v] + 1;
        que.push({dist[u], u});
      }
  }

  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (num[i] >= 0 && dist[i] != num[i])
      ok = false;
    for (int j : graph[i])
      if (dist[i] == dist[j])
        ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  if (ok)
    for (auto &&x : dist)
      cout << x << endl;

  return 0;
}

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

typedef pair<int, int> P;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> graph(n);
  for (int i = 0, a, b; i < n - 1; i++) {
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int k;
  cin >> k;
  vector<int> num(n, -1);
  for (int i = 0, v, p; i < k; i++) {
    cin >> v >> p;
    num[v - 1] = p;
  }

  vector<int> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  for (int i = 0; i < n; i++)
    if (num[i] >= 0) {
      dist[i] = num[i];
      que.push({dist[i], i});
    }
  while (que.size()) {
    int v = que.top().second;
    que.pop();
    for (int u : graph[v])
      if (dist[u] > dist[v] + 1) {
        dist[u] = dist[v] + 1;
        que.push({dist[u], u});
      }
  }

  bool ok = true;
  for (int i = 0; i < n; i++) {
    if (num[i] >= 0 && dist[i] != num[i])
      ok = false;
    for (int j : graph[i])
      if (dist[i] == dist[j])
        ok = false;
  }
  cout << (ok ? "Yes" : "No") << endl;
  if (ok)
    for (auto &&x : dist)
      cout << x << endl;

  return 0;
}