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

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

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

long long extend_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    long long d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
  }
}

int main() {
  long long n;
  scanf("%lld", &n);

  vector<long long> primes;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      long long tmp = 1;
      while (n % i == 0) {
        tmp *= i;
        n /= i;
      }
      primes.push_back(tmp);
    }
  }
  if (n != 1) {
    primes.push_back(n);
  }

  if (primes[0] % 2 == 0) {
    primes[0] *= 2;
  } else {
    primes.push_back(2);
  }

  long long ans = 1e16;
  for (long long i = 0; i < (1 << primes.size()); ++i) {
    long long a = 1;
    long long b = 1;
    for (int j = 0; j < primes.size(); ++j) {
      if (i & (1 << j)) {
        a *= primes[j];
      } else {
        b *= primes[j];
      }
    }
    if (a == 1 or b == 1) {
      continue;
    }
    long long x = 1;
    long long y = 1;
    extend_gcd(a, b, x, y);
    long long k = min(a * abs(x), b * abs(y));
    if (k == 0) {
      continue;
    }
    ans = min(ans, k);
  }

  cout << ans << endl;

  return 0;
}

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

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

long long extend_gcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  } else {
    long long d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
  }
}

int main() {
  long long n;
  scanf("%lld", &n);
  if (n == 1 << 0 or n == 1 << 1 or n == 1 << 2 or n == 1 << 3 or n == 1 << 4 or
      n == 1 << 5 or n == 1 << 6 or n == 1 << 7 or n == 1 << 8 or n == 1 << 9 or
      n == 1 << 10 or n == 1 << 11 or n == 1 << 12 or n == 1 << 13 or
      n == 1 << 14 or n == 1 << 15 or n == 1 << 16 or n == 1 << 17 or
      n == 1 << 18 or n == 1 << 19 or n == 1 << 20 or n == 1 << 21 or
      n == 1 << 22) {
    cout << n * 2 - 1 << endl;
    return 0;
  }

  vector<long long> primes;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      long long tmp = 1;
      while (n % i == 0) {
        tmp *= i;
        n /= i;
      }
      primes.push_back(tmp);
    }
  }
  if (n != 1) {
    primes.push_back(n);
  }

  if (primes[0] % 2 == 0) {
    primes[0] *= 2;
  } else {
    primes.push_back(2);
  }

  long long ans = 1e16;
  for (long long i = 0; i < (1 << primes.size()); ++i) {
    long long a = 1;
    long long b = 1;
    for (int j = 0; j < primes.size(); ++j) {
      if (i & (1 << j)) {
        a *= primes[j];
      } else {
        b *= primes[j];
      }
    }
    if (a == 1 or b == 1) {
      continue;
    }
    long long x = 1;
    long long y = 1;
    extend_gcd(a, b, x, y);
    long long k = min(a * abs(x), b * abs(y));
    if (k == 0) {
      continue;
    }
    ans = min(ans, k);
  }

  cout << ans << endl;

  return 0;
}
Problem p02541 (C++)

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

vector<ll> prime_factorize(ll n) {
  vector<ll> res;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      res.emplace_back(1);
      while (n % i == 0) {
        n /= i;
        res.back() *= i;
      }
    }
  }
  if (n > 1) {
    res.emplace_back(n);
  }
  return res;
}

ll extended_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = extended_euclid(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

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

  ll n;
  cin >> n;
  n *= 2;

  auto factor = prime_factorize(n);

  ll min_k = LLONG_MAX;
  for (int mask = 0; mask < (1 << factor.size()); mask++) {
    ll a = 1, b = 1;
    for (int i = 0; i < factor.size(); i++) {
      if (mask & (1 << i)) {
        b *= factor[i];
      } else
        a *= factor[i]; // p1, p2, b*p2 = a*p1 + 1 = by - ax = 1
    }
    //-a(x - k*b) + b(y - k*a) = 1, ax + by = 1
    ll x0, y0;
    extended_euclid(a, b, x0, y0);
    x0 = -x0;

    ll limit = (ll)1e18 / max(a, b);
    ll lo = -limit, hi = limit;
    while (lo < hi) {
      ll mid = lo + (hi - lo + 1) / 2;
      if (x0 - mid * b > 0 and y0 - mid * a > 0)
        lo = mid;
      else
        hi = mid - 1;
    }
    min_k = min(min_k, b * (y0 - lo * a) - 1);
  }
  cout << min_k << '\n';
  return 0;
}

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

