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

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#define llint long long
#define inf 1e9

using namespace std;

llint n, m;
vector<llint> G[605], revG[605];
double dp[605], dp2[605];

void dfs(int v, int f) {
  if (f) {
    double sum = 0;
    for (int j = 0; j < G[v].size(); j++) {
      sum += dp2[G[v][j]];
    }
    dp2[v] = sum / (int)G[v].size() + 1;
  }
  for (int i = 0; i < revG[v].size(); i++)
    dfs(revG[v][i], 1);
}

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

  cin >> n >> m;
  llint u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    revG[v].push_back(u);
  }

  dp[n] = 0;
  for (int i = n - 1; i >= 1; i--) {
    double sum = 0;
    for (int j = 0; j < G[i].size(); j++) {
      sum += dp[G[i][j]];
    }
    dp[i] = sum / (int)G[i].size() + 1;
  }

  // for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl;

  double ans = dp[1];
  for (int i = 1; i <= n; i++) {

    int N = G[i].size();
    if (N <= 1)
      continue;

    double mx = 0;
    for (int j = 0; j < G[i].size(); j++) {
      mx = max(mx, dp[G[i][j]]);
    }
    for (int j = 1; j <= n; j++)
      dp2[j] = dp[j];
    dp2[i] = ((dp[i] - 1) * N - mx) / (N - 1) + 1;

    dfs(i, 0);
    ans = min(ans, dp2[1]);

    // for(int i = 1; i <= n; i++) cout << dp2[i] << " "; cout << endl;
  }
  printf("%.11f\n", ans);

  return 0;
}

Fixed submission:
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#define llint long long
#define inf 1e9

using namespace std;

llint n, m;
vector<llint> G[605], revG[605];
double dp[605], dp2[605];

void dfs(int v, int f) {
  if (f) {
    double sum = 0;
    for (int j = 0; j < G[v].size(); j++) {
      sum += dp2[G[v][j]];
    }
    dp2[v] = sum / (int)G[v].size() + 1;
  }
  for (int i = 0; i < revG[v].size(); i++)
    dfs(revG[v][i], 1);
}

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

  cin >> n >> m;
  llint u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    revG[v].push_back(u);
  }

  dp[n] = 0;
  for (int i = n - 1; i >= 1; i--) {
    double sum = 0;
    for (int j = 0; j < G[i].size(); j++) {
      sum += dp[G[i][j]];
    }
    dp[i] = sum / (int)G[i].size() + 1;
  }

  // for(int i = 1; i <= n; i++) cout << dp[i] << " "; cout << endl;

  double ans = dp[1];
  for (int i = 1; i <= n; i++) {

    int N = G[i].size();
    if (N <= 1)
      continue;

    double mx = 0;
    for (int j = 0; j < G[i].size(); j++) {
      mx = max(mx, dp[G[i][j]]);
    }
    for (int j = 1; j <= n; j++)
      dp2[j] = dp[j];
    dp2[i] = ((dp[i] - 1) * N - mx) / (N - 1) + 1;

    for (int v = i - 1; v >= 1; v--) {
      double sum = 0;
      for (int j = 0; j < G[v].size(); j++) {
        sum += dp2[G[v][j]];
      }
      dp2[v] = sum / (int)G[v].size() + 1;
    }

    ans = min(ans, dp2[1]);

    // for(int i = 1; i <= n; i++) cout << dp2[i] << " "; cout << endl;
  }
  printf("%.11f\n", ans);

  return 0;
}
Problem p02885 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())

ans = a // (b * 2)

if ans <= 0:
    ans = 0

print(ans)


Fixed submission:
a, b = map(int, input().split())
ans = a - (b * 2)

if ans <= 0:
    ans = 0

print(ans)
Problem p02885 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())

if a > b * 2:
    print(a - b * 2)
else:
    print(0)


Fixed submission:
list = input().split()

a = int(list[0])
b = int(list[1])

if a > b * 2:
    print(a - b * 2)
else:
    print(0)
Problem p02885 (C++)

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

int main() {
  int a, b, c;
  scanf("%d %d", a, b);
  if (a > 2 * b) {
    c = a - 2 * b;
    printf("%d", c);
  } else {
    printf("%d", 0);
  }
}

Fixed submission:
#include <stdio.h>

