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

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (auto &&h : H) {
    cin >> h;
  }
  int point = 0;
  int move = 0;
  for (int i = 0; i < N - 1; i++) {
    int m = 0;
    int j = 0;
    int dh = 0;
    dh = H[i + j] - H[i + j + 1];
    while (dh >= 0) {
      m++;
      j++;
      if (i + j + 1 >= N)
        break;
      dh = H[i + j] - H[i + j + 1];
    }
    move = max(move, m);
  }
  cout << move << endl;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (auto &&h : H) {
    cin >> h;
  }
  int point = 0;
  int move = 0;
  for (int i = 0; i < N - 1; i++) {
    int m = 0;
    int j = 0;
    int dh = 0;
    dh = H[i + j] - H[i + j + 1];
    while (dh >= 0) {
      m++;
      j++;
      if (i + j + 1 >= N)
        break;
      dh = H[i + j] - H[i + j + 1];
    }
    i += j;
    move = max(move, m);
  }
  cout << move << endl;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int curr = 0, max = INT_MIN;
  for (int i = 0; i < n; i++) {
    curr = 0;
    for (int j = i + 1; j < n; j++) {
      if (h[j] > h[j - 1]) {
        break;
      } else
        curr++;
      if (curr > max)
        max = curr;
    }
  }
  if (max == INT_MIN)
    max = 0;
  cout << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int curr = 0, max = INT_MIN;
  for (int i = 1; i < n; i++) {
    if (h[i] > h[i - 1])
      curr = 0;
    else
      curr++;
    if (curr > max)
      max = curr;
  }
  if (max == INT_MIN)
    max = 0;
  cout << max << endl;
}
Problem p02923 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define Maxn 10005
int n, s, ans;
int h[Maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 2; i <= n; i++)
    if (h[i] <= h[i - 1]) {
      s++;
      ans = max(ans, s);
    } else
      s = 0;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Maxn 100005
int n, s, ans;
int h[Maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> h[i];
  for (int i = 2; i <= n; i++)
    if (h[i] <= h[i - 1]) {
      s++;
      ans = max(ans, s);
    } else
      s = 0;
  cout << ans << endl;
  return 0;
}
Problem p02923 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  int max = -1;
  for (int i = 0; i < N; i++) {
    int j = i;
    int cnt = 0;
    while ((j != N - 1) && (v.at(j) >= v.at(j + 1))) {
      j++;
      cnt++;
    }
    if (max < cnt) {
      max = cnt;
    }
  }
  cout << max << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v.at(i);
  }
  int max = -1;
  for (int i = 0; i < N; i++) {
    int j = i;
    int cnt = 0;
    if (max < N - i) {
      while ((j != N - 1) && (v.at(j) >= v.at(j + 1))) {
        j++;
        cnt++;
      }
    }
    if (max < cnt) {
      max = cnt;
    }
  }
  cout << max << endl;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) ((v).begin(), (v).end())
using namespace std;

int main() {
  int n;
  cin >> n;
  int h[n];
  REP(i, n) cin >> h[i];

  int sum[100010] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = i + 2; j < n; j++) {
      if (h[j - 1] >= h[j]) {
        sum[i]++;
      } else {
        break;
      }
    }
  }
  // REP(i,n) cout << i << ": " << sum[i] << endl;

  int result = sum[0];
  for (int i = 1; i < n; i++) {
    result = max(sum[i], result);
  }

  cout << result << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define ALL(v) ((v).begin(), (v).end())
using namespace std;

int main() {
  int n;
  cin >> n;
  int h[n];
  REP(i, n) cin >> h[i];

  int result = 0;
  int val = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (h[i] <= h[i - 1])
      val++;
    else
      val = 0;
    result = max(result, val);
  }

  cout << result << endl;
  return 0;
}
Problem p02923 (C++)

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

using namespace std;

int main(void) {

  int n, count = 0, tmp = 0;
  vector<int> h;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    h.push_back(x);
  }

  for (int i = 0; i < n - 1; i++) {
    if (h[i] >= h[i + 1]) {
      for (int j = i;; j++) {
        if (h[j] >= h[j + 1] && j + 1 != n) {
          tmp++;
        } else {
          if (count < tmp)
            count = tmp;
          tmp = 0;
          break;
        }
      }
    }
  }

  cout << count << endl;

  return 0;
}

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