vector<ll> prime_factorize(ll n) {
  vector<ll> res;
  for (int i = 2; (ll)i * i <= n; i++) {
    if (n % i == 0) {
      res.emplace_back(1);
      while (n % i == 0) {
        n /= i;
        res.back() *= i;
      }
    }
  }
  if (n > 1) {
    res.emplace_back(n);
  }
  return res;
}

ll extended_euclid(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  ll x1, y1;
  ll d = extended_euclid(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

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

  ll n;
  cin >> n;
  n *= 2;

  auto factor = prime_factorize(n);

  ll min_k = LLONG_MAX;
  for (int mask = 0; mask < (1 << factor.size()); mask++) {
    ll a = 1, b = 1;
    for (int i = 0; i < factor.size(); i++) {
      if (mask & (1 << i)) {
        b *= factor[i];
      } else
        a *= factor[i]; // p1, p2, b*p2 = a*p1 + 1 = by - ax = 1
    }
    //-a(x - k*b) + b(y - k*a) = 1, ax + by = 1
    ll x0, y0;
    extended_euclid(a, b, x0, y0);
    x0 = -x0;

    ll limit = (ll)1e18 / max(a, b);
    ll lo = -limit, hi = limit;
    while (lo < hi) {
      ll mid = lo + (hi - lo + 1) / 2;
      if (x0 - mid * b > 0 and y0 - mid * a > 0)
        lo = mid;
      else
        hi = mid - 1;
    }
    min_k = min(min_k, b * (y0 - lo * a) - 1);
  }
  cout << min_k << '\n';
  return 0;
}
Problem p02542 (Python)

Buggy submission (status: Runtime Error):
import networkx as nx

n, m = map(int, input().split())

S = [list(input()) for _ in range(n)]
G = nx.DiGraph()

start = (n, m)
cnt = 0
goal = (n, m + 1)

for i in range(n):
    for j in range(n):
        if S[i][j] != "#":
            if S[i][j] == "o":
                cnt += 1
                G.add_edge(start, (i, j), capacity=1)
            if i + 1 < n:
                if S[i + 1][j] != "#":
                    G.add_edge((i, j), (i + 1, j), weight=-1)
            if j + 1 < m:
                if S[i][j + 1] != "#":
                    G.add_edge((i, j), (i, j + 1), weight=-1)
            G.add_edge((i, j), goal, capacity=1)
# G.add_node(start, demand=cnt)
# G.add_node(goal, demand=-cnt)
mincostflow = nx.max_flow_min_cost(G, start, goal)
ans = nx.cost_of_flow(G, mincostflow)
print(abs(ans))


Fixed submission:
import networkx as nx

n, m = map(int, input().split())

S = [list(input()) for _ in range(n)]
G = nx.DiGraph()

start = (n, m)
cnt = 0
goal = (n, m + 1)

for i in range(n):
    for j in range(m):
        if S[i][j] != "#":
            if S[i][j] == "o":
                cnt += 1
                G.add_edge(start, (i, j), capacity=1)
            if i + 1 < n:
                if S[i + 1][j] != "#":
                    G.add_edge((i, j), (i + 1, j), weight=-1)
            if j + 1 < m:
                if S[i][j + 1] != "#":
                    G.add_edge((i, j), (i, j + 1), weight=-1)
            G.add_edge((i, j), goal, capacity=1)
# G.add_node(start, demand=cnt)
# G.add_node(goal, demand=-cnt)
mincostflow = nx.max_flow_min_cost(G, start, goal)
ans = nx.cost_of_flow(G, mincostflow)
print(abs(ans))
Problem p02546 (C++)

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

int main() {
  string S;
  cin >> S;
  int n = 0;
  n = S.size();

  if (S.at(n) == 's') {
    cout << S + "es" << endl;
  } else {
    cout << S + 's' << endl;
  }
}


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

int main() {
  string S;
  cin >> S;
  int n = 0;
  n = S.size();

  if (S.at(n - 1) == 's') {
    cout << S + "es" << endl;
  } else {
    cout << S + 's' << endl;
  }
}
Problem p02546 (Python)

Buggy submission (status: Runtime Error):
N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)
N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)


Fixed submission:
N = input()

if N[len(N) - 1] == "s":
    N += "es"
else:
    N += "s"