int main() {
  int a, b, c;
  scanf("%d %d", &a, &b);
  if (a > 2 * b) {
    c = a - 2 * b;
    printf("%d", c);
  } else {
    printf("%d", 0);
  }
}
Problem p02885 (C++)

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

using namespace std;

int main(void) {
  int A, B;

  cin >> A >> B;

  if (B * 2 > A) {
    cout << "0" << endl;
  } else {
    cout << (A - B * 2) << endl;
  }

  return 1;
}


Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  int A, B;

  cin >> A >> B;

  if (B * 2 > A) {
    cout << "0" << endl;
  } else {
    cout << (A - B * 2) << endl;
  }

  return 0;
}
Problem p02885 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;

ll modulo(ll num, ll MOD = mod) {
  return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
  ll ans = 1;
  while (e) {
    if (e % 2)
      ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e /= 2;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  cout << fixed << setprecision(15);

  ll a, b;
  cin >> a >> b;
  cout << max(0LL, a - 2LL * b);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;

ll modulo(ll num, ll MOD = mod) {
  return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
  ll ans = 1;
  while (e) {
    if (e % 2)
      ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e /= 2;
  }
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  /* #ifndef ONLINE_JUDGE
   // for getting input from input.txt
   freopen("input.txt", "r", stdin);
   // for writing output to output.txt
   freopen("output.txt", "w", stdout);
   #endif*/
  cout << fixed << setprecision(15);

  ll a, b;
  cin >> a >> b;
  cout << max(0LL, a - 2LL * b);

  return 0;
}
Problem p02885 (C++)

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

#define ll long long
#define db double
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;

const ll mod = 1000000007;
ll po(ll k, ll n) {
  if (n == 1)
    return k % mod;
  else {
    ll a = po(k, n / 2) % mod;
    if (n % 2 == 0)
      return (a * a) % mod;
    else
      return (((a * a) % mod) * k) % mod;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (a - 2 * b > 0)
      cout << a - 2 * b << endl;
    else
      cout << "0" << endl;
  }

  return 0;
}


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

#define ll long long
#define db double
#define ld long double
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n; i >= 0; i--)
#define rep_a(i, a, n) for (int i = a; i < n; i++)
#define tr(ds, it) for (auto it = ds.begin(); it != ds.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue<int> pq;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;

const ll mod = 1000000007;
ll po(ll k, ll n) {
  if (n == 1)
    return k % mod;
  else {
    ll a = po(k, n / 2) % mod;
    if (n % 2 == 0)
      return (a * a) % mod;
    else
      return (((a * a) % mod) * k) % mod;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r" , stdin);
  // freopen("output.txt", "w" , stdout);
  // #endif
  int t = 1;
  // cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    if (a - 2 * b > 0)
      cout << a - 2 * b << endl;
    else
      cout << "0" << endl;
  }

  return 0;
}
Problem p02885 (Python)

Buggy submission (status: Runtime Error):
A = int(input())
B = int(input())

remain = max(0, A - B * 2)

print(remain)


Fixed submission:
data = input().split()
A = int(data[0])
B = int(data[1])

remain = max(0, A - B * 2)

print(remain)
Problem p02885 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii pair<long long int, long long int>
#define vi vector<long long int>
#define vii vector<pair<long long int, long long int>>
#define all(cont) cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast")

int main() {

  IOS;
  clock_t clk = clock();
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int a, b;
  cin >> a >> b;
  if (2 * b <= a)
    cout << a - (2 * b);
  else
    cout << 0;

  cerr << endl
       << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < n; i++)
#define forn1(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii pair<long long int, long long int>
#define vi vector<long long int>
#define vii vector<pair<long long int, long long int>>
#define all(cont) cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#pragma GCC optimize("Ofast")

int main() {

  IOS;
  clock_t clk = clock();
  // freopen("input.txt",  "r", stdin);
  // freopen("output.txt", "w", stdout);
  int a, b;
  cin >> a >> b;
  if (2 * b <= a)
    cout << a - (2 * b);
  else
    cout << 0;

  cerr << endl
       << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int MAX = 50;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> d(MAX);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  int k = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      ans += d.at(i) * d.at(j + k);
    }
    k++;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int MAX = 100;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> d(MAX);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  int k = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 1; j < N; j++) {
      ans += d.at(i) * d.at(j + k);
    }
    k++;
  }
  cout << ans;
  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Runtime Error):

