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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pi 3.14159265359
#define nl printf("\n")
#define gcd(a, b) __gcd(a, b)
#define yes                                                                    \
  cout << "Yes"                                                                \
       << "\n"
#define no                                                                     \
  cout << "No"                                                                 \
       << "\n"
#define pf printf
#define sf scanf
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int N = 2e5 + 5;
typedef long long int ll;

int main() {

  FIO;
  int i, j, k, temp, n, f = 0, ans = 1;
  cin >> n;
  string str;
  rep(i, n) {
    cin >> str[i];
    if (i > 0 && (str[i] != str[i - 1]))
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pi 3.14159265359
#define nl printf("\n")
#define gcd(a, b) __gcd(a, b)
#define yes                                                                    \
  cout << "Yes"                                                                \
       << "\n"
#define no                                                                     \
  cout << "No"                                                                 \
       << "\n"
#define pf printf
#define sf scanf
#define FIO                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
const int N = 2e5 + 5;
typedef long long int ll;

int main() {

  FIO;
  int i, j, k, temp, n, f = 0, ans = 1;
  cin >> n;
  string str;
  cin >> str;
  for (i = 1; i < str.size(); i++) {
    if (str[i] != str[i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
/*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main() {
#ifndef ONLINE_JUDGE
  freopen("C:\\Users\\sharr\\Documents\\Input.txt", "r", stdin);
  freopen("C:\\Users\\sharr\\Documents\\Output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  string res = "";
  res.pb(s[0]);
  for (ll i = 0; i < n; i++) {
    if (res.back() != s[i]) {
      res.pb(s[i]);
    }
  }
  cout << res.size();
}

Fixed submission:
/*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin >> n;
  string s;
  cin >> s;
  string res = "";
  res.pb(s[0]);
  for (ll i = 0; i < n; i++) {
    if (res.back() != s[i]) {
      res.pb(s[i]);
    }
  }
  cout << res.size();
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  int sum = 1;
  for (int i = 1; i < N; i++) {
    if (s[i] != s[i - 1]) {
      sum++;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int sum = 1;
  for (int i = 1; i < N; i++) {
    if (s[i] != s[i - 1]) {
      sum++;
    }
  }
  cout << sum << endl;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < x; i++)
#include <string>

using namespace std;

int main() {
  long long N;
  cin >> N;
  string S;
  rep(i, N) { cin >> S[i]; }

  long long count = N;
  for (long long i = 0; i < (N - 1); i++) {
    if (S[i] == S[i + 1]) {
      count--;
    }
  }
  cout << count;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < x; i++)
#include <string>

using namespace std;

int main() {
  long long N;
  cin >> N;
  string S;
  cin >> S;

  long long count = N;
  for (long long i = 0; i < (N - 1); i++) {
    if (S[i] == S[i + 1]) {
      count--;
    }
  }
  cout << count;
}
Problem p02887 (C++)

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

int main() {
  int n, cou = 1;
  char str[10001];
  cin >> n >> str;

  for (int i = 0; i < n - 1; ++i)
    if (str[i] != str[i + 1])
      cou++;

  cout << cou << endl;
  return 0;
}

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

int main() {
  int n, cou = 1;
  char str[100001];
  cin >> n >> str;

  for (int i = 0; i < n - 1; ++i)
    if (str[i] != str[i + 1])
      cou++;

  cout << cou << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int N = 0, i = 0, j = 0, sum = 0;
  char S[10 ^ 5];
  scanf("%d", &N);
  scanf("%s", S);
  sum = N;
  for (i = 0; i < N - 1; i++) {
    // for (j = i + 1; j < N ; j++)
    //{
    if (S[i] == S[i + 1]) {
      sum -= 1;
    }

    //}
  }
  printf("%d", sum);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int N = 0, i = 0, j = 0, sum = 0;
  char S[100000];
  scanf("%d", &N);
  scanf("%s", S);
  sum = N;
  for (i = 0; i < N - 1; i++) {
    // for (j = i + 1; j < N ; j++)
    //{
    if (S[i] == S[i + 1]) {
      sum -= 1;
    }

    //}
  }
  printf("%d", sum);
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  string str;
  cin >> n >> str;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (str[i] == str[j]) {
        continue;
      } else {
        ans++;
        i = j - 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  string str;
  cin >> n >> str;
  int ans = 1;
  char c = str.at(0);
  for (int i = 1; i < n; i++) {
    if (c == str.at(i)) {
      continue;
    } else {
      ans++;
      c = str.at(i);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    char tmp = S[i];
    for (int j = i + 1; j < N; j++) {
      if (S[j] != tmp) {
        ans++;
        i = j - 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    char tmp = S[i];
    for (int j = i + 1; j < N; j++) {
      if (S[j] != tmp) {
        ans++;
        i = j - 1;
        break;
      }
      if (j == N - 1)
        i = j + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  char S[10000];
  int N;
  int k = 1;
  scanf("%d", &N);
  scanf("%s", S);
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1]) {
      k++;
    }
  }
  printf("%d\n", k);
}

Fixed submission:
#include <stdio.h>
int main(void) {
  char S[100000];
  int N;
  int k = 1;
  scanf("%d", &N);
  scanf("%s", S);
  for (int i = 0; i < N - 1; i++) {
    if (S[i] != S[i + 1]) {
      k++;
    }
  }
  printf("%d\n", k);
}
Problem p02887 (C++)

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

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

  int n, c = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (s[i] != s[j]) {
        c++;
        i = j - 1;
        break;
      }
    }
  }
  cout << c + 1 << endl;
  return 0;
}


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

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

  int n, c = 0;
  cin >> n;
  string s;
  cin >> s;
  char key = s[0];
  for (int i = 1; i < n; i++) {
    //      for(int j=i;j<n;j++)
    //      {
    //          if(s[i]!=s[j])
    //          {
    //              c++;
    //              i=j-1;
    //              break;
    //          }
    //      }
    if (key != s[i]) {
      c++;
      key = s[i];
    }
  }
  cout << c + 1 << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  bool flag = 1;
  int i = 0;
  while (flag) {
    while (s[i] == s[i + 1]) {
      s.erase(i, 1);
      if (s.size() == i + 1) {
        flag = 0;
        break;
      }
    }
    i++;
    if (s.size() == i + 1)
      break;
  }

  cout << s.size() << endl;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  bool flag = 1;
  int i = 0;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  while (flag) {
    while (s[i] == s[i + 1]) {
      s.erase(i, 1);
      if (s.size() == i + 1) {
        flag = 0;
        break;
      }
    }
    i++;
    if (s.size() == i + 1)
      break;
  }

  cout << s.size() << endl;
}
Problem p02887 (C++)

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

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

  int ans = 1;

  for (int i = 1; i < S.size() - 1; i++) {
    if (S.at(i) == S.at(i + 1) && S.at(i - 1) != S.at(i)) {
      ans++;
    } else if (S.at(i) != S.at(i + 1) && S.at(i - 1) != S.at(i)) {
      ans++;
    }
  }

  if (S.at(N - 1) != S.at(N - 2)) {
    ans++;
  }

  cout << ans << endl;
}

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

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

  int ans = 1;

  if (N == 1) {
    cout << ans << endl;
    return 0;
  }

  for (int i = 1; i < S.size() - 1; i++) {
    if (S.at(i) == S.at(i + 1) && S.at(i - 1) != S.at(i)) {
      ans++;
    } else if (S.at(i) != S.at(i + 1) && S.at(i - 1) != S.at(i)) {
      ans++;
    }
  }

  if (S.at(N - 1) != S.at(N - 2)) {
    ans++;
  }

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

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int i, N;
  char S[10 ^ 5]; // おいしさ
  int sum = 1;    // おいしさのサム値
  // 数を取得
  scanf("%d", &N);

  // 文字列を取得
  scanf("%s", S);

  for (i = 1; i < N; i++) {
    if (S[i] == S[i - 1]) {
      //      printf("一緒:%d,%c\n", i,S[i]);
    } else {
      sum++;
      //      printf("違う:%d,%c\n", i,S[i]);
    }
  }

  printf("%d", sum);
}

Fixed submission:
#include <stdio.h>
int main() {
  long int i, N;
  char S[10 * 10 * 10 * 10 * 10]; // おいしさ
  long int sum = 1;               // おいしさのサム値
  // 数を取得
  scanf("%d", &N);

  // 文字列を取得
  scanf("%s", S);

  for (i = 1; i < N; i++) {
    if (S[i] == S[i - 1]) {
      //      printf("一緒:%d,%c\n", i,S[i]);
    } else {
      sum++;
      //      printf("違う:%d,%c\n", i,S[i]);
    }
  }

  printf("%d", sum);
}
Problem p02887 (C++)

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

using namespace std;

int main() {
  int N, count = 1;
  char s[10000];
  cin >> N >> s[0];
  for (int i = 1; i < N; i++) {
    cin >> s[i];
    if (s[i] != s[i - 1])
      count += 1;
  }
  cout << count << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, count = 1;
  char s[100000];
  cin >> N >> s[0];
  for (int i = 1; i < N; i++) {
    cin >> s[i];
    if (s[i] != s[i - 1])
      count += 1;
  }
  cout << count << endl;
}
Problem p02887 (C++)

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int a = S.size();
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == S.at(i + 1)) {
      a--;
    }
  }
  cout << a << endl;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int a = S.size();
  for (int i = 0; i < S.size() - 1; i++) {
    if (S.at(i) == S.at(i + 1)) {
      a--;
    }
  }
  cout << a << endl;
}
Problem p02887 (C++)

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(i + 1)) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  for (int i = 0; i < n - 1; i++) {
    if (s.at(i) != s.at(i + 1)) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02887 (C++)

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

using namespace std;

int main() {
  char s[10001];
  int n, c = 0;
  cin >> n;
  cin >> s;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] != s[i + 1])
      c++;
  }
  cout << c;
  return 0;
}


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

using namespace std;

int main() {
  char s[100001];
  int n, c = 0;
  cin >> n;
  cin >> s;
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] != s[i + 1])
      c++;
  }
  cout << c;
  return 0;
}
Problem p02887 (C++)

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

int main() {
  int n;
  char s[10001] = {};
  cin >> n;
  int tag = 0;
  int ans = 0;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == s[i + 1]) {
      continue;
    }
    ans++;
  }
  cout << ans;
  return 0;
}


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

int main() {
  int n;
  char s[100001] = {};
  cin >> n;
  int tag = 0;
  int ans = 0;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == s[i + 1]) {
      continue;
    }
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main(void) {
  int N;
  char S[10001];
  scanf("%d", &N);
  scanf("%s", S);
  int i;
  int ans = N;
  for (i = 0; i < N; i++) {
    if (S[i] == S[i + 1]) {
      ans = ans - 1;
    }
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main(void) {
  int N;
  char S[100001];
  scanf("%d", &N);
  scanf("%s", S);
  int i;
  int ans = N;
  for (i = 0; i < N; i++) {
    if (S[i] == S[i + 1]) {
      ans = ans - 1;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int n, i;
  char s[10000];
  while (~scanf("%d", &n)) {
    int acm = 1;
    scanf("%s", s);
    for (i = 0; i < n - 1; i++)
      if (s[i] != s[i + 1])
        acm++;
    printf("%d\n", acm);
  }
  return 0;
}


Fixed submission:
#include <stdio.h>
int main() {
  int n, i;
  char s[120000];
  while (~scanf("%d", &n)) {
    int acm = 1;
    scanf("%s", s);
    for (i = 0; i < n - 1; i++)
      if (s[i] != s[i + 1])
        acm++;
    printf("%d\n", acm);
  }
  return 0;
}
Problem p02887 (C++)

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

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S.at(i) == S.at(j)) {
        continue;
      } else {
        ans++;
        i = j;
      }
    }
  }

  printf("%d", ans + 1);
  return 0;
}

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

int main() {
  int N;
  scanf("%d", &N);
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == S.at(i + 1)) {
      continue;
    } else {
      ans++;
    }
  }

  printf("%d", ans + 1);
  return 0;
}
Problem p02887 (C++)

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

using namespace std;

ifstream fin("fisier.in");
ofstream fout("fisier.out");

char s[1005];
char actual;

int main() {
  int n, i, j, answer = 1;

  cin >> n;
  cin >> s;

  actual = s[0];

  for (i = 1; i < n; i++)
    if (s[i] != actual) {
      actual = s[i];
      answer++;
    }

  cout << answer;

  return 0;
}


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

using namespace std;

ifstream fin("fisier.in");
ofstream fout("fisier.out");

char s[100005];
char actual;

int main() {
  int n, i, j, answer = 1;

  cin >> n;
  cin >> s;

  actual = s[0];

  for (i = 1; i < n; i++)
    if (s[i] != actual) {
      actual = s[i];
      answer++;
    }

  cout << answer;

  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
// 此程序使用了qt专属名称，请勿模仿。侵权必究！！！
// 我真是太菜了……
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1010, P = 1 << 30;
int n, ans = 0;
char a[N];
inline int read() {
  int sum = 0, flag = 1;
  char c;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    sum = (sum << 1) + (sum << 3) + c - '0';
  return sum * flag;
}
int main() {
  //	freopen(".in","r",stdin);
  //	freopen(".out","w",stdout);
  n = read();
  scanf("%s", a + 1);
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
// 此程序使用了qt专属名称，请勿模仿。侵权必究！！！
// 我真是太菜了……
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100100, P = 1 << 30;
int n, ans = 0;
char a[N];
inline int read() {
  int sum = 0, flag = 1;
  char c;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-')
      flag = -1;
  for (; c >= '0' && c <= '9'; c = getchar())
    sum = (sum << 1) + (sum << 3) + c - '0';
  return sum * flag;
}
int main() {
  //	freopen(".in","r",stdin);
  //	freopen(".out","w",stdout);
  n = read();
  scanf("%s", a + 1);
  for (int i = 1; i <= n; ++i) {
    if (a[i] != a[i - 1]) {
      ++ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1.0);
const ll mod = pow(10, 9) + 7;
const ll INF = pow(2, 31) - 1;
using str = string;
typedef pair<int, int> P;
typedef vector<int> vi;

ll gcd(ll a, ll b) {
  ll v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  }
  return v1;
}

ll lcm(ll a, ll b) { return (a * b / gcd(a, b)); }

int main() {
  int n;
  cin >> n;
  str S;
  cin >> S;
  S.erase(unique(S.begin(), S.end()));
  cout << S.size() << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1.0);
const ll mod = pow(10, 9) + 7;
const ll INF = pow(2, 31) - 1;
using str = string;
typedef pair<int, int> P;
typedef vector<int> vi;

ll gcd(ll a, ll b) {
  ll v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  }
  return v1;
}

ll lcm(ll a, ll b) { return (a * b / gcd(a, b)); }

int main() {
  int n;
  cin >> n;
  str S;
  cin >> S;
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#define int long long
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
}
char s[10020];
int n, cnt;
signed main() {
  scanf("%lld", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] != s[i - 1])
      cnt++;

  cout << cnt;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#define int long long
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (c > '9' || c < '0') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  x *= f;
}
char s[100020];
int n, cnt;
signed main() {
  scanf("%lld", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] != s[i - 1])
      cnt++;

  cout << cnt;
}
Problem p02888 (C++)

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

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

  long long int n, i, j, k, flag, count = 0;
  cin >> n;
  long long int l[n];
  for (i = 0; i < n; i++) {
    cin >> l[i];
  }
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      for (k = j + 1; k < n; k++) {
        if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
            (l[k] + l[j] > l[i]))
          count++;
      }
    }
  }
  cout << count;

  return 0;
}


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

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

  long long int n, i, j, k, flag, count = 0;
  cin >> n;
  long long int l[n];
  for (i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l, l + n);
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      for (k = j + 1; k < n; k++) {
        if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
            (l[k] + l[j] > l[i]))
          count++;
      }
    }
  }
  cout << count;

  return 0;
}
Problem p02888 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  vector<pair<int, int>> combi;

  for (int i = 0; i < n - 2; i++) {
    int iL = l.at(i);
    for (int j = i + 1; j < n - 1; j++) {
      int jL = l.at(j);
      combi.push_back(make_pair(j, iL + jL));
      //
    }
  }
  int cnt = 0;

  for (int k = 0; k < n; k++) {
    int kL = l.at(k);
    for (int i = 0; i < combi.size(); i++) {
      if (k <= combi.at(i).first) {
        continue; // kがj以下なら被るのでサヨナラ
      } else if (kL >= combi.at(i).second) {
        continue; // kLが二辺の和以上なら条件xなのでサヨナラ
      } else {
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++) {
    cin >> l.at(i);
  }
  sort(l.begin(), l.end());
  vector<pair<int, int>> combi;

  for (int i = 0; i < n - 2; i++) {
    int iL = l.at(i);
    for (int j = i + 1; j < n - 1; j++) {
      int jL = l.at(j);
      combi.push_back(make_pair(j, iL + jL));
      //
    }
  }
  int cnt = 0;

  for (int i = 0; i < combi.size(); i++) {
    for (int k = combi.at(i).first + 1; k < n; k++) {
      int kL = l.at(k);
      if (kL < combi.at(i).second) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}
Problem p02888 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  rep(i, n) rep(j, i + 1, n) {
    int low = (upper_bound(ALL(l), l[j] - l[i]) - l.begin());
    for (int k = low; l[k] < l[i] + l[j]; k++) {
      if (i < k && k < j) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(ALL(l));
  int ans = 0;
  rep(i, n) rep(j, i + 1, n) {
    int low = (upper_bound(ALL(l), l[j] - l[i]) - l.begin());
    for (int k = max(low, (int)i + 1); l[k] < l[i] + l[j] && k < j; k++) {
      if (i < k && k < j) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02888 (C++)

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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> l(N);
  for (auto &l_i : l) {
    cin >> l_i;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

int main() { answer1(); }


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

void answer1() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> l(N);
  for (auto &l_i : l) {
    cin >> l_i;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

void answer2() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> l(N);
  for (auto &l_i : l) {
    cin >> l_i;
  }
  sort(l.begin(), l.end());
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      //
      int target = l[i] + l[j];
      // target以上値を探す
      auto itr = lower_bound(l.begin() + j + 1, l.end(), target);

      count += itr - (l.begin() + j + 1);
    }
  }
  cout << count << endl;
}

int main() {
  // answer1(); // 実行時間制限超過
  answer2();
}
Problem p02888 (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 main() {
  int n, num, i;
  cin >> n;
  num = 0;
  vector<int> L;
  for (i = 0; i < n; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

  rep(b, n) rep(a, b) {
    int ab = L[a] + L[b];
    int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
    int l = b + 1;
    num += max(0, r - l);
  }

  cout << num << endl;
}


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

int main() {
  int n, num, i;
  cin >> n;
  num = 0;
  vector<int> L(n);
  for (i = 0; i < n; i++) {
    cin >> L[i];
  }

  sort(L.begin(), L.end());

  rep(b, n) rep(a, b) {
    int ab = L[a] + L[b];
    int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
    int l = b + 1;
    num += max(0, r - l);
  }

  cout << num << endl;
}
Problem p02888 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  ll N;
  cin >> N;
  vector<ll> l(N);
  rep(i, N) cin >> l[i];
  sort(l.begin(), l.end());
  ll ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      int a = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
      ans += a - (j + 1);
    }
  }
  cout << ans << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  ll N;
  cin >> N;
  vector<ll> l(N);
  rep(i, N) cin >> l[i];
  sort(l.begin(), l.end());
  ll ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      int a = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
      ans += a - (j + 1);
    }
  }
  cout << ans << endl;
}
Problem p02888 (C++)

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

int vect[1006];

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

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

  sort(vect + 1, vect + n + 1);

  int ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      int st = j + 1;
      int dr = n;
      int sol = -1;
      while (st <= dr) {
        int mij = (st + dr) / 2;
        if (vect[mij] < vect[i] + vect[j]) {
          sol = mij;
          st = mij + 1;
        } else {
          dr = mij - 1;
        }
      }

      if (sol != -1) {
        ans = ans + sol - j;
      }
    }
  }

  cout << ans;
  return 0;
}

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

int vect[2006];

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

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

  sort(vect + 1, vect + n + 1);

  int ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      int st = j + 1;
      int dr = n;
      int sol = -1;
      while (st <= dr) {
        int mij = (st + dr) / 2;
        if (vect[mij] < vect[i] + vect[j]) {
          sol = mij;
          st = mij + 1;
        } else {
          dr = mij - 1;
        }
      }

      if (sol != -1) {
        ans = ans + sol - j;
      }
    }
  }

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

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int l[1005];
  for (int i = 0; i < n; ++i)
    scanf("%d", &l[i]);
  sort(l, l + n, greater<int>());
  long long ans = 0;
  for (int i = 0; i < n - 2; ++i) {
    int left = i + 1;
    int right = n - 1;
    while (left < right) {
      if (l[left] + l[right] > l[i]) {
        ans += right - left;
        ++left;
      } else
        --right;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int l[2005];
  for (int i = 0; i < n; ++i)
    scanf("%d", &l[i]);
  sort(l, l + n, greater<int>());
  long long ans = 0;
  for (int i = 0; i < n - 2; ++i) {
    int left = i + 1;
    int right = n - 1;
    while (left < right) {
      if (l[left] + l[right] > l[i]) {
        ans += right - left;
        ++left;
      } else
        --right;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02888 (C++)

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;

#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define endl "\n"
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main() {
  int n;
  cin >> n;
  vi l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (l[i] < l[j] + l[k] && l[j] < l[i] + l[k] && l[k] < l[i] + l[j])
          ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;

#define fastIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define endl "\n"
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

int main() {
  int n;
  cin >> n;
  vi l(n);
  for (int i = 0; i < n; i++)
    cin >> l[i];
  ll ans = 0;
  sort(l.begin(), l.end());
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      auto it = lower_bound(l.begin() + j, l.end(), l[i] + l[j]);
      int k = it - l.begin();
      if (k == n)
        --k;
      if (k < n && l[k] >= l[i] + l[j])
        --k;
      // cout << i << " " << j << " " << k << endl;
      ans += (k - j);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02888 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, l[1002];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l, l + n);
  int ans = 0;
  for (int i = n - 1; i > 1; i--) {
    for (int j = i - 1; j > 0; j--) {
      int mmin = l[i] - l[j];
      for (int k = j - 1; k >= 0; k--) {
        if (l[k] <= mmin)
          break;
        else
          ans++;
      }
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, l[2002];
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> l[i];
  sort(l, l + n);
  int ans = 0;
  for (int i = n - 1; i > 1; i--) {
    for (int j = i - 1; j > 0; j--) {
      int mmin = l[i] - l[j];
      for (int k = j - 1; k >= 0; k--) {
        if (l[k] <= mmin)
          break;
        else
          ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02888 (C++)

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

#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  rep(i, n - 2) REP(j, i + 1, n - 1) {
    int a = l[i] + l[j];
    int k = j + 1;
    while (a > l[k] && k < n)
      ans++;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

void Main() {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  rep(i, n - 2) REP(j, i + 1, n - 1) {
    int a = l[i] + l[j];
    auto position = lower_bound(l.begin() + j, l.end(), a);
    ans += distance(l.begin(), position) - j - 1;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02888 (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);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if ((v.at(i) < v.at(j) + v.at(k)) && (v.at(j) < v.at(i) + v.at(k)) &&
            (v.at(k) < v.at(i) + v.at(j))) {
          ans++;
        }
      }
    }
  }
  cout << ans << 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);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int itr = lower_bound(v.begin(), v.end(), v.at(i) + v.at(j)) - v.begin();
      ans += max(itr - (j + 1), 0);
    }
  }
  cout << ans << endl;
}
Problem p02888 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N;
  cin >> N;
  int L[2010];
  REP(i, N) cin >> L[i];

  ll ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[i] < L[j] + L[k]) {
          if (L[j] < L[i] + L[k]) {
            if (L[k] < L[i] + L[j]) {
              ans++;
            }
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main() {
  int N;
  cin >> N;
  int L[2010];
  REP(i, N) cin >> L[i];

  sort(L, L + N);

  ll ans = 0;
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[i] < L[j] + L[k]) {
          if (L[j] < L[i] + L[k]) {
            if (L[k] < L[i] + L[j]) {
              ans++;
            }
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02888 (C++)

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

using namespace std;

int main() {
  int n, a, cnt = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (v[i] < v[j] + v[k] && v[j] < v[k] + v[i] && v[k] < v[i] + v[j])
          cnt++;
        else
          break;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}


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

using namespace std;

int main() {
  int n, a, cnt = 0;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (v[i] < v[j] + v[k] && v[j] < v[k] + v[i] && v[k] < v[i] + v[j])
          cnt++;
        else
          continue;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p02888 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans;
  ans = 0;
  vector<int> L;
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[k] < (L[i] + L[j])) {
          ans = ans + 1;
        } else {
          break;
        }
      }
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans;
  ans = 0;
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L[i];
  }
  sort(L.begin(), L.end());
  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L[k] < (L[i] + L[j])) {
          ans = ans + 1;
        } else {
          break;
        }
      }
    }
  }
  cout << ans;
  return 0;
}
Problem p02888 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> vc(n);
  for (int i = 0; i < n; i++) {
    cin >> vc.at(i);
  }

  sort(vc.begin(), vc.end());
  int ans = 0;
  int a, b, c;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        a = vc.at(i);
        b = vc.at(j);
        c = vc.at(k);
        if (a + b <= c)
          break;
        else if (a < (b + c) && b < (a + c) && c < (b + c)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> vc(n);
  for (int i = 0; i < n; i++) {
    cin >> vc.at(i);
  }

  sort(vc.begin(), vc.end());
  int ans = 0;
  int a, b, c;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        a = vc.at(i);
        b = vc.at(j);
        c = vc.at(k);
        if (a + b <= c)
          break;
        else if (c < (b + c)) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02888 (C++)

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

int main(void) {
  int input, ans = 0, flag;
  cin >> input;

  vector<int> side(input);
  for (int i = 0; i < input; i++) {
    cin >> side.at(i);
  }

  sort(side.begin(), side.end());
  reverse(side.begin(), side.end());

  vector<int> num;
  for (int i = 0; i < input; i++) {
    flag = 0;
    for (int j = i + 1; j < input; j++) {
      for (int k = j + 1; k < input; k++) {
        if (side.at(i) < side.at(j) + side.at(k) &&
            side.at(j) < side.at(k) + side.at(i) &&
            side.at(k) < side.at(i) + side.at(j)) {
          ans++;
          num.push_back(i);
        } else {
          break;
          flag++;
        }
      }
      if (flag != 0) {
        break;
      }
    }
  }

  cout << ans << endl;
}

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

int main(void) {
  int input, ans = 0, flag;
  cin >> input;

  vector<int> side(input);
  for (int i = 0; i < input; i++) {
    cin >> side.at(i);
  }

  sort(side.begin(), side.end());
  reverse(side.begin(), side.end());

  vector<int> num;
  for (int i = 0; i < input; i++) {
    flag = 0;
    for (int j = i + 1; j < input; j++) {
      for (int k = j + 1; k < input; k++) {
        if (side.at(i) < side.at(j) + side.at(k) &&
            side.at(j) < side.at(k) + side.at(i) &&
            side.at(k) < side.at(i) + side.at(j)) {
          ans++;
        } else {
          break;
          flag++;
        }
      }
      if (flag != 0) {
        break;
      }
    }
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls(s) (s & (-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod = 1e9 + 7;
ll n, ans;
ll arr[1005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  rep(i, 1, n + 1) cin >> arr[i];
  sort(arr, arr + n + 1);
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      ll sum = arr[i] + arr[j];

      ll x = lower_bound(arr, arr + n, sum) - arr;

      while (arr[x] >= sum)
        x--;
      if (x > j)
        ans += (x - j);
      //	cout<<i<<" "<<j<<" "<<x<<endl;
    }
  }
  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls(s) (s & (-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end)                                                     \
  for (__typeof(end) i = (begin) - ((begin) > (end));                          \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod = 1e9 + 7;
ll n, ans;
ll arr[2005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  cin >> n;
  rep(i, 1, n + 1) cin >> arr[i];
  sort(arr, arr + n + 1);
  for (int i = 1; i <= n - 2; i++) {
    for (int j = i + 1; j <= n - 1; j++) {
      ll sum = arr[i] + arr[j];

      ll x = lower_bound(arr, arr + n, sum) - arr;

      while (arr[x] >= sum)
        x--;
      if (x > j)
        ans += (x - j);
      //	cout<<i<<" "<<j<<" "<<x<<endl;
    }
  }
  cout << ans;
}
Problem p02888 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[10000] = {0};
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  long long num = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (a[k] < (a[i] + a[j]) && a[i] < (a[j] + a[k]) &&
            a[j] < (a[k] + a[i]))
          num++;
      }
    }
  }
  printf("%lld\n", num);
}

Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[10000] = {0};
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  sort(a, a + n);
  long long num = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      for (int k = j + 1; k < n; k++) {
        if (a[k] < (a[i] + a[j]) && a[i] < (a[j] + a[k]) &&
            a[j] < (a[k] + a[i]))
          num++;
      }
    }
  }
  printf("%lld\n", num);
}