print(N)
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, c;
  cin >> s;
  c = s;
  if (s[s.length() - 1] != 's')
    c += "s";
  else {
    c.erase(c.end());
    c += "es";
  }
  cout << c;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, c;
  cin >> s;
  c = s;
  if (s[s.length() - 1] != 's')
    c += "s";
  else {
    c += "es";
  }
  cout << c;
  return 0;
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#pragma warning(disable : 4996)
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 1001

char str[MAX];

int main() {
  scanf("%s", str);
  for (int i = 0; str[i] != '\0'; i++) {
    if (str[i + 1] == '\0') {
      if (str[i] == 's')
        strcat(str, "es");
      else
        strcat(str, "s");
      break;
    }
  }
  printf("%s", str);
}

Fixed submission:
#pragma warning(disable : 4996)
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MAX 1010

char str[MAX];

int main() {
  scanf("%s", str);
  for (int i = 0; str[i] != '\0'; i++) {
    if (str[i + 1] == '\0') {
      if (str[i] == 's')
        strcat(str, "es");
      else
        strcat(str, "s");
      break;
    }
  }
  printf("%s", str);
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a;
  string d = "es", e = "s";
  int b = a.size();
  char c = a.at(b - 1);
  if (c == 's')
    cout << a + d;
  else
    cout << a + e;

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string a;
  cin >> a;
  string d = "es", e = "s";
  int b = a.size();
  char c = a.at(b - 1);
  if (c == 's')
    cout << a + d;
  else
    cout << a + e;

  return 0;
}
Problem p02546 (C++)

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

int main() {
  string s;
  if (s.at(s.size() - 1) == 's') {
    cout << s << "es";
  } else {
    cout << s << "s";
  }
}

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

int main() {
  string s;
  int a;
  cin >> s;
  a = s.size();
  if (s.at(a - 1) == 's') {
    cout << s << "es";
  } else {
    cout << s << "s";
  }
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):

#include <iostream>
#include <string>
using namespace std;
int main() {
  int i;
  string str;
  cin >> str;
  int str1 = str.size();
  if (str.at(str1) == 's') {
    cout << str + "es" << endl;
  } else {
    cout << str + "s" << endl;
  }
}


Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int i;
  string str;
  cin >> str;
  int str1 = str.size();
  if (str.at(str1 - 1) == 's') {
    cout << str + "es" << endl;
  } else {
    cout << str + "s" << endl;
  }
}
Problem p02546 (C++)

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

typedef long long ll;
// sort(rt,rt+sizeof(rt)/sizeof(rt[0]),greater<>());
using namespace std;

#define rep(i, n) for (i = 0; i < n; i++)
int main() {
  char n[100];
  cin >> n;
  int a;
  a = (int)strlen(n);
  if (n[a - 1] == 's') {
    cout << n << "es";
    return 0;
  } else if (n[a - 1] != 's') {
    cout << n << 's';
    return 0;
  }
}


Fixed submission:
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <vector>

typedef long long ll;
// sort(rt,rt+sizeof(rt)/sizeof(rt[0]),greater<>());
using namespace std;

#define rep(i, n) for (i = 0; i < n; i++)
int main() {
  char n[1001];
  cin >> n;
  int a;
  a = (int)strlen(n);
  if (n[a - 1] == 's') {
    cout << n << "es";
    return 0;
  } else if (n[a - 1] != 's') {
    cout << n << 's';
    return 0;
  }
}
Problem p02546 (C++)

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

int main() {
  char s[1000];
  cin >> s;
  char s0[] = "es";
  char s1[] = "s";

  if (s[strlen(s) - 1] == 's') {
    strcat(s, s0);
    cout << s << endl;
  } else {
    strcat(s, s1);
    cout << s << endl;
  }
}

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

