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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1 << 29;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int p[N];
  rep(i, N) cin >> p[i];
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    bool flg = true;
    for (int j = 0; j < i; ++j) {
      if (p[j] < p[i]) {
        flg = false;
        break;
      }
    }
    ans += ((flg) ? 1 : 0);
  }
  cout << ans;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1 << 29;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int p[N];
  rep(i, N) cin >> p[i];
  int ans = 0;
  int minv[N + 1];
  minv[0] = INF;
  rep(i, N) minv[i + 1] = min(minv[i], p[i]);
  rep(i, N) {
    if (minv[i] >= p[i])
      ans += 1;
  }
  cout << ans;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    int res = 0;
    for (int j = 0; j < i; ++j) {
      if (a[i] <= a[j])
        ++res;
      else
        continue;
    }
    if (res == i)
      ++cnt;
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int cnt = 0;
  int res = 10000000;
  for (int i = 0; i < n; ++i) {
    res = min(res, a[i]);
    if (a[i] <= res)
      ++cnt;
  }
  cout << cnt << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

long long gcd(int x, int y) {
  if (x == 0)
    return y;

  return gcd(y % x, x);
}

long long lcm(int x, int y) {
  if (y == 0) {
    return x;
  }

  return x * y / gcd(x, y);
}

int min(int a, int b) { return a > b ? b : a; }

int max(int a, int b) { return a > b ? a : b; }

int n;
vector<int> tree(400005, 0);

int query(int a) {
  int res = 0;
  for (; a > 0; a -= a & -a) {
    res += tree[a];
  }

  return res;
}

int update(int a) {
  for (; a <= 200000; a += a & -a) {
    tree[a]++;
  }
}

int main() {
  cin.sync_with_stdio(false);
  cin >> n;

  int res = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (i == 0) {
      update(a);
      res++;
    } else {
      update(a);
      if (query(a) - 1 == 0) {
        res++;
      }
    }
  }

  cout << res << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

long long gcd(int x, int y) {
  if (x == 0)
    return y;

  return gcd(y % x, x);
}

long long lcm(int x, int y) {
  if (y == 0) {
    return x;
  }

  return x * y / gcd(x, y);
}

int min(int a, int b) { return a > b ? b : a; }

int max(int a, int b) { return a > b ? a : b; }

int n;
vector<int> tree(400005, 0);

int query(int a) {
  int res = 0;
  for (; a > 0; a -= a & -a) {
    res += tree[a];
  }

  return res;
}

void update(int a) {
  for (; a <= 200000; a += a & -a) {
    tree[a]++;
  }
}

int main() {
  cin.sync_with_stdio(false);
  cin >> n;

  int res = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (i == 0) {
      update(a);
      res++;
    } else {
      update(a);
      if (query(a) - 1 == 0) {
        res++;
      }
    }
  }

  cout << res << endl;
}
Problem p02791 (C++)

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

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

  ll count = 0;

  ll mini = P[0];
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j <= i; j++) {
      mini = min(mini, P[j]);
    }
    if (P[i] <= mini) {
      count++;
    }
  }

  cout << count << endl;
}

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

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

  ll count = 0;

  ll mini = P[0];
  for (ll i = 0; i < N; i++) {
    mini = min(mini, P[i]);
    if (mini == P[i]) {
      count++;
    }
  }

  cout << count << endl;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif //*/
  ll n;
  cin >> n;
  ll a[n + 1];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll mm = a[0];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (mm >= a[i]) {
      cnt++;
      mm = min(mm, a[i]);
    }
  }
  cout << cnt;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Fixed submission:
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // #ifndef ONLINE_JUDGE
  //   freopen("input.txt", "r", stdin);
  //   freopen("output.txt", "w", stdout);
  // #endif //*/
  ll n;
  cin >> n;
  ll a[n + 1];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  ll mm = a[0];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (mm >= a[i]) {
      cnt++;
      mm = min(mm, a[i]);
    }
  }
  cout << cnt;
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
Problem p02791 (C++)

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x)                                                                  \
  int x;                                                                       \
  cin >> x
#define inn(x, y)                                                              \
  int x, y;                                                                    \
  cin >> x >> y
#define innn(x, y, z)                                                          \
  int x, y, z;                                                                 \
  cin >> x >> y >> z