using namespace std;

int main(void) {

  int n, count = 0, tmp = 0;
  vector<int> h;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    h.push_back(x);
  }

  for (int i = 0; i < n - 1; i++) {
    if (h[i] >= h[i + 1] && n - i >= count) {
      for (int j = i;; j++) {
        if (h[j] >= h[j + 1] && j + 1 != n) {
          tmp++;
        } else {
          if (count < tmp)
            count = tmp;
          tmp = 0;
          break;
        }
      }
    }
  }

  cout << count << endl;

  return 0;
}
Problem p02923 (C++)

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

int main() {
  int N;
  cin >> N;

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

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (data[i] < data[i + 1]) {
      continue;
    }
    int tmp_i = i;
    int count = 0;
    for (int j = i + 1; j < N; j++) {
      if (data[tmp_i] >= data[j]) {
        count++;
        tmp_i++;
      } else
        break;
    }
    ans = max(count, ans);
  }

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

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

int main() {
  int N;
  cin >> N;

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

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (data[i] < data[i + 1]) {
      continue;
    }
    int tmp_i = i;
    int count = 0;
    for (int j = i + 1; j < N; j++) {
      if (data[tmp_i] >= data[j]) {
        count++;
        tmp_i++;
      } else
        break;
    }
    ans = max(count, ans);
    if (ans >= (N / 2))
      break;
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

int main() {

  int n;
  cin >> n;
  int h[n];
  rep(i, n) cin >> h[i];

  int max = 0;
  int count = 0;
  rep(i, n) {
    count = 0;
    for (int j = i; j < n - 1; j++) {
      if (h[j] >= h[j + 1])
        count++;
      else
        break;
    }
    if (max < count)
      max = count;
  }
  cout << max;
  return 0;
}

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

int main() {

  int n;
  cin >> n;
  int h[n];
  rep(i, n) cin >> h[i];

  int max = 0;
  int count = 0;
  rep(i, n) {
    if (n - i < max)
      break;

    count = 0;
    for (int j = i; j < n - 1; j++) {
      if (h[j] >= h[j + 1])
        count++;
      else
        break;
    }
    if (max < count)
      max = count;
  }
  cout << max;
  return 0;
}
Problem p02923 (C++)

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

int main() {
  long long n, a[10005];
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0, m = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1] || i == n - 2) {
      if (a[i] >= a[i + 1])
        sum++;
      if (m < sum) {
        m = sum;
      }
      sum = 0;
    } else {
      sum++;
    }
  }
  cout << m << endl;
}

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

int main() {
  long long n, a[100005];
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0, m = 0;
  for (long long i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1] || i == n - 2) {
      if (a[i] >= a[i + 1])
        sum++;
      if (m < sum) {
        m = sum;
      }
      sum = 0;
    } else {
      sum++;
    }
  }
  cout << m << endl;
}
Problem p02923 (C++)

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

int main() {
  int N;
  cin >> N;
  priority_queue<int> A;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) {
      count++;
    } else {
      A.push(count);
      count = 0;
    }
  }
  cout << A.top() << endl;
}

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

int main() {
  int N;
  cin >> N;
  priority_queue<int> A;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] >= H[i + 1]) {
      count++;
    } else {
      A.push(count);
      count = 0;
    }
  }
  A.push(count);
  cout << A.top() << endl;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    for (int j = i; j + 1 < n; j++) {
      if (s.at(j) >= s.at(j + 1))
        cnt++;
      else
        break;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++)
    cin >> s.at(i);
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    for (int j = i; j + 1 < n; j++) {
      if (s.at(j) >= s.at(j + 1))
        cnt++;
      else
        break;
    }
    i += cnt;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
Problem p02923 (C++)

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

int main(void) {
  int n;
  std::cin >> n;

  std::vector<int> h(n);
  for (int i = 0; i < n; i++) {
    std::cin >> h.at(i);
  }

  std::reverse(h.begin(), h.end());
  int ans = 0;
  int cnt = 0;

  for (int i = 0; i < n; i++) {
    if (h.at(i) <= h.at(i + 1)) {
      cnt++;
    } else {
      cnt = 0;
    }
    ans = std::max(ans, cnt);
  }
  std::printf("%d\n", ans);
  return 0;
}

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