int main() {
  char s[10000];
  cin >> s;
  char s0[] = "es";
  char s1[] = "s";

  if (s[strlen(s) - 1] == 's') {
    strcat(s, s0);
    cout << s << endl;
  } else {
    strcat(s, s1);
    cout << s << endl;
  }
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  char s[103];
  int i, len, k = 0;
  scanf("%s", s);
  len = strlen(s);
  if (s[len - 1] == 's') {
    s[len] = 'e';
    s[len + 1] = 's';
    k = 1;
  } else
    s[len] = 's';
  if (k == 1) {
    for (i = 0; i < len + 2; i++)
      printf("%c", s[i]);
  } else {
    for (i = 0; i <= len; i++)
      printf("%c", s[i]);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  char s[1003];
  int i, len, k = 0;
  scanf("%s", s);
  len = strlen(s);
  if (s[len - 1] == 's') {
    s[len] = 'e';
    s[len + 1] = 's';
    k = 1;
  } else
    s[len] = 's';
  if (k == 1) {
    for (i = 0; i < len + 2; i++)
      printf("%c", s[i]);
  } else {
    for (i = 0; i <= len; i++)
      printf("%c", s[i]);
  }
  return 0;
}
Problem p02546 (C++)

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

int main() {
  char s[255];
  scanf("%s", s);
  if (s[strlen(s) - 1] == 's')
    printf("%ses", s);
  else
    printf("%ss", s);
  return 0;
}

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

int main() {
  char s[1005];
  scanf("%s", s);
  if (s[strlen(s) - 1] == 's')
    printf("%ses", s);
  else
    printf("%ss", s);
  return 0;
}
Problem p02546 (C++)

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

int main() {
  string str;
  if (str.at(str.size() - 1) == 's')
    cout << str + "es" << endl;
  else
    cout << str + 's' << endl;
}

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

int main() {
  string str;
  cin >> str;
  if (str.at(str.size() - 1) == 's')
    cout << str + "es" << endl;
  else
    cout << str + 's' << endl;
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string.h>
using namespace std;
int main() {
  char w[1000];
  cin >> w;
  int l = strlen(w);
  if (w[l - 1] == 's') {
    char p[l + 1];
    w[l] = 'e';
    w[l + 1] = 's';
    strcpy(p, w);
    for (int i = 0; i <= l + 1; i++) {
      cout << p[i];
    }
  }

  else {
    w[l] = 's';
    char p[l];
    strcpy(p, w);
    for (int i = 0; i <= l; i++) {
      cout << p[i];
    }
  }
}

Fixed submission:
#include <iostream>
#include <string.h>
using namespace std;
int main() {
  char w[1000];
  cin >> w;
  int l = strlen(w);
  if (w[l - 1] == 's')
    cout << w << "es";
  else
    cout << w << 's';
}
Problem p02546 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  char S[256];
  cin >> S;
  int len = strlen(S);
  if (S[len - 1] != 's')
    cout << S << "s";
  if (S[len - 1] == 's')
    cout << S << "es";
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  char s[1000];
  cin >> s;
  int len = strlen(s);
  if (s[len - 1] != 's')
    cout << s << "s";
  else if (s[len - 1] == 's')
    cout << s << "es";
  return 0;
}
Problem p02546 (C++)

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

void change_to_plural(char *input_string, char *output_string) {
  int n;
  n = strlen(input_string);

  if (input_string[n - 1] == 's') {
    input_string[n] = 'e';
    input_string[n + 1] = 's';
    input_string[n + 2] = '\0';
  } else

  {
    input_string[n] = 's';
    input_string[n + 1] = '\0';
  }

  output_string = input_string;
  n = strlen(input_string);
  for (int i = 0; i < n; i++)
    cout << output_string[i];
}

int main() {

  char in[10], out[10];

  cin >> in;

  change_to_plural(in, out);

  cout << endl;
}


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

void change_to_plural(char *input_string, char *output_string) {
  int n;
  n = strlen(input_string);

  if (input_string[n - 1] == 's') {
    input_string[n] = 'e';
    input_string[n + 1] = 's';
    input_string[n + 2] = '\0';
  } else

  {
    input_string[n] = 's';
    input_string[n + 1] = '\0';
  }

  output_string = input_string;
  n = strlen(input_string);
  for (int i = 0; i < n; i++)
    cout << output_string[i];
}

int main() {

  char in[1000], out[1000];

  cin >> in;

  change_to_plural(in, out);

  cout << endl;
}
Problem p02546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  scanf("%s", &s);
  if (s[s.size() - 1] == 's')
    cout << s << "es" << endl;
  else
    cout << s << 's' << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's')
    cout << s << "es" << endl;
  else
    cout << s << 's' << endl;
  return 0;
}
Problem p02546 (C++)

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

int main() {
  string X;
  cin >> X;
  if (X.at(-1) == 's') {
    cout << X << "es" << endl;
  } else {
    cout << X << "s" << endl;
  }
}

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

int main() {
  string X;
  cin >> X;
  char a = X[X.size() - 1];

  if (a == 's') {
    cout << X << "es" << endl;
  } else {
    cout << X << "s" << endl;
  }
}
Problem p02547 (C++)

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

