alexjercan/bugnet huggingface dataset:
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N;
  cin >> N;
  int A[N];
  rep(i, 0, N) cin >> A[i];
  int X[N + 1] = {0};
  ll ret = 0;
  rep(i, 0, N) {
    if (i + A[i] < N)
      X[i + A[i]]++;
    if (i - A[i] >= 0) {
      ret += X[i - A[i]];
    }
  }
  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll n;
  cin >> n;
  ll a[n];
  vi L, R;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) {
    L.push_back(i + 1 + a[i]);
    R.push_back(i + 1 - a[i]);
  }
  ll X[20001] = {0};
  rep(i, 0, L.size()) {
    if (0 < L[i] && L[i] < 20001)
      X[L[i]]++;
  }
  ll ans = 0;
  rep(i, 0, R.size()) {
    if (0 < R[i])
      ans += X[R[i]];
  }

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

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

int main() {
  int64_t n, a, ans;
  ans = 0;
  cin >> n;
  vector<int64_t> wa(1000001);
  vector<int64_t> sa(1000001);

  for (int64_t i = 0; i < n; i++) {
    cin >> a;
    if (a < 200000) {
      wa.at(a + i + 500000 + 1)++;
      sa.at(i + 500000 + 1 - a)++;
    }
  }
  for (int i = 0; i < 1000001; i++) {
    ans = ans + wa.at(i) * sa.at(i);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int64_t n, a, ans;
  ans = 0;
  cin >> n;
  vector<int64_t> wa(400001);
  vector<int64_t> sa(400001);

  for (int64_t i = 0; i < n; i++) {
    cin >> a;
    if (a < 200000) {
      wa.at(a + i + 200000 + 1)++;
      sa.at(i + 200000 + 1 - a)++;
    }
  }
  for (int i = 0; i < 400001; i++) {
    ans += wa.at(i) * sa.at(i);
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main() {
  ll n, ans = 0;
  cin >> n;
  map<ll, ll> mp;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;

    ans += mp[i - x];

    mp[i + x]++;
  }

  cout << ans;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define ll long long;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;
      if (abs(i - j) == arr[i] + arr[j])
        ans++;
    }
  }
  cout << ans / 2;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N;
vector<long long> A;
vector<long long> L;
vector<long long> R;

void input() {
  cin >> N;
  A.resize(N);
  L.resize(N);
  R.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    L[i] = i + 1 + A[i];
    R[i] = i + 1 - A[i];
  }
}

void solve() {
  map<long long, int> dic;
  for (int i = 0; i < N; i++) {
    dic[L[i]] += 0;
    dic[R[i]] += 0;
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += dic[R[i]];
    dic[L[i]]++;
  }

  // int ans=0;
  //   map <string,int>::iterator it;
  //   for(it=dic.begin();it!=dic.end();it++){
  //     cout << it->second << endl;
  //     ans += it->second/2;
  //   }
  cout << ans << endl;
}

int main() {
  //  ifstream in("input.txt");
  //  cin.rdbuf(in.rdbuf());

  input();
  solve();
  return 0;
}


Error: TLE

Fixed submission:

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

int N;
vector<int> A;

void input() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
}

void solve() {
  int d = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + A[i]; j < N; j++) {
      if (abs(A[j] + A[i]) == j - i) {
        d += 1;
      }
    }
  }
  cout << d << endl;
}

