Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03394 (python)

Fixed submission:
N = int(input())
if N < 5002:
    if N % 2  == 0:
        sans = [6 * i  + 3 for i in range(N-2)]
        ans = sans + [2,4]
    if N % 2 == 1:
        sans = [6 * i  + 3 for i in range(N-3)]
        ans = sans + [2,4,6]
    if N == 3:
        ans = [2,3,25]
else:
    sans = [6 * i  + 3 for i in range(5000)]
    nis = [2 * i + 2 for i in range(N - 5000 )]
    if (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 1:
        nis[-1] += 2
    elif    (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 2:
        nis[-1] += 2
        nis[-2] += 2
    ans = sans + nis
ans = map(str,ans)
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N < 5002:
    if N % 2  == 0:
        sans = [6 * i  + 3 for i in range(N-2)]
        ans = sans + [2,4]
    if N % 2 == 1:
        sans = [6 * i  + 3 for i in range(N-3)]
        ans = sans + [2,4,6]
    if N == 3:
        ans = [2,3,25]
else:
    sans = [6 * i  + 3 for i in range(5000)]
    nis = [2 * i + 2 for i in range(N - 5000 )]
    else:
        if (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 1:
            nis[-1] += 2
        elif    (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 2:
            nis[-1] += 2
            nis[-2] += 2
    ans = sans + nis
ans = map(str,ans)
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
if N < 5002:
    if N % 2  == 0:
        sans = [6 * i  + 3 for i in range(N-2)]
        ans = sans + [2,4]
    if N % 2 == 1:
        sans = [6 * i  + 3 for i in range(N-3)]
        ans = sans + [2,4,6]
    if N == 3:
        ans = [2,3,25]
else:
    sans = [6 * i  + 3 for i in range(4999)]
    nis = [2 * i + 2 for i in range(N - 50000 )]
    if N == 20000:
        nis[-1] = 5
    else:
        if (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 1:
            nis[-1] += 2
        elif    (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 2:
            nis[-1] += 2
            nis[-2] += 2
    ans = sans + nis
print(ans)
Problem p03399 (python)

Fixed submission:
#a b = map(int,input().split())
a = [ int(input()) for i in range(4)]
#print(a)
print(min(a[:2]) + min(a[2:]))

Buggy submission (verdict: Runtime Error):
N = int(input())
D,X= list(map(int,input().split()))
A = [int(input()) for i  in range(N)]
nums = [ (D-1)//a + 1 for a in A]

print(sum(nums) + X)
Problem p03419 (python)

Fixed submission:
N,M = list(map(int,input().split()))
if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max([N,M]) -2)
else:
    print( N * M + 4 - 2*(N+M))

Buggy submission (verdict: Runtime Error):
N,N = list(map(int,input().split()))
if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max([N,M]) -2)
else:
    print( N * M + 4 - 2*(N+M))
Problem p02694 (python)

Fixed submission:
X = int(input())

yen = 100
ret = 0
while yen<X:
  yen = 101*yen//100
  ret += 1
print(ret)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long X) {
  ll yen = 100;
  ll ret = 0;
  while(yen<X){
    yen += yen / 100LL;
    ret++;
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long X;
  std::cin >> X;
  solve(X);
  return 0;
}
Problem p02618 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import random

D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(j) for j in input().split()])

for i in range(D):
    print(random.randint(1, 26))

Buggy submission (verdict: Runtime Error):
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    s.append([int(j) for j in input().split()])

for i, s_i in enumerate(s):
    print(s.index(max(s_i)))
Problem p03220 (python)

Fixed submission:
import math

N = int(input())
T, A = [int(i) for i in input().split()]

diff_min = 999999999
diff_i = 0
H = [int(i) for i in input().split()]
for i, n in enumerate(H):
    diff = math.fabs(A - (T - 0.006*n))
    if diff < diff_min:
        diff_min = diff
        diff_i = i + 1

print(diff_i)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
T, A = [int(i) for i in input().split()]

diff_min = 999999999
diff_i = 0
H = [int(i) for i in input().split()]
for i, n in enumerate(H):
    diff = math.abs(A - (T - 0.006*n))
    if diff < diff_min:
        diff = diff_min
        diff_i = i + 1

print(diff_i)
Problem p03486 (python)

Fixed submission:
s = list(input())
s.sort()
s = ''.join(s)
t= list(input())
t.sort()
t = ''.join(reversed(list(t)))

if s < t:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
s.sort()
t= input()
t.sort()
t = ''.join(reversed(list(t)))

if s < t:
    print('Yes')
else:
    print('No')
Problem p03644 (python)

Fixed submission:
N = int(input())
min = 0
max = 0

for i in range(N):
    if 2**i <= N:
        min = 2**i
    else:
        break

print(min)

Buggy submission (verdict: Runtime Error):
N = int(input())
min = 0
max = 0

for i in range(N):
    if 2**i <= N:
        min = i
    else:
        break

print(min)


N = int(input())
min = 0
max = 0

for i in range(N):
    if 2**i <= N:
        min = i
    else:
        break

print(min)
Problem p02885 (python)

Fixed submission:
A,B = map(int, input().split())
print(max(0, A-2*B))

Buggy submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
#print(D)
sum = 0
for i in range(N):
  for j in range(i+1,N):
    sum += D[i]*D[j]

print(sum)
Problem p02900 (python)

Fixed submission:
import math
A, B = map(int, input().strip().split())

divisors = []

minAB = min(A,B)
maxAB = max(A,B)
upper = int(math.sqrt(minAB+1) + 1)
ans = 1

for i in range(1, upper):
    if minAB % i == 0:
        divisors.append(i)
        if i != minAB//i:
            divisors.append(minAB//i)

divisors.sort()
#print(divisors)

flag = [True] * len(divisors)
for i, num in enumerate(divisors):
    if maxAB % num != 0:
        flag[i] = False
        continue
    for x in divisors:
        if x == 1 :
            continue
        if x > math.sqrt(num):
            break
        if num % x ==0:
            flag[i] = False
            break

print(flag.count(True))

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)
"""
upper = int(math.sqrt(minAB+1))
ans = 1

for i in range(2, upper+1):

    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False

    if A % i == 0  and B % i == 0:
        ans += 1
"""
ans = 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)
"""
upper = int(math.sqrt(minAB+1))
ans = 1

for i in range(2, upper+1):

    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False

    if A % i == 0  and B % i == 0:
        ans += 1
"""
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)

upper = int(math.sqrt(minAB+1))
ans = 1
"""
for i in range(2, upper+1):

    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False

    if A % i == 0  and B % i == 0:
        ans += 1
"""
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)