int main(void) {
  int n;
  std::cin >> n;

  std::vector<int> h(n);
  for (int i = 0; i < n; i++) {
    std::cin >> h.at(i);
  }

  std::reverse(h.begin(), h.end());
  int ans = 0;
  int cnt = 0;

  for (int i = 0; i < n - 1; i++) {
    if (h.at(i) <= h.at(i + 1)) {
      cnt++;
    } else {
      cnt = 0;
    }
    ans = std::max(ans, cnt);
  }
  std::printf("%d\n", ans);
  return 0;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int n, h[123456], c;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++) {
    int j = i, k = i + 1, a = 0;
    while (h[j] >= h[k] && h[k] != 0) {
      j++;
      k++;
      a++;
    }
    if (c < a)
      c = a;
  }
  cout << c;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, h[123456], c;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> h[i];
  for (int i = 0; i < n; i++) {
    int j = i, k = i + 1, a = 0;
    while (h[j] >= h[k] && h[k] != 0) {
      j++;
      k++;
      a++;
    }
    if (c < a)
      c = a;
    i = j++;
  }
  cout << c;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>
/*ABC 139 C*/

int main(void) {
  int N;
  int *heap;
  int count = 0;
  int max = 0;
  scanf("%d", &N);

  heap = (int *)malloc(sizeof(int) * N);
  if (heap == NULL) {
    exit(0);
  }

  for (size_t i = 0; i < N; i++) {
    scanf("%d", &heap[i]);
  }

  for (size_t i = 0; i < N; i++) {
    for (size_t j = i; j < N - 1; j++) {
      if (heap[j] >= heap[j + 1]) {
        count++;
      } else
        break;
    }
    if (max < count) {
      max = count;
    }
    count = 0;
  }
  free(heap);

  printf("%d\n", max);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>
/*ABC 139 C*/

int main(void) {
  int N;
  int *heap;
  int count = 0;
  int max = 0;
  scanf("%d", &N);

  heap = (int *)malloc(sizeof(int) * N);
  if (heap == NULL) {
    exit(0);
  }

  for (size_t i = 0; i < N; i++) {
    scanf("%d", &heap[i]);
  }

  for (size_t i = 0; i < N; i++) {
    for (size_t j = i; j < N - 1; j++) {
      if (heap[j] >= heap[j + 1]) {
        count++;
      } else
        break;
    }
    if (max < count) {
      max = count;
    }
    if (max == N - 1) {
      printf("%d", N - 1);
      return 0;
    }
    count = 0;
  }
  free(heap);

  printf("%d\n", max);

  return 0;
}
Problem p02923 (C++)

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

int N;
int Hs[10005];

int main() {
  cin >> N;
  rep(i, N) { cin >> Hs[i]; }
  int st = Hs[0];
  int mx = 0;
  int now = 0;
  for (int i = 1; i < N; i++) {
    if (Hs[i] <= Hs[i - 1]) {
      now++;
    } else {
      mx = max(mx, now);
      now = 0;
    }
  }
  mx = max(mx, now);
  cout << mx << endl;
  return 0;
}


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

int N;
int Hs[100005];

int main() {
  cin >> N;
  rep(i, N) { cin >> Hs[i]; }
  int st = Hs[0];
  int mx = 0;
  int now = 0;
  for (int i = 1; i < N; i++) {
    if (Hs[i] <= Hs[i - 1]) {
      now++;
    } else {
      mx = max(mx, now);
      now = 0;
    }
  }
  mx = max(mx, now);
  cout << mx << endl;
  return 0;
}
Problem p02923 (C++)

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

int main() {
  int N;

  cin >> N;

  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  int count = 0;
  int countt = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - i - 1; j++) {
      if (H.at(i + j) >= H.at(i + j + 1)) {
        count++;
      } else {
        break;
      }
    }
    if (count > countt) {
      countt = count;
    }

    i -= count;
    count = 0;
  }

  cout << countt << endl;
}

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

int main() {
  int N;

  cin >> N;

  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }

  int count = 0;
  int countt = -1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - i - 1; j++) {
      if (H.at(i + j) >= H.at(i + j + 1)) {
        count++;
      } else {
        break;
      }
    }
    if (count > countt) {
      countt = count;
    }

    i += count;
    count = 0;
  }

  cout << countt << endl;
}
Problem p02923 (C++)

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