#define int long long
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

using namespace std;

void solve() {
  deque<pair<int, int>> v;
  int n, cnt = 0;
  cin >> n;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x == y)
      cnt++;
    if (i >= 3) {
      if (v[0].first == v[0].second)
        cnt--;
      v.pop_front();
    }
    if (cnt == 3) {
      ok = true;
    }
  }
  cout << (ok ? "Yes\n" : "No\n");
}

signed main() {
  fastio int t = 1;
  // cin >> t;
  while (t--)
    solve();
}

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

#define int long long
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);

using namespace std;

void solve() {
  deque<pair<int, int>> v;
  int n, cnt = 0;
  cin >> n;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v.emplace_back(x, y);
    if (x == y)
      cnt++;
    if (i >= 3) {
      if (v[0].first == v[0].second)
        cnt--;
      v.pop_front();
    }
    if (cnt == 3) {
      ok = true;
    }
  }
  cout << (ok ? "Yes\n" : "No\n");
}

signed main() {
  fastio int t = 1;
  // cin >> t;
  while (t--)
    solve();
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 13;

int a[maxn];
int b[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  for (int i = 1; i <= n - 2; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (a[i + j] == b[i + j]) {
        cnt++;
      }
    }
    if (cnt == 3) {
      return printf("Yes");
    }
  }
  printf("No");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 13;

int a[maxn];
int b[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  for (int i = 1; i <= n - 2; i++) {
    int cnt = 0;
    for (int j = 0; j < 3; j++) {
      if (a[i + j] == b[i + j]) {
        cnt++;
      }
    }
    if (cnt == 3) {
      return printf("Yes"), 0;
    }
  }
  printf("No");
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
struct XX {
  int s;
  int e;
};

class xxGreater {
public:
  bool operator()(const XX &riLeft, const XX &riRight) const {
    // 第2条件
    if ((riLeft.s) == (riRight.s)) {
      return riLeft.e <
             riRight.e; //<:昇順(小さいものから順番)、>:降順(大きいものから順番)
                        // プライオリティキューの場合は >
                        // で、top()すると値の小さいものがとれる
    }
    // 第1条件
    return (riLeft.s) > (riRight.s);
  }
};

int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      ans.push_back(i);
    }
  }

  int f = 0;
  for (int i = 0; i < n - 2; i++) {
    if (ans[i + 2] - ans[i + 1] == 1 && ans[i + 1] - ans[i] == 1) {
      f = 1;
    }
  }

  if (f == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
struct XX {
  int s;
  int e;
};

class xxGreater {
public:
  bool operator()(const XX &riLeft, const XX &riRight) const {
    // 第2条件
    if ((riLeft.s) == (riRight.s)) {
      return riLeft.e <
             riRight.e; //<:昇順(小さいものから順番)、>:降順(大きいものから順番)
                        // プライオリティキューの場合は >
                        // で、top()すると値の小さいものがとれる
    }
    // 第1条件
    return (riLeft.s) > (riRight.s);
  }
};

int main(int argc, const char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      ans.push_back(i);
    }
  }

  int f = 0;
  if (ans.size() > 2) {
    for (int i = 0; i < n - 2; i++) {
      if (ans[i + 2] - ans[i + 1] == 1 && ans[i + 1] - ans[i] == 1) {
        f = 1;
      }
    }
  }

  if (f == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

static const int MAX = 100000;
static const int INFTY = (1 << 20);
using namespace std;

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

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (d[i][0] == d[i][1])
      count++;
    else
      count = 0;
    if (count >= 3) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

static const int MAX = 100000;
static const int INFTY = (1 << 20);
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> d(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> d[i][0];
    cin >> d[i][1];
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (d[i][0] == d[i][1])
      count++;
    else
      count = 0;
    if (count >= 3) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");
  return 0;
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vint D1(n), D2(n);
  int check = 0;
  int is_yes = 0;
  REP(i, n) {
    cin >> D1[n] >> D2[n];
    if (D1[n] == D2[n]) {
      check++;
    } else {
      check = 0;
    }
    if (check == 3) {
      is_yes = 1;
    }
  }
  if (is_yes) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vint D1(n), D2(n);
  int check = 0;
  int is_yes = 0;
  REP(i, n) {
    cin >> D1[i] >> D2[i];
    if (D1[i] == D2[i]) {
      check++;
    } else {
      check = 0;
    }
    if (check == 3) {
      is_yes = 1;
    }
  }
  if (is_yes) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}
Problem p02547 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ds;
  for (auto &p : ds)
    cin >> p.first >> p.second;
  bool ok = false;
  for (int i = 0; i < n - 2; ++i) {
    if (ds[i].first == ds[i].second && ds[i + 1].first == ds[i + 1].second &&
        ds[i + 2].first == ds[i + 2].second) {
      ok |= 1;
    }
  }
  cout << (ok ? "Yes\n" : "No\n");
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ds(n);
  for (auto &p : ds)
    cin >> p.first >> p.second;
  bool ok = false;
  for (int i = 0; i < n - 2; ++i) {
    if (ds[i].first == ds[i].second && ds[i + 1].first == ds[i + 1].second &&
        ds[i + 2].first == ds[i + 2].second) {
      ok |= 1;
    }
  }
  cout << (ok ? "Yes\n" : "No\n");
  return 0;
}
Problem p02547 (C++)

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