upper = int(math.sqrt(minAB+1))
ans = 1
for i in range(2, upper+1):
    """
    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False
    """
    if A % i == 0  and B % i == 0:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B = map(int, input().strip().split())

minAB = min(A,B);

hurui = [True] * (minAB+1)

upper = int(math.sqrt(minAB+1))
ans = 1
for i in range(2, upper+1):
    if not(hurui[i]):
        continue
    
    for j in range(2*i, minAB+1, i):
        hurui[j] = False
    
    if A % i == 0  and B % i == 0:
        ans += 1
        
print(ans)
Problem p02814 (python)

Fixed submission:
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
sum = 0
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
for i in range(len(l)):
    if (lcm // int(l[i])) % 2 == 1:
        sum += 1
if sum == len(l):
    x = m // (int(lcm) // 2)
    y = m // lcm
    print(int(x - y))
else:
    print(0)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

ll gcd(ll a, ll b) {
    if(a < b) return gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}


int main(){
    ll n, m, a[101000];
    cin >> n >> m;

    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] /= 2;
    }

    ll hist = a[0];
    for(int i = 1; i < n; i++){
        if(hist > m){
            cout << 0 << endl;
            return 0;
        }
        ll x = hist * a[i] / gcd(hist, a[i]);
        if((x / hist) % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
        else{
            hist = x;
        }

        if(hist > m){
            cout << 0 << endl;
            return 0;
        }
    }
    if(hist > m){
        cout << 0 << endl;
        return 0;
    }

    cout << (m - hist) / (2 * hist) + 1 << endl;



    return 0;
}

