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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n;
int calc(int x) {
  //	printf("%d\n", x);
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += (a[i] - x) * (a[i] - x);
  }
  return res;
}
map<char, vector<int>> v;
int main() {
  // freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  int tc;
  // scanf("%d", &tc);
  tc = 1;
  int h = -200;
  int l = 200;
  for (int tt = 1; tt <= tc; ++tt) {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); ++i) {
      v[s[i]].push_back(i);
    }
    for (int i = 0; i < (int)s.size() - 1; ++i) {
      if (s[i] == s[i + 1]) {
        printf("%d %d\n", i + 1, i + 2);
        return 0;
      }
      if (i + 2 < (int)s.size() && s[i] == s[i + 2]) {
        printf("%d %d\n", i + 1, i + 3);
        return 0;
      }
    }
    for (auto vv : v) {
      vector<int> now = vv.second;
      for (int i = 0; i < (int)now.size(); ++i) {
        for (int j = i + 1; j < (int)now.size(); ++j) {
          int tot = now[j] - now[i] + 1;
          int cur = j - i + 1;
          if (cur > tot / 2) {
            printf("%d %d\n", now[i] + 1, now[j] + 1);
            return 0;
          }
        }
      }
    }
    printf("-1 -1\n");

    //	fprintf(stderr, "caso de teste %d resolvido\n", tt);
    //	fflush(stderr);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
int n;
int calc(int x) {
  //	printf("%d\n", x);
  int res = 0;
  for (int i = 0; i < n; ++i) {
    res += (a[i] - x) * (a[i] - x);
  }
  return res;
}
map<char, vector<int>> v;
int main() {
  // freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  int tc;
  // scanf("%d", &tc);
  tc = 1;
  int h = -200;
  int l = 200;
  for (int tt = 1; tt <= tc; ++tt) {
    string s;
    cin >> s;
    for (int i = 0; i < (int)s.size(); ++i) {
      v[s[i]].push_back(i);
    }
    for (int i = 0; i < (int)s.size() - 1; ++i) {
      if (s[i] == s[i + 1]) {
        printf("%d %d\n", i + 1, i + 2);
        return 0;
      }
      if (i + 2 < (int)s.size() && s[i] == s[i + 2]) {
        printf("%d %d\n", i + 1, i + 3);
        return 0;
      }
    }
    for (auto vv : v) {
      vector<int> now = vv.second;
      for (int i = 0; i < (int)now.size(); ++i) {
        for (int j = i + 1; j < (int)now.size(); ++j) {
          int tot = now[j] - now[i] + 1;
          if (tot > 25)
            break;
          int cur = j - i + 1;
          if (cur > tot / 2) {
            printf("%d %d\n", now[i] + 1, now[j] + 1);
            return 0;
          }
        }
      }
    }
    printf("-1 -1\n");

    //	fprintf(stderr, "caso de teste %d resolvido\n", tt);
    //	fflush(stderr);
  }

  return 0;
}
Problem p04032 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, n)
#define pb push_back
#define en "\n"
#define ITER(i, a) for (typeof(a.begin()) i = a.begin(); i != a.end(); i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a, b) memset((a),(b),sizeof((a))
typedef map<int, int> MI;
typedef pair<int, int> PI;
typedef vector<int> VI;
typedef long long int LL;

int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  for (int i = 0; i <= s.size() - 3; i++) {
    int a[26] = {0};
    for (int j = i; j < i + 3; j++)
      a[s[j] - 'a']++;
    for (int k = 0; k < 26; k++) {
      if (a[k] >= 2) {
        cout << i + 1 << " " << i + 3;
        return 0;
      }
    }
  }
  cout << "-1 -1";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, n)
#define pb push_back
#define en "\n"
#define ITER(i, a) for (typeof(a.begin()) i = a.begin(); i != a.end(); i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a, b) memset((a),(b),sizeof((a))
typedef map<int, int> MI;
typedef pair<int, int> PI;
typedef vector<int> VI;
typedef long long int LL;

int main() {
  // your code goes here
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int l = s.size();
  l = l - 2;
  for (int i = 0; i <= l; i++) {
    int a[26] = {0};
    for (int j = i; j < i + 2; j++)
      a[s[j] - 'a']++;
    for (int k = 0; k < 26; k++) {
      if (a[k] > 1) {
        cout << i + 1 << " " << i + 2;
        return 0;
      }
    }
  }
  l++;
  for (int i = 0; i <= l; i++) {
    int a[26] = {0};
    for (int j = i; j < i + 3; j++)
      a[s[j] - 'a']++;
    for (int k = 0; k < 26; k++) {
      if (a[k] >= 2) {
        cout << i + 1 << " " << i + 3;
        return 0;
      }
    }
  }
  cout << "-1 -1";
  return 0;
}
Problem p04032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (INT_MAX / 3)
#define PSB push_back
#define M 1000000007
typedef long long LL;
// #define int long long