/// HR_Bappy
//
///*******

#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define maxx 1000000005
#define MOD 1000003
#define sf(n) scanf("%lld", &n);
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define pf(n) printf("%lld\n", n)
#define pff(n, m) printf("%lld %lld\n", n, m)
#define mem(a) memset(a, 0, sizeof(a))
#define fr(i, n) for (ll i = 0; i < n; i++)
#define my_sizeof(type) ((char *)(&type + 1) - (char *)(&type))
#define pi 2 * acos(0.0)
#define F first
#define S second
#define EPS 1e-9

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    if (b)
      v.pb(b);
  }
  int c = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    if (!v[i])
      continue;
    for (int j = i + 1; j < v.size(); j++) {
      c += v[i] * v[j];
    }
  }
  cout << c << endl;
  return 0;
}


Fixed submission:

/// HR_Bappy
//
///*******

#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define maxx 1000000005
#define MOD 1000003
#define sf(n) scanf("%lld", &n);
#define sff(n, m) scanf("%lld %lld", &n, &m)
#define pf(n) printf("%lld\n", n)
#define pff(n, m) printf("%lld %lld\n", n, m)
#define mem(a) memset(a, 0, sizeof(a))
#define fr(i, n) for (ll i = 0; i < n; i++)
#define my_sizeof(type) ((char *)(&type + 1) - (char *)(&type))
#define pi 2 * acos(0.0)
#define F first
#define S second
#define EPS 1e-9

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    if (b)
      v.pb(b);
  }
  int c = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = i + 1; j < v.size(); j++) {
      c += v[i] * v[j];
    }
  }
  cout << c << endl;
  return 0;
}
Problem p02886 (C++)

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

int main(void) {
  int n;
  cin >> n;
  vector<long long> d;
  for (int i = 0; i < n; i++)
    cin >> d[i];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<long long> d(n);
  for (int i = 0; i < n; i++)
    cin >> d[i];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}
Problem p02886 (C++)

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

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  int sum = 0;
  rep(i, n) {
    for (int j = i + 1; i < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  int sum = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  int s[51];
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> s[i];
  }
  int sum = 0;
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; i < a; j++) {
      sum = sum + s[i] * s[j];
    }
  }

  cout << sum;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  int s[51];
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> s[i];
  }
  int sum = 0;
  for (int i = 0; i < a - 1; i++) {
    for (int j = i + 1; j < a; j++) {
      sum = sum + s[i] * s[j];
    }
  }

  cout << sum;

  return 0;
}
Problem p02886 (C++)

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

#define rep(i, beg, end) for (auto i = (beg); i < (end); i++)
#define rep2(name, container)                                                  \
  for (auto name = begin(container); name != end(container); name++)
#define all(cont) begin(cont), end(cont)
#define rall(cont) rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vi d;
  rep(i, 0, n) {
    ll t;
    cin >> t;
    if (t > 0)
      d.push_back(t);
  }

  const ll SENTINEL_D = 101;
  ll dp[SENTINEL_D][SENTINEL_D] = {
      0,
  };
  ll sum = 0;
  rep(i, 0, d.size() - 1) {
    ll x = d[i];
    rep(j, i + 1, d.size()) {
      ll y = d[j];
      if (dp[x][y])
        sum += dp[x][y];
      else
        sum += dp[x][y] = x * y;
    }
  }
  cout << sum << endl;

  return 0;
}


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

#define rep(i, beg, end) for (auto i = (beg); i < (end); i++)
#define rep2(name, container)                                                  \
  for (auto name = begin(container); name != end(container); name++)
#define all(cont) begin(cont), end(cont)
#define rall(cont) rbegin(cont), rend(cont)
using ll = long long;
using vi = vector<ll>;
const ll INFMAX = LLONG_MAX;
const ll INFMIN = LLONG_MIN;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vi d;
  rep(i, 0, n) {
    ll t;
    cin >> t;
    if (t > 0)
      d.push_back(t);
  }
  if (d.empty())
    d.push_back(0);

  const ll SENTINEL_D = 101;
  ll dp[SENTINEL_D][SENTINEL_D] = {
      0,
  };
  ll sum = 0;
  rep(i, 0, d.size() - 1) {
    ll x = d[i];
    rep(j, i + 1, d.size()) {
      ll y = d[j];
      if (dp[x][y])
        sum += dp[x][y];
      else
        sum += dp[x][y] = x * y;
    }
  }
  cout << sum << endl;

  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Runtime Error):
