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

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;

int main() {
  long long N;
  cin >> N;
  vector<int> H(N + 1);
  map<long long, long long> L;
  for (long long i = 1; i <= N; i++) {
    long long h;
    cin >> h;
    H.at(i) = h;
    L[i + h]++;
  }
  long long count = 0;
  for (long long i = 1; i <= N; i++) {
    if (L.count(i - H.at(i)))
      count += L[i - H.at(i)];
  }
  cout << count << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();
  int n;
  cin >> n;
  map<int, int> cnt;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ans += cnt[i - x];
    cnt[i + x]++;
  }
  cout << ans;

  return 0;
}
// just a comment


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)                                                                   \\
  int x;                                                                       \\
  cin >> x;                                                                    \\
  while (x--)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
  c_p_c();
  int t;
  int cnt = 0;
  cin >> t;
  int ar[t];
  for (int i = 0; i < t; i++) {
    cin >> ar[i];
  }
  FOR(i, 0, t) {
    FOR(j, 0, t) {
      if ((j - i) == (ar[i] + ar[j])) {
        ++cnt;
      }
    }
  }
  cout << cnt;

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

#include <iostream>
#include <map>
#include <vector>
#define ll long long
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> L(N), R(N);
  map<ll, ll> m;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    L[i] = a + i;
    R[i] = i - a;
    m[R[i]]++;
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ans += m[L[i]];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll count = 0;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  ll m = *min_element(A.begin(), A.end());
  for (ll i = 0; i < N - 1; ++i) {
    for (int j = max(2 * m, i); j < N; j++) {
      if ((j - i) == (A[i] + A[j]))
        count++;
    }
  }

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

// #pragma GCC optimize ("O3")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

  int N;
  cin >> N;

  int A[200000];
  rep(i, N) cin >> A[i];

  map<int, int> MP;

  rep(i, N) { MP[i + A[i]]++; }

  ll kotae = 0;
  rep(i, N) {
    int tmp = i - A[i];
    kotae += MP[tmp];
  }

  co(kotae);

  Would you please return 0;
}

Error: 0

Fixed submission:

// #pragma GCC optimize ("O3")
// #pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

  int N;
  cin >> N;

  int A[100000];
  rep(i, N) cin >> A[i];

  map<int, int> MP;

  rep(i, N) { MP[i + A[i]]++; }

  ll kotae = 0;
  rep(i, N) {
    int tmp = i - A[i];
    kotae += MP[tmp];
  }

  co(kotae);

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

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