#define bit(n) (1 << (n))

#define out(x) cout << (x) << endl;
#define err(x) cerr << (x) << endl;
#define errr(x, y) cerr << (x) << " " << (y) << endl;
#define errrr(x, y, z) cerr << (x) << " " << (y) << " " << (z) << endl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, n) for (int i = 1; i <= (n); i++)
#define reppp(j, i, n) for (int j = i + 1; j < n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad) / 2 / M_PI) * 360)
#define mid(min, max) ((min + max) / 2)

int main() {
  in(n);
  int p[lim5] = {}, cnt = 0, max = lim5;

  rep(i, n) cin >> p[i];

  rep(i, n) {
    if (max > p[i]) {
      max = p[i];
      ++cnt;
    }
  }

  out(cnt);

  return 0;
}


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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x)                                                                  \
  int x;                                                                       \
  cin >> x
#define inn(x, y)                                                              \
  int x, y;                                                                    \
  cin >> x >> y
#define innn(x, y, z)                                                          \
  int x, y, z;                                                                 \
  cin >> x >> y >> z
#define bit(n) (1 << (n))

#define out(x) cout << (x) << endl;
#define err(x) cerr << (x) << endl;
#define errr(x, y) cerr << (x) << " " << (y) << endl;
#define errrr(x, y, z) cerr << (x) << " " << (y) << " " << (z) << endl;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repp(i, n) for (int i = 1; i <= (n); i++)
#define reppp(j, i, n) for (int j = i + 1; j < n; j++)

#define lim5 100002
#define lim9 1000000002

#define deg(rad) (((rad) / 2 / M_PI) * 360)
#define mid(min, max) ((min + max) / 2)

int main() {
  in(n);
  int p[200004] = {}, cnt = 0, max = 200004;

  rep(i, n) cin >> p[i];

  rep(i, n) {
    if (max > p[i]) {
      max = p[i];
      ++cnt;
    }
  }

  out(cnt);

  return 0;
}
Problem p02791 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> per(n);
  for (int i = 0; i < n; i++) {
    cin >> per.at(i);
  }
  int ans = 0;
  set<int> num;
  for (int i = 0; i < n; i++) {
    for (int j = i; j > -1; j--) {
      num.insert(per.at(i));
    }
    if (*begin(num) == per.at(i))
      ans += 1;
  }
  cout << ans;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> per(n);
  for (int i = 0; i < n; i++) {
    cin >> per.at(i);
  }
  int ans = 0;
  set<int> num;
  for (int i = 0; i < n; i++) {
    num.insert(per.at(i));
    if (*begin(num) == per.at(i))
      ans += 1;
  }
  cout << ans;
}
Problem p02791 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
P = map(int, input().split())

ret = 0
currmin = P[0]
for i in range(N):
    if P[i] <= currmin:
        currmin = P[i]
        ret += 1

print(ret)


Fixed submission:
N = int(input())
P = list(map(int, input().split()))

ret = 0
currmin = P[0]
for i in range(N):
    if P[i] <= currmin:
        currmin = P[i]
        ret += 1

print(ret)
Problem p02791 (C++)

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

