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

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 0 false, 1 true
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  cin >> n;
  vector<long long> vec(n);
  vector<long long> vec2(n);
  ll ans = 0;

  map<ll, ll> mp;

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

  rep(i, n) { ans += mp[vec[i]]; }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n - 1); i >= 0; i--)
#define all(x) x.begin(), x.end()
#define br cout << "\\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector<vector<ll>>;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 0 false, 1 true
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
  std::cout << std::fixed << std::setprecision(15);
  ll n;
  cin >> n;

  ll ans = 0;

  vector<pair<ll, ll>> vec;
  rep(i, n) {
    ll a;
    cin >> a;
    if (n - 1 >= (a + 1 + i) || (i - 1 - a) >= 0) {
      /*
      cout << n-1 << " " << (a + 1 + i) << endl;
      cout << (i - 1 - a) << " " << 0 << endl;
      cout << "----" << endl;
      */
      vec.push_back(make_pair(i, a));
    }
  }

  for (ll i = 0; i < vec.size(); i++) {
    for (ll j = i + 1; j < vec.size(); j++) {
      if (vec[j].first - vec[i].first == vec[j].second + vec[i].second) {
        ans++;
      }
    }
  }

  /*
  for(ll i = 0; i < n; i++){
      for(ll j = i+1+vec[i]; j < n; j++){
          if(j - i == vec[i] + vec[j]){
              ans++;
          }
      }
  }
  */

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

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  ll n, x, count = 0;
  cin >> n;
  map<ll, ll> v1;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    v1[i + x]++;
    if (i - x > 0)
      count += v1[i - x];
  }
  cout << count << "\\n";
}
int main() {
  fast();
  solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a
#define vb vector<long long int> b
#define M 1000000007
using namespace std;
ll t;
void fast() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
}
ll power(ll x, ul y, ll p) {
  ll res = 1;
  x = x % p;
  if (x == 0)
    return 0;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
void solve() {
  ll n, x, count = 0;
  cin >> n;
  vector<ll> v1(100000);
  for (ll i = 0; i < n; i++) {
    cin >> x;
    v1[i + x]++;
    if (i - x > 0)
      count += v1[i - x];
  }
  cout << count << "\\n";
}
int main() {
  fast();
  solve();
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

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

  int64 n;
  cin >> n;
  vector<int64> a(n + 1);
  map<int64, int> mp;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mp[i - a[i]]++;
  }
  int64 cnt = 0;
  for (int i = 1; i <= n; ++i) {
    mp[i - a[i]]--;
    cnt += mp[a[i] + i];
  }
  cout << cnt;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long int64;

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

  int n;
  cin >> n;
  vector<int64> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int64 cnt = 0;
  for (int64 d = 1; d <= n - 1; ++d) {
    for (int i = 0; i + d < n; ++i) {
      if (a[i] + a[i + d] == d)
        cnt++;
    }
  }
  cout << cnt;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

  IOS

      ll n;
  cin >> n;

  ll h[n + 1];
  for (ll i = 1; i <= n; i++)
    cin >> h[i];

  ll c = 0;
  map<ll, ll> iAi;
  for (ll i = 1; i <= n; i++) {
    c += iAi[i - h[i]];
    iAi[i + h[i]]++;
  }

  cout << c << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define deb(x) cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

  IOS

      int n;
  cin >> n;

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

  map<int, set<int>> jAj;
  for (int i = 0; i < n; i++)
    jAj[i - h[i]].insert(i);

  int c = 0, iAi;
  for (int i = 0; i < n; i++) {
    iAi = i + h[i];

    if (jAj.find(iAi) != jAj.end()) {
      c += distance(jAj[iAi].upper_bound(i), jAj[iAi].end());
    }
  }

  cout << c << endl;

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

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

// #pragma gcc optimize("O3,unroll-loop")
// #pragma gcc
// target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
// #define double long double

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> v(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++)
    cin >> v[i], v[i] -= i, mp[v[i]]++;

  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += mp[i * -2 - v[i]];
  cout << ans << '\\n';

  return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *


Error: TLE

Fixed submission:

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

// #pragma gcc optimize("O3,unroll-loop")
// #pragma gcc
// target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
// #define int long long
// #define double long double

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n;
  cin >> n;

  vector<int> v(n);
  multiset<int> s;
  for (int i = 0; i < n; i++)
    cin >> v[i], v[i] -= i, s.insert(v[i]);

  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += s.count(i * -2 - v[i]);
  cout << ans << '\\n';

  return 0;
}