int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int count = 0;
  vector<int> v;
  for (int i = 1; i < n; i++) {
    if (h[i - 1] >= h[i]) {
      ++count;
      v.push_back(count);
    } else {
      count = 0;
    }
  }
  sort(v.begin(), v.end());
  cout << v.back();
}


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

int main() {
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int count = 0;
  vector<int> v(1);
  for (int i = 1; i < n; i++) {
    if (h[i - 1] >= h[i]) {
      ++count;
      v.push_back(count);
    } else {
      count = 0;
    }
  }
  sort(v.begin(), v.end());
  cout << v.back();
}
Problem p02923 (C++)

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

int main(int argc, char const *argv[]) {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int low = 0, high = 1, ans = 0, cnt = 0;
  while (high < n) {
    if (v[low] >= v[high]) {
      cnt++;
      ans = max(ans, cnt);
      low++;
      high++;
    } else {
      low = high;
      high++;
      cnt = 0;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int low = 0, high = 1, ans = 0, cnt = 0;
  while (high < n) {
    if (v[low] >= v[high]) {
      cnt++;
      ans = max(ans, cnt);
      low++;
      high++;
    } else {
      low = high;
      high++;
      cnt = 0;
    }
  }
  cout << ans << endl;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  vector<int> count(n);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n - 1; j++) {
      if (h.at(j) >= h.at(j + 1))
        count.at(i)++;
      else
        break;
    }
  }
  sort(count.begin(), count.end());
  cout << count.at(n - 1) << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  vector<int> count(n, 0);
  int p = 0;
  for (int i = 0; i < n - 1; i++) {
    if (h.at(i) >= h.at(i + 1))
      count.at(p)++;
    else
      p++;
  }
  sort(count.begin(), count.end());
  cout << count.at(n - 1) << endl;
  return 0;
}
Problem p02923 (C++)

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

using namespace std;

int main() {
  int N, max = 0;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < N - 1; i++) {
    int count = 0;
    for (int j = i; j < N - 1; j++) {
      if (H[j] >= H[j + 1]) {
        count++;
      } else {
        break;
      }
    }
    if (max < count) {
      max = count;
    }
  }
  cout << max << endl;
  return 0;
}

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

using namespace std;

int main() {
  int N, max = 0;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (int i = 0; i < N - 1; i++) {
    if (max > N - i - 2) {
      break;
    }
    int count = 0;
    for (int j = i; j < N - 1; j++) {
      if (H[j] >= H[j + 1]) {
        count++;
      } else {
        break;
      }
    }
    if (max < count) {
      max = count;
    }
  }
  cout << max << endl;
  return 0;
}
Problem p02923 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[10000];
int n, m, ans;
int main() {
  int i, ans = 0, anss = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i != 1) {
      if (a[i] <= a[i - 1])
        ans++, anss = max(anss, ans);
      else
        anss = max(anss, ans), ans = 0;
    }
  }
  printf("%d\n", anss);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int n, m, ans;
int main() {
  int i, ans = 0, anss = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (i != 1) {
      if (a[i] <= a[i - 1])
        ans++, anss = max(anss, ans);
      else
        anss = max(anss, ans), ans = 0;
    }
  }
  printf("%d\n", anss);
  return 0;
}
Problem p02923 (C++)

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

using namespace std;

int main(void) {
  long long count = 0;
  long long max = 0;
  long long N;

  cin >> N;

  vector<long long> H(N);

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

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

    if (count > max) {
      max = count;
    }
  }

  cout << max << endl;

  return 0;
}

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

using namespace std;

