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

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  string a, b;
  cin >> a >> b;

  int n = a.length();

  rep(i, n) { a += a; }

  if (a.find(b) != std::string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  string a, b;
  cin >> a >> b;

  a += a;

  if (a.find(b) != std::string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
// include
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
// using
using namespace std;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using ll = long long;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
// vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector<double>;
// define
// #define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(n) cout << n << endl;
#define sortp(d) sort(d.begin(), d.end())   // 1234
#define sortm(d) sort(d.rbegin(), d.rend()) // 4321
// 素数判定　O(√A)
bool is_prime(int x) {
  if (x <= 1)
    return false;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
// 各位の和　
int wa(ll x) {
  ll sum = 0;
  while (x != 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

// 絶対値　abs()
// 文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
// 型キャスト　char('a'+1)
// reverse 回文
// if(isupper('A'))->大なら真

// グローバル変数宣言
ll p = 0, q = 0, r = 0;

int main() {
  string s, t, u;
  cin >> s >> t;

  rep(j, s.size()) {
    rep(i, s.size()) {
      if (i == 0)
        u[i] = s[s.size() - 1];
      else
        u[i] = s[i - 1];
    }
    rep(i, s.size()) { s[i] = u[i]; }
    if (s == t) {
      print("Yes") return 0;
    }
  }
  print("No")
}

Fixed submission:
// include
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
// using
using namespace std;
using vl = vector<long long>;
using vs = vector<string>;
using vc = vector<char>;
using ll = long long;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
// vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector<double>;
// define
// #define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(n) cout << n << endl;
#define sortp(d) sort(d.begin(), d.end())   // 1234
#define sortm(d) sort(d.rbegin(), d.rend()) // 4321
// 素数判定　O(√A)
bool is_prime(int x) {
  if (x <= 1)
    return false;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
// 各位の和　
int wa(ll x) {
  ll sum = 0;
  while (x != 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

// 絶対値　abs()
// 文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
// 型キャスト　char('a'+1)
// reverse 回文
// if(isupper('A'))->大なら真

// グローバル変数宣言
ll p = 0, q = 0, r = 0;

int main() {
  string s, t, u;
  cin >> s >> t;
  u = s;
  rep(j, s.size()) {
    rep(i, s.size()) {
      if (i == 0)
        u[i] = s[s.size() - 1];
      else
        u[i] = s[i - 1];
    }
    rep(i, s.size()) { s[i] = u[i]; }
    if (s == t) {
      print("Yes") return 0;
    }
  }
  print("No")
}
Problem p03293 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n); // 最大公倍数
ll lcm(ll m, ll n); // 最小公倍数

int main(void) {

  string ans = "No";

  //	int n;
  //	cin >> n;
  //	vector<int> v;
  string a, b;
  cin >> a;
  cin >> b;
  for (int i = 0; a.size(); i++) {
    if (a == b) {
      ans = "Yes";
      break;
    }
    b = b.back() + b;
    b.pop_back();
  }

  cout << ans << endl;

  return 0;
}

// 2番目から3要素だけ抜き出した部分文字列を取得する
// std::string result = s.substr(2, 3);

#if 1
// 最大公倍数
ll gcd(ll m, ll n) {
  ll temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }
#endif

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n); // 最大公倍数
ll lcm(ll m, ll n); // 最小公倍数

int main(void) {

  string ans = "No";

  //	int n;
  //	cin >> n;
  //	vector<int> v;
  string a, b;
  cin >> a;
  cin >> b;
  for (int i = 0; i < a.size(); i++) {
    if (a == b) {
      ans = "Yes";
      break;
    }
    b = b.back() + b;
    b.pop_back();
  }

  cout << ans << endl;

  return 0;
}

// 2番目から3要素だけ抜き出した部分文字列を取得する
// std::string result = s.substr(2, 3);

#if 1
// 最大公倍数
ll gcd(ll m, ll n) {
  ll temp;
  while (m % n != 0) {
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }
#endif
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main(void) {
  int L;
  char S[1][110], T[1][110], tmp[][110] = {""};
  scanf("%s%s", S, T);
  L = strlen(S[0]);
  strncpy(tmp[0], S[0], L);
  strncat(S[0], tmp[0], L);
  if (strstr(S[0], T[0])) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main(void) {
  int L;
  char S[100][1100], T[100][1100], tmp[][110] = {""};
  scanf("%s%s", S, T);
  L = strlen(S[0]);
  strncpy(tmp[0], S[0], L);
  strncat(S[0], tmp[0], L);
  if (strstr(S[0], T[0])) {
    printf("Yes");
  } else {
    printf("No");
  }

  return 0;
}
Problem p03293 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
string s1, s2;
int main() {
  cin >> s1;
  s1 = s1 + s1; // cout<<s1;
  cin >> s2;
  int l = s2.size();
  int pos = s1.find(s2);
  return puts(pos ? "Yes" : "No");
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
string s1, s2;
int main() {
  cin >> s1;
  s1 = s1 + s1; // cout<<s1;
  cin >> s2;
  int l = s2.size();
  int pos = s1.find(s2);
  for (int i = pos; i < pos + l; i++)
    if (s1[i] != s2[i - pos])
      return puts("No"), 0;
  puts("Yes");
}
Problem p03293 (C++)

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  char x;
  int count = 0;
  for (int i = 0; i < n; i++) {
    x = s[n - 1];
    for (int j = n - 1; j = 1; j--) {
      s[i] = s[i - 1];
    }
    s[0] = x;
    if (s == t) {
      count++;
    }
  }

  if (count > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  char x;
  int count = 0;
  for (int i = 0; i < n; i++) {
    x = s[n - 1];
    s.pop_back();
    s = x + s;
    if (s == t) {
      count++;
    }
  }

  if (count > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03293 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  string ans = "No";
  while (1) {
    S = S[N - 1] + S;
    if (S.substr(0, N) == T) {
      ans = "Yes";
      break;
    }
  }

  cout << ans << endl;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  string ans = "No";
  rep(i, N + 1) {
    if (S == T) {
      ans = "Yes";
      break;
    }
    S = S[N - 1] + S;
    if (S.substr(0, N) == T) {
      ans = "Yes";
      break;
    }
  }

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

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T) {
  for (int i = S.size() - 1; i >= 0; i--) {
    char tmp = S[i];
    S.erase(S.end());
    S = tmp + S;
    if (S == T) {
      cout << YES;
      return;
    }
  }
  cout << NO;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T) {
  for (int i = 0; i < S.size(); i++) {
    if (S.substr(i) + S.substr(0, i) == T) {
      cout << YES;
      return;
    }
  }
  cout << NO;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  std::string S;
  std::cin >> S;
  std::string T;
  std::cin >> T;
  solve(S, T);
  return 0;
}
Problem p03294 (C++)

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

int n;
int a[3000];
int ans = 0;

int main() {
  cin >> n;
  rep(i, n) {
    cin >> a[n];
    ans += a[n];
  }
  cout << ans - n << endl;
  return 0;
}


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

int n;
int a[3000];
int ans = 0;

int main() {
  cin >> n;
  rep(i, n) {
    cin >> a[i];
    ans += a[i];
  }
  cout << ans - n << endl;
  return 0;
}
Problem p03294 (C++)

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

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  // std::stack<int> stack;
  int n;
  cin >> n;
  vector<int> a(n);
  long ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", a[i]);
    ans += a[i] - 1;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  // std::stack<int> stack;
  int n;
  cin >> n;
  vector<int> a(n);
  long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i] - 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p03294 (Python)

Buggy submission (status: Time Limit Exceeded):
import numpy as np

N = int(input())
alist = np.array(list(map(int, input().split())))
ranges = np.arange(1, 10**5)


def f(m):
    return np.sum(np.mod(alist, m))


num_f = np.frompyfunc(f, 1, 1)
print(max(num_f(ranges)) - N)


Fixed submission:
import numpy as np

N = int(input())
alist = np.array(list(map(int, input().split())))
print(np.sum(alist - 1))
Problem p03294 (Python)

Buggy submission (status: Runtime Error):
from math import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
a = list(map(int, input().split()))
ll = lcm_list(a) - 1
ans = 0
for i in a:
    ans += ll % i
print(ans)


Fixed submission:
from fractions import gcd
from functools import reduce


def lcm_base(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
a = list(map(int, input().split()))
ll = lcm_list(a) - 1
ans = 0
for i in a:
    ans += ll % i
print(ans)
Problem p03294 (Python)

Buggy submission (status: Runtime Error):
def solve(string):
    n, *a = map(int, string.split())
    return str(sum(a) - n)


if __name__ == "__main__":
    n = int(input())
    print(solve("{}\n".format(n) + "\n".join([input() for _ in range(n)])))


Fixed submission:
def solve(string):
    n, *a = map(int, string.split())
    return str(sum(a) - n)


if __name__ == "__main__":
    print(solve("\n".join([input(), input()])))
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(int argc, char *argv[]) {
  int i, n, a[100], s = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s = s + a[i] - 1;
  }
  printf("%d\n", s);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(int argc, char *argv[]) {
  int i, n, a[10000], s = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s = s + a[i] - 1;
  }
  printf("%d\n", s);
  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  ll ans = 0;
  rep(i, 100000000) {
    ll key = 0;
    for (int j = 0; j < n; j++)
      key += i % a[j];
    ans = max(ans, key);
  }
  cout << ans << endl;
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define ll long long
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) { cin >> a[i]; }
  ll ans = 0;
  rep(i, n) ans += a[i];
  cout << ans - n << endl;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
int main() {
  long long a = 0, b = 0, c = 0, hairetu[1000] = {}, mi = 0, ma = 0, ansa = 0,
            ansb = 0, count = 1;

  using namespace std;

  int x = 0, y = 0, z = 0;
  std::string str, strt, str_s;
  bool okada = false;
  cin >> x;
  for (int i = 0; i < x; i++) {
    std::cin >> hairetu[i];
    a += hairetu[i] - 1;
  }
  cout << a << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
int main() {
  long long a = 0, b = 0, c = 0, hairetu[4000] = {}, mi = 0, ma = 0, ansa = 0,
            ansb = 0, count = 1;

  using namespace std;

  int x = 0, y = 0, z = 0;
  std::string str, strt, str_s;
  bool okada = false;
  cin >> x;
  for (int i = 0; i < x; i++) {
    std::cin >> hairetu[i];
    a += hairetu[i] - 1;
  }
  cout << a << endl;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <string.h>
int main() {
  int a[1000], b[1000], n, m, i, j, t;
  char s1[1010], s2[1010];
  while (scanf("%d", &n) != EOF) {
    int sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      sum = sum + a[i] - 1;
    }
    printf("%d\n", sum);
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <string.h>
int main() {
  int a[10000], b[1000], n, m, i, j, t;
  char s1[1010], s2[1010];
  while (scanf("%d", &n) != EOF) {
    int sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
      sum = sum + a[i] - 1;
    }
    printf("%d\n", sum);
  }
  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
#include <utility>

using namespace std;
#define int long long
#define br cout << "\n"
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define umap unordered_map
#define uset unordered_set

typedef vector<int> vi;
typedef vector<vi> vvi;

bool isPwrOf2(int x) { return x && (!(x & (x - 1))); }
/*------------------------------------------------*/

/*------------------------------------------------*/

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("./input.txt", "r", stdin);
  freopen("./output.txt", "w", stdout);
#endif
  /*------------------------------------------------*/
  int n;
  cin >> n;
  int arr[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt += arr[i] - 1;
  }
  cout << cnt;
  /*------------------------------------------------*/
  return 0;
}

Fixed submission:

#include <bits/stdc++.h>
#include <utility>

using namespace std;
#define int long long
#define br cout << "\n"
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define umap unordered_map
#define uset unordered_set

typedef vector<int> vi;
typedef vector<vi> vvi;

bool isPwrOf2(int x) { return x && (!(x & (x - 1))); }
/*------------------------------------------------*/

/*------------------------------------------------*/

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // #ifndef ONLINE_JUDGE
  //     freopen("./input.txt", "r", stdin);
  //     freopen("./output.txt", "w", stdout);
  // #endif
  /*------------------------------------------------*/
  int n;
  cin >> n;
  int arr[n];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    cnt += arr[i] - 1;
  }
  cout << cnt;
  /*------------------------------------------------*/
  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5 + 5;
const int mod = 1e9 + 7;

ll n, m, ans = 0;

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

#ifndef OJ
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> m;
    ans += m - 1;
  }

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define vi vector<int>
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define qi queue<int>
#define si stack<int>
#define mii map<int, int>
#define msi map<string, int>
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
using namespace std;

const int MAX = 1e5 + 5;
const int mod = 1e9 + 7;

ll n, m, ans = 0;

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  // #ifndef OJ
  // freopen(".in", "r", stdin);
  // freopen(".out", "w", stdout);
  // #endif

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> m;
    ans += m - 1;
  }

  cout << ans;

  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)

#define huge 1000000007
typedef long long ll;

int main(void) {

  ll N = 0;
  ll A = 0;
  ll B = 0;
  ll C = 0;
  ll K = 0;
  ll W = 0;
  ll X = 0;
  // ll m[100000] = {};
  ll w[300] = {};
  ll v[100] = {};
  ll *x, *c, *d;
  string S, T, U;
  ll count = 0;
  ll sum = 0;
  ll min = 1;
  ll max = 0;
  int flag = 0;
  char temp, head;
  // char p;
  cin >> N;

  rep(i, 0, N) { cin >> w[i]; }

  rep(i, 0, N) { sum += (w[i] - 1); }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
// #include "bits/stdc++.h"
using namespace std;
// using namespace std::vector;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)

#define huge 1000000007
typedef long long ll;

int main(void) {

  ll N = 0;
  ll A = 0;
  ll B = 0;
  ll C = 0;
  ll K = 0;
  ll W = 0;
  ll X = 0;
  // ll m[100000] = {};
  ll w[3000] = {};
  ll v[100] = {};
  ll *x, *c, *d;
  string S, T, U;
  ll count = 0;
  ll sum = 0;
  ll min = 1;
  ll max = 0;
  int flag = 0;
  char temp, head;
  // char p;
  cin >> N;

  rep(i, 0, N) { cin >> w[i]; }

  rep(i, 0, N) { sum += (w[i] - 1); }

  cout << sum << endl;

  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < n; i++)
const int MAX = 2e3 + 3;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int a[MAX];

int main() {

  int n;
  cin >> n;
  REP(i, n) cin >> a[i];
  ll ans = 0;
  REP(i, n) ans += a[i] - 1;
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < n; i++)
const int MAX = 5e3 + 3;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int a[MAX];

int main() {

  int n;
  cin >> n;
  REP(i, n) cin >> a[i];
  ll ans = 0;
  REP(i, n) ans += a[i] - 1;
  cout << ans << endl;

  return 0;
}
Problem p03294 (C++)

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

using namespace std;

int main() {
  int N;
  int a[N];
  cin >> N;
  int i;
  for (i = 0; i <= N - 1; i++)
    cin >> a[i];
  int sum = 0;
  for (i = 0; i <= N - 1; i++)
    sum = sum + a[i];
  sum -= N;
  cout << sum << endl;
}


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

using namespace std;

int main() {
  int N;
  int a[3333];
  cin >> N;
  int i;
  for (i = 0; i <= N - 1; i++)
    cin >> a[i];
  int sum = 0;
  for (i = 0; i <= N - 1; i++)
    sum = sum + a[i];
  sum -= N;
  cout << sum << endl;
}
Problem p03294 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, v, c[100];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    v += c[i];
  }
  cout << v - n;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, v, c[3010];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
    v += c[i];
  }
  cout << v - n;
  return 0;
}
Problem p03294 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i, N) for (ll i = 0; i < (ll)N; ++i)
#define rpt(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define all(v) v.begin(), v.end()
#define IO                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll waz = 76543217;

void printVector(const vector<int> &vec) {
  for (int value : vec) {
    cout << value << " ";
  }
  cout << endl;
}

int main() {
  IO;

  ll N;
  cin >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  ll G = a[0];
  rpt(i, 1, N) { G = lcm(a[i], G); }

  ll ans = 0;

  rep(i, N) ans += (G - 1) % a[i];

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i, N) for (ll i = 0; i < (ll)N; ++i)
#define rpt(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define all(v) v.begin(), v.end()
#define IO                                                                     \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

ll waz = 76543217;

void printVector(const vector<int> &vec) {
  for (int value : vec) {
    cout << value << " ";
  }
  cout << endl;
}

int main() {
  IO;

  ll N;
  cin >> N;
  vl a(N);
  rep(i, N) cin >> a[i];

  cout << accumulate(all(a), 0) - N << endl;
}
Problem p03295 (C++)

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

int main() {
  int a[100001] = {0};
  int n, m, i, j;
  int tempa, tempb;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    a[i] = 100005;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &tempa, &tempb);
    if (a[tempa] > tempb) {
      a[tempa] = tempb;
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i] < 100005) {
      for (j = i + 1; j < a[i]; j++) {
        if (a[j] < 100005) {
          if (a[j] <= a[i])
            a[i] = 100005;
          else {
            a[j] = a[i];
            a[i] = 100005;
          }
        }
      }
    }
  }
  int sum = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] < 100005)
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}


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