// GCD, LCM
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() {
  ll ans = 0;
  int N, A[200010] = {};
  ll l[200010] = {}, r[200010] = {};
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    int le = i - A[i];
    int ri = i + A[i];

    if (1 <= le) {
      l[le]++;
    }
    if (ri <= N) {
      r[ri]++;
    }
  }

  for (int i = 2; i < N; i++) {
    ans += l[i] * r[i];
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

// GCD, LCM
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, A[200000] = {}, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }

  for (int i = 1; i < N; i++) {

    if (i + A[i] > N)
      continue;

    for (int j = i + A[i]; j <= N; j++) {
      if ((j - i) == A[i] + A[j])
        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;
using p = pair<int, int>;
#define rep(i, n) for (ll i = 0; i < n; i++)

const ll INF = 1001001001;

const double PI = 3.141592653;

const ll sosu = 1000000007; // 大きい素数

// 提出のときに言語がc＋＋似合っていることを確認する

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  map<ll, ll> mp;

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

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

const ll INF = 1001001001;

const double PI = 3.141592653;

const ll sosu = 1000000007; // 大きい素数

// 提出のときに言語がc＋＋似合っていることを確認する

ll abs(ll a, ll b) {
  if (a > b) {
    return a - b;
  } else {
    return b - a;
  }
}

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

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

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  vector<long long> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++)
    b[i] = a[i] + i;
  for (int i = 0; i < n; i++)
    c[i] = i - a[i];
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  long long i = 0;
  long long j = 1;
  while (i < n && j < n) {
    long long num1 = 0;
    long long num2 = 0;
    long long d = b[i];
    while (i < n) {
      if (b[i] == d)
        num1++;
      else
        break;
      i++;
    }
    while (j < n) {
      if (c[j] > d)
        break;
      else if (c[j] == d)
        num2++;
      j++;
    }
    ans += num1 * num2;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n - 1; i += 2) {
    long long c, b;
    c = a[i];
    b = a[i + 1] + 1;
    for (int j = i + 1; j < n; j++) {
      if (c + a[j] == j - i && b + a[j] == j - i)
        ans += 2;
      else if (c + a[j] == j - i || b + a[j] == j - i)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include "math.h"
#include <iostream>
#include <map>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  ll a[n];
  map<ll, ll> m;
  ll an = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (m.find(i - a[i]) != m.end())
      an += m[i - a[i]];
    if (m.find(a[i] + i) != m.end())
      m[i + a[i]]++;
    else
      m[i + a[i]] = 1;
  }
  cout << an << '\\n';
}


Error: -11

Fixed submission:

#include "math.h"
#include <iostream>
#include <map>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
int main() {
  ll n;
  ll a[n];
  cin >> n;
  map<ll, ll> m;
  map<ll, ll> m2;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (m.find(m[a[i] - i]) != m.end())
      m[a[i] - i]++;
    else
      m[a[i] - i] = 1;
    if (m2.find(m[a[i] + i]) != m2.end())
      m2[a[i] + i]++;
    else
      m2[a[i] + i] = 1;
  }
  ll an = 0;
  for (auto i : m) {
    if (m2.find(i.se) != m2.end())
      an += i.se * m2[i.fi];
  }
  cout << an << '\\n';
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  map<ll, ll> mpp, mpm, mpt;
  ll A;
  for (int i = 0; i < N; i++) {
    cin >> A;
    mpp[i + A]++;
    mpm[i - A]++;
    mpt[i + A] = mpp[i + A] * mpm[i + A];
    mpt[i - A] = mpp[i - A] * mpm[i - A];
  }

  ll ans = 0;

  for (auto [key, value] : mpt)
    ans += value;
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
int main(void) {
  // Your code here!
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll i, c, k, n;
  c = 0;
  cin >> n;
  ll a[n];
  map<ll, vector<ll>> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    m[i + a[i]].pb(i);
  }
  for (i = 0; i < n; i++) {
    k = i - a[i];
    if (m.find(k) != m.end()) {
      auto it = lower_bound(m[k].begin(), m[k].end(), i);
      c += (ll)(it - m[k].begin());
    }
  }
  cout << c;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
int main(void) {
  // Your code here!
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, c, k, n;
  c = 0;
  cin >> n;
  int a[n];
  map<int, set<int>> m;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    m[i + a[i]].insert(i);
  }
  for (i = 0; i < n; i++) {
    k = i - a[i];
    if (m.find(k) != m.end()) {
      vector<int> v;
      v.insert(v.begin(), m[k].begin(), m[k].end());
      auto it = lower_bound(v.begin(), v.end(), i);
      c += (int)(it - v.begin());
    }
  }
  cout << c;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int n, m, cnt = 0, o, p, aa[220000], cntl = 0, ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
char c, cc[5000][5000] = {};
queue<int> que;
signed main() {
  cin >> n;
  rep(i, n) {
    cin >> aa[i];
    pp[i].first = aa[i] + i + 1;
    pp[i].second = i + 1 - aa[i];
    if (pp[i].second >= 2) {
      ab[pp[i].second]++;
    }
  }
  rep(i, n) {
    if (pp[i].first < 200010) {
      cnt += ab[pp[i].first];
    }
    if (pp[i].second >= 2) {
      ab[pp[i].second]--;
    }
  }
  cout << cnt;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, n, m) for (int i = n; i < m; i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int n, m, cnt = 0, o, p, aa[220000], cntl = 0, ab[220000];
pair<int, int> pp[220000];
string s, ss[220000];
char c, cc[5000][5000] = {};
queue<int> que;
signed main() {
  cin >> n;
  rep(i, n) {
    cin >> aa[i];
    pp[i].first = aa[i] + i + 1;
    pp[i].second = i + 1 - aa[i];
    if (pp[i].second >= 2) {
      ab[pp[i].second]++;
    }
  }
  rep(i, n) {
    cnt += ab[pp[i].first];
    if (pp[i].second >= 2) {
      ab[pp[i].second]--;
    }
  }
  cout << cnt;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long N; // 参加者人数
  cin >> N;

  vector<vector<long>> chukeip(N);
  vector<vector<long>> chukeim(N);

  vector<long> A(N); // 参加者の伸長
  for (long i = 0; i < N; i++) {
    cin >> A[i];

    long tmp = i - A[i];
    if (tmp >= 0)
      chukeim[tmp].emplace_back(i);

    tmp = i + A[i];
    if (tmp < N)
      chukeip[tmp].emplace_back(i);
  }

  long result = 0;
  for (long i = 0; i < N; i++) {
    result += chukeim[i].size() * chukeip[i].size();
  }
  cout << result << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N; // 参加者人数
  cin >> N;

  vector<long> A(N); // 参加者の伸長
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

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

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

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

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = 0;
  vector<int64_t> h(n);
  rep(i, n) cin >> h.at(i);
  vector<int64_t> cnt(1000005);
  rep(i, n) {
    if (h.at(i) + i <= 1000000)
      cnt.at(h.at(i) + i)++;
    if (i - h.at(i) >= 0 && i - h.at(i) <= 1000000) {
      ans += cnt.at(i - h.at(i));
    }
  }
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int64_t n;
  cin >> n;
  int64_t ans = 0;
  vector<int64_t> h(n);
  rep(i, n) cin >> h.at(i);
  vector<int64_t> cnt(1000005);
  rep(i, n) {
    cnt.at(h.at(i) + i)++;
    if (i - h.at(i) >= 0 && i - h.at(i) <= 1000000) {
      ans += cnt.at(i - h.at(i));
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
signed main() {
  ll N, i, ans = 0;
  cin >> N;
  ll A[N], X[N], Y[N];
  REP(i, N) {
    cin >> A[i];
    X[i] = i - A[i];
    Y[i] = i + A[i];
  }
  sort(X, X + N);
  sort(Y, Y + N);
  REP(i, N) ans += upper_bound(X, X + N, Y[i]) - lower_bound(X, X + N, Y[i]);
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i, l, r) for (i = l; i < r; i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define P pair<ll, ll>
#define F first
#define S second
signed main() {
  ll N, i, j, ans = 0;
  cin >> N;
  ll A[N];
  REP(i, N) cin >> A[i];
  REP(i, N) REP(j, i - A[i]) if (A[i] + A[j] == i - j) ans++;
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

//////////////////////////////
// Author: whatisit
// Date: 2020-05-18 03:00
//////////////////////////////
#include <bits/stdc++.h>
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  map<int, int> m;
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int sa = i - a[i];
    int wa = i + a[i];
    ans += m[sa];
    m[wa]++;
  }
  cout << ans;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(0);
  solve();
  return 0;
}

Error: TLE

Fixed submission:

//////////////////////////////
// Author: whatisit
// Date: 2020-05-15 02:47
//////////////////////////////
#include <bits/stdc++.h>
using namespace std;

void solve_brute() {
  int n, ans = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      if ((j - i) == (v[i] + v[j]))
        ++ans;
  cout << ans;
}

int n, a, ans;
map<int, int> m1, m2;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if ((a + i) < n)
      ++m1[a + i];
    if ((i - a) > 1)
      ++m2[i - a];
  }
  for (auto it1 = m1.begin(); it1 != m1.end(); ++it1) {
    auto it2 = m2.find(it1->first);
    if (it2 != m2.end())
      ans += it1->second * it2->second;
  }
  cout << ans;
}

int main() {
  // cin.tie(0); ios_base::sync_with_stdio(0);
  // solve();
  solve_brute();
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define inf 0x3ffffffffffff
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const int maxn = 8000009;
const double pi = acos(-1.0);
const int N = 40010;
using namespace std;
const ll mod = 1e9 + 7;
map<ll, ll> mp;
int a[200000];
int main() {
  int n;
  ll sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[i + a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    sum += mp[i - a[i]];
  cout << sum << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define ll long long
const int N = 1e5 + 10;
using namespace std;
const int f[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6,
                   6, 6, 7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0}; // 26个字母对应的数字
int p[N];
map<int, int> m;
// p[i]+p[j]==j-i;(j>=i)
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    m[i + p[i]]++;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += m[i - p[i]];
  cout << sum << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define int long long int

signed main() {
  int n;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    A.push_back(d);
  }
  unordered_map<int, int> mp;
  reverse(A.begin(), A.end());
  int count = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (mp.find(A[i] + i) == mp.end()) {
      mp[i - A[i]]++;
    } else {
      count += mp[A[i] + i];
      mp[i - A[i]]++;
    }
  }
  cout << count;
}


Error: TLE

Fixed submission:

#include <cstdlib>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int A[n];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (j - i == (A[j] + A[i])) {
        count++;
        //				cout<<i<<" "<<j<<endl;
      }
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200050;
ll po[maxn];
ll a[maxn], b[maxn];
map<ll, ll> m;
int main() {
  IOS int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i] - i;
    m[-b[i]] += 1;
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll t = b[i] + 2 * i;
    if (m[t])
      ans += m[t];
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#define ll long long
#define f(i, l, r) for (ll i = l; i <= r; i++)
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n;
  ll ans = 0;
  cin >> n;
  ll a[n + 1];
  f(i, 1, n) {
    cin >> a[i];
    f(j, 1, i) if (i - j == a[i] + a[j]) ans++;
  }
  cout << ans;
  return 0;
}