int main(void) {
  long long count = 0;
  long long max = 0;
  long long N;

  cin >> N;

  vector<long long> H(N);

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

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

    if (count > max) {
      max = count;
    }
    if (N - i < max) {
      break;
    }
  }

  cout << max << endl;

  return 0;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int res = 0;
    for (int j = i + 1; j < n; j++) {
      if (h[j - 1] >= h[j])
        res = j - i;
      else {
        i = j - 1;
        break;
      }
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int ans = 0;
  int res = 0;
  for (int i = 1; i < n; i++) {
    if (h[i] <= h[i - 1])
      res++;
    else
      res = 0;
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}
Problem p02923 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long h[110000];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int ans[110000] = {0};

  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int j = i;
    while (h[j] >= h[j + 1] && j + 1 < n) {
      cnt++;
      j++;
    }
    ans[i] = cnt;
  }

  int mx = 0;
  for (int i = 0; i < n; i++)
    if (mx < ans[i])
      mx = ans[i];

  cout << mx << endl;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  long long h[110000];
  for (int i = 0; i < n; i++)
    cin >> h[i];
  int ans[110000] = {0};

  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int j = i;
    while (h[j] >= h[j + 1] && j + 1 < n) {
      cnt++;
      j++;
    }
    ans[i] = cnt;
    i = j;
  }

  int mx = 0;
  for (int i = 0; i < n; i++)
    if (mx < ans[i])
      mx = ans[i];

  cout << mx << endl;
}
Problem p02923 (C++)

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

int main() {
  int count = 0;
  int N;
  cin >> N;
  vector<int> H(N + 1);
  H[N] = 1000000001;
  vector<int> Hc(N);
  rep(i, N) { cin >> H[i]; }
  rep(i, N) {
    int c = 0;
    for (int j = i; j < N; j++) {
      if (H[j] >= H[j + 1]) {
        c++;
      } else {
        Hc[i] = c;
        break;
      }
    }
  }
  cout << *max_element(Hc.begin(), Hc.end());
}


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

int main() {
  int count = 0;
  int N;
  cin >> N;
  vector<int> H(N + 1);
  H[N] = 1000000001;
  vector<int> Hc(N);
  rep(i, N) { cin >> H[i]; }
  rep(i, N) {
    int c = 0;
    for (int j = i; j < N; j++) {
      if (H[j] >= H[j + 1]) {
        c++;
      } else {
        Hc[i] = c;
        break;
      }
    }
    i += c;
  }
  cout << *max_element(Hc.begin(), Hc.end());
}
Problem p02923 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define INF 2147483647

int dp[100];
int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a[0];
  int cnt = 0;
  int max = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] > a[i - 1]) {
      dp[i] = dp[i - 1];
      cnt = 0;

    } else if (a[i] <= a[i - 1]) {
      cnt += 1;
      if (max < cnt) {
        max = cnt;
      }
      dp[i] = max;
    }
  }

  cout << max << "\n";
}

Fixed submission:
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define INF 2147483647

int dp[100001];
int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a[0];
  int cnt = 0;
  int max = 0;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] > a[i - 1]) {
      dp[i] = dp[i - 1];
      cnt = 0;

    } else if (a[i] <= a[i - 1]) {
      cnt += 1;
      if (max < cnt) {
        max = cnt;
      }
      dp[i] = max;
    }
  }

  cout << max << "\n";
}
Problem p02923 (C++)

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