int main() {
  int n;
  cin >> n;
  int d11, d12, d21, d22, d31, d32;
  string s = "No";
  cin >> d11 >> d12 >> d21 >> d22;
  for (int i = 0; n - 2; i++) {
    int a, b;
    cin >> a >> b;
    if (i > 0) {
      d11 = d21;
      d12 = d22;
      d21 = d31;
      d22 = d32;
      d31 = a;
      d32 = b;
    } else {
      d31 = a;
      d32 = b;
    }
    if (d11 == d12 && d21 == d22 && d31 == d32) {
      s = "Yes";
    }
  }
  cout << s << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int d11, d12, d21, d22, d31, d32;
  string s = "No";
  cin >> d11 >> d12 >> d21 >> d22;
  for (int i = 0; i < n - 2; i++) {
    int a, b;
    cin >> a >> b;
    if (i > 0) {
      d11 = d21;
      d12 = d22;
      d21 = d31;
      d22 = d32;
      d31 = a;
      d32 = b;
    } else {
      d31 = a;
      d32 = b;
    }
    if (d11 == d12 && d21 == d22 && d31 == d32) {
      s = "Yes";
    }
  }
  cout << s << endl;
  return 0;
}
Problem p02547 (C++)

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
struct edge {
  ll to, cost;
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> d(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> d[i][0] >> d[i][1];
  }
  bool flag = false;
  for (int i = 0; i <= n - 2; i++) {
    if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] &&
        d[i + 2][0] == d[i + 2][1]) {
      flag = true;
      break;
    }
  }
  if (flag == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
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;
}
struct edge {
  ll to, cost;
};

int main() {
  int n;
  cin >> n;
  vector<vector<int>> d(n, vector<int>(2));
  for (int i = 0; i < n; i++) {
    cin >> d[i][0] >> d[i][1];
  }
  bool flag = false;
  for (int i = 0; i <= n - 3; i++) {
    if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] &&
        d[i + 2][0] == d[i + 2][1]) {
      flag = true;
      break;
    }
  }
  if (flag == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fir first
#define sec second
#define MOD 1000000007
#define vvi vector<vector<int>>
#define vvs vector<vector<string>>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define pb push_back
#define vi vector<int>
#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vvl vector<vl>
#define loopin(i, n) for (int i = 0; i < (n); i++)
#define loopdec(i, n) for (int i = n - 1; i >= 0; i--)
const int mod = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  int a[10][10];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0];
    cin >> a[i][1];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i][0] == a[i][1]) {
      count++;
    } else {
      count = 0;
    }
    if (count >= 3) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
}

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

  solve();

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fir first
#define sec second
#define MOD 1000000007
#define vvi vector<vector<int>>
#define vvs vector<vector<string>>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define pb push_back
#define vi vector<int>
#define test(t)                                                                \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vvl vector<vl>
#define loopin(i, n) for (int i = 0; i < (n); i++)
#define loopdec(i, n) for (int i = n - 1; i >= 0; i--)
const int mod = 1e9 + 7;

