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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 60, p = 9, maxl = 2e5 + 5;
long long l[maxl];
long long ans = 0;
int nx[maxl], ny[maxl];
int a[maxn][maxn];
int n, it = 0;
long long read() {
  long long digit = 0;
  int cnt = 0, f = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0')
    ch = getchar();
  while ((ch <= '9' && ch >= '0') || ch == '.') {
    if (f)
      ++cnt;
    if (ch == '.')
      f = 1;
    else
      digit = 10 * digit + ch - '0';
    ch = getchar();
  }
  for (int i = 1; i <= 9 - cnt; i++)
    digit *= 10;
  return digit;
}
int main() {
  memset(nx, 0, sizeof(nx));
  memset(ny, 0, sizeof(ny));
  memset(a, 0, sizeof(a));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x;
    x = read(); // printf("%lld\\n",x);
    while (x % 2 == 0)
      ++nx[i], x /= 2;
    while (x % 5 == 0)
      ++ny[i], x /= 5;
    ++a[nx[i]][ny[i]];
  }
  for (int i = maxn - 2; i >= 0; i--)
    for (int j = maxn - 2; j >= 0; j--)
      a[i][j] += a[i + 1][j] + a[i][j + 1] - a[i + 1][j + 1];
  for (int i = 1; i <= n; i++) {
    ans += a[max(2 * p - nx[i], 0)][max(2 * p - ny[i], 0)];
    if (nx[i] >= p && ny[i] >= p)
      --ans;
  }
  printf("%lld\\n", ans / 2);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 60, p = 9, maxl = 2e5 + 5;