int main() {
  int a = 0, N;
  cin >> N;
  vector<int> H(N), X(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  if (N > 1) {
    for (int i = 0; i < N - 1; i++) {
      if (H.at(i) >= H.at(i + 1)) {
        int j = i;
        while (j < N - 1 && H.at(j) >= H.at(j + 1)) {
          X.at(i)++;
          j++;
        }
      }
    }
  }
  sort(X.begin(), X.end());
  cout << X.at(N - 1) << endl;
}

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

int main() {
  int a = 0, N;
  cin >> N;
  vector<int> H(N), X(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  if (N > 1) {
    for (int i = 0; i < N - 1; i++) {
      if (i == 0 ||
          (i > 0 && H.at(i) >= H.at(i + 1) && H.at(i - 1) < H.at(i))) {
        int j = i;
        while (j < N - 1 && H.at(j) >= H.at(j + 1)) {
          X.at(i)++;
          j++;
        }
      }
    }
  }
  sort(X.begin(), X.end());
  cout << X.at(N - 1) << endl;
}
Problem p02923 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> h;
  for (int i = 0; i < n; ++i) {
    int height;
    cin >> height;
    h.push_back(height);
  }

  int max_ = 0;
  for (int i = 0; i < n; ++i) {
    int current = 0;
    for (int j = i; j < n - 1; ++j) {
      if (h[j + 1] <= h[j]) {
        current++;
        max_ = max(max_, current);
      } else {
        current = 0;
      }
    }
  }
  cout << max_ << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h;
  for (int i = 0; i < n; ++i) {
    int height;
    cin >> height;
    h.push_back(height);
  }

  int max_ = 0, curr = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (h[i + 1] <= h[i]) {
      curr++;
      max_ = max(max_, curr);
    } else {
      curr = 0;
    }
  }
  cout << max_ << endl;
}
Problem p02923 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 40)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n + 1);
  rep(i, n) cin >> h[i];
  h[n] = INF; // sentinel

  ll dp[10010] = {0}; // i番目のマスまでで移動してくるときの最大移動回数

  ll ans = 0;
  rep(i, n) {
    if (h[i + 1] <= h[i]) {
      dp[i + 1] = dp[i] + 1; // 右の方が小さいとき(もしくは同じ)
    } else {
      ans = max(ans, dp[i]);
      dp[i + 1] = 0;
    }
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define INF (1ll << 40)
#define mod 1000000007
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> h(n + 1);
  rep(i, n) cin >> h[i];
  h[n] = INF; // sentinel

  ll dp[100100] = {0}; // i番目のマスまでで移動してくるときの最大移動回数

  ll ans = 0;
  rep(i, n) {
    if (h[i + 1] <= h[i]) {
      dp[i + 1] = dp[i] + 1; // 右の方が小さいとき(もしくは同じ)
    } else {
      ans = max(ans, dp[i]);
      dp[i + 1] = 0;
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    int j, count;
    for (j = i, count = 0; j < N - 1 && H.at(j + 1) <= H.at(j); j++, count++) {
    }
    if (answer < count)
      answer = count;
  }
  cout << answer << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  int answer = 0;
  for (int i = 0; i < N - 1; i++) {
    int j, count;
    for (j = i, count = 0; j < N - 1 && H.at(j + 1) <= H.at(j); j++, count++) {
      i++;
    }
    if (answer < count)
      answer = count;
  }
  cout << answer << endl;
}
Problem p02923 (C++)

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

using namespace std;

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    ll currentHeight = H[i];
    int step = 0;
    for (int j = i + 1; H[j] <= currentHeight && j < N; j++) {
      step++;
      currentHeight = H[j];
    }
    ans = max(ans, step);
  }

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


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

using namespace std;

#define ll long long

int main() {
  int N;
  cin >> N;
  vector<ll> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    ll currentHeight = H[i];
    int step = 0;
    for (int j = i + 1; H[j] <= currentHeight && j < N; j++) {
      step++;
      currentHeight = H[j];
    }
    i += step;
    ans = max(ans, step);
  }

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

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

int main() {
  int n;
  cin >> n;
  vector<int> height(n);
  for (int i = 0; i < n; i++) {
    cin >> height.at(i);
  }
  int max = 0;
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int j = i;
    while (j < n - 1 && height.at(j) >= height.at(j + 1)) {
      j++;
      cnt++;
    }
    if (cnt >= max)
      max = cnt;
  }
  cout << max << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> height(n);
  for (int i = 0; i < n; i++) {
    cin >> height.at(i);
  }
  int max = 0;
  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    int j = i;
    while (j < n - 1 && height.at(j) >= height.at(j + 1)) {
      j++;
      cnt++;
    }
    if (cnt >= max)
      max = cnt;
    if (max > n / 2)
      break;
  }
  cout << max << endl;
}
Problem p02923 (C++)

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

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

  int res = 0;
  for (int i = 0; i < N; ++i) {
    int cnt = 0;
    for (int k = i + 1; k < N; ++k) {
      if (H[k - 1] >= H[k]) {
        cnt++;
      } else {
        break;
      }
    }

    if (res < cnt) {
      res = cnt;
    }
  }

  cout << res << endl;
}

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

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

  int res = 0;
  int cnt = 0;
  for (int i = 1; i < N; ++i) {
    if (H[i - 1] >= H[i]) {
      cnt++;
    } else {
      cnt = 0;
    }

    if (res < cnt) {
      res = cnt;
    }
  }

  cout << res << endl;
}
Problem p02923 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
typedef long long int ll;

using namespace std;

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

  cin >> N;
  rep(i, N) {
    int val;
    cin >> val;
    H.push_back(val);
  }

  int count[10000] = {0};
  REP(i, 1, N) count[i] = H[i] <= H[i - 1] ? count[i - 1] + 1 : 0;
  cout << *max_element(count, count + N) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
typedef long long int ll;