int main() {
  int a[100001] = {0};
  int n, m, i, j;
  int tempa, tempb;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    a[i] = 100005;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &tempa, &tempb);
    if (a[tempa] > tempb) {
      a[tempa] = tempb;
    }
  }
  for (i = 1; i <= n; i++) {
    if (a[i] < 100005) {
      for (j = i + 1; j < a[i]; j++) {
        if (a[j] < 100005) {
          if (a[j] <= a[i])
            a[i] = 100005;
          else {
            a[j] = a[i];
            a[i] = 100005;
          }
          break;
        }
      }
    }
  }
  int sum = 0;
  for (i = 1; i <= n; i++) {
    if (a[i] < 100005)
      sum++;
  }
  printf("%d\n", sum);
  return 0;
}
Problem p03295 (C++)

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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

bool cmp(P a, P b) { return a.second < b.second; }

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

  vector<P> ab(M);
  for (int i = 0; i < M; i++)
    cin >> ab[i].first >> ab[i].second;

  sort(ab.begin(), ab.end(), cmp);

  int count = 0;
  ll tmp = 0;
  for (int i = 0; i < N; i++) {
    if (ab[i].first >= tmp) {
      tmp = ab[i].second;
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

// cout << setprecision(13);
// next_permutation();
//__gcd();
// reverse();
// set ,tuple ,pair;
// bitset
// vector.find
// vector.count


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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

bool cmp(P a, P b) { return a.second < b.second; }

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

  vector<P> ab(M);
  for (int i = 0; i < M; i++)
    cin >> ab[i].first >> ab[i].second;

  sort(ab.begin(), ab.end(), cmp);

  int count = 0;
  ll tmp = 0;
  for (int i = 0; i < M; i++) {
    if (ab[i].first >= tmp) {
      tmp = ab[i].second;
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

// cout << setprecision(13);
// next_permutation();
//__gcd();
// reverse();
// set ,tuple ,pair;
// bitset
// vector.find
// vector.count
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
/*
考虑一个很显然的O(nlogn)的做法
首先对所有线段按照右端点排序，然后按照右端点切

由于所有线段的值域为1 - n，我们可以对所有左端点，直接记录出右端点为位置
再扫一遍即可
*/
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 2001;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int N, M;
int r[MAXN];
int main() {
  N = read();
  M = read();
  for (int i = 1; i <= N; i++)
    r[i] = N + 1;
  for (int i = 1; i <= M; i++) {
    int x = read(), y = read();
    r[x] = min(y, r[x]);
  }
  int cur = N + 1, ans = 0;
  for (int i = 1; i <= N; i++) {
    if (r[i] != N + 1)
      cur = min(cur, r[i]);
    if (i == cur)
      cur = min(N + 1, r[i]), ans++;
  }
  printf("%d", ans);
  return 0;
}
/*

*/

Fixed submission:
/*
考虑一个很显然的O(nlogn)的做法
首先对所有线段按照右端点排序，然后按照右端点切

由于所有线段的值域为1 - n，我们可以对所有左端点，直接记录出右端点为位置
再扫一遍即可
*/
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 1e6 + 10;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int N, M;
int r[MAXN];
int main() {
  N = read();
  M = read();
  for (int i = 1; i <= N; i++)
    r[i] = N + 1;
  for (int i = 1; i <= M; i++) {
    int x = read(), y = read();
    r[x] = min(y, r[x]);
  }
  int cur = N + 1, ans = 0;
  for (int i = 1; i <= N; i++) {
    if (r[i] != N + 1)
      cur = min(cur, r[i]);
    if (i == cur)
      cur = min(N + 1, r[i]), ans++;
  }
  printf("%d", ans);
  return 0;
}
/*

*/
Problem p03295 (C++)

Buggy submission (status: Time Limit Exceeded):
// https://atcoder.jp/contests/abc103/tasks/abc103_d
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 100005

struct span {
  int s;
  int e;
  span() : s(0), e(0) {}
  span(int a, int b) : s(a), e(b) {}
  bool operator<(const span &right) const { return e < right.e; }
};

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

  vector<span> p;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p.push_back(span(a, b));
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  while (p.size() > 0) {
    cnt++;
    int cut_p = p.front().e;
    while (p.size() > 0 && p.front().s < cut_p) {
      p.erase(p.begin());
    }
  }
  cout << cnt << endl;

  return 0;
}


Fixed submission:
// https://atcoder.jp/contests/abc103/tasks/abc103_d
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 100005

struct span {
  int s;
  int e;
  span() : s(0), e(0) {}
  span(int a, int b) : s(a), e(b) {}
  bool operator<(const span &right) const { return e < right.e; }
};

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

  vector<span> p;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    p.push_back(span(a, b));
  }
  sort(p.begin(), p.end());
  int cnt = 0;
  int cut_p = 0;
  for (int i = 0; i < m; i++) {
    if (p[i].s >= cut_p) {
      cnt++;
      cut_p = p[i].e;
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9 + 7;

void chmod(ll &M) {
  if (M >= mod)
    M %= mod;
  else if (M < 0) {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}

ll modpow(ll x, ll n) {
  if (n == 0)
    return 1;

  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

ll power(ll x, ll n) {
  if (n == 0)
    return 1;

  ll res = power(x, n / 2);
  if (n % 2 == 0)
    return res * res;
  else
    return res * res * x;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };

/* <--------------------------------------------> */

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

  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> ba(M);
  for (int i = 0; i < M; ++i)
    cin >> ba[i].second >> ba[i].first;
  sort(ba.begin(), ba.end());

  int ans = 0;
  int pos = 0;
  while (pos < M) {
    int nowb = ba[pos].first - 1;
    while (ba[pos].second <= nowb)
      ++pos;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9 + 7;

void chmod(ll &M) {
  if (M >= mod)
    M %= mod;
  else if (M < 0) {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}

ll modpow(ll x, ll n) {
  if (n == 0)
    return 1;

  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

ll power(ll x, ll n) {
  if (n == 0)
    return 1;

  ll res = power(x, n / 2);
  if (n % 2 == 0)
    return res * res;
  else
    return res * res * x;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };

/* <--------------------------------------------> */

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

  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> ba(M);
  for (int i = 0; i < M; ++i)
    cin >> ba[i].second >> ba[i].first;
  sort(ba.begin(), ba.end());

  int ans = 0;
  int pos = 0;
  while (pos < M) {
    int nowb = ba[pos].first - 1;
    while (pos < M && ba[pos].second <= nowb)
      ++pos;
    ++ans;
  }

  cout << ans << endl;

  return 0;
}
Problem p03295 (C++)

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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, s, t) for (int i = (s); i < (t); ++i)

#define INF 2000000007
#define MOD 998244353

#define MAX 100005

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

struct edge {
  int a, b;
  bool operator<(const edge &left) const { return (b < left.b); }
};

bool flag[MAX];

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<edge> a(M);
  REP(i, M) cin >> a[i].a >> a[i].b;

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

  int ans = 0;
  REP(i, M) {
    ans++;
    int x = a[i].b;
    while (a[++i].a < x)
      ;
    --i;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, s, t) for (int i = (s); i < (t); ++i)

#define INF 2000000007
#define MOD 998244353

#define MAX 100005

typedef unsigned int uint;
typedef unsigned long long int ull;
typedef long long int ll;

struct edge {
  int a, b;
  bool operator<(const edge &left) const { return (b < left.b); }
};

bool flag[MAX];

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<edge> a(M);
  REP(i, M) cin >> a[i].a >> a[i].b;

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

  int ans = 0;
  REP(i, M) {
    ans++;
    int x = a[i].b;
    while (a[++i].a < x)
      if (i == M)
        break;
    --i;
  }

  cout << ans << endl;

  return 0;
}
Problem p03295 (C++)

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

using namespace std;

bool comp(pair<int, int> p, pair<int, int> q) {
  if (p.second < q.second)
    return true;
  else if (p.second > q.second)
    return false;
  else if (p.first <= q.first)
    return true;
  return false;
}

int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> *island = new pair<int, int>[m];
  for (int i = 0; i < m; i++)
    cin >> island[i].first >> island[i].second;

  sort(island, island + m, comp);

  int ans = 0;
  for (int i = 0; i < m;) {
    int a = island[i].second;
    int j = i;
    while (j < m && island[j].first < a)
      j++;
    ans++;
    i = j;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

bool comp(pair<int, int> p, pair<int, int> q) {
  if (p.second < q.second)
    return true;
  else if (p.second > q.second)
    return false;
  else if (p.first < q.first)
    return true;
  return false;
}

int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> *island = new pair<int, int>[m];
  for (int i = 0; i < m; i++)
    cin >> island[i].first >> island[i].second;

  sort(island, island + m, comp);

  int ans = 0;
  for (int i = 0; i < m;) {
    int a = island[i].second;
    int j = i;
    while (j < m && island[j].first < a)
      j++;
    ans++;
    i = j;
  }

  cout << ans << endl;

  return 0;
}
Problem p03295 (C++)

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

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> G(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    G[i] = {b, a};
  }
  REP(i, M) { sort(ALL(G)); }

  int r = -1; // 右端
  int ans = 0;
  REP(i, M) {
    if (r < G[i].second || G[i].first < r) {
      r = G[i].first - 1;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

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

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> G(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    G[i] = {b, a};
  }

  sort(ALL(G));

  int r = -1; // 右端
  int ans = 0;
  REP(i, M) {
    if (r < G[i].second || G[i].first < r) {
      r = G[i].first - 1;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REPR(i, n) FORR(i, n, 0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int N, M, a[10001], b[10001], D[10001];
  cin >> N >> M;
  REP(i, N) { D[i] = N + 1; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    D[a[i] - 1] = min(D[a[i] - 1], b[i] - 1);
  }

  int cnt = 0, k = N + 1;

  REP(i, N) {
    if (i >= k) {
      cnt++;
      k = D[i];
    }
    k = min(k, D[i]);
  }

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define REPR(i, n) FORR(i, n, 0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  int N, M, a[100001], b[100001], D[100001];
  cin >> N >> M;
  REP(i, N) { D[i] = N + 1; }
  REP(i, M) {
    cin >> a[i] >> b[i];
    D[a[i] - 1] = min(D[a[i] - 1], b[i] - 1);
  }

  int cnt = 0, k = N + 1;

  REP(i, N) {
    if (i >= k) {
      cnt++;
      k = D[i];
    }
    k = min(k, D[i]);
  }

  cout << cnt << endl;

  return 0;
}
Problem p03295 (C++)

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

using namespace std;

bool cmp(pair<int, int> A, pair<int, int> B) {
  if (A.second == B.second)
    return A.first < B.second;
  return A.second < B.second;
}
int main() {
  int n, m;
  vector<pair<int, int>> v(m);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end(), cmp);
  int ans = 1;
  int cur = v[0].second;
  for (int i = 1; i < m; i++) {
    if (v[i].first >= cur) {
      ans++;
      cur = v[i].second;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;

bool cmp(pair<int, int> A, pair<int, int> B) {
  if (A.second == B.second)
    return A.first < B.first;
  return A.second < B.second;
}
int main() {
  int n, m;
  vector<pair<int, int>> v(m);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    v.push_back(make_pair(a, b));
  }
  sort(v.begin(), v.end(), cmp);
  int ans = 1;
  int cur = v[0].second;
  for (int i = 1; i < m; i++) {
    if (v[i].first >= cur) {
      ans++;
      cur = v[i].second;
    }
  }
  printf("%d\n", ans);
  return 0;
}