int main() {
  input();
  solve();
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

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

class UnionFind {
public:
  vector<int> par;
  vector<int> val;
  int root(int input) {
    if (par[input] == input)
      return input;
    return par[input] = root(par[input]);
  }
  void unite(int val1, int val2) { par[val1] = root(par[val2]); }
  bool same(int val1, int val2) { return root(par[val1]) == root(par[val2]); }
  UnionFind() { return; }
};

const ll N_MAX = 10 * 100000 + 100;
ll N, M;
ll A[N_MAX];
vector<ll> Alist;

int main() {

  cin >> N;
  ll res = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    if (i + a < N_MAX) {
      A[i + a]++;
    }
    if (i - a >= 0) {
      res += A[i - a];
    }
  }

  cout << res << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

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

class UnionFind {
public:
  vector<int> par;
  vector<int> val;
  int root(int input) {
    if (par[input] == input)
      return input;
    return par[input] = root(par[input]);
  }
  void unite(int val1, int val2) { par[val1] = root(par[val2]); }
  bool same(int val1, int val2) { return root(par[val1]) == root(par[val2]); }
  UnionFind() { return; }
};

const ll N_MAX = 2 * 100000 + 100;
ll N, M;
ll A[N_MAX];
vector<int> Alist;

int main() {

  cin >> N;
  int res = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    A[i] = a;
    Alist.push_back(a + i);
    if (i - a > 0) {
      size_t n_count = count(Alist.begin(), Alist.end(), i - a);
      res += n_count;
    }
  }

  cout << res << 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 < (n); ++i)
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vec a(n), b(n);
  rep(i, n) {
    cin >> a[i];
    b[i] = a[i] + i;
  }

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

  ll c = 0;
  rep(i, n) {
    c += upper_bound(b.begin(), b.end(), i - a[i]) -
         lower_bound(b.begin(), b.end(), i - a[i]);
  }

  cout << c << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vec a(n);
  rep(i, n) cin >> a[i];

  int c = 0;
  rep(i, n) {
    for (int j = i + 1; j < n; j++) {
      if (j - i == a[i] + a[j])
        c++;
    }
  }

  cout << c << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> A(N);
  vector<int> under(N, 0);
  vector<int> over(N, 0);
  rep(i, N) {
    cin >> A[i];
    if (i + A[i] < N)
      under[i + A[i]]++;
    if (i - A[i] >= 0)
      over[i - A[i]]++;
  }

  long long pair = 0;
  rep(i, N) { pair += (long long)under[i] * over[i]; }

  cout << pair << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int pair = 0;
  rep(i, N) {
    for (int j = i + 1; j < N; j++) {
      if (j - i == A[i] + A[j])
        pair++;
    }
  }

  cout << pair << endl;

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

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
  int n;
  cin >> n;
  ll ans = 0;
  vector<int> v(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v[i] = i + a;
    mp[i - a]++;
  }
  for (int i = 0; i < n; i++)
    ans += mp[v[i]];
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
const int INF32 = 1 << 30;
const ll INF64 = 1LL << 60;
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vector<int> l(n);
  vector<int> r(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    l[i] = i + a;
    r[i] = i - a;
  }
  for (int i = 0; i < n - 1; i++)
    for (int j = 1; j < n - i; j++) {
      if (l[i] == r[i + j])
        sum++;
    }
  cout << sum;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  long long a, N, i, cnt = 0;
  cin >> N;
  map<long long, long long> R, L;

  for (i = 0; i < N; i++) {

    cin >> a;
    R[i + 1 + a]++;
    L[i + 1 - a]++;
  }

  for (auto j : R) {

    cnt += j.second * L[j.first];
  }

  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  long long N, i, j, cnt = 0;
  cin >> N;
  vector<long long> A(N);

  for (i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (i = 0; i < N; i++) {
    if (A.at(i) > N)
      continue;
    for (j = A.at(i) - 1; j < N; j++) {

      if (j - i == A.at(i) + A.at(j)) {

        cnt++;
      }
    }
  }

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

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define forn(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) forn(i, 0, n)
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rev(x) x.rbegin(), x.rend()

#define int long long
#define ld long double
#define str string
#define uset unordered_set
#define umap unordered_map
#define pq priority_queue
#define vc vector
#define pii pair<int, int>
#define vi vc<int>
#define vii vc<pii>

#define endl '\\n'

inline void FASTIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}

const int MAXN = 2E5 + 5;
int a[MAXN];

void solve() {}

signed main() {
  FASTIO();
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  map<int, int> s;
  int ans = 0;
  rep(i, n) {
    int x = a[i] - i, y = -i - a[i];
    if (s.count(x)) {
      ans += s[x];
    }
    if (s.count(y)) {
      s[y]++;
    } else {
      s[y] = 1;
    }
  }
  cout << ans;
}


Error: TLE

Fixed submission:

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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define forn(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) forn(i, 0, n)
#define len(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rev(x) x.rbegin(), x.rend()

#define int long long
#define ld long double
#define str string
#define uset unordered_set
#define umap unordered_map
#define pq priority_queue
#define vc vector
#define pii pair<int, int>
#define vi vc<int>
#define vii vc<pii>

#define endl '\\n'

inline void FASTIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}

const int MAXN = 2E5 + 5;
int a[MAXN];

void solve() {}

signed main() {
  FASTIO();
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  multiset<int> s;
  int ans = 0;
  rep(i, n) {
    int x = a[i] - i;
    ans += distance(s.lower_bound(x), s.upper_bound(x));
    s.insert(-i - a[i]);
  }
  cout << ans;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);

  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }

  long long ans = 0;
  map<long long, long long> LiMap;
  for (long long i = 1; i <= N; i++) {
    LiMap[i + A[i - 1]]++;
  }
  for (long long i = 1; i <= N; i++) {
    ans += LiMap[i - A[i - 1]];
  }

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