/*
//booooooooooooost
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/

int inv_mod(int a, int m) {
  int b, x, u, q, tmp;

  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? m + x : x;
}

signed main() {

  const int AS = 97;
  const int NR = 26;
  string s;
  cin >> s;
  int N = s.size();
  int ans[2] = {-1, -1};

  int arr[26];
  int sum = 0;

  REP(i, N) {
    REP(j, NR) { arr[j] = 0; }
    arr[int(s[i] - AS)] = 1;

    FOR(j, i + 1, N) {
      ++arr[int(s[j] - AS)];
      REP(k, NR) {
        if ((j - i + 1) / 2 < arr[k]) {
          ans[0] = i + 1;
          ans[1] = j + 1;
          break;
        }
      }
    }
  }

  cout << ans[0] << " " << ans[1] << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define INF (INT_MAX / 3)
#define PSB push_back
#define M 1000000007
typedef long long LL;
// #define int long long

/*
//booooooooooooost
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int)
*/

int inv_mod(int a, int m) {
  int b, x, u, q, tmp;

  b = m;
  x = 1;
  u = 0;
  while (b > 0) {
    q = a / b;
    tmp = u;
    u = x - q * u;
    x = tmp;
    tmp = b;
    b = a - q * b;
    a = tmp;
  }

  return (x < 0) ? m + x : x;
}

signed main() {

  const int AS = 97;
  const int NR = 26;
  string s;
  cin >> s;
  int N = s.size();
  int ans[2] = {-1, -1};

  REP(i, N - 1) {
    if (s[i] == s[i + 1]) {
      ans[0] = i + 1;
      ans[1] = i + 2;
      break;
    } else if (i < N - 2 && s[i] == s[i + 2]) {
      ans[0] = i + 1;
      ans[1] = i + 3;
      break;
    }
  }

  cout << ans[0] << " " << ans[1] << endl;

  return 0;
}
Problem p04032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

string s;

int cnt[26];
bool good(int x, int y) {
  for (int i = 0; i < 26; i++) {
    cnt[i] = 0;
  }

  int l = y - x + 1;
  for (int i = x; i <= y; i++) {
    cnt[s[i] - 'a']++;
    if (cnt[s[i] - 'a'] > l / 2) {
      return true;
    }
  }
  return false;
}