//      *   *  *****  *   *  *   *
//     *   *  *      **  *  *   *
//    *****  *****  * * *  *   *
//   *   *      *  *  **  *   *
//  *   *  *****  *   *   ***

//      ***** ***** *   * *     ***** *   * ***** *****
//        *  *   * *   * *       *   **  *   *   *   *
//       *  *   * ***** *       *   * * *   *   *****
//   *  *  *   *   *   *       *   *  **   *   *
//  ****  *****   *   ***** ***** *   *   *   *
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

#include <math.h>
// #include <stack>
// #include <queue>

/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

#define MAXV 1000000

ll VALM[MAXV] = {};
ll VALP[MAXV] = {};
ll C;
ll N;
ll M;
ll K;

int main() {

  cin >> N;
  ll H[N + 1];
  for (int ni = 1; ni <= N; ni++) {
    ll tmp;
    cin >> tmp;
    H[ni] = tmp;
  }

  ll cnt = 0;
  for (int ni = N; ni >= 1; ni--) {
    ll hi = H[ni];
    if (hi < MAXV) {
      if (ni + hi < MAXV) {
        VALP[ni + hi]++;
        cnt += VALM[ni + hi];
      }
      if (ni - hi >= 0) {
        VALM[ni - hi]++;
      }
    }
  }

  cout << cnt << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

#include <math.h>
// #include <stack>
// #include <queue>

/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes";
string ans_No = "No";
string ans_yes = "yes";
string ans_no = "no";

#define MAXV 1000000

ll VALM[MAXV] = {};
ll VALP[MAXV] = {};
ll C;
ll N;
ll M;
ll K;

int main() {

  cin >> N;
  ll H[N + 1];
  for (int ni = 1; ni <= N; ni++) {
    ll tmp;
    cin >> tmp;
    H[ni] = tmp;
  }

  ll cnt = 0;
  for (int ni = N; ni >= 1; ni--) {
    ll hi = H[ni];
    if (hi < MAXV) {
      VALP[ni + hi]++;
      cnt += VALM[ni + hi];
      if (ni - hi >= 0) {
        VALM[ni - hi]++;
      }
    }
  }

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

#include <cstdio>
#include <map>
using std::map;
#define int long long
map<int, int> m;
int a[(int)2 * (int)1e6 + 1], n, ans;
signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++)
    scanf("%lld", a + i);
  m[a[1] + 1]++;
  for (int i = 2; i <= n; i++) {
    ans += m[i - a[i]], m[a[i] + i]++;
  }
  printf("%lld\\n", ans);
}

Error: 0

Fixed submission:

#include <cstdio>
#include <map>
using std::map;
map<int, int> m;
int a[(int)1e5 + 1], n, ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  m[a[1] + 1]++;
  for (int i = 2; i <= n; i++) {
    ans += m[i - a[i]], m[a[i] + i]++;
  }
  printf("%d\\n", ans);
}
Problem p02691 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mkpr(x1, x2) make_pair(x1, x2)
typedef long long int ll;

// stack<char> stk;
// set<ll> sll;
// map<string,ll> mp,mp1;
// map<pair<ll,ll>,ll>::iterator iter;
// map<ll,ll> mp;
// deque<char> deq;
// vector<ll> vll;
ll num[ten52];
ll num2[ten52];