Error: TLE

Fixed submission:

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

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);

  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }

  long long ans = 0;
  for (long long i = 1; i < N; i++) {
    for (long long j = i + 1; j <= N; j++) {
      if (abs(i - j) == A[i - 1] + A[j - 1]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\\n";

using namespace std;

template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\\n";
  return out;
}
template <typename T, typename N>
std::ostream &operator<<(std::ostream &out, vector<pair<T, N>> &v) {
  for (size_t i = 0; i < v.size(); ++i)
    out << "(" << v[i].first << ", " << v[i].second << ") ";
  out << "\\n";
  return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<vector<T>> &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    for (size_t j = 0; j < v[i].size(); ++j) {
      out << v[i][j] << " ";
    }
    out << "\\n";
  }
  return out;
}

int main() {

  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;

  vector<int> b(n + 1), c(2e5 + 1);
  int a;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    b[i] = a + i;
    if (i - a >= 0) {
      ++c[i - a];
    }
  }

  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i] <= 2e5) {
      ans += c[b[i]];
    }
  }

  cout << ans << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\\n";

using namespace std;

template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\\n";
  return out;
}
template <typename T, typename N>
std::ostream &operator<<(std::ostream &out, vector<pair<T, N>> &v) {
  for (size_t i = 0; i < v.size(); ++i)
    out << "(" << v[i].first << ", " << v[i].second << ") ";
  out << "\\n";
  return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<vector<T>> &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    for (size_t j = 0; j < v[i].size(); ++j) {
      out << v[i][j] << " ";
    }
    out << "\\n";
  }
  return out;
}

int main() {

  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;

  vector<int> b(n + 1), c(2e5 + 1);
  int a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    b[i + 1] = a + i + 1;
    if (i - a + 1 >= 0) {
      ++c[i - a + 1];
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += c[b[i]];
  }

  cout << ans << "\\n";

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

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/abc166/tasks/abc166_e
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll ans = 0;
  ll n;
  cin >> n;
  vector<ll> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];

  map<ll, ll> m;
  for (int i = 1; i <= n; i++) {
    if (m[i - v[i]] != 0)
      ans += m[i - v[i]];
    if (m[i + v[i]] != 0)
      m[i + v[i]] += 1;
    else {
      m[i + v[i]] = 1;
    }
  }

  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
// https://atcoder.jp/contests/abc166/tasks/abc166_d
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll ans = 0;
  ll n;
  cin >> n;
  vector<ll> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (j - i == v[j] + v[i])
        ans++;
    }
  }
  cout << ans;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: 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 < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI =
    3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n;
map<ll, ll> mp;
map<ll, ll> mpp;
ll ans = 0;
int a[200000];

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    mp[i - a[i - 1]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (mp.count(a[i - 1] + i))
      mpp[a[i - 1] + i]++;
  }
  for (pair<ll, ll> x : mp) {
    // cout << x.first << " " <<x.second <<endl;
    ans += mpp[x.first] * x.second;
  }
  cout << ans << endl;
}

Error: 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 < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define m1(x) memset(x, -1, sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI =
    3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n;
map<ll, ll> mp;
map<ll, ll> mpp;
ll ans = 0;
int a[100000];

int main() {
  cin >> n;
  rep(i, n) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    mp[i - a[i - 1]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (mp.count(a[i - 1] + i))
      mpp[a[i - 1] + i]++;
  }
  for (pair<ll, ll> x : mp) {
    // cout << x.first << " " <<x.second <<endl;
    ans += mpp[x.first] * x.second;
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
lol n, m, k, r;
int a[200010];
lol sum[200010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  lol ans = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] + i < n) {
      sum[a[i] + i]++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i - a[i] >= 0) {
      ans += sum[i - a[i]];
    }
  }
  cout << ans << '\\n';
  return (0);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define lol long long
#define gcd(x, y) __gcd(x, y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed fixed << setprecision(14)
using namespace std;
using pii = pair<int, int>;
template <class A, class B> inline bool chmax(A &a, const B &b) {
  return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
  return b < a && (a = b, true);
}
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
const lol Mod = (1e9) + 7;
const lol mod = 998244353;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
lol n, m, k, r;
int a[200010];
int sum[200010];
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  lol ans = 0;
  for (int i = 0; i < n; i++) {
    // ans+=dfs(a[i]+i+1,1);
    sum[a[i] + i]++;
  }
  for (int i = 0; i < n; i++) {
    if (i - a[i] < 0)
      continue;
    ans += sum[i - a[i]];
  }
  cout << ans << '\\n';
  return (0);
}