void solve() {
  cin >> s;
  int n = (int)s.length();
  for (int l = 2; l <= n; l++) {
    for (int i = 0; i + l - 1 < n; i++) {
      int j = i + l - 1;
      if (good(i, j)) {
        cout << i + 1 << " " << j + 1;
        return;
      }
    }
  }
  cout << -1 << " " << -1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  // freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
  solve();
  cout << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

string s;

int cnt[26];
bool good(int x, int y) {
  for (int i = 0; i < 26; i++) {
    cnt[i] = 0;
  }

  int l = y - x + 1;
  for (int i = x; i <= y; i++) {
    cnt[s[i] - 'a']++;
    if (cnt[s[i] - 'a'] > l / 2) {
      return true;
    }
  }
  return false;
}

void solve() {
  cin >> s;
  int n = (int)s.length();
  for (int l = 2; l <= min(100, n); l++) {
    for (int i = 0; i + l - 1 < n; i++) {
      int j = i + l - 1;
      if (good(i, j)) {
        cout << i + 1 << " " << j + 1;
        return;
      }
    }
  }
  cout << -1 << " " << -1;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  // freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
  solve();
  cout << "\n";
  return 0;
}
Problem p04032 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <sstream>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define cerr                                                                   \
  if (false)                                                                   \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

string S;
const int alp = 'z' - 'a' + 1;
int sizes[alp];
ll sss = 0;
int pos[2][alp];

bool isuUnbalance() {
  int buf = sss / 2;

  REP(i, alp) {
    if (sizes[i] > buf)
      return true;
  }

  return false;
}

void solve() {

  REP(s, S.size() - 1) {
    int len = 0;
    sss = 0;
    REP(i, alp) sizes[i] = 0;

    for (int i = s; i < S.size(); ++i) {
      sizes[S[i] - 'a']++;
      len++;
      sss++;
      if (len < 2)
        continue;
      if (isuUnbalance()) {
        cout << (s + 1) << " " << (i + 1) << endl;
        return;
      }
    }
  }

  cout << "-1 -1" << endl;
}

int main() {
  cin >> S;

  if (S.size() < 2) {
    cout << "-1 -1" << endl;
  } else {
    solve();
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <sstream>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define cerr                                                                   \
  if (false)                                                                   \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

string S;
const int alp = 'z' - 'a' + 1;
int sizes[alp];
ll sss = 0;
int pos[2][alp];

bool isuUnbalance() {
  int buf = sss / 2;

  REP(i, alp) {
    if (sizes[i] > buf)
      return true;
  }

  return false;
}

void solve() {

  REP(s, S.size() - 1) {
    int len = 0;
    sss = 0;
    REP(i, alp) sizes[i] = 0;

    for (int i = s; i < S.size() && i - s < 3; ++i) {
      sizes[S[i] - 'a']++;
      len++;
      sss++;
      if (len < 2)
        continue;
      if (isuUnbalance()) {
        cout << (s + 1) << " " << (i + 1) << endl;
        return;
      }
    }
  }

  cout << "-1 -1" << endl;
}

int main() {
  cin >> S;

  if (S.size() < 2) {
    cout << "-1 -1" << endl;
  } else {
    solve();
  }

  return 0;
}
Problem p04032 (C++)

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

int main() {
  string s;
  cin >> s;

  int l = -1, r = -1;
  for (int i = 0; i < s.length() - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      l = i + 1;
      r = i + 2;
      break;
    } else if (s.at(i) == s.at(i + 2)) {
      l = i + 1;
      r = i + 3;
      break;
    }
  }

  cout << l << " " << r << endl;
}

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

int main() {
  string s;
  cin >> s;

  int l = -1, r = -1;
  for (int i = 0; i < s.length() - 1; i++) {
    if (s.at(i) == s.at(i + 1)) {
      l = i + 1;
      r = i + 2;
      break;
    }
  }

  for (int i = 0; i < s.length() - 2; i++) {
    if (s.at(i) == s.at(i + 2)) {
      l = i + 1;
      r = i + 3;
      break;
    }
  }

  cout << l << " " << r << endl;
}
Problem p04032 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main() {
  int flag = 0;
  char s[10005];
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == s[i + 1]) {
      printf("%d %d\n", i + 1, i + 2);
      flag = 1;
      break;
    } else if (i < strlen(s) - 1 && s[i] == s[i + 2]) {
      printf("%d %d\n", i + 1, i + 3);
      flag = 1;
      break;
    }
  }
  if (!flag)
    printf("-1 -1\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int main() {
  int flag = 0;
  char s[100005];
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++) {
    if (s[i] == s[i + 1]) {
      printf("%d %d\n", i + 1, i + 2);
      flag = 1;
      break;
    } else if (i < strlen(s) - 1 && s[i] == s[i + 2]) {
      printf("%d %d\n", i + 1, i + 3);
      flag = 1;
      break;
    }
  }
  if (!flag)
    printf("-1 -1\n");
  return 0;
}
Problem p04032 (C++)

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

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