int a[100010];
int main() {
  int mn = INT_MAX;
  int i, j, n, m, cnt = 0;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  for (i = 0; i < n; i++) {
    if (mn > a[i]) {
      mn = a[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int a[200010];
int main() {
  int mn = INT_MAX;
  int i, j, n, m, cnt = 0;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  for (i = 0; i < n; i++) {
    if (mn > a[i]) {
      mn = a[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}
Problem p02791 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define fill(a, x) memset(a, x, sizeof(a))
#define zero(a) fill(a, 0)
#define minus(a) fill(a, -1)
#define dbg(x) cout << #x "=" << x << endl

int main() {
  int n;
  cin >> n;
  int count = 0;
  int num;
  int res = 0;
  int minIndex = 0;
  vi array;
  while (count != n) {
    cin >> num;
    array.pb(num);
    count++;
  }

  rep(i, n) {
    if (i == 0) {
      res += 1;
      continue;
    }
    if (array[i] > array[minIndex])
      continue;
    for (int j = 0; j < i; j++) {
      if (array[i] > array[j]) {
        break;
      }
      if (j == i - 1) {
        minIndex = j;
        res += 1;
      }
    }
  }

  cout << res << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define fill(a, x) memset(a, x, sizeof(a))
#define zero(a) fill(a, 0)
#define minus(a) fill(a, -1)
#define dbg(x) cout << #x "=" << x << endl

int main() {
  int n;
  cin >> n;
  int count = 0;
  int num;
  int res = 0;
  int minIndex = 0;
  vi array;
  while (count != n) {
    cin >> num;
    array.pb(num);
    count++;
  }

  rep(i, n) {
    if (i == 0) {
      res += 1;
      continue;
    }
    if (array[i] > array[minIndex])
      continue;
    minIndex = i;
    res += 1;
    continue;
  }

  cout << res << endl;

  return 0;
}
Problem p02791 (C++)

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p[200100], i, ruimin = 300000, ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (i = 0; i < n; i++) {
    if (p[i] <= ruimin) {
      ans++;
      ruimin = p[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

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

using namespace std;

int minn[100010];

int main(void) {
  // freopen("aaa.in","r",stdin);
  int n;
  int ans = 0;
  scanf("%d", &n);
  minn[0] = n + 1;
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    minn[i] = min(minn[i - 1], a);
    if (a <= minn[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int minn[300010];

int main(void) {
  // freopen("aaa.in","r",stdin);
  int n;
  int ans = 0;
  scanf("%d", &n);
  minn[0] = n + 1;
  for (int i = 1, a; i <= n; i++) {
    scanf("%d", &a);
    minn[i] = min(minn[i - 1], a);
    if (a <= minn[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

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

int main() {
  lint n, ans = 0;
  cin >> n;
  vector<lint> p(n), c(n);
  rep(i, n) cin >> p.at(i);
  c = p;
  rep(i, n) {
    sort(c.begin(), c.begin() + i);
    if (p.at(i) <= c.at(0))
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  lint n, ans = 0;
  cin >> n;
  vector<lint> p(n), c(n);
  rep(i, n) cin >> p.at(i);
  c = p;
  rep(i, n) {
    if (c.at(i) < c.at(0))
      c.at(0) = c.at(i);
    if (p.at(i) <= c.at(0))
      ans++;
  }
  cout << ans << endl;
}
Problem p02791 (C++)

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

int main() {
  Int N;
  vector<Int> P(N);

  rep(i, N) cin >> P[i];

  Int m = P[0], ans = 1;

  rep1(i, N - 1) {
    if (m >= P[i])
      ans++;
    m = min(m, P[i]);
  }

  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 rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main() {
  Int N;
  cin >> N;
  vector<Int> P(N);

  rep(i, N) cin >> P[i];

  Int m = P[0], ans = 1;

  rep1(i, N - 1) {
    if (m >= P[i])
      ans++;
    m = min(m, P[i]);
  }

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

Buggy submission (status: Runtime Error):
#include <iostream>
#define N 100005
#define INF 0x3f3f3f3f
using namespace std;
int main() {
  int min0 = INF;
  int ans = 0;
  int n;
  cin >> n;
  int a[N];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] < min0) {
      ans++;
      min0 = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define N 1000005
#define INF 0x3f3f3f3f
using namespace std;
int main() {
  int min0 = INF;
  int ans = 0;
  int n;
  cin >> n;
  int a[N];
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] < min0) {
      ans++;
      min0 = a[i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02791 (C++)

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

int a[40005];
int d[40005];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n == 0) // 0个元素特判一下
  {
    printf("0\n");
    return 0;
  }
  d[1] = a[1]; // 初始化
  int len = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] <= d[len])
      d[++len] = a[i]; // 如果可以接在len后面就接上
    else               // 否则就找一个最该替换的替换掉
    {
      int j = lower_bound(d + 1, d + len + 1, a[i]) -
              d; // 找到第一个大于它的d的下标
      d[j] = a[i];
    }
  }
  printf("%d\n", len);
  return 0;
}


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

int a[200005];
int d[200005];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  if (n == 0) // 0个元素特判一下
  {
    printf("0\n");
    return 0;
  }
  d[1] = a[1]; // 初始化
  int len = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] <= d[len])
      d[++len] = a[i]; // 如果可以接在len后面就接上
    else               // 否则就找一个最该替换的替换掉
    {
      int j = lower_bound(d + 1, d + len + 1, a[i]) -
              d; // 找到第一个大于它的d的下标
      d[j] = a[i];
    }
  }
  printf("%d\n", len);
  return 0;
}
Problem p02791 (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;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI; // 例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int>> QUE_int;
const int INF =
    pow(10, 5) + 1; //+1しないとREになる(out of rangeになるんかな?? )

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

  // for(int i=0; i<N; i++) cout << P[i] << " " ;
  // cout << endl;

  int ans = 0;
  int now_num = 1001001;
  for (int i = 0; i < N; i++) { // 注目するP
    for (int j = 0; j <= i; j++) {
      if (P[i] > P[j])
        break;
      if (P[i] > now_num)
        break;
      if (j == i) {
        ans++;
        now_num = P[i];
      }
    }
  }

  cout << ans << endl;
}


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;
typedef vector<int> VI;
typedef vector<VI> VVI; // 例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int>> QUE_int;
const int INF =
    pow(10, 5) + 1; //+1しないとREになる(out of rangeになるんかな?? )

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

  // for(int i=0; i<N; i++) cout << P[i] << " " ;
  // cout << endl;

  int ans = 1;
  int now_num = P[0];
  for (int i = 1; i < N; i++) {
    if (P[i] > P[i - 1])
      continue;
    if (P[i] > now_num)
      continue;
    ans++;
    now_num = P[i];
    // cout << "i : " << i << endl;
  }

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

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int v[100005];

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

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int ans = 0;
  int menor = v[0];
  for (int i = 0; i < n; i++) {
    if (v[i] <= menor) {
      ans++;
    }

    menor = min(menor, v[i]);
  }

  cout << ans << endl;

  // Dado um v[i], todos os seus antecessores devem ser menor que ele;

  return 0;
}


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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int v[200005];

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

  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int ans = 0;
  int menor = v[0];
  for (int i = 0; i < n; i++) {
    if (v[i] <= menor) {
      ans++;
    }

    menor = min(menor, v[i]);
  }

  cout << ans << endl;

  // Dado um v[i], todos os seus antecessores devem ser menor que ele;

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, a, b, arr[100009];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  m = arr[0];
  a = 1;
  for (i = 1; i < n; i++) {
    if (arr[i] <= m) {
      m = arr[i];
      a++;
    }
  }
  printf("%d\n", a);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j, a, b, arr[200009];
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  m = arr[0];
  a = 1;
  for (i = 1; i < n; i++) {
    if (arr[i] <= m) {
      m = arr[i];
      a++;
    }
  }
  printf("%d\n", a);
}
Problem p02791 (C++)

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

int main() {
  int N;
  int min = 2000001, ans = 0;
  int P[10000] = {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    if (min > P[i]) {
      min = P[i];
      ans++;
    }
  }
  cout << ans;
}

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

int main() {
  int N;
  int min = 200001, ans = 0;
  int P[200000] = {0};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  for (int i = 0; i < N; i++) {
    if (min > P[i]) {
      min = P[i];
      ans++;
    }
  }
  cout << ans;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif
  int n;
  SCD(n);
  int x;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    SCD(x);
    v.emplace_back(x, i);
  }
  sort(v.begin(), v.end());
  int ans = 1;
  int ind = v[0].second;
  for (int i = 1; i < n; i++) {
    if (v[i].second < ind)
      ans++;
    ind = min(ind, v[i].second);
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MOD7 1000000007
#define MOD9 1e9 + 9
#define SCD(t) scanf("%d", &t)
#define SCLD(t) scanf("%ld", &t)
#define SCLLD(t) scanf("%lld", &t)
#define SCC(t) scanf("%c", &t)
#define SCS(t) scanf("%s", t)
#define SCF(t) scanf("%f", &t)
#define SCLF(t) scanf("%lf", &t)
#define MEM(a, b) memset(a, (b), sizeof(a))
typedef long long ll;
typedef long double ld;
typedef string str;
typedef double d;
typedef unsigned u;
typedef unsigned long long ull;

const long long BIGINF = 2e18 + 7;
const int INF = 2e9 + 7;

int main() {
  /*#ifndef ONLINE_JUDGE
          freopen("inputf.txt", "r", stdin);
          freopen("outputf.txt", "w", stdout);
  #endif*/
  int n;
  SCD(n);
  int x;
  vector<pair<int, int>> v;
  for (int i = 0; i < n; i++) {
    SCD(x);
    v.emplace_back(x, i);
  }
  sort(v.begin(), v.end());
  int ans = 1;
  int ind = v[0].second;
  for (int i = 1; i < n; i++) {
    if (v[i].second < ind)
      ans++;
    ind = min(ind, v[i].second);
  }
  printf("%d", ans);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[20005], n, ans = 0, ma = 9999999;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &p[i]);
  for (int i = 0; i < n; i++) {
    if (p[i] <= ma)
      ans++;
    ma = min(p[i], ma);
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int p[200006], n, ans = 0, ma = 9999999;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &p[i]);
  for (int i = 0; i < n; i++) {
    if (p[i] <= ma)
      ans++;
    ma = min(p[i], ma);
  }
  printf("%d", ans);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
/*
 * Author: pawanmsr
 */

/*
 * Run in Mac using the following command:
 * g++ -std=c++14 <cpp_filename>
 * A binary will be generated. Then run:
 * ./a.out
 */

#include <algorithm>
#include <bitset>
#include <climits>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int, int>
#define pll pair<ll, ll>

// Global //
int n, p[100005];

// Functions //

// Main //
int main(int argc, char const *argv[]) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // // freopen("output.txt", "w", stdout);
  // #else
  // // online submission
  // #endif

  /* code */
  cin >> n;
  int mn = INT_MAX;

  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] <= mn) {
      mn = p[i];
      res++;
    }
  }
  cout << res << endl;

  return 0;
}

Fixed submission:
/*
 * Author: pawanmsr
 */

/*
 * Run in Mac using the following command:
 * g++ -std=c++14 <cpp_filename>
 * A binary will be generated. Then run:
 * ./a.out
 */

#include <algorithm>
#include <bitset>
#include <climits>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

// Macro //
#define X first
#define Y second
#define pii pair<int, int>
#define pll pair<ll, ll>

// Global //
int n, p[200005];

// Functions //

// Main //
int main(int argc, char const *argv[]) {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // // freopen("output.txt", "w", stdout);
  // #else
  // // online submission
  // #endif

  /* code */
  cin >> n;
  int mn = INT_MAX;

  int res = 0;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    if (p[i] <= mn) {
      mn = p[i];
      res++;
    }
  }
  cout << res << endl;

  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int a[10005];
int main() {
  int n;
  cin >> n;
  int k = 0;
  int mina = 0xfffff;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] <= mina) {
      k++;
      mina = a[i];
    }
  }
  cout << k << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a[2000005];
int main() {
  int n;
  cin >> n;
  int k = 0;
  int mina = 0xfffff;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] <= mina) {
      k++;
      mina = a[i];
    }
  }
  cout << k << endl;
}
Problem p02791 (C++)

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

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> p(n);
  for (size_t i = 0; i < n; i++)
    cin >> p[i];

  int ans = 0;
  for (size_t i = 1; i <= n; i++) {
    int minidx = min_element(p.begin(), p.begin() + i) - p.begin();
    if (p[minidx] == p[i - 1])
      ++ans;
  }

  cout << ans << endl;
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> p(n);
  for (size_t i = 0; i < n; i++)
    cin >> p[i];

  int ans = 0;
  int min = 3000000;
  for (size_t i = 0; i < n; i++) {
    if (p[i] < min)
      min = p[i];
    if (min == p[i])
      ++ans;
  }

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

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

using namespace std;

const int maxn = 1e5 + 5;

typedef long long ll;

const ll mod = 1e9 + 7;

int a[maxn];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int ans = 0;
  int mn = 0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    if (mn < a[i])
      continue;
    mn = min(mn, a[i]);
    ans++;
  }
  printf("%d", ans);
  return 0;
}

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

using namespace std;

const int maxn = 2e5 + 5;

typedef long long ll;

const ll mod = 1e9 + 7;

int a[maxn];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int ans = 0;
  int mn = 0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    if (mn < a[i])
      continue;
    mn = min(mn, a[i]);
    ans++;
  }
  printf("%d", ans);
  return 0;
}
Problem p02791 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i, v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
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;
}
typedef long long ll;
#define pint pair<int, int>
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vint(v);
  rep(i, n) cin >> v[i];
  int cnt = 1;
  int minnum = v[0];
  REP(i, 1, n) {
    if (v[i] < minnum) {
      cnt++;
      minnum = v[i];
    }
  }
  cout << cnt << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i, v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
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;
}
typedef long long ll;
#define pint pair<int, int>
using namespace std;
// オーバーフローに気をつけろよおおおおおお
// 確認忘れるなよおおおおおお

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  int cnt = 1;
  int minnum = v[0];
  REP(i, 1, n) {
    if (v[i] < minnum) {
      cnt++;
      minnum = v[i];
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p02791 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);

  rep(i, n) cin >> p[i];
  int ans = n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (p[i] > p[j]) {
        --ans;
        break;
      }
    }
  }

  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);

  rep(i, n) cin >> p[i];
  int ans = n;
  int low = p[0];
  for (int i = 1; i < n; i++) {
    if (p[i] > low) {
      --ans;
    } else
      low = p[i];
  }

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

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

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

  // 組み合わせ配列初期化
  int cmb[10][10]; // 先頭, 末尾
  for (int head = 0; head < 11; head++) {
    for (int tail = 0; tail < 11; tail++) {
      cmb[head][tail] = 0;
    }
  }

  // 組み合わせ配列を先に求める
  for (int i = 1; i <= N; i++) {
    std::string s = std::to_string(i);
    int head = s[0] - '0';
    int tail = s[s.size() - 1] - '0';
    cmb[head][tail]++;
  }

  // AとBの組み合わせ数を求める
  int ans = 0;
  for (int head = 1; head <= 9; head++) {
    for (int tail = 1; tail <= 9; tail++) {
      ans += cmb[head][tail] * cmb[tail][head];
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


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

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

  // 組み合わせ配列初期化
  int cmb[10][10]; // 先頭, 末尾
  for (int head = 0; head < 10; head++) {
    for (int tail = 0; tail < 10; tail++) {
      cmb[head][tail] = 0;
    }
  }

  // 組み合わせ配列を先に求める
  for (int i = 1; i <= N; i++) {
    std::string s = std::to_string(i);
    int head = s[0] - '0';
    int tail = s[s.size() - 1] - '0';
    cmb[head][tail]++;
  }

  // AとBの組み合わせ数を求める
  int ans = 0;
  for (int head = 1; head <= 9; head++) {
    for (int tail = 1; tail <= 9; tail++) {
      ans += cmb[head][tail] * cmb[tail][head];
    }
  }

  std::cout << ans << std::endl;

  return 0;
}
Problem p02792 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  cin >> N;
  vector<vector<int>> c(9, vector<int>(9));
  for (int i = 1; i <= N; i++) {
    int keta = to_string(i).length();
    // cout << keta << endl;
    int last_num = i % 10;
    if (last_num == 0)
      continue;
    int first_num = 0;
    if (keta == 1) {
      first_num = i;
    } else {
      first_num = i / ((keta - 1) * 10);
    }
    // cout << first_num << endl;
    // cout << last_num << endl;

    c.at(last_num - 1).at(first_num - 1) += 1;
  }
  int cnt = 0;
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cnt += c.at(i).at(j) * c.at(j).at(i);
    }
  }
  cout << cnt;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N = 0;
  cin >> N;
  vector<vector<int>> c(9, vector<int>(9));
  for (int i = 1; i <= N; i++) {
    int keta = to_string(i).length();
    // cout << keta << endl;
    int last_num = i % 10;
    if (last_num == 0)
      continue;
    int first_num = 0;
    if (keta == 1) {
      first_num = i;
    } else {
      first_num = i / pow(10, (keta - 1));
    }
    if (last_num > 9 || first_num > 9) {
      cout << i << endl;
      cout << pow(10, (keta - 1)) << endl;
      cout << first_num << endl;
      cout << last_num << endl;
      exit(1);
    }
    // cout << first_num << endl;
    // cout << last_num << endl;

    c.at(last_num - 1).at(first_num - 1) += 1;
  }
  int cnt = 0;
  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      cnt += c.at(i).at(j) * c.at(j).at(i);
    }
  }
  cout << cnt;
}
Problem p02792 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

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