#include <iostream> //atcoder143B
using namespace std;
int main(void) {
  int n, d[n], a, i, j, all = 0;
  cin >> n;
  for (a = 0; a < n; a++)
    cin >> d[a];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      all += d[i] * d[j];
    }
  }
  cout << all << endl;
  return 0;
}

Fixed submission:
#include <iostream> //atcoder143B
using namespace std;
int main(void) {
  int n, d[100], a, i, j, all = 0;
  cin >> n;
  for (a = 0; a < n; a++)
    cin >> d[a];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      all += d[i] * d[j];
    }
  }
  cout << all << endl;
  return 0;
}
Problem p02886 (C++)

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

using namespace std;

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

  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++i) {
      sum += (v[i] * v[j]);
    }
  }
  cout << sum << endl;
}

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

using namespace std;

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

  long long sum = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      sum += (v[i] * v[j]);
    }
  }
  cout << sum << endl;
}
Problem p02886 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; i++) {
      sum = sum + a[i] * a[j];
    }
  }
  cout << sum << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      sum = sum + a[i] * a[j];
    }
  }
  cout << sum << "\n";
}
Problem p02886 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      sum += a[i] * a[j];
    }
  }
  cout << sum << endl;
}
Problem p02886 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  int n;
  int d[101];

  cin >> n;

  for (size_t i = 0; i < n; i++) {
    cin >> d[i];
  }

  int ans = 0;

  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < n; i++) {
      if (i < j) {
        ans += d[i] * d[j];
      }
    }
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

int main() {
  int n;
  int d[101];

  cin >> n;

  for (size_t i = 0; i < n; i++) {
    cin >> d[i];
  }

  int ans = 0;

  for (size_t i = 0; i < n; i++) {
    for (size_t j = 0; j < n; j++) {
      if (i < j) {
        ans += d[i] * d[j];
      }
    }
  }

  cout << ans;

  return 0;
}
Problem p02886 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int all = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; i < N; j++) {
      all += vec.at(i) * vec.at(j);
    }
  }
  int same = 0;
  for (int i = 0; i < N; i++) {
    same += vec.at(i) * vec.at(i);
  }
  cout << (all - same) / 2 << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  int all = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      all += vec.at(i) * vec.at(j);
    }
  }
  int same = 0;
  for (int i = 0; i < N; i++) {
    same += vec.at(i) * vec.at(i);
  }
  cout << (all - same) / 2 << endl;
}
Problem p02886 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  int s = 0;
  rep(i, n) for (int j = i + 1; j < n; ++i) { s += d[i] * d[j]; }
  cout << s << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d[i];
  int s = 0;
  rep(i, n) for (int j = i + 1; j < n; ++j) { s += d[i] * d[j]; }
  cout << s << endl;
  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d;
  for (int i = 0; i < n; i++)
    cin >> d.at(i);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      else {
        ans += d.at(i) * d.at(j);
      }
    }
  }
  long long t = 2;
  cout << ans / t << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++)
    cin >> d.at(i);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      else {
        ans += d.at(i) * d.at(j);
      }
    }
  }
  long long t = 2;
  cout << ans / t << endl;
}
Problem p02886 (C++)

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02886 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];

  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; i++) {
      ans += d[i] * d[j];
    }
  }

  cout << ans;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];

  int ans = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      ans += d[i] * d[j];
    }
  }

  cout << ans;

  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <vector>
using namespace std;

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

  long long total = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++i) {
      total += list[i] * list[j];
    }
  }
  cout << total << endl;
  return 0;
}


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

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

  long long total = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      total += list[i] * list[j];
    }
  }
  cout << total << endl;
  return 0;
}
Problem p02886 (C++)

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

int main() {

  int N, sum = 0;
  cin >> N;

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

  int rep = N * (N - 1) / 2;

  for (int i = 0; i < rep; i++) {
    for (int j = i; j < rep; j++) {
      if (i != j) {
        sum += d[i] * d[j];
      }
    }
  }

  cout << sum << endl;

  return 0;
}

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

