alexjercan/bugnet huggingface dataset:
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("sumsqr.in");                                                    \\
  ofstream out("sumsqr.out");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  fast;
  ll a;
  cin >> a;
  vec<ll> m(a);
  for (int q = 0; q < a; q++)
    cin >> m[q];
  map<ll, ll> mp;
  ll o = 0;
  for (int q = a - 2; q >= 0; q--) {
    mp[m[q + 1] + (a - 1 - q - 1)]++;
    o += mp[-m[q] + 1 + a - 1 - (q + 1)];
  }
  cout << o;
}

Error: TLE

Fixed submission:

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node *, Node *>
#define uid uniform_int_distribution
#define FILE                                                                   \\
  ifstream in("sumsqr.in");                                                    \\
  ofstream out("sumsqr.out");
#define fast                                                                   \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);                                                      \\
  cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int a;
int m[200001];

int main() {
  fast;
  ll o = 0;
  cin >> a;
  for (int q = 0; q < a; q++)
    cin >> m[q];
  for (int d = 1; d <= a; d++) {
    for (int q = d; q < a; q++) {
      o += d == m[q] + m[q - d];
    }
  }
  cout << o;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

/* 解説を見て考えてみた */

int main() {
  // 入力スタンダード
  ll n; // n人の参加者
  cin >> n;

  ll gp = 0; // 最終的に出力するpair数

  map<ll, ll> mp;

  for (ll i = 0; i < n; i++) {
    ll ai;
    cin >> ai;
    mp[i + ai]++;
    gp += mp[i - ai];
  }

  cout << gp << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

/* 探索しない版*/

void swap(ll &a, ll &b) {
  ll i = a;
  a = b;
  b = i;
}

int main() {
  ll n; // n人の参加者
  cin >> n;

  ll gp = 0;

  vector<vector<ll>> a(n + 1); // n番目の参加者の身長

  for (ll i = 1; i < n + 1; i++) {
    ll hi;
    cin >> hi;
    for (ll j = i + hi + 1; j < n + 1; j++) {
      // 後で i+hi+n 番目以降の人に期待する身長
      // 後でsortしないようsortしておく
      if (a.at(j).size() != 0) {
        a.at(j).push_back(j - i - hi);
        for (ll k = a.at(j).size() - 1; k > 0; k--) {
          if (a.at(j).at(k) < a.at(j).at(k - 1)) {
            swap(a.at(j).at(k), a.at(j).at(k - 1));
          } else {
            break;
          }
        }
      } else {
        a.at(j).push_back(j - i - hi);
      }
    }

    if (a.at(i).size() > 0) { // i番目の人に調査用の人がいるなら
      for (ll j = 0; j < a.at(i).size(); j++) {
        if (hi == a.at(i).at(j)) {
          gp++;
        }
        if (hi < a.at(i).at(j)) {
          break;
        }
      }
    }
  }

  cout << gp << endl;

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, d;
  long long int cnt = 0;
  cin >> n;
  multiset<long long int> l, r;
  set<long long int> s;
  for (long long int i = 0; i < n; ++i) {
    cin >> d;
    l.insert(i + d);
    r.insert(i - d);
    s.insert(i + d);
  }
  for (auto it = s.begin(); it != s.end(); ++it) {
    cnt += l.count(*it) * r.count(*it);
  }
  cout << cnt << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if ((j - i) == a[i] + a[j])
        ++cnt;
    }
  }
  cout << cnt << "\\n";
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  long long N, i, res, a;
  cin >> N;
  map<int, int> m;

  res = 0;
  for (i = 0; i < N; i++) {
    cin >> a;
    res += m[i - a];
    m[i + a]++;
  }

  cout << res << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int N;
  cin >> N;

  vector<int> A(N + 1);
  int i, j;
  for (i = 1; i <= N; i++)
    cin >> A[i];

  multimap<int, int> J;
  vector<int> I(N + 1);
  for (i = 1; i <= N; i++) {
    I[i] = A[i] + i;
    J.insert(make_pair(i - A[i], i));
  }
  int ct = 0;
  for (i = 1; i <= N; i++) {
    auto s = J.lower_bound(I[i]);
    auto e = J.upper_bound(I[i]);
    while (s != e) {
      if (s->second > i)
        ct++;
      s++;
    }
  }
  cout << ct << endl;

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define repl(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n, 0);
  rep(i, n) cin >> a[i];
  unordered_map<ll, ll> um;
  rep(i, n) um[i + a[i]]++;
  ll res = 0;
  rep(i, n) res += um[i - a[i]];
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define repl(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
// ミョ(-ω- ?)
int main() {
  ll n;
  cin >> n;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  ll ans = 0;
  rep(i, n) {
    repl(j, i + 1, n) {
      if (abs(i - j) == h[i] + h[j])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 2e5 + 10;
vector<long long> v;
vector<long long> u;
int C(int n) { return n * (n - 1) / 2; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long num;
    cin >> num;
    v.push_back(i * 1LL + num);
    u.push_back(i * 1LL - num);
  }
  sort(v.begin(), v.end());
  sort(u.begin(), u.end());
  long long ans = 0;
  int last = 0;
  for (int i = 0; i < n; i++) {
    long long now = 0;
    for (int j = last; j < n; j++) {
      if (u[i] > v[j])
        continue;
      else if (u[i] == v[j]) {
        ans++;
        now++;
      } else if (u[i] < v[j]) {
        while (i != n - 1 && u[i + 1] == u[i]) {
          ans += now;
          i++;
        }
        last = j;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
const int maxn = 2e5 + 10;
long long num[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> num[i];
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if ((j - i) * 1LL == num[i] + num[j])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
int a[maxn];
map<int, int> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    cnt += mp[i - a[i]];
    mp[i + a[i]]++;
  }
  cout << cnt << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  ll cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] + a[j] == (j - i))
        cnt++;
    }
  }
  cout << cnt << '\\n';
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}

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

int main() {

  ll n;
  cin >> n;

  ll A[n];
  rep(i, n) cin >> A[i];

  map<ll, ll> l, r;
  rep(i, n) {
    l[i - A[i]]++;
    r[i + A[i]]++;
  }

  ll ans = 0;
  for (auto p : l) {
    auto a = p.first;
    auto b = p.second;
    ans += b * r[a];
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}

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

int main() {

  ll n;
  cin >> n;

  ll A[n];
  rep(i, n) cin >> A[i];

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int l = 1;
    for (int j = i + A[i] + 1; j < n; j++) {
      if (l == A[j])
        ans++;
      l++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  long long ans = 0;
  map<int, int> nums;
  for (int i = 0; i < n; ++i)
    nums[i + a[i]]++;
  for (int i = 0; i < n; ++i)
    ans += nums[i - a[i]];
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  vector<int> maxr(n);
  long long ans = 0;
  maxr[n - 1] = -1;
  for (int i = n - 2; i >= 0; --i)
    maxr[i] = max(maxr[i + 1], a[i + 1]);
  for (int i = 0; i < n - 1; ++i) {
    int mind = a[i];
    for (int j = 1; j <= maxr[j - 1] && i + j + mind < n; ++j) {
      int k = i + j + mind;
      if (a[i] + a[k] == k - i)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

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


Error: TLE

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(2));
  ll ans = 0;
  rep(i, n) {
    cin >> a[i][0];
    a[i][1] = i + 1;
  }
  // cout<<3<<endl;
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a[i][0] >= n - 1)
      break;
    for (int j = i + 1; j < n; j++) {
      if (a[i][0] + a[j][0] <= n - 1) {
        if (a[i][0] + a[j][0] == abs(a[i][1] - a[j][1]))
          ans++;
      } else
        break;
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long
#define N 200123
#define endl '\\n'

using namespace std;

ll v[N], foward[N], ans, n;

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n;

  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }

  for (int i = 1; i <= n; ++i) {
    if (i + v[i] <= n)
      foward[i + v[i]]++;
  }

  for (int i = n; i >= 1; --i) {
    if (i - v[i] > 0) {
      ans += foward[i - v[i]];
    }
  }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define N 100123
#define endl '\\n'

using namespace std;

ll v[N], foward[N], ans, n;

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n;

  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }

  for (int i = 1; i <= n; ++i) {
    if (i + v[i] <= n)
      foward[i + v[i]]++;
  }

  for (int i = n; i >= 1; --i) {
    if (i - v[i] > 0) {
      ans += foward[i - v[i]];
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  vector<int> sum, diff;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    sum.push_back(x + i + 1);
    diff.push_back(i + 1 - x);
  }
  ll ans = 0;
  sort(diff.begin(), diff.end());
  rep(i, n) {
    int tmp = sum[i];
    auto l = lower_bound(diff.begin(), diff.end(), tmp);
    auto u = upper_bound(diff.begin(), diff.end(), tmp);
    if (l == diff.end() && u == diff.end())
      continue;
    ans += (u - diff.begin()) - (l - diff.begin());
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n;
  vector<int> sum, diff;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    sum.push_back(x + i);
    diff.push_back(i - x);
  }
  int ans = 0;
  rep(i, n) {
    int tmp = sum[i];
    ans += count(diff.begin(), diff.end(), tmp);
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

using namespace std;

void Main() {
  long long N;
  cin >> N;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<long long> i_p_Ai(N, 0LL);
  vector<long long> j_m_Aj(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    i_p_Ai[i] = i + 1LL + A[i];
    j_m_Aj[i] = i + 1LL - A[i];
  }
  map<long long, vector<long long>> valueIndexes;
  for (long long i = 0; i < N; ++i) {
    if (valueIndexes.count(j_m_Aj[i]) == 0) {
      valueIndexes.insert(make_pair(j_m_Aj[i], vector<long long>()));
    }
    valueIndexes[j_m_Aj[i]].push_back(i);
  }

  long long ans = 0;
  for (long long i = 0; i < N; ++i) {
    if (valueIndexes.count(i_p_Ai[i]) == 0) {
      continue;
    }
    const vector<long long> &indexes = valueIndexes[i_p_Ai[i]];
    auto iter = upper_bound(indexes.begin(), indexes.end(), i);

    ans += distance(iter, indexes.end());
  }
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"

using namespace std;

void Main() {
  long long N;
  cin >> N;
  vector<long long> A(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }

  vector<long long> i_p_Ai(N, 0LL);
  vector<long long> j_m_Aj(N, 0LL);
  for (long long i = 0; i < N; ++i) {
    i_p_Ai[i] = (long long)i + 1LL + A[i];
    j_m_Aj[i] = (long long)i + 1LL - A[i];
  }
  map<long long, vector<long long>> valueIndexes;
  for (long long i = 0; i < N; ++i) {
    if (valueIndexes.count(j_m_Aj[i]) == 0) {
      valueIndexes.insert(make_pair(j_m_Aj[i], i));
    }
    valueIndexes[j_m_Aj[i]].push_back(i);
  }

  int ans = 0;
  for (long long i = 0; i < N; ++i) {
    if (valueIndexes.count(i_p_Ai[i]) == 0) {
      continue;
    }
    const vector<long long> &indexes = valueIndexes[i_p_Ai[i]];
    auto iter = upper_bound(indexes.begin(), indexes.end(), i);

    ans += distance(iter, indexes.end());
  }
  cout << ans << endl;
}

int main() {
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long dp[200010];

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  vector<ll> C(N);
  map<ll, ll> mp;
  map<ll, ll> mp2;
  REP(i, N) {
    cin >> A[i];
    B.at(i) = A[i] + i;
    mp[B.at(i)]++;
    C.at(i) = -A[i] + i;
    mp2[C.at(i)]++;
  }

  ll cnt = 0;
  for (auto x : mp) {
    cnt += mp2[x.first] * x.second;
  }

  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long dp[200010];

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  ll cnt = 0;
  REP(i, N) {
    FOR(j, min(N, i + A[i] + 1), N) {
      ll x = j - min(N, i + A[i] + 1) + 1;
      if (A[j] == x) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> pre(n);
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++mp[i - a[i]];
    pre[i] = i - a[i];
  }
  ll ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    --mp[pre[i]];
    ans += mp[a[i] + i];
  }

  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932; // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> pre(n);
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    ++mp[i - a[i]];
    pre[i] = i - a[i];
  }
  ll ans = 0;
  for (int i = 0; i + 1 < n; ++i) {
    --mp[pre[i - a[i]]];
    ans += mp[a[i] + i];
  }

  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  int n = 0, b;
  long c = 0;
  cin >> n;
  vector<int> mp(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> b;
    if (i - b >= 0) {
      c += mp[i - b];
    }
    if (i + b < n + 1) {
      mp[i + b]++;
    }
  }
  cout << c;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;

int main() {
  int n = 0, b, c = 0;
  vector<int> mp(n + 1, 0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> b;
    if (i - b > 0) {
      c += mp[i - b];
    }
    if (i + b < n + 1) {
      mp[i + b]++;
    }
  }
  cout << c;
  return 0;
}