P f(int n) {
  int a, b = n % 10;
  while (n)
    n / 10;
  a = n;
  return P(a, b);
}

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

  map<P, int> freq;
  REP2(i, 1, n + 1) {
    P p = f(i);
    freq[p]++;
  }
  ll ans = 0;
  REP2(i, 1, 10) {
    REP2(j, 1, 10) {
      P p = make_pair(i, j), q = make_pair(j, i);
      ans += freq[p] * freq[q];
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

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

P f(int n) {
  int a, b = n % 10;
  while (n) {
    a = n;
    n /= 10;
  }
  return P(a, b);
}

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

  map<P, int> freq;
  REP2(i, 1, n + 1) {
    P p = f(i);
    freq[p]++;
  }
  ll ans = 0;
  REP2(i, 1, 10) {
    REP2(j, 1, 10) {
      P p = make_pair(i, j), q = make_pair(j, i);
      ans += freq[p] * freq[q];
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02792 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

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

ll comb(ll n, ll r) {
  ll ret = 1;
  for (ll i = 0; i < r; i++)
    ret = ret * (n - i);
  for (ll i = 1; i <= r; i++)
    ret /= i;
  return ret;
}

int main() {
  ll n, l, r;
  cin >> n;
  vector<vector<ll>> c(9, vector<ll>(9, 0));
  ll ans = 0;

  for (int i = 1; i <= n; i++) {
    r = i % 10;
    l = i;
    while (l / 10 != 0) {
      l /= 10;
    }
    c[l - 1][r - 1]++;
  }

  rep(i, 9) { rep(j, 9) ans += c[i][j] * c[j][i]; }

  cout << ans;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

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

ll comb(ll n, ll r) {
  ll ret = 1;
  for (ll i = 0; i < r; i++)
    ret = ret * (n - i);
  for (ll i = 1; i <= r; i++)
    ret /= i;
  return ret;
}

int main() {
  ll n, l, r;
  cin >> n;
  vector<vector<ll>> c(9, vector<ll>(9, 0));
  ll ans = 0;

  for (int i = 1; i <= n; i++) {
    r = i % 10;
    l = i;
    while (l / 10 != 0) {
      l /= 10;
    }
    if (l != 0 && r != 0)
      c[l - 1][r - 1]++;
  }

  rep(i, 9) { rep(j, 9) ans += c[i][j] * c[j][i]; }

  cout << ans;
}
Problem p02792 (C++)

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

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

  vector<vector<int>> p(10, vector<int>(10, 0));
  for (int i = 1; i <= 9; i++) {
    for (int j = i; j <= 9; j++) {
      for (int k = 1; k <= n; k++) {
        ostringstream oss2;
        oss2 << k;
        string num = oss2.str();
        int begin = int(num[0] - '0');
        int end = int(num[num.size() - 1] - '0');
        if (i == begin && j == end) {
          p[i][j]++;
        }
        if (i != j && i == end && j == begin) {
          p[j][i]++;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += p[i][j] * p[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

  vector<vector<int>> p(10, vector<int>(10, 0));

  for (int k = 1; k <= n; k++) {
    ostringstream oss2;
    oss2 << k;
    string num = oss2.str();
    int begin = int(num[0] - '0');
    int end = int(num[num.size() - 1] - '0');
    p[begin][end]++;
  }

  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += p[i][j] * p[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02792 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("INPUT.txt", "r", stdin);
  freopen("OUTPUT.txt", "w", stdout);
#endif

  // -------------------------------------Code starts
  // here---------------------------------------------------------------------

  int n;
  cin >> n;
  int zz[10][10] = {};
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    string a = to_string(i);
    zz[a[0] - '0'][a[a.length() - 1] - '0']++;
  }
  // for(int i=1;i<=9;i++)
  // {
  //    if(i<=n)
  //       zz[i][i]++;
  // }
  // for(int i=1;i<=9;i++)
  // {
  //    for(int j=1;j<=9;j++)
  //    {
  //       if(10*i+j<=n)
  //          zz[i][j]++;
  //    }
  // }
  // cout<<zz[1][1]<<'\n';
  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += zz[i][j] * zz[j][i];
    }
  }
  cout << ans;

  // -------------------------------------Code ends
  // here------------------------------------------------------------------
  clock_t clk;
  clk = clock();

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //  #ifndef ONLINE_JUDGE
  //     freopen ("INPUT.txt" , "r" , stdin);
  //     freopen ("OUTPUT.txt" , "w" , stdout);
  //  #endif

  // -------------------------------------Code starts
  // here---------------------------------------------------------------------

  int n;
  cin >> n;
  int zz[10][10] = {};
  int cnt = 0;
  for (int i = 0; i <= n; i++) {
    string a = to_string(i);
    zz[a[0] - '0'][a[a.length() - 1] - '0']++;
  }
  // for(int i=1;i<=9;i++)
  // {
  //    if(i<=n)
  //       zz[i][i]++;
  // }
  // for(int i=1;i<=9;i++)
  // {
  //    for(int j=1;j<=9;j++)
  //    {
  //       if(10*i+j<=n)
  //          zz[i][j]++;
  //    }
  // }
  // cout<<zz[1][1]<<'\n';
  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += zz[i][j] * zz[j][i];
    }
  }
  cout << ans;

  // -------------------------------------Code ends
  // here------------------------------------------------------------------
  clock_t clk;
  clk = clock();

  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}
Problem p02792 (C++)

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

int main() {
  // freopen("test.in","r",stdin);
  // freopen("test.ok","w",stdout);
  int64_t n, a = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int64_t x = i, y = j, z = i, t = j;
      while (x >= 10)
        x = x / 10;
      while (t >= 10)
        t = t / 10;
      if (x == (y % 10) && t == (z % 10))
        a++;
    }
  cout << a;
}

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

int main() {
  // freopen("test.in","r",stdin);
  // freopen("test.ok","w",stdout);
  int64_t n, a = 0;
  cin >> n;
  /*for (int i=1;i<=n;i++)
  for (int j=1;j<=n;j++)
      {
          int64_t x=i,y=j,
          z=i,
          t=j;
          while (x>=10)
          x=x/10;
          while (t>=10)
          t=t/10;
          if (x==(y%10)&&t==(z%10)) a++;
      }*/
  int64_t s[20][20];
  memset(s, 0, sizeof(s));
  for (int i = 1; i <= n; i++) {
    int x = i;
    while (x >= 10)
      x = x / 10;
    s[x][i % 10]++;
  }
  for (int i = 1; i <= 9; i++)
    for (int j = 1; j <= 9; j++)
      a = a + s[i][j] * s[j][i];
  cout << a;
}
Problem p02792 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }

  return res;
}

ll comb(ll a, ll b) {
  ll ans = 1;

  for (ll i = a; i > a - b; i--) {
    ans = ans * i % mod;
  }
  for (ll i = 1; i <= b; i++) {
    ans = (ans * modpow(i, mod - 2)) % mod;
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  ll res = 0;
  vector<vector<ll>> num(10, vector<ll>(10, 0));
  for (int i = 0; i <= N; i++) {
    vector<int> d;
    int nn = i;
    while (nn) {
      d.push_back(nn % 10);
      nn /= 10;
    }

    int a = d[0];
    int b = d.back();
    if (!a || !b)
      continue;
    ++num[a][b];
  }
  for (int a = 1; a < 10; a++) {
    for (int b = 1; b < 10; b++) {
      res += num[a][b] * num[b][a];
    }
  }

  cout << res << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll modpow(ll a, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }

  return res;
}

ll comb(ll a, ll b) {
  ll ans = 1;

  for (ll i = a; i > a - b; i--) {
    ans = ans * i % mod;
  }
  for (ll i = 1; i <= b; i++) {
    ans = (ans * modpow(i, mod - 2)) % mod;
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  ll res = 0;
  vector<vector<ll>> num(10, vector<ll>(10, 0));
  for (int i = 1; i <= N; i++) {
    vector<int> d;
    int nn = i;
    while (nn) {
      d.push_back(nn % 10);
      nn /= 10;
    }

    int a = d[0];
    int b = d.back();
    if (!a || !b)
      continue;
    ++num[a][b];
  }
  for (int a = 1; a < 10; a++) {
    for (int b = 1; b < 10; b++) {
      res += num[a][b] * num[b][a];
    }
  }

  cout << res << endl;

  return 0;
}