int main(void) {
  // double ans=0.0,d,d1,d2;
  // float f,g,h;
  long long int m, n, i, j, k = 1;
  long long int a, a1, a2, a3, sum;
  string s, s1, s2;
  // char c,c1;
  sum = a = a1 = a2 = a3 = 0;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> num[i];
  for (i = 1; i <= n; i++)
    if (i + num[i] <= n)
      num2[i + num[i]]++;
  for (i = 1; i <= n; i++) {
    if (i - num[i] > 0)
      sum += num2[i - num[i]];
  }
  cout << sum;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define mkpr(x1, x2) make_pair(x1, x2)
typedef long long int ll;

// stack<char> stk;
// set<ll> sll;
// map<string,ll> mp,mp1;
// map<pair<ll,ll>,ll>::iterator iter;
// map<ll,ll> mp;
// deque<char> deq;
// vector<ll> vll;
ll num[ten52];
ll num2[ten52];

int main(void) {
  // double ans=0.0,d,d1,d2;
  // float f,g,h;
  long long int m, n, i, j, k = 1;
  long long int a, a1, a2, a3, sum;
  string s, s1, s2;
  // char c,c1;
  sum = a = a1 = a2 = a3 = 0;
  cin >> n;
  for (i = 1; i <= n; i++)
    cin >> num[i];
  for (i = 1; i <= n; i++)
    num2[i + num[i]]++;
  for (i = 1; i <= n; i++) {
    if (i - num[i] > 0)
      sum += num2[i - num[i]];
  }
  cout << sum;
  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 v = vector<ll>;

int main() {
  int n;
  cin >> n;
  v a(n);

  rep(i, n) cin >> a[i];
  map<ll, v> l, r;

  rep(i, n) {
    l[a[i] + i].push_back(i);
    r[i - a[i]].push_back(i);
  }

  ll ans = 0;

  for (auto p : l) { // pair<ll, v>
    ll i = p.first;
    v vj = p.second;
    if (!r.count(i))
      continue;
    for (auto j : vj) { // ll
      ll len = r[i].end() - upper_bound(r[i].begin(), r[i].end(), i);
      ans += len;
    }
  }

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

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

  int ans = 0;

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

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

signed main() {
  int n;
  cin >> n;
  map<long, long> rValues;
  map<long, long> lValues;

  for (int i = 0; i < n; i++) {
    long height;
    cin >> height;
    long rValue = height + i;
    long lValue = i - height;
    rValues[rValue]++;
    lValues[lValue]++;
  }

  long long count = 0;
  for (auto itr = rValues.begin(); itr != rValues.end(); itr++) {
    count += itr->second * lValues[itr->first];
  }
  cout << count << endl;
}

Error: 0

Fixed submission:

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

struct {
  int no;
  long val;
} typedef Agent;

signed main() {
  int n;
  cin >> n;
  vector<Agent> agents;
  for (int i = 0; i < n; i++) {
    Agent agent;
    cin >> agent.val;
    agent.no = i + 1;
    agents.push_back(agent);
  }

  auto sortA = [](Agent a, Agent b) { return a.val <= b.val; };
  sort(agents.begin(), agents.end(), sortA);

  int numCount = 0;
  int sum = 0;
  long numA[200000];
  int prev = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < numCount; j++) {
      if (prev != agents[i].val) {
        numA[j]--;
      }
      if (agents[i].no == numA[j]) {
        sum++;
      }
    }

    prev = agents[i].val;

    numA[numCount] = agents[i].no - (agents[i].val * 2);
    numCount++;
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

int main() {
  long long int n;
  cin >> n;
  vector<long long int> v;
  map<long long int, long long int> mp;
  for (long long int i = 1; i <= n; i++) {
    long long int a;
    cin >> a;
    mp[i - a]++;
    v.push_back(a);
  }
  long long int sum = 0;

  for (long long int i = 0; i < n; i++) {
    if (mp[v[i] + i + 1] > 0) {
      sum += mp[v[i] + i + 1];
    }
  }
  cout << sum;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int arr[n + 1];
  int count = 0;
  map<long long int, int> check;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (arr[i] + arr[j] == abs(j - i))
        count++;
    }
  }
  cout << count;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1, 0);
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  ll ans = 0;
  for (int i = 1; i <= n - 1; ++i) {
    for (int j = i + a[i] + 1; j <= n; ++j) {
      if (a[j] + a[i] == abs(i - j))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define ll long long int

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, i, j;
  cin >> n;
  vector<ll> arr(n);
  unordered_map<ll, ll> umap;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (umap.find(i + 1 + arr[i]) == umap.end())
      umap[i + 1 + arr[i]] = 1;
    else
      umap[i + 1 + arr[i]] += 1;
  }

  ll ans = 0;
  for (i = 0; i < n; i++) {
    if (i + 1 - arr[i] >= 2 && umap.find(i + 1 - arr[i]) != umap.end())
      ans += umap[i + 1 - arr[i]];
  }
  cout << ans << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long int

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, i, j;
  cin >> n;
  vector<ll> arr(n);
  for (i = 0; i < n; i++)
    cin >> arr[i];

  ll ans = 0;
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (j - i == arr[j] + arr[i])
        ans++;
    }
  }
  cout << ans << "\\n";

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

