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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const bool DEBUG = true;

int main() {

  int n;
  cin >> n;

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

  vector<ll> v2(n);
  for (ll i = 0; i < n; i++)
    v2[i] = v[i] - i;

  ll ans = 0;
  map<ll, ll> m;
  for (int i = 0; i < n; i++) {
    m[v2[i]]++;
  }

  for (ll i = 0; i < n; i++) {
    m[v2[i]]--;
    ans += m[-(i + v[i])];
  }

  for (auto it = m.begin(); it != m.end(); it++) {
    //  cout << it->first <<":" << it->second << endl;
  }
  cout << ans << endl;
  /*
  for(int diff = 1; diff < n; diff++){
      for(int i = 0; i + diff < n; i++){
          if( v[i] + v[i + diff] == diff ){
              ans ++;
          }
      }
  }
  */

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const bool DEBUG = true;

int main() {

  int n;
  cin >> n;

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

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

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

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

typedef long long ll;

int main() {

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

  int n;
  cin >> n;
  ll arr[n + 1];
  unordered_map<ll, ll> count;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    count[arr[i] + i]++;
  }

  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    if (count.find(i - arr[i]) != count.end()) {
      ans += count[i - arr[i]];
    }
  }
  cout << ans << '\\n';
  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
ll mod = 1000000007;

ll power(ll x, ll y) {
  ll res = 1;
  x = x % mod;
  while (y) {
    if (y & 1)
      res = ((res % mod) * (x % mod)) % mod;

    y >>= 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}

int main() {

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

  ll n;
  cin >> n;
  ll arr[n];

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

  vector<ll> v;
  for (int i = 1; i < n; i++) {
    v.push_back(i);
  }

  ll count = 0;
  for (int i = 0; i < n - 1; i++) {
    ll x = 0;
    for (int j = i + 1; j < n; j++) {
      if (arr[i] + arr[j] == v[x])
        count++;
      x++;
    }
    v.pop_back();
  }

  cout << count << '\\n';

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0)
      m[i - a[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int v = a[i] + i;
    ans += m[v];
    m[i + 1 - a[i + 1]]--;
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  multiset<int> ms;
  vector<int> v(n, 0);
  for (int i = 1; i < n; i++) {
    ms.insert(a[i] - i);
    v[i] = a[i] - i;
  }
  int cc = 0;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cand = -1 * a[i] - cc;
    ans += ms.count(cand);
    auto itr = ms.find(v[i]);
    if (i > 0)
      ms.erase(itr);
    cc++;
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// 解説既読....
int main() {
  int n;
  cin >> n;
  map<ll, int> M;
  ll ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    ans += M[i - a];
    M[i + a]++;
  }
  cout << ans << endl;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/


Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  ll ans = 0;
  rep(i, N) { cin >> A[i]; }
  for (int i = N - 1; 0 < i; i--) {
    if (A[i] >= i)
      continue;
    int count = 0;
    for (int j = i - A[i]; 0 <= j; j--) {
      if (A[j] == count)
        ans++; // if(A[j]==count){cout<<i<<":"<<j<<endl;}
      count++;
    }
  }

  cout << ans << endl;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int maxn = 2e5 + 5;
int h[maxn], n;
long long ans = 0;
map<int, int> s;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    s[i - h[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    if (s.find(i + h[i]) == s.end())
      continue;
    ans += s[i + h[i]];
  }
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

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

const int maxn = 2e5 + 5;
int h[maxn], n;
multiset<int> s;
long long ans = 0;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> h[i];
    s.insert(i - h[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans += s.count(i + h[i]);
  }
  cout << ans;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
using ll = long long int;

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

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

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

using namespace std;
using ll = long long int;

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 2, cnt = 0;
  while (l < n - 1) {
    if (r - l == a[r] + a[l])
      cnt++;
    r++;
    if (r >= n) {
      l++;
      r = l + 2;
    }
  }
  cout << cnt << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<int> a(200005);
  vector<int> b(200005);
  vector<int> c(200005);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = i - a[i];
    c[i] = i + a[i];
  }

  map<int, int> mp;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp.count(b[i])) {
      ans += mp[b[i]];
    }
    mp[c[i]]++;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  map<int, int> data;
  long long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    data[i] = A[i];
  }
  int ans = 0;
  for (int i = N - 1; i > -1; i--) {
    if (i < data[i])
      continue;
    for (int j = i - 1; j > -1; j--) {
      if (i - j == data[i] + data[j]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <vector>

long solve(int n, const std::vector<long> &heights) {
  std::unordered_map<long, std::vector<int>> m1;
  std::unordered_map<long, std::vector<int>> m2;

  for (int i = 0; i < n; ++i) {
    m1[i + 1 + heights.at(i)].push_back(i);
    m2[i + 1 - heights.at(i)].push_back(i);
  }

  long result = 0;
  for (const auto &p : m1) {
    auto it = m2.find(p.first);
    if (it == m2.end())
      continue;
    result += p.second.size() * it->second.size();
  }

  return result;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<long> heights(n);
  for (auto &h : heights) {
    std::cin >> h;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, heights) << std::endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

struct S {
  int number;
  long height;
};

using V = std::vector<S>;

long solve(int n, V &v) {
  std::sort(v.begin(), v.end(), [](const S &lhs, const S &rhs) {
    if (lhs.height == rhs.height)
      return lhs.number < rhs.number;
    return lhs.height < rhs.height;
  });
  long result = 0;

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      const auto &e1 = v[i];
      const auto &e2 = v[j];
      const auto wa = e1.height + e2.height;
      if (wa == std::abs(e1.number - e2.number))
        ++result;

      if (wa + e1.number > n && e1.number - wa < 0)
        break;
    }
  }

  return result;
}

int main() {
  int n;
  std::cin >> n;
  V v(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> v[i].height;
    v[i].number = i + 1;
  }

  std::cout << std::setprecision(20);
  std::cout << solve(n, v) << std::endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 7;

int main() {

  int n;
  scf(n);

  ll ctr = 0;

  map<int, int> m;

  rep(i, 1, n + 1) {
    int a;
    scf(a);

    if (i - a >= 0)
      ctr += (m[i - a]);

    m[a + i]++;
  }

  lprin(ctr);
}

Error: TLE

Fixed submission:

/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d", &n)
#define lscf(n) scanf("%lld", &n)
#define lpri(n) printf("%lld ", n)
#define pri(n) printf("%d ", (int)n)
#define prin(n) printf("%d\\n", (int)n)
#define lprin(n) printf("%lld\\n", n)
#define rep(i, ini, n) for (int i = ini; i < (int)n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e6 + 7;

int main() {

  int n, ctr = 0;
  scf(n);

  int a[n];

  rep(i, 1, n + 1) scf(a[i]);

  rep(i, 1, n + 1) {
    int j = n;

    while (j > i) {
      if (abs(j - i) == a[i] + a[j])
        ctr++;

      j--;
    }
  }

  prin(ctr);
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX_N = 200000 + 2;
ll sum[MAX_N] =
    {
        0,
},
   A[MAX_N];

int main() {
  ll N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (i - A[i] >= 1)
      sum[i - A[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    if (i + A[i] < MAX_N) {
      // cout << "i=" << i << "," << sum[i+A[i]] << endl;
      ans += sum[i + A[i]];
    }
  }
  cout << ans;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int MAX_N = 100000 + 2;
int sum[MAX_N] =
    {
        0,
},
    A[MAX_N];

int main() {
  int N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    if (i - A[i] >= 1)
      sum[i - A[i]]++;
  }
  for (int i = 1; i <= N; i++) {
    if (i + A[i] < MAX_N) {
      // cout << "i=" << i << "," << sum[i+A[i]] << endl;
      ans += sum[i + A[i]];
    }
  }
  cout << ans;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  ll a, ans = 0;
  cin >> n;
  map<ll, int> height;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ans += height[i - a];
    height[i + a]++;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(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++) {
      if (j - i == a[i] + a[j])
        ans++;
    }
  }

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

#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.at(i);
  }

  map<int, int> cnt; // i+Aiを記録するmap

  // mapを作成しながら、indexが自身より小さいモノに関してi-Aiと一致する個数を数える。
  int64_t ans = 0;
  for (int i = 0; i < n; i++) {
    // 条件を満たすペアを数える。
    if (cnt.count(i - a.at(i))) {
      ans += cnt.at(i - a.at(i));
    }
    // mapの更新
    if (cnt.count(i + a.at(i))) {
      cnt.at(i + a.at(i))++;
    } else {
      cnt[i + a.at(i)] = 1;
    }
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int NUM = 200000;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int a_in;
    cin >> a_in;
    a.at(i) = a_in;
  }

  vector<vector<int>> n_plus_a(400000);
  for (int i = 0; i < n; i++) {
    if (a.at(i) > NUM) {
      continue;
    }
    n_plus_a.at(i + 1 + a.at(i)).push_back(i + 1);
  }

  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (a.at(i) > NUM) {
      continue;
    }
    int num = i + 1 - a.at(i);
    if (num < 0) {
      continue;
    }
    for (auto aaa : n_plus_a.at(num)) {
      if (aaa < i + 1) {
        ans++;
      }
    }
  }

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

/*input
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
*/
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mod 998244353
#define int long long
#define N 200005

int H[N];
map<int, int> ok;
signed main() {
  int n, m, ans = 0;
  cin >> n; //>>m;
  // memset(ok,1,sizeof(ok));
  for (int i = 1; i <= n; i++) {
    cin >> H[i];
    int reqd = i - H[i];

    ok[i + H[i]]++;
    if (reqd >= 0)
      ans += ok[reqd];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

/*input
32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5
*/
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define mod 998244353
#define int long long
#define N 100005

int H[N];
map<int, int> ok;
signed main() {
  int n, m, ans = 0;
  cin >> n; //>>m;
  // memset(ok,1,sizeof(ok));
  for (int i = 1; i <= n; i++) {
    cin >> H[i];
    int reqd = i - H[i];

    ok[i + H[i]]++;
    if (reqd >= 0)
      ans += ok[reqd];
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  map<ll, ll> cnt;
  ll ans = 0;
  rep(i, N) {
    ans += cnt[i + 1 - A[i]];
    cnt[i + 1 + A[i]]++;
  }
  cout << ans << '\\n';
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  rep(i, N) {
    ll a = A[i];
    rep2(j, i + a, N) {
      ll a2 = A[j];
      if (a2 + a == abs(j - i)) {
        ans++;
      }
    }
  }
  cout << ans << '\\n';
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

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

  map<ll, ll> x;
  REP(i, N) x[i + A[i]]++;

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

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

  ll cnt = 0;
  for (ll i = N - 1; 0 <= i; i--) {
    for (ll j = N - 1; 0 <= j; j--) {
      if (i <= j)
        continue;
      ll tmp = i - j;
      if (A.at(i) + A.at(j) == tmp) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
map<int, int> mp;
int a[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i] + i]++;
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i - a[i] >= 1) {
      cnt += mp[i - a[i]];
    }
  }
  cout << cnt << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
map<int, int> mp;
int a[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i] + i]++;
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (i - a[i] >= 1) {
      cnt += mp[i - a[i]];
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>

using namespace std;

int main() {
  long long N;
  cin >> N;
  long long A[N], Amin = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Amin = min(Amin, A[i]);
  }

  map<long long, long long> L, R;
  for (int i = 0; i < N; i++) {
    L[i + A[i]]++;
    R[i - A[i]]++;
  }

  long long ans = 0;
  for (long long i = Amin; i <= N - Amin; i++) {
    ans += L[i] * R[i];
  }

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


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

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

  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    for (long long j = i + 1; j < N; j++) {
      if (j - i == A[i] + A[j]) {
        ans++;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int n, m;
map<int, int> vf;

int main() {
  /**
      #ifndef ONLINE_JUDGE

          ifstream cin("test.in");

      #endif // ONLINE_JUDGE
  */

  cin >> n;

  long long ans = 0, x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    ans += vf[(i - x > 0 ? i - x : 0)];
    vf[x + i]++;
  }

  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int Nmax = 2e5 + 10;
const int Mod = 1e9 + 7;
const int oo = 1e9;

int n, m;
int vf[Nmax];

int main() {
  /**
      #ifndef ONLINE_JUDGE

          ifstream cin("test.in");

      #endif // ONLINE_JUDGE
  */

  cin >> n;

  long long ans = 0, x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    ans += vf[(i - x > 0 ? i - x : 0)];
    vf[x + i]++;
  }

  cout << ans;
  return 0;
}