Problem p02792 (C++)

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)                                                               \
  do {                                                                         \
    cerr << #x << ": " << x << "\n";                                           \
  } while (0)
#define debugv(x)                                                              \
  do {                                                                         \
    cerr << #x << ": ";                                                        \
    for (auto &e : (x))                                                        \
      cerr << e << " ";                                                        \
    cerr << "\n";                                                              \
  } while (0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template <typename T> bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T> bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
#define RETURN(x)                                                              \
  do {                                                                         \
    cout << x << '\n';                                                         \
    return 0;                                                                  \
  } while (0)

const int MOD = 1e9 + 7;
const int MAXN = 5e3 + 5;

int main(int argc, char **argv) {
#ifdef OJ
  freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<pii> p(n);
  vector<vector<int>> cnt(10, vector<int>(10));
  fore(i, 1, n) {
    int r = i % 10;
    int l = i;
    while (l / 10 > 0)
      l /= 10;
    p[i] = {l, r};
    cnt[l][r]++;
  }

  LL ans = 0;
  fore(i, 1, n) {
    int l = p[i].fi;
    int r = p[i].se;
    ans += cnt[r][l];
  }

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


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)                                                               \
  do {                                                                         \
    cerr << #x << ": " << x << "\n";                                           \
  } while (0)
#define debugv(x)                                                              \
  do {                                                                         \
    cerr << #x << ": ";                                                        \
    for (auto &e : (x))                                                        \
      cerr << e << " ";                                                        \
    cerr << "\n";                                                              \
  } while (0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template <typename T> bool mmax(T &m, const T q) {
  if (m < q) {
    m = q;
    return true;
  } else
    return false;
}
template <typename T> bool mmin(T &m, const T q) {
  if (m > q) {
    m = q;
    return true;
  } else
    return false;
}
#define RETURN(x)                                                              \
  do {                                                                         \
    cout << x << '\n';                                                         \
    return 0;                                                                  \
  } while (0)

const int MOD = 1e9 + 7;
const int MAXN = 5e3 + 5;

int main(int argc, char **argv) {
#ifdef OJ
  freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;
  vector<pii> p(n + 1);
  vector<vector<int>> cnt(10, vector<int>(10));
  fore(i, 1, n) {
    int r = i % 10;
    int l = i;
    while (l / 10 > 0)
      l /= 10;
    p[i] = {l, r};
    cnt[l][r]++;
  }

  LL ans = 0;
  fore(i, 1, n) {
    int l = p[i].fi;
    int r = p[i].se;
    ans += cnt[r][l];
  }

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