int main() {

  int N, sum = 0;
  cin >> N;

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

  int rep = N * (N - 1) / 2;

  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (i != j) {
        sum += d[i] * d[j];
      }
    }
  }

  cout << sum << endl;

  return 0;
}
Problem p02886 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d;
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      count += d.at(i) * d.at(j);
    }
  }
  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      count += d.at(i) * d.at(j);
    }
  }
  cout << count << endl;
}
Problem p02886 (C++)

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

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

  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; i < n; j++) {
      ans += d[i] * d[j];
    }
  }

  cout << ans << endl;
}

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

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

  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += d[i] * d[j];
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i += 1) {
    cin >> a[i];
  }
  int A = 0;
  for (int i = 0; i < N; i += 1) {
    for (int j = i + 1; i < N; j += 1) {
      A += a[i] * a[j];
    }
  }
  cout << A << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i += 1) {
    cin >> a[i];
  }
  int A = 0;
  for (int i = 0; i < N - 1; i += 1) {
    for (int j = i + 1; j < N; j += 1) {
      A += a[i] * a[j];
    }
  }
  cout << A << endl;
}
Problem p02886 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;

void func143b() {
  int n, d[50] = {};
  int i, j, x, y, cnt = 0;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> d[i];
  for (i = 1; i < n; i++) {
    x = d[i];
    // cout << "takoyaki_" << i << ": " << x << endl;
    for (j = i + 1; j <= n; j++) {
      y = d[j];
      cnt += x * y;
      // cout << "takoyaki_" << j << ": " << y << endl;
      // cout << "x * y: " << x * y << endl;
      // cout << "cnt: " << cnt << endl;
    }
  }
  cout << cnt;
}

int main() {
  while (true) {
    // func140b();
    // func141b();
    // func142b();
    func143b();
    // func144b();
    // func145b();
    // func146b();
    // func147b();
    // func148b();
    // func149b();
    // func150b();
  }
  return 0;
}

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

void func143b() {
  int n, d[50] = {};
  int i, j, x, y, cnt = 0;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> d[i];
  for (i = 1; i < n; i++) {
    x = d[i];
    // cout << "takoyaki_" << i << ": " << x << endl;
    for (j = i + 1; j <= n; j++) {
      y = d[j];
      cnt += x * y;
      // cout << "takoyaki_" << j << ": " << y << endl;
      // cout << "x * y: " << x * y << endl;
      // cout << "cnt: " << cnt << endl;
    }
  }
  cout << cnt;
}

int main() {
  func143b();
  return 0;
}
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 count = 0;
  int i = 0;
  while (i < N - 1) {
    count++;
    int j = i + 1;
    while (j < N) {
      if (s.at(i) == s.at(j)) {
        j++;
        if (j == N - 1) {
          break;
        }
      } else {
        break;
      }
    }
    i = j;
  }
  if (s.at(N - 2) != s.at(N - 1)) {
    count++;
  }
  cout << count << endl;
}

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

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  int i = 0;
  while (i < N - 1) {
    count++;
    int j = i + 1;
    while (j < N) {
      if (s.at(i) == s.at(j)) {
        j++;
        if (j == N - 1) {
          break;
        }
      } else {
        break;
      }
    }
    i = j;
  }
  if (N == 1) {
    count = 1;
  } else if (s.at(N - 2) != s.at(N - 1)) {
    count++;
  }
  cout << count << endl;
}
Problem p02887 (C++)

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