Buggy submission (verdict: Runtime Error):
import fractions
n,m = map(int,input().split())
l = input().split()
lcm = 1
sum = 0
for i in range(len(l)):
    lcm = (int(l[i]) * lcm) // fractions.gcd(int(l[i]), lcm)
for i in range(len(l)):
    if (lcm // int(l[i])) % 2 == 1:
        sum += 1
if sum == len(l):
    x = m // (int(lcm) / 2)
    y = m // lcm
    print(int(x - y))
else:
    print(0)
Problem p02885 (python)

Fixed submission:
input_lst = input().split(' ')
cand = int(input_lst[0]) -  2 * int(input_lst[1])
print(max(0, cand))

Buggy submission (verdict: Runtime Error):
input_lst = readline().split(' ')
cand = int(input_lst[1]) - 2 * int(input_lst[0])
print(max(0, cand))
Problem p02692 (python)

Fixed submission:
n, A, B, C = map(int, input().split())
s = [list(input()) for _ in range(n)]

cur = dict()
cur['A'], cur['B'], cur['C'] = A, B, C

f = True
ans = []
for i, ss in enumerate(s):
    if cur[ss[0]] == 1 and cur[ss[1]] == 1 and sorted(list(cur.values())) == [0, 1, 1] and i < len(s) - 1:
        if ss[0] in s[i + 1]:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])
        elif ss[1] in s[i + 1]:
            cur[ss[1]] += 1
            cur[ss[0]] -= 1
            ans.append(ss[1])

    else:
        if cur[ss[0]] >= cur[ss[1]]:
            cur[ss[0]] -= 1
            cur[ss[1]] += 1
            ans.append(ss[1])
        else:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])

    if -1 in list(cur.values()):
        f = False
        break

if f:
    print('Yes')
    for a in ans:
        print(a)
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, A, B, C = map(int, input().split())
s = [list(input()) for _ in range(n)]

cur = dict()
cur['A'], cur['B'], cur['C'] = A, B, C

counts = dict()
counts['AB'], counts['AC'], counts['BC'] = 0, 0, 0
for ss in s:
    counts[''.join(ss)] += 1

f = True
ans = []
for i, ss in enumerate(s):
    if cur[ss[0]] == 1 and cur[ss[1]] == 1 and sorted(list(cur.values())) == [0, 1, 1] and i < len(s):
        if ss[0] in s[i + 1]:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])
        elif ss[1] in s[i + 1]:
            cur[ss[1]] += 1
            cur[ss[0]] -= 1
            ans.append(ss[1])

    else:
        if cur[ss[0]] >= cur[ss[1]]:
            cur[ss[0]] -= 1
            cur[ss[1]] += 1
            ans.append(ss[1])
        else:
            cur[ss[0]] += 1
            cur[ss[1]] -= 1
            ans.append(ss[0])

    if -1 in list(cur.values()):
        f = False
        break

if f:
    print('Yes')
    for a in ans:
        print(a)
else:
    print('No')
Problem p02733 (python)

Fixed submission:
h, w, K = map(int, input().split())
s = [input() for _ in range(h)]

ans = float('inf')
for i in range(1 << (h - 1)):
    cut_h = []
    for j in range(h - 1):
        if (i >> j) & 1:
            cut_h.append(j)

    blocks = []
    before = 0
    for cut in cut_h:
        blocks.append([before, cut])
        before = cut + 1
    blocks.append([before, h - 1])

    counts = [[0] * w for _ in range(len(blocks))]
    for b in range(len(blocks)):
        for j in range(blocks[b][0], blocks[b][1] + 1):
            for k in range(w):
                if s[j][k] == '1':
                    counts[b][k] += 1

    # print(cut_h)
    # print(blocks)
    # print(counts)

    maxcounts = 0
    for j in range(len(counts)):
        for k in range(len(counts[0])):
            maxcounts = max(maxcounts, counts[j][k])
    if maxcounts > K:
        continue

    tmpans = len(cut_h)
    cumsums = [0] * len(blocks)
    for k in range(w):
        for b in range(len(blocks)):
            cumsums[b] += counts[b][k]

        if max(cumsums) > K:
            # print(cumsums)
            tmpans += 1
            cumsums = [counts[b][k] for b in range(len(blocks))]


    ans = min(ans, tmpans)
    # print(tmpans)