void solve() {
  int n;
  cin >> n;
  int a[n + 1][10];
  for (int i = 0; i < n; i++) {
    cin >> a[i][0];
    cin >> a[i][1];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (a[i][0] == a[i][1]) {
      count++;
    } else {
      count = 0;
    }
    if (count >= 3) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
}

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

  solve();

  return 0;
}
Problem p02547 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> s(n, vector<int>(2));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int f = 0; f < 2; f++) {
      cin >> s.at(i).at(f);
    }
  }
  for (int i = 0; i < n; i++) {
    if (s.at(i).at(0) == s.at(i).at(1))
      ans++;
    if (ans == 3)
      break;
    else if (s.at(i).at(0) != s.at(i).at(i))
      ans = 0;
  }
  if (ans >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<vector<int>> s(n, vector<int>(2));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int f = 0; f < 2; f++) {
      cin >> s.at(i).at(f);
    }
  }
  for (int i = 0; i < n; i++) {
    if (s.at(i).at(0) == s.at(i).at(1))
      ans++;
    if (ans == 3)
      break;
    else if (s.at(i).at(0) != s.at(i).at(1))
      ans = 0;
  }
  if (ans >= 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  int a[2][n];
  cin >> a[0][0] >> a[0][1] >> a[1][0] >> a[1][1];
  for (int i = 2; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
    if (a[i - 2][1] == a[i - 2][0] && a[i - 1][1] == a[i - 1][0] &&
        a[i][1] == a[i][0]) {
      sum++;
      cout << "Yes";
      break;
    }
  }

  if (sum == 0)
    cout << "No";

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  int a[n][2];
  cin >> a[0][0] >> a[0][1] >> a[1][0] >> a[1][1];
  for (int i = 2; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
    if (a[i - 2][1] == a[i - 2][0] && a[i - 1][1] == a[i - 1][0] &&
        a[i][1] == a[i][0]) {
      sum++;
      cout << "Yes";
      break;
    }
  }

  if (sum == 0)
    cout << "No";

  return 0;
}
Problem p02547 (C++)

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

#define ll long long int

static const auto _____ = []() {
  // fast IO code : this I understand
  ios::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(0);
  return 0;
}();

int main() {
  int n;
  cin >> n;
  int a[2][n];
  int cnt = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
    if (a[i][0] == a[i][1]) {
      cnt++;
      if (cnt == 3)
        flag = 1;
    } else
      cnt = 0;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

#define ll long long int

static const auto _____ = []() {
  // fast IO code : this I understand
  ios::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(0);
  return 0;
}();

int main() {
  int n;
  cin >> n;
  int a[n][2];
  int cnt = 0;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1];
    if (a[i][0] == a[i][1]) {
      cnt++;
      if (cnt == 3)
        flag = 1;
    } else
      cnt = 0;
  }
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02547 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d[10][3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> d[i][j];
    }
  }
  bool flag = 0;
  for (int i = 0; i <= n - 3; i++) {
    if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] &&
        d[i + 2][0] == d[i + 2][1]) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d[110][3];
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> d[i][j];
    }
  }
  bool flag = 0;
  for (int i = 0; i <= n - 3; i++) {
    if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] &&
        d[i + 2][0] == d[i + 2][1]) {
      flag = 1;
      break;
    }
  }
  if (flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
Problem p02548 (C++)

Buggy submission (status: Time Limit Exceeded):
// AC - C - A x B + C

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

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

  int n, r, i, j, d, s = 0;
  cin >> n;
  r = sqrt(n);

  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      d = n - (i * j);
      if (d > 0)
        s = s + 1;
    }
  cout << s << "\n";
  return 0;
}

Fixed submission:
// AC - C - A x B + C

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

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

  int n, r, i, j, d, s = 0;
  cin >> n;
  r = sqrt(n);

  for (i = 1; i <= n; i++)
    for (j = 1; j <= (n / i); j++) {
      d = n - (i * j);
      if (d > 0)
        s = s + 1;
    }
  cout << s << "\n";
  return 0;
}
Problem p02548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <fstream>
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int GCD(int x, int y) {
  if (x < y) {
    swap(x, y);
  }
  while (x % y != 0) {
    int temp = x;
    x = y;
    y = temp % y;
  }
  return y;
}

int digitsum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    int cnt = 0;
    int cur;
    for (int j = 1; j <= sqrt(i); j++) {
      if (i % j == 0) {
        cnt++;
        cur = j;
      }
    }
    if (cur * cur == i)
      cnt = 2 * cnt - 1;
    else
      cnt *= 2;
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

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

ll mod(ll a, ll b) {
  ll ret = a % b;
  if (ret < 0)
    ret += b;
  return ret;
}