#include <iostream>
#include <map>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
using namespace std;

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

  long ans = 0;
  map<int, int> m;
  rep(i, 0, N - 1) {
    int tmp;
    cin >> tmp;
    int a = i - tmp;
    int b = i + tmp;
    ans += m[a];
    m[b]++;
  }

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


Error: TLE

Fixed submission:

#include <iostream>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
using namespace std;

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

  long A[N];
  int cnt = 0;
  rep(i, 0, N - 1) {
    cin >> A[i];
    rep(j, 0, i - 1) {
      if (i - j == A[i] + A[j])
        cnt++;
    }
  }

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

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

int n;
ll all[maxN] = {};

void solve() {
  ll ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> all[i];
  }
  map<ll, ll> m;
  for (int i = 0; i < n; i++) {
    if (m[i - all[i]]) {
      ans += m[i - all[i]];
    }
    m[i + all[i]]++;
  }
  cout << ans << endl;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

ll n;
int all[maxN] = {};
void solve() {
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> all[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (abs(j - i) == all[i] + all[j]) {
        ans++;
      }
    }
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
Problem p02691 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

ll combination(ll n, ll r) {
  if (n < r)
    return 0;
  if (r == 0 || r == n)
    return 1;
  else if (r == 1)
    return n;
  return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str) {
  string checkStr = str;
  reverse(checkStr.begin(), checkStr.end());
  if (str == checkStr)
    return true;
  else
    return false;
}

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  map<ll, ll> m1;
  map<ll, ll> m2;
  rep(i, N) {
    m1[a[i] + i]++;
    m2[i - a[i]]++;
  }
  ll ans = 0;
  for (auto x : m1) {
    ans += x.second * m2[x.first];
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

ll combination(ll n, ll r) {
  if (n < r)
    return 0;
  if (r == 0 || r == n)
    return 1;
  else if (r == 1)
    return n;
  return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str) {
  string checkStr = str;
  reverse(checkStr.begin(), checkStr.end());
  if (str == checkStr)
    return true;
  else
    return false;
}

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  ll ans = 0;
  // 101を探す
  for (int i = 0; i <= N - 3; i++) {
    if (a[i] == 1 && a[i + 2] == 1)
      ans++;
  }
  // あとは自由に見る
  rep(i, N) {
    for (int j = i + 3; j < N; j++) {
      if (a[i] + a[j] == abs(j - i))
        ans++;
    }
  }
  cout << ans << endl;
}