int main() {
  int N;
  int ans = 1;
  char S[10005] = "A";
  cin >> N >> S;
  for (int i = 0; i < N - 1; ++i) {
    if (S[i] != S[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  int ans = 1;
  char S[100005] = "A";
  cin >> N >> S;
  for (int i = 0; i < N - 1; ++i) {
    if (S[i] != S[i + 1]) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
char a[20000];
int main() {
  int n;
  int sum = 0;
  scanf("%d", &n);
  scanf("%s", a);
  for (int i = 0; i <= n - 1; i++) {
    int j = i + 1;
    if (a[i] != a[j]) {
      sum += 1;
    }
  }
  printf("%d\n", sum);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
char a[200000];
int main() {
  int n;
  int sum = 0;
  scanf("%d", &n);
  scanf("%s", a);
  for (int i = 0; i <= n - 1; i++) {
    int j = i + 1;
    if (a[i] != a[j]) {
      sum += 1;
    }
  }
  printf("%d\n", sum);
  return 0;
}
Problem p02887 (C++)

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

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

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

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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  // freopen("street.in", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int main() {
  file();
  fast();
  int n;
  cin >> n;
  int ans = 0;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && str[j] == str[i])
      j++;
    i = j - 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define allr(s) s.rbegin(), s.rend()
#define RT(s) return cout << s, 0
#define watch(x) cout << (#x) << " = " << x << endl
#define sz(s) (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> row;
typedef vector<row> matrix;
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#else
  // freopen("street.in", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
int main() {
  // file();
  fast();
  int n;
  cin >> n;
  int ans = 0;
  string str;
  cin >> str;
  for (int i = 0; i < n; i++) {
    int j = i;
    while (j < n && str[j] == str[i])
      j++;
    i = j - 1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  char ar[100];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] == ar[i + 1]) {
      continue;
    }
    count++;
  }
  cout << count;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n;
  int count = 0;
  cin >> n;
  char ar[100000];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 0; i < n; i++) {
    if (ar[i] == ar[i + 1]) {
      continue;
    }
    count++;
  }
  cout << count;
}
Problem p02887 (C++)

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

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

  std::string s;
  std::cin >> s;

  int index = 1;
  while (s.size() - 1 != index) {
    if (s.at(index - 1) == s.at(index)) {
      s.erase(index, 1);
      --index;
    }

    ++index;
  }

  std::cout << s.size() << std::endl;

  return 0;
}

Fixed submission:
#include <iostream>

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

  std::string s;
  std::cin >> s;

  int index = 1;
  while (s.size() != index) {
    if (s.at(index - 1) == s.at(index)) {
      s.erase(index, 1);
      --index;
    }

    ++index;
  }

  std::cout << s.size() << std::endl;

  return 0;
}
Problem p02887 (C++)

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

int main() {

  int N, ans;
  ans = 1;
  string S;
  cin >> N, S;

  for (int i = 0; i < N - 1; 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, ans;
  ans = 1;
  string S;
  cin >> N >> S;

  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 <iostream>
using namespace std;
int main() {
  char ch[20001];
  int n, ans = 1;
  cin >> n;
  cin >> ch;
  for (int i = 1; i < n; ++i) {
    if (ch[i] != ch[i - 1])
      ++ans;
  }
  cout << ans;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  char ch[200001];
  int n, ans = 1;
  cin >> n;
  cin >> ch;
  for (int i = 1; i < n; ++i) {
    if (ch[i] != ch[i - 1])
      ++ans;
  }
  cout << ans;
}
Problem p02887 (C++)

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

using namespace std;

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

  string V;

  for (int j = 0; j < N; j++) {
    for (int i = 0; i < S.size(); i++) {
      V += S[i];
      if (S[i] == S[i + 1]) {
        i++;
      }
    }
    S = V;
    V = "";
  }

  size_t size = S.size();
  cout << size << endl;
}

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

using namespace std;

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

  string V;

  for (int j = 0; j < N; j++) {
    for (int i = 0; i < S.size(); i++) {
      V += S[i];
      if (S[i] == S[i + 1]) {
        i++;
      }
    }
    if (S.size() == V.size()) {
      break;
    }
    S = V;
    V = "";
  }

  size_t size = S.size();
  cout << size << endl;
}
Problem p02887 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n;
char a[1001];
int main() {
  int d = 1;
  int res = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != a[d]) {
      res++;
      d = i;
    }
  }
  cout << res;
}

Fixed submission:
#include <iostream>
using namespace std;
int n;
char a[100001];
int main() {
  int d = 1;
  int res = 1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] != a[d]) {
      res++;
      d = i;
    }
  }
  cout << res;
}
Problem p02887 (Python)

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3
import sys
import re


def solve(N: int, S: str):
    result = 0
    for s in set(S):
        regex = re.compile(f"{s}+")
        # print(regex.findall(S))
        result += len(regex.findall(S))
    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import re


def solve(N: int, S: str):
    result = 0
    for s in set(S):
        regex = re.compile(s + "+")
        # print(regex.findall(S))
        result += len(regex.findall(S))
    print(result)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == "__main__":
    main()