print(ans)

Buggy submission (verdict: Runtime Error):
h, w, K = map(int, input().split())
s = [input() for _ in range(h)]

ans = float('inf')
for i in range(1 << (h - 1)):
    cut_h = []
    for j in range(h - 1):
        if (i >> j) & 1:
            cut_h.append(j)

    blocks = []
    before = 0
    for cut in cut_h:
        blocks.append([before, cut])
        before = cut + 1
    blocks.append([before, h - 1])

    counts = [[0] * w for _ in range(len(blocks))]
    for b in range(len(blocks)):
        for j in range(blocks[b][0], blocks[b][1] + 1):
            for k in range(w):
                if s[j][k] == '1':
                    counts[b][k] += 1

    # print(cut_h)
    # print(blocks)
    # print(counts)

    maxcounts = 0
    for j in range(len(counts)):
        for k in range(len(counts[0])):
            mincounts = max(mincounts, counts[j][k])
    if maxcounts > K:
        continue

    tmpans = len(cut_h)
    cumsums = [0] * len(blocks)
    for k in range(w):
        for b in range(len(blocks)):
            cumsums[b] += counts[b][k]

        if max(cumsums) > K:
            # print(cumsums)
            tmpans += 1
            cumsums = [counts[b][k] for b in range(len(blocks))]


    ans = min(ans, tmpans)
    # print(tmpans)
print(ans)
Problem p02824 (python)

Fixed submission:
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
a = a[::-1]

s = [0] * p
for i in range(p, n + 1):
    s.append(s[-1] + a[i - 1])
s = s[1:]

ans = 0
for i in range(1, n + 1):
    if i <= p:
        ans += 1
    else:
        if v - 1 <= p - 1:
            if a[i - 1] + m >= a[p - 1]:
                ans += 1

        else:
            if v - p <= n - i:
                if a[i - 1] + m >= a[p - 1]:
                    ans += 1
            else:
                if a[i - 1] + m < a[p - 1]:
                    continue
                elif a[i-1] * (i - p) >= m * (v - n) + s[i - 2]:
                    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, v, p = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
a = a[::-1]

s = [0] * (p - 1)
for i in range(p, n + 1):
    s.append(s[-1] + a[i - 1])


ans = 0
for i in range(1, n + 1):
    if i <= p:
        ans += 1
    else:
        if v <= p - 1:
            if a[i - 1] + m >= a[p - 1]:
                ans += 1

        else:
            if v - p <= n - i:
                if a[i - 1] + m >= a[p - 1]:
                    ans += 1
            else:
                if (a[i-1] + m) * (i - p) - s[i - 1] >= m * (v - p - n + i):
                    ans += 1

print(ans)
Problem p02843 (python)

Fixed submission:
x = int(input())

dp = [0] * (x + 1)
cost = [100, 101, 102, 103, 104, 105]

if x < 100:
    print('0')
elif x <= 105:
    print('1')
else:
    dp[0] = 1
    for _x in range(1, x + 1):
        for c in cost:
            if dp[_x - c] == 1:
                dp[_x] = 1
                continue

    if dp[-1]:
        print('1')
    else:
        print('0')

Buggy submission (verdict: Runtime Error):
x = int(input())

dp = [0] * (x + 1)
cost = [100, 101, 102, 103, 104, 105]

dp[0] = 1
for _x in range(1, x + 1):
    for c in cost:
        if dp[_x - c] == 1:
            dp[_x] = 1
            continue

if dp[-1]:
    print('1')
else:
    print('0')
Problem p02844 (python)

Fixed submission:
n = int(input())
s = input()

from collections import Counter
left = Counter('')
right = Counter(s[1:])