#define long long ll

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> pre_cnt(n, vector<int>(26, 0));
  char temp;
  int base = int('a');
  rep(i, n) {
    temp = s[i];
    pre_cnt[i] = pre_cnt[max(i - 1, 0)];
    pre_cnt[i][int(temp) - base] += 1;
  }
  int cnt;
  if (s.size() < 2) {
    cout << -1 << " " << -1 << endl;
    return 0;
  }
  if (s.size() == 2) {
    int max_cnt = 0;
    for (int k = 0; k < 26; k++) {
      cnt = pre_cnt[1][k];
      max_cnt = max(max_cnt, cnt);
    }
    if (max_cnt * 2 > 2) {
      cout << 1 << " " << 2 << endl;
      return 0;
    } else {
      cout << -1 << " " << -1 << endl;
      return 0;
    }
  }
  rep(i, n) {

    for (int j = i + 2; j < n; j++) {
      int max_cnt = 0;
      if (i > 0) {
        for (int k = 0; k < 26; k++) {
          cnt = pre_cnt[j][k] - pre_cnt[i - 1][k];
          max_cnt = max(max_cnt, cnt);
        }
      } else {
        for (int k = 0; k < 26; k++) {
          cnt = pre_cnt[j][k];
          max_cnt = max(max_cnt, cnt);
        }
      }
      if (i > 0) {
        if (max_cnt * 2 > j - i + 1) {
          cout << i + 1 << " " << j + 1 << endl;
          return 0;
        }
      } else {
        if (max_cnt * 2 > j + 1) {
          cout << 1 << " " << j + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


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

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

#define long long ll

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> pre_cnt(n, vector<int>(26, 0));
  char temp;
  int base = int('a');
  rep(i, n) {
    temp = s[i];
    pre_cnt[i] = pre_cnt[max(i - 1, 0)];
    pre_cnt[i][int(temp) - base] += 1;
  }
  int cnt;
  if (s.size() < 2) {
    cout << -1 << " " << -1 << endl;
    return 0;
  }
  if (s.size() == 2) {
    int max_cnt = 0;
    for (int k = 0; k < 26; k++) {
      cnt = pre_cnt[1][k];
      max_cnt = max(max_cnt, cnt);
    }
    if (max_cnt * 2 > 2) {
      cout << 1 << " " << 2 << endl;
      return 0;
    } else {
      cout << -1 << " " << -1 << endl;
      return 0;
    }
  }
  rep(i, n) {

    for (int j = i + 2; j < min(n, i + 3); j++) {
      int max_cnt = 0;
      if (i > 0) {
        for (int k = 0; k < 26; k++) {
          cnt = pre_cnt[j][k] - pre_cnt[i - 1][k];
          max_cnt = max(max_cnt, cnt);
        }
      } else {
        for (int k = 0; k < 26; k++) {
          cnt = pre_cnt[j][k];
          max_cnt = max(max_cnt, cnt);
        }
      }
      if (i > 0) {
        if (max_cnt * 2 > j - i + 1) {
          cout << i + 1 << " " << j + 1 << endl;
          return 0;
        }
      } else {
        if (max_cnt * 2 > j + 1) {
          cout << 1 << " " << j + 1 << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}
Problem p04032 (C++)

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

#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define endl "\n"
#define repp(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
const int N = 1e5 + 5;

string s;

string substr(int i, int j) {
  string str = "";
  int k;
  for (k = i; k <= j; k++) {
    str += s[k];
  }
  return str;
}

bool ok(string x) {
  vector<ll> cnt(27, 0);
  for (ll i : x)
    cnt[i - 'a']++;
  for (ll i : x) {
    if (cnt[i - 'a'] > (ll)x.size() / 2)
      return 1;
  }
  return 0;
}

int32_t main() {
  IOS;
  cin >> s;
  int n = s.size();
  int cur = 2;
  int i = 0;
  int j = 0;
  int k = 0;
  for (cur = 2; cur <= n; cur++) {
    for (j = cur - 1; j < n; j++) {
      string str = substr(j - cur + 1, j);
      if (ok(str) == 1) {
        cout << j - cur + 2 << " " << j + 1 << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 " << endl;
}


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

#define int long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define endl "\n"
#define repp(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
const int N = 1e5 + 5;

string s;

string substr(int i, int j) {
  string str = "";
  int k;
  for (k = i; k <= j; k++) {
    str += s[k];
  }
  return str;
}

bool ok(string x) {
  vector<ll> cnt(27, 0);
  for (ll i : x)
    cnt[i - 'a']++;
  for (ll i : x) {
    if (cnt[i - 'a'] > (ll)x.size() / 2)
      return 1;
  }
  return 0;
}

int32_t main() {
  IOS;
  cin >> s;
  int n = s.size();
  int cur = 2;
  int i = 0;
  int j = 0;
  int k = 0;
  for (cur = 2; cur <= min(n, 5ll); cur++) {
    for (j = cur - 1; j < n; j++) {
      string str = substr(j - cur + 1, j);
      if (ok(str) == 1) {
        cout << j - cur + 2 << " " << j + 1 << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 " << endl;
}
Problem p04032 (C++)

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

bool ub(string s, int a, int b) {
  vector<char> chr(1, s.at(a - 1));
  vector<int> cnt(1, 1);
  for (int i = a; i < b; i++) {
    for (int j = 0; j < chr.size(); j++) {
      if (s.at(i) == chr.at(j)) {
        cnt.at(j)++;
      } else if (j = chr.size() - 1)
        chr.push_back(s.at(i));
    }
  }
  sort(cnt.begin(), cnt.end());
  if (2 * cnt.at(cnt.size() - 1) > b - a + 1)
    return true;
  else
    return false;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = -1;
  int b = -1;
  bool bk = false;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (ub(s, i, j)) {
        a = i;
        b = j;
        bk = true;
        break;
      }
    }
    if (bk)
      break;
  }
  cout << a << " " << b << endl;
}

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

bool ub(string s, int a, int b) {
  vector<char> chr(1, s.at(a - 1));
  vector<int> cnt(1, 1);
  for (int i = a; i < b; i++) {
    for (int j = 0; j < chr.size(); j++) {
      if (s.at(i) == chr.at(j)) {
        cnt.at(j)++;
      } else if (j = chr.size() - 1)
        chr.push_back(s.at(i));
    }
  }
  sort(cnt.begin(), cnt.end());
  if (2 * cnt.at(cnt.size() - 1) > b - a + 1)
    return true;
  else
    return false;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int a = -1;
  int b = -1;
  bool bk = false;
  for (int i = 1; i < 4; i++) {
    for (int j = 1; j + i <= n; j++) {
      if (ub(s, j, j + i)) {
        a = j;
        b = j + i;
        bk = true;
        break;
      }
    }
    if (bk)
      break;
  }
  cout << a << " " << b << endl;
}
Problem p04033 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b = map(int, input().split())
p = 1
for i in range(a, b + 1):
    p *= i
if p > 0:
    print("Positive")
elif p == 0:
    print("Zero")
else:
    print("Negative")


Fixed submission:
a, b = map(int, input().split())
res = "Positive"
if b < 0:
    if (b - a + 1) & 1:
        res = "Negative"
elif b >= 0:
    if a <= 0:
        res = "Zero"
print(res)
Problem p04033 (C++)

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

using ll = long long;

int main() {
  ll a, b;
  std::cin >> a >> b;

  ll num = 1LL;
  for (ll i = a; i <= b; i++) {
    if (i < 0)
      num *= -1;
    if (i == 0)
      num = 0LL;
  }

  std::string ans = "Zero";
  if (num > 0)
    ans = "Positive";
  if (num < 0)
    ans = "Negative";
  std::cout << ans << std::endl;

  return 0;
}


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

using ll = long long;

int main() {
  ll a, b;
  std::cin >> a >> b;

  ll num = 1LL;
  ll max_value = std::min(0LL, b);
  for (ll i = a; i <= max_value; i++) {
    if (i < 0)
      num *= -1;
    if (i == 0)
      num = 0LL;
  }

  std::string ans = "Zero";
  if (num > 0)
    ans = "Positive";
  if (num < 0)
    ans = "Negative";
  std::cout << ans << std::endl;

  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int N, M, K, A, B, C, ans = 0, cnt = 0;
string S, T;
vector<int> P, Q;
vector<pair<int, int>> PP;
bool CAN = false;

int main() {
  cin >> N >> M;
  int X[M + 1], Y[M + 1], num[N + 1];
  bool red[N + 1];

  RREP(i, N) {
    num[i] = 1;
    red[i] = false;
  }

  red[1] = true;

  RREP(i, M) cin >> X[i] >> Y[i];

  RREP(i, M) {
    if (red[X[i]]) {
      red[Y[i]] = true;
    }
    num[X[i]]--;
    num[Y[i]]++;
    if (num[X[i]] == 0)
      red[X[i]] = false;
  }

  RREP(i, N) {
    if (red[X[i]] == true)
      ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define ll long long
#define itn int
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FFOR(i, 1, n)
#define SORT(V) sort((V).begin(), (V).end())
#define REVERSE(V) reverse((V).begin(), (V).end())
#define INF ((1LL << 62) - (1LL << 31))
#define MOD 1000000007
using namespace std;

int N, M, K, A, B, C, ans = 0, cnt = 0;
string S, T;
vector<int> P, Q;
vector<pair<int, int>> PP;
bool CAN = false;

int main() {
  cin >> N >> M;
  int X[M + 1], Y[M + 1], num[N + 1];
  bool red[N + 1];

  RREP(i, N) {
    num[i] = 1;
    red[i] = false;
  }

  red[1] = true;

  RREP(i, M) cin >> X[i] >> Y[i];

  RREP(i, M) {
    if (red[X[i]]) {
      red[Y[i]] = true;
    }
    num[X[i]]--;
    num[Y[i]]++;
    if (num[X[i]] == 0)
      red[X[i]] = false;
  }

  RREP(i, N) if (red[i]) ans++;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
using namespace std;
signed main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vec(a, n);
  vec(b, n);
  vec(c, n);
  vec(d, n);
  REP(i, n) {
    c[i] = 0;
    d[i] = 1;
  }
  c[0] = 1;
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    d[a[i]]--;
    d[b[i]]++;
    if (c[a[i]] == 1) {
      c[b[i]] = 1;
    }
    if (d[a[i]] == 0) {
      c[a[i]] = 0;
    }
  }
  REP(i, n) {
    if (c[i] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
using namespace std;
signed main() {
  int n, m, ans = 0;
  cin >> n >> m;
  vec(a, m);
  vec(b, m);
  vec(c, n);
  vec(d, n);
  REP(i, n) {
    c[i] = 0;
    d[i] = 1;
  }
  c[0] = 1;
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    d[a[i]]--;
    d[b[i]]++;
    if (c[a[i]] == 1) {
      c[b[i]] = 1;
    }
    if (d[a[i]] == 0) {
      c[a[i]] = 0;
    }
  }
  REP(i, n) {
    if (c[i] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> X(N), Y(N), cnt(N, 1);
  for (int i = 0; i < M; i++)
    cin >> X.at(i) >> Y.at(i);
  vector<bool> B(N, false);
  B.at(0) = true;
  for (int i = 0; i < M; i++) {
    int x = X.at(i);
    int y = Y.at(i);
    cnt.at(x - 1)--;
    cnt.at(y - 1)++;
    if (B.at(x - 1))
      B.at(y - 1) = true;
    if (cnt.at(x - 1) == 0)
      B.at(x - 1) = false;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i))
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> X(M), Y(M), cnt(N, 1);
  for (int i = 0; i < M; i++)
    cin >> X.at(i) >> Y.at(i);
  vector<bool> B(N, false);
  B.at(0) = true;
  for (int i = 0; i < M; i++) {
    int x = X.at(i);
    int y = Y.at(i);
    cnt.at(x - 1)--;
    cnt.at(y - 1)++;
    if (B.at(x - 1))
      B.at(y - 1) = true;
    if (cnt.at(x - 1) == 0)
      B.at(x - 1) = false;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (B.at(i))
      ans++;
  }
  cout << ans << endl;
}
Problem p04034 (C++)

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

using namespace std;

int s[10001];
bool h[10001];

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

  for (int i = 1; i <= n; i++) {
    s[i] = 1;
    h[i] = false;
  }

  h[1] = true;
  int num = 1;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    s[y]++;
    if (!h[y] && h[x]) {
      h[y] = true;
      num++;
    }

    s[x]--;
    if (s[x] == 0 && h[x]) {
      h[x] = false;
      num--;
    }
  }

  cout << num << endl;

  return 0;
}

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

using namespace std;

int s[100001];
bool h[100001];

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

  for (int i = 1; i <= n; i++) {
    s[i] = 1;
    h[i] = false;
  }

  h[1] = true;
  int num = 1;

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;

    s[y]++;
    if (!h[y] && h[x]) {
      h[y] = true;
      num++;
    }

    s[x]--;
    if (s[x] == 0 && h[x]) {
      h[x] = false;
      num--;
    }
  }

  cout << num << endl;

  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> num(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  rep(i, 0, N) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]) {
      red[y] = true;
    }
    num[x]--;
    num[y]++;
    if (num[x] == 0) {
      red[x] = false;
    }
  }
  ll ans = 0;
  rep(i, 0, N) {
    if (red[i])
      ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define mod 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> num(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  rep(i, 0, M) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]) {
      red[y] = true;
    }
    num[x]--;
    num[y]++;
    if (num[x] == 0) {
      red[x] = false;
    }
  }
  ll ans = 0;
  rep(i, 0, N) {
    if (red[i])
      ans++;
  }
  cout << ans << endl;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()), ((v).end())
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long power(int n, int k) {
  long long power = 1;
  for (int i = 0; i < k; i++) {
    power *= n;
  }
  return power;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
int dp[100050];
int arr[100050] = {0};
int main() {
  fast();
  freopen("input.txt", "r", stdin);
  for (int i = 0; i < 100050; i++)
    arr[i] = 1;
  int n, m, x, y;
  cin >> n >> m;
  dp[1] = 1;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    arr[x]--;
    arr[y]++;
    if (dp[x] == 1 && arr[x] == 0) {
      dp[x] = 0;
      dp[y] = 1;
    } else if (dp[x] == 1 && arr[x] != 0)
      dp[y] = 1;
  }
  ll cnt = 0;
  for (int i = 0; i <= 100000; i++) {
    if (dp[i] == 1)
      cnt++;
  }
  cout << cnt;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
typedef vector<int> vi;
#define all(v) ((v).begin()), ((v).end())
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long power(int n, int k) {
  long long power = 1;
  for (int i = 0; i < k; i++) {
    power *= n;
  }
  return power;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
// freopen("input.txt" ,"r",stdin );
// freopen("output.txt","w",stdout);
int dp[100050];
int arr[100050] = {0};
int main() {
  fast();
  for (int i = 0; i < 100050; i++)
    arr[i] = 1;
  int n, m, x, y;
  cin >> n >> m;
  dp[1] = 1;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    arr[x]--;
    arr[y]++;
    if (dp[x] == 1 && arr[x] == 0) {
      dp[x] = 0;
      dp[y] = 1;
    } else if (dp[x] == 1 && arr[x] != 0)
      dp[y] = 1;
  }
  ll cnt = 0;
  for (int i = 0; i <= 100000; i++) {
    if (dp[i] == 1)
      cnt++;
  }
  cout << cnt;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lim 10000
int main() {
  int n, m, x, y;
  int num[lim + 1];
  bool f[lim + 1] = {};
  fill(num, num + lim + 1, 1);
  f[1] = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (f[x])
      f[y] = true;
    num[x]--;
    num[y]++;
    if (num[x] == 0)
      f[x] = false;
  }
  cout << count(f, f + lim + 1, true) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lim 100000
int main() {
  int n, m, x, y;
  int num[lim + 1];
  bool f[lim + 1] = {};
  fill(num, num + lim + 1, 1);
  f[1] = true;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    if (f[x])
      f[y] = true;
    num[x]--;
    num[y]++;
    if (num[x] == 0)
      f[x] = false;
  }
  cout << count(f, f + lim + 1, true) << endl;
}
Problem p04034 (C++)

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

#define mp make_pair
#define pb push_back
#define pf push_front
#define pbp pop_back
#define pfp pop_front
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define ios_base ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define open(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 3 * 1e3 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, m, x, y;
int ok[N], cnt[N];
int main() {
  ios_base cin >> n >> m;
  ok[1] = 1;
  for (int i = 1; i <= n; i++) {
    cnt[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (ok[x] == 1 && cnt[x] == 1) {
      ok[x] = 0;
      ok[y] = 1;
    } else if (ok[x] == 1) {
      ok[y] = 1;
    }
    cnt[x]--;
    cnt[y]++;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ok[i] == 1)
      cnt++;
  }
  cout << cnt;
  return 0;
}


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

#define mp make_pair
#define pb push_back
#define pf push_front
#define pbp pop_back
#define pfp pop_front
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define ios_base ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define open(x) freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout)
#define F first
#define S second

using namespace std;

typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18;
const double eps = 1e-5;

int n, m, x, y;
int ok[N], cnt[N];
int main() {
  ios_base cin >> n >> m;
  ok[1] = 1;
  for (int i = 1; i <= n; i++) {
    cnt[i] = 1;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    if (ok[x] == 1 && cnt[x] == 1) {
      ok[x] = 0;
      ok[y] = 1;
    } else if (ok[x] == 1) {
      ok[y] = 1;
    }
    cnt[x]--;
    cnt[y]++;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (ok[i] == 1)
      cnt++;
  }
  cout << cnt;
  return 0;
}
Problem p04034 (C++)

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

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

  int n, m;
  cin >> n >> m;
  vector<int> num(n, 1), red(n, 0);
  red[0] = 1;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]) {
      if (num[x] > 1) {
        red[y] = 1;
        num[x]--;
        num[y]++;
      } else {
        red[y] = 1;
        num[x]--;
        num[y]++;
        red[x] = 0;
      }
    } else {
      num[x]--;
      num[y]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += red[i];
  }
  cout << ans << endl;
  return 0;
}

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

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

  int n, m;
  cin >> n >> m;
  vector<int> num(n, 1), red(n, 0);
  red[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]) {
      if (num[x] > 1) {
        red[y] = 1;
        num[x]--;
        num[y]++;
      } else {
        red[y] = 1;
        num[x]--;
        num[y]++;
        red[x] = 0;
      }
    } else {
      num[x]--;
      num[y]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += red[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<ll> &v) {
  std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
  std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2018/09/09/015414
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> x(N), y(N);
  // 1番目の箱には赤いボールが1 個入っています。 また、 2 ～ N
  /// 番目の箱には白いボールが 1 個ずつ入っています。
  REP(i, M) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<ll> cnt(N, 1);
  vector<bool> flag(N, false);
  flag[0] = true;
  REP(i, M) {
    cnt[x[i]]--;
    cnt[y[i]]++;
    if (flag[x[i]]) {
      flag[y[i]] = true;
    }
    if (cnt[x[i]] == 0) {
      flag[x[i]] = false;
    }
  }
  ll res = 0;
  REP(i, N) {
    if (flag[i]) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<ll> &v) {
  std::for_each(v.begin(), v.end(), [](ll x) { std::cout << x << " "; });
  std::cout << std::endl;
}
// http://drken1215.hatenablog.com/entry/2018/09/09/015414
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> x(M), y(M);
  // 1番目の箱には赤いボールが1 個入っています。 また、 2 ～ N
  /// 番目の箱には白いボールが 1 個ずつ入っています。
  REP(i, M) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  vector<ll> cnt(N, 1);
  vector<bool> flag(N, false);
  flag[0] = true;
  REP(i, M) {
    cnt[x[i]]--;
    cnt[y[i]]++;
    if (flag[x[i]]) {
      flag[y[i]] = true;
    }
    if (cnt[x[i]] == 0) {
      flag[x[i]] = false;
    }
  }
  ll res = 0;
  REP(i, N) {
    if (flag[i]) {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}
Problem p04034 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n), y(n), ball(n, 1);
  bool poss[n];

  for (int i = 0; i < n; i++)
    poss[i] = false;
  poss[0] = true;

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    if (poss[x[i]] && ball[x[i]] > 1) {
      poss[y[i]] = true;
      // ball[x[i]]--;
      // ball[y[i]]++;
    } else if (poss[x[i]]) {
      poss[y[i]] = true;
      poss[x[i]] = false;
    }
    ball[x[i]]--;
    ball[y[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (poss[i])
      ans++;

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m), ball(n, 1);
  bool poss[n];

  for (int i = 0; i < n; i++)
    poss[i] = false;
  poss[0] = true;

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    if (poss[x[i]] && ball[x[i]] > 1) {
      poss[y[i]] = true;
      // ball[x[i]]--;
      // ball[y[i]]++;
    } else if (poss[x[i]]) {
      poss[y[i]] = true;
      poss[x[i]] = false;
    }
    ball[x[i]]--;
    ball[y[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++)
    if (poss[i])
      ans++;

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 5005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, M, ct[MAXN], cnt[MAXN];
void Solve() {
  read(N);
  read(M);
  for (int i = 1; i <= N; ++i)
    cnt[i] = 1;
  ct[1] = 1;
  int x, y;
  for (int i = 1; i <= M; ++i) {
    read(x);
    read(y);
    cnt[x]--;
    cnt[y]++;
    if (ct[x]) {
      ct[y] = 1;
    }
    if (cnt[x] == 0)
      ct[x] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += ct[i];
  }
  out(ans);
  enter;
}

int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
// #define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T> void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
int N, M, ct[MAXN], cnt[MAXN];
void Solve() {
  read(N);
  read(M);
  for (int i = 1; i <= N; ++i)
    cnt[i] = 1;
  ct[1] = 1;
  int x, y;
  for (int i = 1; i <= M; ++i) {
    read(x);
    read(y);
    cnt[x]--;
    cnt[y]++;
    if (ct[x]) {
      ct[y] = 1;
    }
    if (cnt[x] == 0)
      ct[x] = 0;
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans += ct[i];
  }
  out(ans);
  enter;
}

int main() {
#ifdef ivorysi
  freopen("f1.in", "r", stdin);
#endif
  Solve();
  return 0;
}
Problem p04034 (C++)

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

using namespace std;

int N, M;
int B[10010], C[10010];

int main(int argc, char const *argv[]) {
  cin >> N >> M;
  for (size_t i = 1; i <= N; i++)
    C[i] = 1;
  B[1] = 1;
  for (size_t i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    if (B[x])
      B[y] = 1;
    --C[x];
    if (!C[x])
      B[x] = 0;
    ++C[y];
  }
  int ans = 0;
  for (size_t i = 1; i <= N; i++)
    if (B[i])
      ++ans;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int N, M;
int B[100010], C[100010];

int main(int argc, char const *argv[]) {
  cin >> N >> M;
  for (size_t i = 1; i <= N; i++)
    C[i] = 1;
  B[1] = 1;
  for (size_t i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    if (B[x])
      B[y] = 1;
    --C[x];
    if (!C[x])
      B[x] = 0;
    ++C[y];
  }
  int ans = 0;
  for (size_t i = 1; i <= N; i++)
    if (B[i])
      ++ans;
  cout << ans << endl;
  return 0;
}
Problem p04034 (C++)

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

using namespace std;
typedef long long ll;

#define N 10005
int a[N], f[N];

int main() {
  int n, m;
  cin >> n >> m;
  memset(a, 1, sizeof(a));
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++)
    a[i] = 1;
  f[1] = 1;
  while (m--) {
    int x, y;
    cin >> x >> y;
    a[x]--;
    a[y]++;
    if (f[x]) {
      f[y] = 1;
      if (a[x] == 0)
        f[x] = 0;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    if (f[i])
      res++;
  cout << res << endl;
}

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

using namespace std;
typedef long long ll;

#define N 100005
int a[N], f[N];

int main() {
  int n, m;
  cin >> n >> m;
  memset(a, 1, sizeof(a));
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++)
    a[i] = 1;
  f[1] = 1;
  while (m--) {
    int x, y;
    cin >> x >> y;
    a[x]--;
    a[y]++;
    if (f[x]) {
      f[y] = 1;
      if (a[x] == 0)
        f[x] = 0;
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    if (f[i])
      res++;
  cout << res << endl;
}