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

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge {
  ll to, cost;
};

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

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

ll keta(ll N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {
    IsPrime.resize(max + 1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for (size_t i = 2; i * i <= max; ++i) {
    if (IsPrime[i]) {
      for (size_t j = 2; i * j <= max; ++j) {
        IsPrime[i * j] = false;
      }
    }
  }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      (res *= a) %= mod;
    } else {
      (a *= a) %= mod;
    }
    n >>= 1;
  }
  return res;
}

// 回文
bool kai(string S) {
  bool flag = true;
  for (ll i = 0; i < S.size() / 2; ++i) {
    if (S[i] != S[S.size() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
// ---------------------------------------------

int main() {
  ll n;
  cin >> n;
  vector<ll> a(2 * 1e5 + 10);
  ll ans = 0;
  map<ll, ll> ma;
  for (ll i = 1; i <= n; ++i) {
    cin >> a[i];
    ma[a[i] + i]++;
    ans += ma[i - a[i]];
  }
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge {
  ll to, cost;
};

ll gcd(ll a, ll b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

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

ll keta(ll N) {
  int tmp{};
  while (N > 0) {
    tmp += (N % 10);
    N /= 10;
  }
  N = tmp;
  return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {
    IsPrime.resize(max + 1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for (size_t i = 2; i * i <= max; ++i) {
    if (IsPrime[i]) {
      for (size_t j = 2; i * j <= max; ++j) {
        IsPrime[i * j] = false;
      }
    }
  }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1) {
      (res *= a) %= mod;
    } else {
      (a *= a) %= mod;
    }
    n >>= 1;
  }
  return res;
}

// 回文
bool kai(string S) {
  bool flag = true;
  for (ll i = 0; i < S.size() / 2; ++i) {
    if (S[i] != S[S.size() - i - 1]) {
      flag = false;
      break;
    }
  }
  return flag;
}
// ---------------------------------------------

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll ans = 0;
  map<ll, ll> ma;
  for (ll i = 1; i <= n; ++i) {
    cin >> a[i];
    ma[a[i] + i]++;
    ans += ma[i - a[i]];
  }
  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 int N;
  cin >> N;
  vector<long long int> A(N);
  for (auto &a : A) {
    cin >> a;
  }

  // ii < jj
  // jj - ii = A[ii] + A[jj]
  // ii + A[ii] = jj - A[jj]
  // x = ii + A[ii]
  // y = jj - A[jj]
  long long int ans = 0;
  vector<map<long long int, long long int>> B(N);
  for (long long int ii = 0; ii < N; ii++) {
    long long int x = ii + A[ii];
    long long int y = ii - A[ii];
    if (x < N) {
      B[x][x]++;
    }
    if (y >= 0) {
      if (B[y].find(y) != B[y].end())
        ans += B[y][y];
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  for (auto &a : A) {
    cin >> a;
  }

  int ans = 0;
  vector<list<pair<int, int>>> B(N);
  for (int ii = 0; ii < N; ii++) {
    if (ii + A[ii] < N) {
      B[ii + A[ii]].push_back({ii, A[ii]});
    }
    if (ii - A[ii] >= 0) {
      for (auto &b : B[ii - A[ii]]) {
        if (ii - b.first == A[ii] + b.second)
          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 a[N];
  map<long long, long long> mpr;
  map<long long, long long> mpl;
  map<long long, long long> mpX;
  for (long long i = 0; i < N; i++) {
    cin >> a[i];
    mpr[1 + i + a[i]]++;
    mpl[1 + i - a[i]]++;
    mpX[i + 1 + a[i]]++;
  }
  long long ans = 0;

  for (auto itr = mpX.begin(); itr != mpX.end(); itr++) {
    if (mpr[itr->first] * mpl[itr->first] != 0) {
      ans = ans + mpr[itr->first] * mpl[itr->first];
    }
  }

  cout << setprecision(20) << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  int a[N];
  map<int, int> mpr;
  map<int, int> mpl;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    mpr[1 + i + a[i]]++;
    mpl[1 + i - a[i]]++;
  }
  int ans = 0;
  for (auto itrr = mpr.begin(); itrr != mpr.end(); itrr++) {
    for (auto itrl = mpl.begin(); itrl != mpl.end(); itrl++) {
      // cout<<itrr->first<<" "<<itrl->first<<endl;
      if (itrr->first == itrl->first) {
        ans = ans + (itrr->second) * (itrl->second);
      }
    }
  }

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

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  uint64_t N;
  uint64_t Ai[200000];
  uint64_t difAN[200000];

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

  for (uint64_t i = 0; i < N; i++) {
    uint64_t temp;
    cin >> temp;
    Ai[i] = temp + i + 1;
    if (i + 1 > temp) {
      difAN[i + 1 - temp]++;
    }
  }

  uint64_t countnum = 0;
  for (int i = 0; i < N; i++) {
    if (Ai[i] < N) {
      countnum += difAN[Ai[i]];
    }
  }
  cout << countnum << endl;
}


Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  uint64_t N;
  uint64_t Ai[200000];
  uint64_t difAN[200000];

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

  for (uint64_t i = 0; i < N; i++) {
    uint64_t temp;
    cin >> temp;
    Ai[i] = temp + i + 1;
    if (i + 1 > temp) {
      difAN[i + 1 - temp]++;
    }
  }

  uint64_t countnum = 0;
  for (int i = 0; i < N; i++) {
    countnum += difAN[Ai[i]];
  }
  cout << countnum << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 2e5 + 10;
ll a[maxn];
ll l[maxn], r[maxn];
int main() {
  IO;
  ll n;
  cin >> n;
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i - a[i] > 0) {
      r[i - a[i]]++;
    }
    if (i + a[i] <= n) {
      l[i + a[i]]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += l[i] * r[i];
  }
  cout << ans << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 10;
ll a[maxn];
ll l[maxn], r[maxn];
int main() {
  IO;
  ll n;
  cin >> n;
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i - a[i] > 0) {
      r[i - a[i]]++;
    }
    if (i + a[i] <= n) {
      l[i + a[i]]++;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += l[i] * r[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N), R(N, 0), L(N, 0);
  rep(0, i, N) {
    cin >> A.at(i);
    if (i + A.at(i) < N) {
      R.at(i + A.at(i))++;
    }
    if (i - A.at(i) > -1) {
      L.at(i - A.at(i))++;
    }
  }
  ll ans = 0;
  rep(0, i, N) { ans += R.at(i) * L.at(i); }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<P> A;
  int a;
  rep(0, i, N) {
    cin >> a;
    if (a >= N) {
      continue;
    }
    A.push_back(make_pair(a, i));
  }
  sort(all(A));
  ll ans = 0;
  rep(0, i, A.size()) {
    for (int j = i + 1; j < A.size(); j++) {
      if (A.at(i).first + A.at(j).first >= N) {
        break;
      }
      if (A.at(i).first + A.at(j).first ==
          abs(A.at(i).second - A.at(j).second)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<int64_t> S(N);
  map<int64_t, int64_t> D;
  for (int64_t i = 0; i < N; ++i) {
    S.at(i) = A.at(i) + i;
    D[A.at(i) - i] = D[A.at(i) - i] + 1;
  }

  int64_t res = 0;
  for (int64_t i = 0; i < N; ++i) {
    int64_t X;
    X = -S.at(i);
    int64_t cnt;
    cnt = D[X];
    if (X == A.at(i) - i) {
      cnt = cnt - 1;
    }
    res = res + cnt;
  }

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


Error: TLE

Fixed submission:

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

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

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

  int64_t ans = 0;
  for (int64_t i = 0; i < N; ++i) {
    B.pop_back();
    int64_t x = A.at(i) + i;
    int64_t n_count = std::count(B.begin(), B.end(), x);
    ans += n_count;
  }

  // ans = ans/2;
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N, ans = 0;
  cin >> N;
  vector<ll> vec(N);
  vector<ll> wa(N);
  ll maxwa = 0;
  vector<ll> sa(N);
  for (ll i = 0; i < N; ++i) {
    cin >> vec.at(i);
    wa.at(i) = vec.at(i) + i + 1;
    maxwa = max(maxwa, wa.at(i));
    sa.at(i) = i + 1 - vec.at(i);
  }
  unordered_map<ll, ll> maxcount;
  for (ll i = 0; i < N; ++i) {
    ++maxcount[wa.at(i) - 1];
  }
  for (ll i = 0; i < N; i++) {
    if (sa.at(i) - 1 >= 0 && sa.at(i - 1) < maxwa) {
      ans += maxcount[sa.at(i) - 1];
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N, ans = 0;
  cin >> N;
  vector<ll> vec(N);
  vector<ll> wa(N);
  ll maxwa = 0;
  vector<ll> sa(N);
  for (ll i = 0; i < N; ++i) {
    cin >> vec.at(i);
    wa.at(i) = vec.at(i) + i + 1;
    maxwa = max(maxwa, wa.at(i));
    sa.at(i) = i + 1 - vec.at(i);
  }
  vector<ll> maxcount(maxwa);
  for (ll i = 0; i < N; ++i) {
    ++maxcount.at(wa.at(i) - 1);
  }
  for (ll i = 0; i < N; i++) {
    if (sa.at(i) - 1 >= 0 && sa.at(i - 1) < maxwa) {
      ans += maxcount.at(sa.at(i) - 1);
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll n;
  std::cin >> n;
  vector<ll> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  set<ll> s;
  map<ll, vector<ll>> od;

  for (int i = 0; i < n; i++) {
    od[-a[i] + i + 1].push_back(i);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += od[a[i] + i + 1].size() -
           distance(od[a[i] + i + 1].begin(),
                    lower_bound(od[a[i] + i + 1].begin(),
                                od[a[i] + i + 1].end(), i));
  }
  std::cout << ans << std::endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  std::cin >> n;
  vector<ll> a(n);

  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  set<ll> s;
  map<pair<ll, ll>, ll> cnt;
  for (int i = 0; i < n; i++) {
    for (auto e : s) {
      cnt[{e, i + 1}] = cnt[{e, i}];
    }
    s.insert(-a[i] + i + 1);
    cnt[{-a[i] + i + 1, i + 1}]++;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[{a[i] + i + 1, n}] - cnt[{a[i] + i + 1, i + 1}];
  }
  std::cout << ans << std::endl;
}
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 rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved

int main() {
  long long n;
  cin >> n;
  vector<long long> A(n + 1);

  rep2(i, n) cin >> A[i];

  map<long long, int> tree;

  rep2(i, n) { tree[-A[i] + i]++; }
  // m[i]:=i番目以降の最大値
  long long m[n];
  m[n - 1] = A[n - 1];

  for (int i = n - 2; i > -1; i--) {
    m[i] = max(m[i + 1], A[i]);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    // for(long long  k=i+A[i]+1;k<n;k++){
    // if(A[i]+A[k]==k-i)ans++;
    ans += tree[A[i] + i];
    // if(m[k]<k-i-A[i])break;
    //}
  }

  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 rep2(i, N) for (int i = 1; i <= N; i++)
using namespace std;
long long INF = 1e18;
long long mod = 1e9 + 7;

// status unsolved

int main() {
  long long n;
  cin >> n;
  vector<long long> A(n + 1);

  rep2(i, n) cin >> A[i];

  multiset<long long> tree;

  rep2(i, n) { tree.emplace(-A[i] + i); }
  // m[i]:=i番目以降の最大値
  long long m[n];
  m[n - 1] = A[n - 1];

  for (int i = n - 2; i > -1; i--) {
    m[i] = max(m[i + 1], A[i]);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    // for(long long  k=i+A[i]+1;k<n;k++){
    // if(A[i]+A[k]==k-i)ans++;
    ans += tree.count(A[i] + i);
    // if(m[k]<k-i-A[i])break;
    //}
  }

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


*/
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define mod 1e+7
#define int long long
#define garou                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
signed main() {
  garou;
  int n;
  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[i + a[i]]++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mp[i - a[i]] > 0) {
      ans += mp[i - a[i]];
    }
  }
  cout << ans;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define mod 1e+7
#define int long long
#define garou                                                                  \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
using namespace std;
signed main() {
  garou;
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((a[j] + a[i]) == (j - i))
        ans++;
    }
  }
  cout << ans;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, A;
  cin >> N;
  map<int, int> M;
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    ans += M[i - A];
    M[A + i]++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    for (int 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 maxn = 1e6 + 7;
typedef long long ll;
int n;
ll a[maxn];
map<ll, ll> mp;
int main() {
  scanf("%d", &n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (i - a[i] >= 0)
      ans += mp[i - a[i]];
    mp[i + a[i]]++;
  }
  printf("%lld\\n", ans);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 7;
typedef long long ll;
int n;
ll a[maxn];
map<ll, int> mp;
int main() {
  scanf("%d", &n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    if (i - a[i] >= 0)
      ans += mp[i - a[i]];
    mp[i + a[i]]++;
  }
  printf("%lld\\n", ans);
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  vector<ll> B(N), C(N);
  map<ll, ll> mp, mp2;
  ll ans = 0;
  rep(i, N) {
    C[i] = i - A[i];
    ans += mp[C[i]];
    B[i] = i + A[i];
    mp[B[i]]++;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int arr[N] = {};
int cnt[N] = {};
int main() {
  int n;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (i - arr[i] > 0)
      ans += cnt[i - arr[i]];
    if (arr[i] + i < N)
      cnt[arr[i] + i]++;
  }
  cout << ans << '\\n';
  return 0;
}

Error: 255

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long N = 6209;
long long arr[N] = {};
int main() {
  // cout << N * N * N * N * N;
  long long x;
  cin >> x;
  for (int i = 0; i < N; i++)
    arr[i] = i * i * i * i * i;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++)
      if (arr[i] - arr[j] == x) {
        cout << i << " " << j << '\\n';
        return 0;
      } else if (arr[i] == x - arr[j]) {
        cout << i << " " << -j << '\\n';
        return 0;
      }
  return -1;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

// ヘッダー
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;

// 定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

// REPマクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

// vectorの扱い
#define ALL(x) (x).begin(), (x).end() // sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      // size
#define MAX(x) *max_element(ALL(x))   // 最大値
#define MIN(x) *min_element(ALL(x))   // 最小値

// グローバル変数

// ライブラリ挿入

int main() {
  int N;
  cin >> N;
  vector<ll> A(N + 1);
  REP(i, N) cin >> A[i + 1];
  ll ans = 0;
  map<ll, int> A1, A2;
  REP2(i, 2, N + 1) { A2[i - A[i]]++; }
  REP2(i, 1, N + 1) {
    ans += A2[A[i] + i];
    if (A2[i - A[i]] > 0)
      A2[i - A[i]]--;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

// ヘッダー
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;

// 定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

// REPマクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

// vectorの扱い
#define ALL(x) (x).begin(), (x).end() // sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      // size
#define MAX(x) *max_element(ALL(x))   // 最大値
#define MIN(x) *min_element(ALL(x))   // 最小値

// グローバル変数

// ライブラリ挿入

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  ll ans = 0;
  int i_n;
  REP2(i, 1, N) {
    REP(j, N) {
      i_n = j + i;
      if (i_n > N - 1)
        break;
      if (A[j] + A[i_n] == i)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
#define NMAX 100005 * 2

ll tab[NMAX];
ll tabdiff[NMAX];
ll tabsum[NMAX];
int main() {
  int n;
  ll count = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tab[i];
    if (i - tab[i] >= 0) {
      tabdiff[i - tab[i]]++;
    }
    if (i + tab[i] < n) {
      tabsum[i + tab[i]]++;
    }
  }

  for (int i = 0; i < NMAX; ++i) {
    count += tabsum[i] * tabdiff[i];
  }

  cout << count << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
#define NMAX 100005

ll tab[NMAX];
ll tabdiff[NMAX];
ll tabsum[NMAX];
int main() {
  int n;
  ll count = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> tab[i];
    if (i - tab[i] >= 0) {
      tabdiff[i - tab[i]]++;
    }
    if (i + tab[i] < n) {
      tabsum[i + tab[i]]++;
    }
  }

  for (int i = 0; i < NMAX; ++i) {
    count += tabsum[i] * tabdiff[i];
  }

  cout << count << endl;
  return 0;
}