ans = set()
for i in range(1, n-1):
    left[s[i-1]] += 1
    right[s[i]] -= 1
    # print(left, right)

    left_u = []
    for k in left.keys():
        if left[k] >= 1:
            left_u.append(k)
    right_u = []
    for k in right.keys():
        if right[k] >= 1:
            right_u.append(k)

    for l in left_u:
        for r in right_u:
            tmp = l + s[i] + r
            ans.add(tmp)

print(len(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()

from collections import Counter
left = Counter('')
right = Counter(s[1:])

ans = set()
for i in range(10):
    lefts[str(i)] = []
    rights[str(i)] = []

for i in range(1, n-1):
    left[s[i-1]] += 1
    right[s[i]] -= 1
    # print(left, right)

    left_u = []
    for k in left.keys():
        if left[k] >= 1:
            left_u.append(k)
    right_u = []
    for k in right.keys():
        if right[k] >= 1:
            right_u.append(k)

    for l in left_u:
        for r in right_u:
            tmp = l + s[i] + r
            ans.add(tmp)

print(len(ans))
Problem p02850 (python)

Fixed submission:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

from collections import defaultdict
g = defaultdict(list)
for a, b in ab:
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

k = 0
for key in g:
    k = max(k, len(g[key]))
print(k)

ans = dict()
q = [(0, -1)] # (pos, used_color)
visited = set([0])
while q:
    cur, col = q.pop()

    if col == 0:
        tmp = 1
    else:
        tmp = 0

    for target in g[cur]:
        if target not in visited:
            q.append((target, tmp))
            visited.add(target)
            ans[(cur, target)] = tmp

            if tmp + 1 == col:
                tmp += 2
            else:
                tmp += 1

for a, b in ab:
    key = (a-1, b-1)
    print(ans[key] + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n - 1)]

from collections import defaultdict
g = defaultdict(list)
for i in range(len(ab)):
    g[ab[i][0]].append(ab[i][1])
    g[ab[i][1]].append(ab[i][0])

k = 0
for key in g.keys():
    k = max(k, len(g[key]))
print(k)

from bisect import bisect_left

ans_d = dict()
for key in g.keys():
    ans_d[key] = [0] * len(g[key])

used_all = dict()
for key in g.keys():
    used_all[key] = []

for key in g.keys():
    used = used_all[key]

    unused = []
    for j in range(1, k+1):
        idx = bisect_left(used, j)
        if idx < len(used) and used[idx] == j:
            continue
        else:
            unused.append(j)
    # print(unused)

    idx = 0
    for j in range(len(g[key])):
        if ans_d[key][j] == 0:
            ans_d[key][j] = unused[idx]

            target = g[key][j]
            idx2 = bisect_left(g[target], key)
            ans_d[target][idx2] = unused[idx]
            used_all[key].append(unused[idx])
            used_all[target].append(unused[idx])
            idx += 1

# print(ans_d)

for i in range(len(ab)):
    idx = bisect_left(g[ab[i][0]], ab[i][1])
    print(ans_d[ab[i][0]][idx])
Problem p02888 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))

l.sort()
from bisect import bisect_left
ans = 0
for i in range(n):
    for j in range(i):
        idx = bisect_left(l, l[i] + l[j])
        ans += idx - i - 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l2 = list(map(int, input().split()))

from collections import Counter
c = Counter(l2)
k = list(c.keys())
k.sort()

from bisect import bisect_left, bisect_right
l2.sort()

ans = 0
for i in range(len(k)):
    for j in range(i+1, len(k)):
        c_min = k[j] - k[i]
        c_max = k[i] + k[j]

        idx = bisect_right(l2, k[j])
        tmp = l2[idx:]

        idx_min = bisect_right(tmp, c_min)
        idx_max = bisect_left(tmp, c_max)

        ans += max(0, idx_max - idx_min) * c[k[i]] * c[k[j]]

for _k in k:
    if c[_k] >= 2:
        idx = bisect_right(l2, _k)
        tmp = l2[idx:]
        idx_min = bisect_right(tmp, 0)
        idx_max = bisect_left(tmp, _k * 2)

        ans += max(0, idx_max - idx_min) * (c[_k] - 1) * c[k] // 2

print(ans)