long long l[maxl];
long long ans = 0;
int nx[maxn], ny[maxn];
int a[maxn][maxn];
int n, it = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    double t;
    scanf("%lf", &t);
    t = t * 1e9;
    l[i] = t;
    long long x = l[i];
    while (x % 2 == 0)
      ++nx[i], x /= 2;
    while (x % 5 == 0)
      ++ny[i], x /= 5;
    ++a[nx[i]][ny[i]];
  }
  for (int i = maxn - 2; i >= 0; i--)
    for (int j = maxn - 2; j >= 0; j--)
      a[i][j] += a[i + 1][j] + a[i][j + 1] - a[i + 1][j + 1];
  for (int i = 1; i <= n; i++) {
    ans += a[2 * p - nx[i]][2 * p - ny[i]];
    if (nx[i] >= p && ny[i] >= p)
      --ans;
  }
  printf("%lld\\n", ans / 2);
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#define val 1000000000
#define for2(x) for (x = 0; x <= 9; x++)
using namespace std;
int n, i, b1, b2, b3, b4, c1, c2, c3, c4;
long long x, y, r, sol;
int a[12][12][12][12];
double curr;
long long cmmdc(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> curr;
    curr += 0.0000000001;
    x = curr * val;
    y = val;
    r = cmmdc(x, y);
    x /= r;
    y /= r;
    b1 = b2 = b3 = b4 = 0;
    if (y == 1) {
      sol--;
    }
    while (x % 2 == 0) {
      b1++;
      x /= 2;
    }
    while (x % 5 == 0) {
      b2++;
      x /= 5;
    }
    while (y % 2 == 0) {
      b3++;
      y /= 2;
    }
    while (y % 5 == 0) {
      b4++;
      y /= 5;
    }
    b1 = min(b1, 9);
    b2 = min(b2, 9);
    a[b1][b2][b3][b4]++;
  }
  for2(b1) {
    for2(b2) {
      for2(b3) {
        for2(b4) {
          if (a[b1][b2][b3][b4] == 0) {
            continue;
          }
          for2(c1) {
            for2(c2) {
              for2(c3) {
                for2(c4) {
                  if (b1 >= c3 && b2 >= c4 && c1 >= b3 && c2 >= b4) {
                    sol += a[b1][b2][b3][b4] * 1LL * a[c1][c2][c3][c4];
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  sol /= 2;
  cout << sol;
}


Error: WA

Fixed submission:

#include <iostream>
#define val 1000000000
#define for2(x) for (x = 0; x <= 9; x++)
using namespace std;
int n, i, b1, b2, b3, b4, c1, c2, c3, c4;
long long x, y, r, sol;
int a[12][12][12][12];
double curr;
long long cmmdc(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> curr;
    curr += 0.0000000001;
    x = curr * val;
    y = val;
    r = cmmdc(x, y);
    x /= r;
    y /= r;
    b1 = b2 = b3 = b4 = 0;
    if (y == 1) {
      sol--;
    }
    while (x % 2 == 0) {
      b1++;
      x /= 2;
    }
    while (x % 5 == 0) {
      b2++;
      x /= 5;
    }
    while (y % 2 == 0) {
      b3++;
      y /= 2;
    }
    while (y % 5 == 0) {
      b4++;
      y /= 5;
    }
    a[b1][b2][b3][b4]++;
  }
  for2(b1) {
    for2(b2) {
      for2(b3) {
        for2(b4) {
          if (a[b1][b2][b3][b4] == 0) {
            continue;
          }
          for2(c1) {
            for2(c2) {
              for2(c3) {
                for2(c4) {
                  if (b1 >= c3 && b2 >= c4 && c1 >= b3 && c2 >= b4) {
                    sol += a[b1][b2][b3][b4] * 1LL * a[c1][c2][c3][c4];
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  sol /= 2;
  cout << sol;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
using namespace std;
#define ll long long
#define it map<par, int>::iterator

int n;
struct par {
  int x, y;
  par(int xx, int yy) : x(xx), y(yy) {}
  bool operator<(const par &B) const { return x == B.x ? y < B.y : x < B.x; }
};
map<par, int> mp;
ll ans = 0;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long double x;
    cin >> x;
    ll y = llround(x * 1e9);
    int c = 0, d = 0;
    while (y % 2 == 0)
      y /= 2, c++;
    while (y % 5 == 0)
      y /= 5, d++;
    mp[par(c, d)]++;
  }
  for (it i = mp.begin(); i != mp.end(); i++) {
    for (it j = mp.begin(); j != mp.end(); j++) {
      if (i->first.x + j->first.x >= 18 && i->first.y + j->first.y >= 18) {
        if (i == j)
          ans += 1ll * i->second * (i->second - 1);
        else
          ans += 1ll * i->second * j->second;
      }
    }
  }
  cout << ans / 2ll;
}

Error: WA

Fixed submission:

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

int n, a[20][20];
ll ans = 0;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long double x;
    cin >> x;
    x *= 1e9;
    ll y = llround(x + 1e-2);
    int c = 0, d = 0;
    while (y % 2 == 0)
      y /= 2, c++;
    while (y % 5 == 0)
      y /= 5, d++;
    if (c * 2 >= 18 && d * 2 >= 18)
      ans += a[c][d];
    a[c][d]++;
  }
  for (int i = 0; i <= 18; i++) {
    for (int j = 0; j <= 18; j++)
      if (a[i][j]) {
        for (int k = i; k <= 18; k++) {
          for (int l = (k == i ? j + 1 : 0); l <= 18; l++)
            if (a[k][l]) {
              if (i + k >= 18 && j + l >= 18)
                ans += 1ll * a[i][j] * a[k][l];
            }
        }
      }
  }
  cout << ans;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) { cout << (expr ? "Yes" : "No") << "\\n"; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> A(N);
  REP(i, N) {
    double x;
    cin >> x;
    A[i] = (lint)(x * 1000000000LL + 0.5);
  }
  lint ans = 0;
  vector<vector<lint>> num(19, vector<lint>(19));
  REP(x, 19) REP(y, 19) num[x][y] = pow(2LL, (lint)x) * pow(5LL, (lint)y);
  vector<vector<lint>> cnt(19, vector<lint>(19));
  REP(i, N) {
    lint tmp = A[i];
    lint s = 0;
    lint t = 0;
    while (tmp > 0 && tmp % 2 == 0) {
      s++;
      tmp /= 2;
    }
    while (tmp > 0 && tmp % 5 == 0) {
      t++;
      tmp /= 5;
    }
    ans += cnt[18 - min(18LL, s)][18 - min(18LL, t)];
    IREP(x, 19) IREP(y, 19) {
      if (A[i] % num[x][y] == 0) {
        cnt[x][y]++;
      }
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) { cout << (expr ? "Yes" : "No") << "\\n"; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> A(N);
  REP(i, N) {
    double x;
    cin >> x;
    A[i] = (lint)(x * 1000000000LL);
  }
  lint ans = 0;
  vector<vector<lint>> num(19, vector<lint>(19));
  REP(x, 19) REP(y, 19) num[x][y] = pow(2LL, (lint)x) * pow(5LL, (lint)y);
  vector<vector<lint>> cnt(19, vector<lint>(19));
  REP(i, N) {
    lint tmp = A[i];
    lint s = 0;
    lint t = 0;
    while (tmp > 0 && tmp % 2 == 0) {
      s++;
      tmp /= 2;
    }
    while (tmp > 0 && tmp % 5 == 0) {
      t++;
      tmp /= 5;
    }
    ans += cnt[18 - s][18 - t];
  a:
    IREP(x, 19) IREP(y, 19) {
      if (A[i] % num[x][y] == 0) {
        cnt[x][y]++;
      }
    }
  }
  cout << ans << endl;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<ll>;
using vv = vector<vi>;
// const int MOD = 1000000007;
const int MOD = 998244353;
const int INF = 1001001001;
const ll LINF = 1001001001001;

int main() {

  int n;
  cin >> n;
  vv faclist(19, vi(19, 0));

  rep(i, n) {
    string a;
    cin >> a;

    ll anum = 0;
    int dot = 0;

    rep(j, a.size()) {
      if (a[j] == '.') {
        dot = j + 1 - a.size();
      } else {
        anum *= 10;
        anum += a[j] - '0';
      }
    }
    int fac2 = dot, fac5 = dot;

    rep(j, 19) {
      if (anum % 2)
        break;
      else {
        anum /= 2;
        fac2++;
      }
    }
    rep(j, 19) {
      if (anum % 5)
        break;
      else {
        anum /= 5;
        fac5++;
      }
    }

    faclist[min(18, fac2 + 9)][min(18, fac5 + 9)]++;
  }

  vv acclist = faclist;

  rep(i, 19) {
    for (int j = 17; j >= 0; j--) {
      acclist[i][j] += acclist[i][j + 1];
    }
  }
  rep(j, 19) {
    for (int i = 17; i >= 0; i--) {
      acclist[i][j] += acclist[i + 1][j];
    }
  }

  ll ans = 0;

  rep(i, 19) rep(j, 19) {
    if (!faclist[i][j])
      continue;

    if (i > 8 && j > 8)
      ans += faclist[i][j] * (acclist[18 - i][18 - j] - 1);
    else
      ans += faclist[i][j] * acclist[18 - i][18 - j];
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<ll>;
using vv = vector<vi>;
// const int MOD = 1000000007;
const int MOD = 998244353;
const int INF = 1001001001;
const ll LINF = 1001001001001;

int main() {

  int n;
  cin >> n;
  vv faclist(19, vi(19, 0));

  rep(i, n) {
    string a;
    cin >> a;

    ll anum = 0;
    int dot = 0;

    rep(j, a.size()) {
      if (a[j] == '.') {
        dot = j + 1 - a.size();
      } else {
        anum *= 10;
        anum += a[j] - '0';
      }
    }
    int fac2 = dot, fac5 = dot;

    rep(j, 19) {
      if (anum % 2)
        break;
      else {
        anum /= 2;
        fac2++;
      }
    }
    rep(j, 19) {
      if (anum % 5)
        break;
      else {
        anum /= 5;
        fac5++;
      }
    }

    faclist[fac2 + 9][fac5 + 9]++;
  }

  vv acclist = faclist;

  rep(i, 19) {
    for (int j = 17; j >= 0; j--) {
      acclist[i][j] += acclist[i][j + 1];
    }
  }
  rep(j, 19) {
    for (int i = 17; i >= 0; i--) {
      acclist[i][j] += acclist[i + 1][j];
    }
  }

  ll ans = 0;

  rep(i, 19) rep(j, 19) {
    if (!faclist[i][j])
      continue;

    if (i > 8 && j > 8)
      ans += faclist[i][j] * (acclist[18 - i][18 - j] - 1);
    else
      ans += faclist[i][j] * acclist[18 - i][18 - j];
  }

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

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

ll solve() {
  ll N;
  cin >> N;
  double x;
  int k2 = 52, k5 = 23;
  vector<vector<ll>> m(k2, vector<ll>(k5)); // 2^(i-9) * 5^(j-9)
  for (int i = 0; i < N; i++) {
    cin >> x;
    ll b = (ll)(x * (ll)(1e9) + 0.5);
    ll p2 = 0, p5 = 0;
    while (b % 2 == 0) {
      p2++;
      b /= 2;
    }
    while (b % 5 == 0) {
      p5++;
      b /= 5;
    }
    m[p2][p5]++;
  }
  ll ans = 0;
  for (int i2 = 0; i2 < k2; i2++) {
    for (int i5 = 0; i5 < k5; i5++) {
      for (int j2 = 0; j2 < k2; j2++) {
        if (i2 + j2 < 18)
          continue;
        for (int j5 = 0; j5 < k5; j5++) {
          if (i5 + j5 < 18)
            continue;
          if (i2 == j2 && i5 == j5) {
            ans += m[i2][i5] * (m[i2][i5] - 1);
          } else {
            ans += m[i2][i5] * m[j2][j5];
          }
        }
      }
    }
  }
  ans /= 2;
  return ans;
}

int main() {
  auto ans = solve();
  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

ll solve() {
  ll N;
  cin >> N;
  double x;
  vector<vector<ll>> m(26, vector<ll>(20)); // 2^(i-9) * 5^(j-9)
  for (int i = 0; i < N; i++) {
    cin >> x;
    ll b = (ll)(x * (ll)(1e9) + 0.5);
    ll p2 = 0, p5 = 0;
    while (b % 2 == 0) {
      p2++;
      b /= 2;
    }
    while (b % 5 == 0) {
      p5++;
      b /= 5;
    }
    m[p2][p5]++;
  }
  ll ans = 0;
  for (int i2 = 0; i2 < 26; i2++) {
    for (int i5 = 0; i5 < 20; i5++) {
      for (int j2 = 0; j2 < 26; j2++) {
        if (i2 + j2 < 18)
          continue;
        for (int j5 = 0; j5 < 20; j5++) {
          if (i5 + j5 < 18)
            continue;
          if (i2 == j2 && i5 == j5) {
            ans += m[i2][i5] * (m[i2][i5] - 1);
          } else {
            ans += m[i2][i5] * m[j2][j5];
          }
        }
      }
    }
  }
  ans /= 2;
  return ans;
}

int main() {
  auto ans = solve();
  cout << ans << "\\n";
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define int long long
int dp[65][35], ans;
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

void F(string s) {
  int two = 0, five = 0, now = 0, a = 0, f = 0;
  while (now < s.size()) {
    if (s[now] == '.')
      f = 1;
    else {
      a *= 10;
      a += s[now] - '0';
      if (f)
        two--, five--;
    }
    now++;
  }
  while (a % 2 == 0)
    a /= 2, two++;
  while (a % 5 == 0)
    a /= 5, five++;
  for (int i = 0; i < 65; i++) {
    for (int j = 0; j < 35; j++) {
      if (two + i >= 30 && five + j >= 15)
        ans += dp[i][j];
    }
  }
  chmin(two, 32LL);
  chmin(five, 15LL);
  dp[two + 30][five + 15]++;
}

signed main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    F(s);
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

#define int long long
int dp[120][120];
int ans = 0;

bool SHOSU(string s) {
  int now = 0;
  while (now < s.size() && s[now] != '.')
    now++;
  if (now == s.size())
    return false;
  now++;
  while (now < s.size() && s[now] == '0')
    now++;
  if (now == s.size())
    return false;
  return 1;
}
int N(string s) {
  int now = 0;
  while (now < s.size() && s[now] != '.')
    now++;
  now++;
  int S = 0, P = 1;
  while (now < s.size()) {
    S += s[now] - '0';
    P *= 10;
    now++;
  }
  P /= __gcd(S, P);
  return P;
}
int se(string s) {
  int res = 0;
  int now = 0;
  while (now < s.size() && s[now] != '.') {
    res *= 10;
    res += s[now] - '0';
    now++;
  }
  return res;
}
void F(string s) {
  int two = 0, five = 0;
  int now = 0;
  while (now < s.size() && s[now] != '.')
    now++;
  if (now != s.size()) {
    while (now + 1 < s.size()) {
      s[now] = s[now + 1];
      two--;
      five--;
      now++;
    }
    s.pop_back();
  }
  int a = se(s);
  while (a % 2 == 0) {
    a /= 2;
    two++;
  }
  while (a % 5 == 0) {
    a /= 5;
    five++;
  }
  for (int i = 0; i < 120; i++) {
    for (int j = 0; j < 120; j++) {
      if (two + i >= 60 && five + j >= 60)
        ans += dp[i][j];
    }
  }
  dp[two + 60][five + 60]++;
}

signed main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    F(s);
  }
  cout << ans << endl;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

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

int64_t cnt[50][50];
int main() {
  int n;
  cin >> n;
  int64_t a[n];
  for (int i = 0; i < n; ++i) {
    double aa;
    cin >> aa;
    a[i] = llround(aa * 1e9);
    int t = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      t++;
    }
    int f = 0;
    while (a[i] % 5 == 0) {
      a[i] /= 5;
      f++;
    }
    ++cnt[t][f];
  }
  int64_t ans = 0;
  for (int i = 0; i < 50 * 50; ++i) {
    int il = i / 50, ir = i % 50;
    for (int j = i; j < 50 * 50; ++j) {
      int jl = j / 50, jr = j % 50;
      if (il + jl >= 18 and ir + jr >= 18) {
        if (i == j) {
          ans += cnt[il][ir] * (cnt[il][ir] - 1) / 2;
        } else {
          ans += cnt[il][ir] * cnt[jl][jr];
        }
      }
    }
  }
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

int64_t cnt[20][20];
int main() {
  int n;
  cin >> n;
  int64_t a[n];
  for (int i = 0; i < n; ++i) {
    double aa;
    cin >> aa;
    a[i] = llround(aa * 1e9);
    int t = 0;
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      t++;
    }
    int f = 0;
    while (a[i] % 5 == 0) {
      a[i] /= 5;
      f++;
    }
    assert(t < 20 and f < 20);
    ++cnt[t][f];
  }
  int64_t ans = 0;
  for (int i = 0; i < 20 * 20; ++i) {
    int il = i / 20, ir = i % 20;
    for (int j = i; j < 20 * 20; ++j) {
      int jl = j / 20, jr = j % 20;
      if (il + jl >= 18 and ir + jr >= 18) {
        if (i == j) {
          ans += cnt[il][ir] * (cnt[il][ir] - 1) / 2;
        } else {
          ans += cnt[il][ir] * cnt[jl][jr];
        }
      }
    }
  }
  cout << ans << '\\n';
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  vector<P> p(n);
  double a;
  REP(i, n) {
    cin >> a;
    ll b = (a * 1000000000 + 0.1);
    int d2 = 0, d5 = 0;
    while (b % 2 == 0) {
      b /= 2;
      d2++;
    }
    while (b % 5 == 0) {
      b /= 5;
      d5++;
    }
    d2 = min(18, d2);
    d5 = min(18, d5);
    mp[{d2, d5}]++;
    p[i] = {d2, d5};
  }
  ll ans = 0;
  REP(i, n) {
    for (int j = max(0ll, 18 - p[i].first); j <= 18; j++) {
      for (int k = max(0ll, 18 - p[i].second); k <= 18; k++) {
        ans += mp[{j, k}];
        if (p[i].first == j && p[i].second == k)
          ans--;
      }
    }
  }
  cout << ans / 2 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  vector<P> p(n);
  double a;
  REP(i, n) {
    cin >> a;
    ll b = (a * 1000000000 + 0.1);
    int d2 = 0, d5 = 0;
    while (b % 2 == 0) {
      b /= 2;
      d2++;
    }
    while (b % 5 == 0) {
      b /= 5;
      d5++;
    }
    mp[{d2, d5}]++;
    p[i] = {d2, d5};
  }
  ll ans = 0;
  REP(i, n) {
    for (int j = max(0ll, 18 - p[i].first); j <= 50; j++) {
      for (int k = max(0ll, 18 - p[i].second); k <= 50; k++) {
        ans += mp[{j, k}];
        if (p[i].first == j && p[i].second == k)
          ans--;
      }
    }
  }
  cout << ans / 2 << endl;
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int up2[maxn], d2[maxn], up5[maxn], d5[maxn];
int cnt[11][11][11][11], n;
long long ans = 0;
int main() {
  cin >> n;
  for (int x = 1; x <= n; x++) {
    string s;
    cin >> s;
    long long upv = 0, dv = 1, flag = 0;
    for (int i = 0; i < (int)s.size(); i++)
      if (isdigit(s[i]))
        upv = 10 * upv + s[i] - '0';
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == '.')
        flag = 1;
      else if (flag)
        dv = 10 * dv;
    }
    long long ttt = __gcd(upv, dv);
    upv /= ttt;
    dv /= ttt;
    while (upv % 2 == 0)
      upv /= 2, up2[x]++;
    while (upv % 5 == 0)
      upv /= 5, up5[x]++;
    while (dv % 2 == 0)
      dv /= 2, d2[x]++;
    while (dv % 5 == 0)
      dv /= 5, d5[x]++;
    up2[x] = min(up2[x], 10);
    d2[x] = min(d2[x], 10);
    up5[x] = min(up5[x], 10);
    d5[x] = min(d5[x], 10);
    for (int A = 0; A <= 10; A++)
      for (int B = 0; B <= (A ? 0 : 10); B++)
        for (int C = 0; C <= 10; C++)
          for (int D = 0; D <= (C ? 0 : 10); D++) {
            if (A >= d2[x] && B <= up2[x] && C >= d5[x] && D <= up5[x])
              ans += cnt[A][B][C][D];
          }
    cnt[up2[x]][d2[x]][up5[x]][d5[x]]++;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int up2[maxn], d2[maxn], up5[maxn], d5[maxn];
int cnt[51][51][51][51], n;
long long ans = 0;
int main() {
  cin >> n;
  for (int x = 1; x <= n; x++) {
    string s;
    cin >> s;
    long long upv = 0, dv = 1, flag = 0;
    for (int i = 0; i < (int)s.size(); i++)
      if (isdigit(s[i]))
        upv = 10 * upv + s[i] - '0';
    for (int i = 0; i < (int)s.size(); i++) {
      if (s[i] == '.')
        flag = 1;
      else if (flag)
        dv = 10 * dv;
    }
    long long ttt = __gcd(upv, dv);
    upv /= ttt;
    dv /= ttt;
    while (upv % 2 == 0)
      upv /= 2, up2[x]++;
    while (upv % 5 == 0)
      upv /= 5, up5[x]++;
    while (dv % 2 == 0)
      dv /= 2, d2[x]++;
    while (dv % 5 == 0)
      dv /= 5, d5[x]++;
    for (int A = 0; A <= 50; A++)
      for (int B = 0; B <= (A ? 0 : 50); B++)
        for (int C = 0; C <= 50; C++)
          for (int D = 0; D <= (C ? 0 : 50); D++) {
            if (A >= d2[x] && B <= up2[x] && C >= d5[x] && D <= up5[x])
              ans += cnt[A][B][C][D];
          }
    cnt[up2[x]][d2[x]][up5[x]][d5[x]]++;
  }
  cout << ans << endl;
}