ll modpow(ll a, ll b, ll c) {
  ll res = 1;
  while (b > 0) {
    if (b & 1)
      res = mod(res * a, c);
    a = mod(a * a, c);
    b >>= 1;
  }
  return res;
}

int GCD(int x, int y) {
  if (x < y) {
    swap(x, y);
  }
  while (x % y != 0) {
    int temp = x;
    x = y;
    y = temp % y;
  }
  return y;
}

int digitsum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += (x % 10);
    x /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n - 1; i++) {
    ans += (n - 1) / i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02548 (C++)

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

using namespace std;

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

  Int ans = 0;
  for (Int C = 1; C < N; ++C) {
    Int n = N - C;
    for (Int A = 1; A * A <= n; ++A) {
      if (n % A != 0) {
        continue;
      }
      if (A * A == n) {
        ans += 1;
      } else {
        ans += 2;
      }
    }
  }
  cout << ans << "\n";

  return 0;
}


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

using namespace std;

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

  Int ans = 0;
  for (int a = 1; a <= N; ++a) {
    for (int b = 1; a * b < N; ++b) {
      ++ans;
    }
  }
  cout << ans << "\n";

  return 0;
}
Problem p02548 (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;
typedef long long ll;
using P = pair<int, int>;

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {

  ll N;
  cin >> N;

  ll ans = 0;

  for (ll c = 1; c < N; c++) {
    ll M = N - c;
    ans += divisor(M).size();
  }

  cout << ans << endl;

  return 0;
}


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

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

int main() {

  ll N;
  cin >> N;

  ll ans = 0;

  for (ll a = 1; a < N; a++) {
    ans += (N - 1) / a;
  }

  cout << ans << endl;

  return 0;
}
Problem p02548 (C++)

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    int x = N - i;
    for (int j = 1; j * j <= x; j++) {
      if (x % j == 0)
        ans += 2;
      if (j * j == x)
        ans--;
    }
  }
  cout << ans;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int a = 1; a < N; a++) {
    ans += N / a;
    if (N % a == 0)
      ans--;
  }
  cout << ans;
  return 0;
}
Problem p02548 (C++)

Buggy submission (status: Time Limit Exceeded):
// It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define mem(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9 + 7;
ll res;

void solve() {
  int n;
  cin >> n;
  for (int c = n - 1; c >= 1; c--) {
    int left = n - c;
    for (int a = 1; a <= left; a++) {
      int b;
      if (left % a == 0) {
        b = left / a;
      }
      if (a && b && c && ((a * b) + c == n)) {
        res++;
      }
    }
  }
  cout << res << endl;
}

int main() {
  IOS;
  ll t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Fixed submission:
// It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define endl "\n"
#define mem(x, y) memset(x, y, sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9 + 7;
ll res;

void solve() {
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    for (int j = 1; i * j < n; j++) {
      res++;
    }
  }
  cout << res << endl;
}

int main() {
  IOS;
  ll t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
Problem p02548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int cnt = 0;
  reps(c, n, 1) {
    reps(b, n, 1) {
      double a = (n - c) / (double)b;
      if (a > 0 && ceil(a) == floor(a)) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  int cnt = 0;
  int same = 0;
  reps(a, sqrt(n), 1) {
    reps(b, n, a) {
      if (a * b < n) {
        if (a == b)
          cnt++;
        else
          cnt += 2;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02548 (C++)

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

int main() {
  int N, count = 0;
  cin >> N;
  int n;
  for (int c = 1; c < N; c++) {
    n = N;
    n -= c;
    int m, del = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (i * i > n) {
        m = i - 1;
        if (m * m == n) {
          del = 1;
        }
        break;
      }
    }
    count -= del;
    for (int a = 1; a <= m; a++) {
      if (n % a == 0) {
        count += 2;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, count = 0;
  cin >> N;
  int n;
  for (int c = 1; c < N; c++) {
    n = N;
    n -= c;
    int m, del = 0;
    for (int i = 1; i <= n + 1; i++) {
      if (i * i > n) {
        m = i - 1;
        if (m * m == n) {
          del = 1;
        }
        break;
      }
    }
    count -= del;
    if (n % 2 == 0) {
      for (int a = 1; a <= m; a++) {
        if (n % a == 0) {
          count += 2;
        }
      }
    } else {
      for (int a = 1; a <= m; a += 2) {
        if (n % a == 0) {
          count += 2;
        }
      }
    }
  }
  cout << count << endl;
}