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

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {
  if (b > a)
    return b;
  else
    return a;
}
int min(int a, int b) {
  if (b < a)
    return b;
  else
    return a;
}
const int INF = 1e18;

signed main() {
  int N;
  cin >> N;
  vi A(N);

  map<int, int> L, R;
  rep(i, N) {
    cin >> A[i];
    L[A[i] + i]++;
    R[i - A[i]]++;
  }

  int res = 0;
  for (auto &l : L) {
    res += l.se * R[l.fi];
  }

  cout << res << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {
  if (b > a)
    return b;
  else
    return a;
}
int min(int a, int b) {
  if (b < a)
    return b;
  else
    return a;
}
const int INF = 1e18;

signed main() {
  int N;
  cin >> N;
  vi A(N);

  map<int, int> L, R;
  rep(i, N) {
    cin >> A[i];
    L[A[i] + i]++;
    R[i - A[i]]++;
  }

  int res = 0;
  for (auto &l : L) {
    for (auto &r : R) {
      if (l.fi == r.fi)
        res += l.se * r.se;
    }
  }

  cout << res << endl;

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

#include <bits/stdc++.h>

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = 1e9 + 7;
void dbg() { cerr << "\\n"; }
template <class F, class... S> void dbg(const F &f, const S &...s) {
  cerr << f << ": ";
  dbg(s...);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  VI a(n);
  for (auto &ia : a)
    cin >> ia;

  map<int, int> mpi, mpj;
  rep(i, n) {
    mpi[a[i] + i]++;
    mpj[i - a[i]]++;
  }
  ll ans = 0;
  for (auto &x : mpi)
    if (mpj.count(x.first)) {
      ans += (ll)x.second * mpj[x.first];
    }
  cout << ans << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
#include <x86intrin.h>

#define rep2(x, fr, to) for (int x = (fr); x < (to); x++)
#define rep(x, to) for (int x = 0; x < (to); x++)
#define repr(x, fr, to) for (int x = (fr); x >= (to); x--)
#define all(c) c.begin(), c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<ll> VL;
const int MD = (int)1e9 + 7;
void dbg() { cerr << "\\n"; }
template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) {
  cerr << fst << ": ";
  dbg(rst...);
}
template <class T, class T2> void amax(T &a, T2 b) {
  if (a < b)
    a = b;
}

int a[200050];

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  rep(i, n) cin >> a[i];
  ll ans[8] = {};
  for (int i = 0; i < n; i++) {
    int j = i + 1;
    for (; j + 7 < n; j += 8) {
      if (j - i + 0 == a[i] + a[j + 0])
        ans[0]++;
      if (j - i + 1 == a[i] + a[j + 1])
        ans[1]++;
      if (j - i + 2 == a[i] + a[j + 2])
        ans[2]++;
      if (j - i + 3 == a[i] + a[j + 3])
        ans[3]++;
      if (j - i + 4 == a[i] + a[j + 4])
        ans[4]++;
      if (j - i + 5 == a[i] + a[j + 5])
        ans[5]++;
      if (j - i + 6 == a[i] + a[j + 6])
        ans[6]++;
      if (j - i + 7 == a[i] + a[j + 7])
        ans[7]++;
    }
    for (; j < n; j++)
      if (j - i == a[i] + a[j])
        ans[0]++;
  }
  ll sm = 0;
  rep(i, 8) sm += ans[i];
  cout << sm << "\\n";
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (ll &i : v)
    cin >> i;
  for (int i = 0; i < n; i++)
    v[i] -= i;
  ll ans = 0;
  map<ll, int> m;
  for (int i = n - 1; i >= 0; i--) {
    ll cur = v[i] + 2 * i;
    ans += m[cur * -1] * 1ll;
    m[v[i]]++;
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<ll> v(n);
  for (ll &i : v)
    cin >> i;
  for (int i = 0; i < n; i++)
    v[i] -= i;
  ll ans = 0;
  multiset<ll> m;
  for (int i = n - 1; i >= 0; i--) {
    ll cur = v[i] + 2 * i;
    ans += m.count(-1 * cur) * 1ll;
    m.insert(v[i]);
  }
  cout << ans;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int x[200000], y[200000];
int32_t main() {
  int n;
  cin >> n;
  int a;

  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (a + i < n)
      x[a + i]++;
    if (i - a > 0)
      y[i - a]++;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += x[i] * y[i];
  }
  cout << ans << "\\n";
}


Error: TLE

Fixed submission:

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

int binpow(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a;
    a = a * a;
    b = b >> 1;
  }
  return res;
}

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

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

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


Error: TLE

Fixed submission:

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

int main() {
  int n, d;
  cin >> n;
  int h[n];
  vector<pair<int, pair<int, int>>> v;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
    v.push_back(make_pair(h[i] + i + 1, make_pair(i, 0)));
    v.push_back(make_pair(h[i] - i - 1, make_pair(i, 1)));
  }
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first > 0)
      break;
    else {
      int x = -v[i].first, i1 = i + 1, j1 = v.size() - 1, x1 = -1, x2 = -1;
      while (i1 <= j1) {
        int mid = i1 + (j1 - i1) / 2;
        if (v[mid].first == x) {
          x1 = mid;
          j1 = mid - 1;
        } else if (v[mid].first > x)
          j1 = mid - 1;
        else
          i1 = mid + 1;
      }
      int i2 = i + 1, j2 = v.size() - 1;
      while (i2 <= j2) {
        int mid = i2 + (j2 - i2) / 2;
        if (v[mid].first == x) {
          x2 = mid;
          i2 = mid + 1;
        } else if (v[mid].first < x)
          i2 = mid + 1;
        else
          j2 = mid - 1;
      }
      if (x1 != -1) {
        for (int j = x1; j <= x2; j++) {
          if (v[j].second.first != v[i].second.first &&
              v[j].second.second != v[i].second.second) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

  ll lim = 200000;
  ll N;
  cin >> N;
  ll L[lim];
  ll R[lim];
  rep(i, lim) {
    L[i] = 0;
    R[i] = 0;
  }
  rep(i, N) {
    ll A = 0;
    cin >> A;
    if (i + A < lim)
      L[i + A]++;
    if (i - A > 0)
      R[i - A]++;
  }
  ll out = 0;
  rep(i, lim) { out += L[i] * R[i]; }
  cout << out << endl;
  return 0;
}


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

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

int main() {

  ll lim = 100000;
  ll N;
  cin >> N;
  ll L[lim];
  ll R[lim];
  rep(i, lim) {
    L[i] = 0;
    R[i] = 0;
  }
  rep(i, N) {
    ll A = 0;
    cin >> A;
    L[i + A]++;
    if (i > A)
      R[i - A]++;
  }
  ll out = 0;
  rep(i, lim) { out += L[i] * R[i]; }
  cout << out << 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;
using P = pair<int, int>;
const int INF = 1000000000;
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

  map<int, int> mpi, mpj;
  for (int i = 0; i < n; ++i) {
    mpi[a[i] + i]++;
  }

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += mpi[i - a[i]];
  }

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


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;
using P = pair<int, int>;
const int INF = 1000000000;
const int MOD = 1000000007;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

  map<int, int> mpi, mpj;
  for (int i = 0; i < n; ++i) {
    mpi[a[i] + i]++;
    mpj[i - a[i]]++;
  }

  ll ans = 0;
  for (auto itr : mpi) {
    for (auto itr2 : mpj) {
      if (itr.first == itr2.first) {
        ans += itr.second * itr2.second;
      }
    }
  }

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

#include <iostream>
#include <map>
using namespace std;
const int N = 2e5 + 10;
int a[N], n;
map<int, int> mp;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = ans + mp[i - a[i]]; // get result at [i]
    mp[a[i] + i]++;           // update result at [i]
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
ll A[1001001];
ll L[1001001];
ll R[1001001];

void solve() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    ll l = i + A[i];
    if (l < N)
      L[l] += 1;
    ll r = i - A[i];
    if (0 < r)
      R[r] += 1;
  }
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    ans += L[i] * R[i];
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int N;
ll A[1001001];

void solve() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  ll p = 0;
  for (int i = 0; i < N; ++i) {
    ll a = A[i];
    for (int j = a + 1; j < N; ++j) {
      ll b = A[j];
      if (j - i == a + b)
        p++;
    }
  }
  cout << p << endl;
}