using namespace std;

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

  cin >> N;
  rep(i, N) {
    int val;
    cin >> val;
    H.push_back(val);
  }

  int count[100000] = {0};
  REP(i, 1, N) count[i] = H[i] <= H[i - 1] ? count[i - 1] + 1 : 0;
  cout << *max_element(count, count + N) << endl;
  return 0;
}
Problem p02924 (C++)

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

using namespace std;

#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define NACHO                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);

typedef long long tint;

int main() {
  int n;
  cin >> n;
  vector<tint> a(n), b(n);
  forn(i, n) {
    a[i] = i + 1;
    b[i] = i + 2;
  }
  b[0] = n;
  b[n - 1] = 1;
  tint sum = 0;
  forn(i, n) { sum += (a[i] % b[i]); }
  cout << sum << endl;
}


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

using namespace std;

#define forsn(i, s, n) for (int i = s; i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define NACHO                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(NULL);

typedef long long tint;

int main() {
  int n;
  cin >> n;
  tint s = (1LL * (n - 1) * n) / 2;
  cout << 1LL * s << endl;
}
Problem p02924 (Python)

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

for i in range(1, N):
    ans += i

print(ans)


Fixed submission:
N = int(input())
print((N - 1) * N // 2)
Problem p02924 (Python)

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

c = 0
for i in range(1, N):
    c += i

print(c)


Fixed submission:
N = int(input())
print(N * (N - 1) // 2)
Problem p02924 (Python)

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

sum = 0
for i in range(n):
    sum += i

print(sum)


Fixed submission:
n = int(input())

print((n * (n - 1)) // 2)
Problem p02924 (Python)

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

sys.setrecursionlimit(int(1e6))

N = int(input())

M_sum = 0
M_sum = sum(range(1, N))
M_sum += N % 1
print(M_sum)


Fixed submission:
import sys

sys.setrecursionlimit(int(1e6))

N = int(input())

n = N - 1
if bool(n % 2):
    ans = (n // 2) * (n) + n
else:
    ans = (n // 2) * (n + 1)

print(ans)
Problem p02924 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
print(sum(list(range(N))))


Fixed submission:
N = int(input())
print((N - 1) * N // 2)
Problem p02924 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
print(sum(list(range(N))[1:]))


Fixed submission:
N = int(input())
print((N - 1) * (N) // 2)
Problem p02924 (Python)

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

for i in range(1, n):
    ans += i

print(ans)


Fixed submission:
n = int(input()) - 1
print(n * (n + 1) // 2)
Problem p02924 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = list(range(1, n))
print(sum(a))


Fixed submission:
n = int(input())
ans = (n - 1) * (1 + n - 1) // 2
print(ans)
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    n = int(input())
    sum = 0
    for i in range(n):
        sum += i
    print(sum)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    print(n * (n - 1) // 2)


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

Buggy submission (status: Runtime Error):
n = int(input())


a = list(range(1, n))

print(sum(a))


Fixed submission:
n = int(input())


a = (1 + n - 1) * (n - 1) // 2
print(a)
Problem p02924 (Python)

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

ans = 0
for i in range(n):
    ans += i

print(ans)


Fixed submission:
n = int(input())

ans = n * (n - 1) // 2

print(ans)
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
print(sum(range(1, N)))


Fixed submission:
N = int(input())
print((N - 1) * N // 2)
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
print(sum([i for i in range(N)]))


Fixed submission:
N = int(input())
print(N * (N - 1) // 2)
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
print(sum(range(1, n)))


Fixed submission:
n = int(input())

ans = n * (n - 1) // 2
print(ans)
Problem p02924 (Python)

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

ans = 0

for i in range(1, n):
    ans += i

print(ans)


Fixed submission:
n = int(input())

print((n * (n - 1)) // 2)
Problem p02924 (Python)

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

N = int(sys.stdin.readline())
print(sum(n + 1 for n in range(N - 1)))


Fixed submission:
import sys

N = int(sys.stdin.readline())
print(int((N - 1) * N // 2))
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
ans = 0
for i in range(1, n):
    ans += i
print(ans)


Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Problem p02924 (Python)

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

result = 0
for i in range(N):
    result += i
print(result)


Fixed submission:
N = int(input())

print(N * (N - 1) // 2)
Problem p02924 (Python)

Buggy submission (status: Time Limit Exceeded):
a = int(input())
sum = 0
for i in range(a):
    sum += i
print(sum)


Fixed submission:
a = int(input())
sum = 0
sum = (a - 1) * a // 2
print(sum)
Problem p02924 (Python)

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

ans = 0
for i in range(n):
    ans += i

print(ans)


Fixed submission:
n = int(input())

print(n * (n - 1) // 2)
Problem p02924 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
// int l[n+1];
int main() {
  int n;
  cin >> n;
  long long res = 0;
  for (int i = 1; i < n; i++) {
    res += i % (i + 1);
  }

  cout << res;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
// int l[n+1];
int main() {
  int n;
  cin >> n;
  long long res = 0;
  for (int i = 1; i < n; i++) {
    res += i;
  }

  cout << res;
}
Problem p02924 (C++)

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

#define ll long long

using namespace std;

ll n, sol;
int main() {
  cin >> n;

  for (int i = 1; i < n; ++i)
    sol += i % (i + 1);

  cout << sol;
  return 0;
}


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

#define ll long long

using namespace std;

ll n, sol;
int main() {
  cin >> n;

  cout << n * (n - 1) / 2;
  return 0;
}
Problem p02924 (C++)

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

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

using namespace std;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;

  long ans = 0;
  rep(i, N) {
    if (i != N - 1)
      ans += (i + 1) % (i + 2);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <iostream>

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

using namespace std;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  long N;
  cin >> N;

  long ans = ((N - 1) * N) / 2;

  cout << ans << endl;

  return 0;
}
Problem p02924 (C++)

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

using namespace std;

int main() {
  long long int N;
  cin >> N;
  long long int sum;
  sum = 0;

  for (long long int i = 0; i < N - 1; i++) {
    sum = sum + ((N - 1 - i) % (N - i));
  }
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  long long int N;
  cin >> N;
  cout << N * (N - 1) / 2 << endl;
  return 0;
}
Problem p02924 (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 all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N;
  cin >> N;
  vector<int> vec(N);

  int ans = 0;

  cout << N * (N - 1) / 2 << endl;
}

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

signed main() {
  int N;
  cin >> N;
  // vector<int> vec(N);

  int ans = 0;

  cout << N * (N - 1) / 2 << endl;
}
Problem p02924 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)

int power(ll x, unsigned int y) {
  ll p = mod;
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  // Base Case
  if (a == 0) {
    *x = 0;
    *y = 1;
    return b;
  }

  ll x1, y1; // To store results of recursive call
  ll gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of
  // recursive call
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {

    if (i == n)
      continue;
    ans += i % (i + 1);
  }
  cout << ans;
  // cout<<"djlk";
}


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

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define P pair<ll, ll>
#define V vector<ll>
#define C vector<char>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)

int power(ll x, unsigned int y) {
  ll p = mod;
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  // Base Case
  if (a == 0) {
    *x = 0;
    *y = 1;
    return b;
  }

  ll x1, y1; // To store results of recursive call
  ll gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of
  // recursive call
  *x = y1 - (b / a) * x1;
  *y = x1;

  return gcd;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  n--;
  ans = (n * (n + 1)) / 2;
  cout << ans;
  // cout<<"djlk";
}
Problem p02924 (C++)

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

using namespace std;

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

  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += i % (n + i - i);
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

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

  cout << (long long)(n - 1) * n / 2 << endl;

  return 0;
}
Problem p02924 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
const ll mod = 1000000007;
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)

int main() {
  ll n;
  cin >> n;
  ll out = 0;
  for (ll i = n - 1; i >= 1; --i) {
    out += i % (i + 1);
  }
  cout << out << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
typedef long long ll;
const ll mod = 1000000007;
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)

int main() {
  ll n;
  cin >> n;
  cout << n * (n - 1LL) / 2LL << endl;
  return 0;
}
Problem p02924 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <vector>
#define int long long
#include <string>
#define float long double
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, s = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n - 1; i++) {
    a[i] = i + 2;
  }
  a[n - 1] = 1;
  for (int i = 0; i < n; i++)
    s = s + ((i + 1) % a[i]);
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
#include <vector>
#define int long long
#include <string>
#define float long double
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, s = 0;
  cin >> n;
  for (int i = 1; i < n; i++)
    s = s + i;
  cout << s;
}