Problem p02887 (C++)

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


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int j = 0; j < n; j++) {
    if (s[j] != s[j + 1])
      c++;
  }
  cout << c << endl;
}
Problem p02887 (C++)

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

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

  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + i)) {
      count++;
    }
  }

  cout << count + 1 << endl;
}

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

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

  int count = 0;
  for (int i = 0; i + 1 < S.size(); i++) {
    if (S.at(i) != S.at(i + 1)) {
      count++;
    }
  }

  cout << count + 1 << endl;
}
Problem p02887 (C++)

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<char> a(n);
  int i = 0;
  while (1) {
    if (s.at(i) == s.at(i + 1)) {
      if (i == s.size() - 2) {
        s.erase(s.begin() + (i + 1));
        break;
      } else
        s.erase(s.begin() + (i + 1));
    } else if (i == s.size() - 2)
      break;
    else
      i++;
  }
  cout << s.size() << endl;
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<char> a(n);
  int i = 0;
  while (1) {
    if (s.size() == 1)
      break;
    else if (s.at(i) == s.at(i + 1)) {
      if (i == s.size() - 2) {
        s.erase(s.begin() + (i + 1));
        break;
      } else
        s.erase(s.begin() + (i + 1));
    } else if (i == s.size() - 2)
      break;
    else
      i++;
  }
  cout << s.size() << endl;
  return 0;
}
Problem p02887 (C++)

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

int main() {
  int N;
  cin >> N;
  char S[N];
  cin >> S;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 1; i + j < N; j++) {
      if (S[i] != S[i + j]) {
        ans++;
        i += j - 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream>  //C++
#include <math.h>
#include <queue> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>    //C++
#include <vector>    //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)

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

  char s[100];
  rep(i, 0, n) cin >> s[i];
  int Ans = 1;

  rep(i, 0, n - 1) {
    if (s[i] == s[i + 1]) {
      continue;
    } else
      Ans++;
  }

  cout << Ans;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream>  //C++
#include <math.h>
#include <queue> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>    //C++
#include <vector>    //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)

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

  char s[100000];
  rep(i, 0, n) cin >> s[i];
  int Ans = 1;

  rep(i, 0, n - 1) {
    if (s[i] == s[i + 1]) {
      continue;
    } else
      Ans++;
  }

  cout << Ans;
}
Problem p02887 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
char a[1000000];
int main() {
  int n, i;
  scanf("%d", &n);
  scanf("%s", &a);
  int sum = 0;
  for (i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j]) {
        a[j] = 0;
      } else {
        if (a[i] != 0)
          sum++;
        break;
      }
    }
  }
  printf("%d", sum + 1);
}

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

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int count = 1;

  for (int i = 0; i < N; i++) {
    if (S.at(i) != S.at(i + 1))
      count++;
  }

  cout << count << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int count = 1;

  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + 1))
      count++;
  }

  cout << count << endl;
}
Problem p02887 (Python)

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

conti = True
while conti:
    conti = False
    for count, char in enumerate(s):
        if (count - 1) >= 0 and s[count] == s[count - 1]:
            s = s[:count] + s[count + 1 :]
            conti = True
            break

print(len(s))


Fixed submission:
n = int(input())
s = input()

conti = True
while conti:
    try:
        conti = False
        for count, char in enumerate(s):
            if (count - 1) >= 0 and s[count] == s[count - 1]:
                s = s[:count] + s[count + 1 :]
                conti = True
    except IndexError:
        pass

print(len(s))
Problem p02887 (C++)

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

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, result = 0;
  string slime;
  cin >> a;
  cin >> slime;
  for (int i = 0; i < a; i++) {
    if (i == 0 || slime[i] != slime[i - 1])
      result++;
  }
  cout << result << endl;
  return 0;
}
Problem p02887 (C++)

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

char s[10005];

int main() {
  int n;
  int slimes = 1;
  cin >> n;
  cin >> s;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      slimes++;
  }
  cout << slimes << endl;
  return 0;
}

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

char s[100005];

int main() {
  int n;
  int slimes = 1;
  cin >> n;
  cin >> s;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      slimes++;
  }
  cout << slimes << endl;
  return 0;
}