int main() {
  solve();
  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 P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  map<int, int> pp, pm;
  rep(i, n) {
    pp[p[i] + i + 1]++;
    pm[i + 1 - p[i]]++;
  }
  ll ans = 0;
  for (auto &v : pp) {
    if (pm[v.first] != 0) {
      ans += ll(v.second) * ll(pm[v.first]);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
using ll = int64_t;
using namespace std;
#define ketasuu(n) fixed << setprecision(n)
#define btoe(p) p.begin(), p.end()
#define etob(p) p.rbegin(), p.rend()

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  ll ans = 0;
  rep(i, n) {
    int a = p[i];
    for (int j = i + a; j < n; ++j) {
      if ((j - i) == (p[i] + p[j]))
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 200005;

ll N, A, ans = 0;
vector<int> a;
int add[MX];

void solve() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (i - (a[i] - 1) >= 0)
      add[i - (a[i] - 1)]++;
  }

  for (int i = 0; i < N; i++) {
    if (i + a[i] + 1 < N)
      ans += add[i + a[i] + 1];
  }
  cout << ans;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  ll T = 1; // cin >> T;
  while (T--)
    solve();
  return 0;
  // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

ll N, A, ans = 0;
vector<int> a;

void solve() {
  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  for (int i = 0; i < N; i++) {
    for (int j = i + (a[i] + 1); j < N; j++)
      ans += (a[i] + a[j] == j - i);
  }
  cout << ans;
}

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  ll T = 1; // cin >> T;
  while (T--)
    solve();
  return 0;
  // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

// ConsoleApplication1.cpp : Defines the entry point for the console
// application.
//

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define MAXCHAR 255

using namespace std;

vector<long> Height;
map<long, long> IndexHeightDif;

int main() {
  int input = 0;
  cin >> input;
  long output = 0;
  for (int i = 0; i < input; i++) {
    long heightInput = 0;
    cin >> heightInput;
    Height.push_back(heightInput);

    output += IndexHeightDif[i - heightInput];
    IndexHeightDif[i + heightInput] += 1;
  }

  cout << output << endl;

  return 0;
}

Error: TLE

Fixed submission:

// ConsoleApplication1.cpp : Defines the entry point for the console
// application.
//

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define MAXCHAR 255

using namespace std;

vector<long> Height;
map<long, int> IndexHeightDif;

int main() {
  int input = 0;
  cin >> input;
  for (int i = 0; i < input; i++) {
    long heightInput = 0;
    cin >> heightInput;
    Height.push_back(heightInput);

    IndexHeightDif.insert(pair<long, int>(i + heightInput, 0));
    auto it = IndexHeightDif.find(i + heightInput);
    it->second += 1;
  }
  int output = 0;
  for (int i = 0; i < input; i++) {
    auto it = IndexHeightDif.find(i - Height[i]);
    int index = distance(IndexHeightDif.begin(), it);
    if (index >= i)
      continue;
    if (it != IndexHeightDif.end())
      output += it->second;
  }
  // for (int i = 0; i < input; i++)
  //{
  //	for (int j = 0; j < i; j++)
  //	{
  //		if (i == j)
  //			continue;
  //		int dif = abs(i - j);
  //		if (dif == Height[i] + Height[j])
  //			output++;
  //	}
  // }

  cout << output << endl;

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  vector<ll> as = {};
  map<ll, ll> r{};

  for (auto i = 0; i < n; i++) {
    ll a;
    cin >> a;
    as.push_back(a);
    r[i + a]++;
  }

  ll cnt = 0;
  for (auto i = 0; i < as.size(); i++) {
    auto a = as[i];
    cnt += r[i - a];
  }

  cout << cnt << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define MOD 1000000007

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

  vector<pair<ll, ll>> as = {};
  for (auto i = 0; i < n; i++) {
    ll a;
    cin >> a;
    if (a >= 200000)
      continue;

    as.push_back(make_pair(a, i));
  }

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

  ll cnt = 0;
  for (auto i = 0; i < as.size(); i++) {
    auto a = as[i];
    for (auto j = i + 1; j < as.size(); j++) {
      auto b = as[j];
      if (a.first + b.first > 200000) {
        break;
      }

      if (abs(a.second - b.second) == a.first + b.first)
        cnt++;
    }
  }

  cout << cnt << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int maxn = 2e5 + 5;
int n, a[maxn];
ll ans;
map<int, int> Map;
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 1; i <= n; i++) {
    ans += Map[i - a[i]];
    ++Map[i + a[i]];
  }
  printf("%lld\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
const int maxn = 2e5 + 5;
int n, a[maxn], ans;
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  for (int i = 2; i <= n; i++)
    for (int j = 1; j < i; j++)
      if (a[i] + a[j] == i - j)
        ++ans;
  printf("%d\\n", ans);
  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<long long> height(n + 1);
  map<int, long long> h_ind;
  map<int, long long> h__ind;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> height[i];
    if (h_ind.count(-1 * height[i] + i))
      h_ind[-1 * height[i] + i] += 1;
    else
      h_ind[-1 * height[i] + i] = 1;
    if (h__ind.count(height[i] + i))
      h__ind[height[i] + i] += 1;
    else
      h__ind[height[i] + i] = 1;
  }
  for (auto e : h_ind) {
    ans += e.second * h__ind[e.first];
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<int> height(n);
  int ans = 0;
  for (int i = 0; i < n; ++i)
    cin >> height[i];
  for (int i = 0; i < n; i++) {
    for (int j = i + height[i]; j < n; j++) {
      if (j - i == height[j] + height[i])
        ans++;
    }
  }
  cout << ans << endl;
}