Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
x = []
for i in range(n-k+1):
    tmp = 1
    for j in range(k):
        tmp *= a[i+j]
    x.append(tmp)

for i in range(n-k):
    if x[i] < x[i+1]:
        print("Yes")
    else:
        print("No")

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n-k):
    if a[i] < a[i+k]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = 0
c = 0
ans = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    b_num = a.count(b)
    ans += b_num*(c-b)
    for j in range(b_num):
        a.remove(b)
        a.append(c)
    print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
x = [0]*100001
for i in range(n):
    x[a[i]] += 1
q = int(input())
ans = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    ans += x[b]*(c-b)
    x[c] += x[b]
    x[b] = 0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
s = 1
for i in range(n):
    s *= a[i]

if s > 1e18:
    print("-1")
else:
    print(s)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
s = 1
if 0 in a:
    print("0")
else:
    for i in range(n):
        s *= a[i]
        if s > 1e18:
            print("-1")
            break
    else:
        print(s)
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
l = []
for i in range(q):
    l.append(list(map(int,input().split())))

t = [1]*(n+1)
ans = 0
while t[0] == 1:
    s = 0
    for i in range(q):
        if t[l[i][1]]-t[l[i][0]] == l[i][2]:
            s += l[i][3]
    ans = max(ans, s)
    k = n
    while t[k] == m and n >= 1:
        k -= 1
    t[k] += 1
    for i in range(k+1, n+1):
        t[i] = t[i-1]

print(ans)

Fixed submission:
n, m, q = map(int, input().split())
l = []
for i in range(q):
    l.append(list(map(int,input().split())))

t = [1]*(n+1)
ans = 0
while t[0] == 1:
    s = 0
    for i in range(q):
        if t[l[i][1]]-t[l[i][0]] == l[i][2]:
            s += l[i][3]
    ans = max(ans, s)
    k = n
    while t[k] == m and k >= 1:
        k -= 1
    t[k] += 1
    for i in range(k+1, n+1):
        t[i] = t[i-1]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
    s = input()
    if s not in l:
        l.append(s)

print(len(l))

Fixed submission:
from collections import deque
n = int(input())
l = deque()
for i in range(n):
    s = input()
    l.append(s)
print(len(set(l)))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def read():
    N, K = map(int, input().strip().split())
    P = [0] + list(map(int, input().strip().split()))
    C = [0] + list(map(int, input().strip().split()))
    return N, K, P, C


def solve(N, K, P, C):
    max_score = -10**9
    # スコアの累積和
    for i in range(1, N+1):
        # スコアの累積和
        D = [0 for i in range(N+1)]
        # 1周の長さ
        size = 0
        # 1周のスコアの最大値: D[size]
        j = i
        score = 0
        while True:
            size += 1
            j = P[j]
            D[size] = D[size-1] + C[P[j]]
            if i == j:
                break
        round_score = D[size]
        for i in range(1, min(K, size)+1):
            max_score = max(max_score, D[i])
        # 周回してみる
        if D[size] > 0 and K > size:
            base_score = round_score * ((K // size)-1)
            max_score = max(max_score, base_score)
            for i in range(1, size+1):
                max_score = max(max_score, base_score + D[i])
            base_score = round_score * (K // size)
            for i in range(1, min(K%size, size)+1):
                max_score = max(max_score, base_score + D[i])
    return max_score


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Fixed submission:
import sys
input = sys.stdin.readline


def read():
    N, K = map(int, input().strip().split())
    P = [0] + list(map(int, input().strip().split()))
    C = [0] + list(map(int, input().strip().split()))
    return N, K, P, C


def solve(N, K, P, C):
    max_score = -10**9
    # スコアの累積和
    for i in range(1, N+1):
        # スコアの累積和
        D = [0 for i in range(N+1)]
        # 1周の長さ
        size = 0
        # 1周のスコアの最大値: D[size]
        j = i
        score = 0
        while True:
            size += 1
            j = P[j]
            D[size] = D[size-1] + C[P[j]]
            if i == j:
                break
        round_score = D[size]
        for i in range(1, min(K, size)+1):
            max_score = max(max_score, D[i])
        # 周回してみる
        if D[size] > 0 and K > size:
            base_score = round_score * ((K // size)-1)
            max_score = max(max_score, base_score)
            for i in range(1, size+1):
                max_score = max(max_score, base_score + D[i])
            base_score = round_score * (K // size)
            for i in range(1, min(K%size, size)+1):
                max_score = max(max_score, base_score + D[i])
    return max_score


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)
from collections import defaultdict
from bisect import bisect_left


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def sieve(n):
    """
    n以下の素数を昇順に列挙する
    """
    is_prime = [True for i in range(n+1)]
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes


def solve(N, A, AMAX=10**3):
    A.sort()
    primes = sieve(AMAX)
    P = len(primes)
    table = [[False for i in range(P)] for j in range(N)]
    L = [[False for i in range(P)] for j in range(N+1)]
    for i in range(N):
        a = A[i]
        for j in range(P):
            p = primes[j]
            if p * p > a:
                break
            while a % p == 0:
                table[i][j] = True
                a //= p
        if a > 1:
            idx = bisect_left(primes, a)
            table[i][idx] = True
    for i in range(N):
        for j in range(P):
            L[i+1][j] = L[i][j] ^ table[i][j]

    ans = 0
    A.append(A[-1])
    for i in range(N):
        not_div = True
        if A[i] == A[i+1]:
            continue
        for j in range(P):
            if table[i][j] and (i > 0 and L[i-1][j]):
                not_div = False
                break
        if not_div:
            ans += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)
from collections import defaultdict
from bisect import bisect_left


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def prime_factorization(n, primes):
    """
    nの素因数分解を求める
    """
    prime_factors = defaultdict(int)
    if n < 2:
        return prime_factors
    for p in primes:
        if p * p > n:
            break
        while n % p == 0:
            prime_factors[p] += 1
            n //= p
    if n > 1:
        prime_factors[n] = 1
    return prime_factors


def sieve(n):
    """
    n以下の素数を昇順に列挙する
    """
    is_prime = [True for i in range(n+1)]
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes


def solve(N, A):
    A.sort()
    AMAX = max(A)
    ans = 0
    is_div = [True for i in range(AMAX+1)]
    for i in range(N):
        a = A[i]
        if is_div[a]:
            if not ((i > 0 and A[i] == A[i-1]) or (i < N-1 and A[i] == A[i+1])):
                ans += 1
            for j in range(a, AMAX+1, a):
                is_div[j] = False
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def read():
    N, S = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, S, A


def solve(N, S, A, MOD=998244353):
    dp = [0 for j in range(S+1)]
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N, S = map(int, input().strip().split())
    A = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, S, A


@njit
def solve(N, S, A, MOD=998244353):
    dp = np.zeros((S+1), dtype=np.int32)
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def read():
    N, S = map(int, input().strip().split())
    A = list(map(int, input().strip().split()))
    return N, S, A


def solve(N, S, A, MOD=998244353):
    A = list(sorted(A))
    dp = [0 for j in range(S+1)]
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N, S = map(int, input().strip().split())
    A = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, S, A


@njit
def solve(N, S, A, MOD=998244353):
    dp = np.zeros((S+1), dtype=np.int32)
    dp[0] = 1
    for i in range(N):
        for j in range(S, -1, -1):
            v = 2 * dp[j]
            if j - A[i] >= 0:
                v += dp[j-A[i]]
            dp[j] = v % MOD
    return dp[S]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def read():
    N, X, Y = list(map(int, input().split()))
    return N, X, Y

def solve(N, X, Y):
    INF = N + N
    X -= 1
    Y -= 1
    e = np.ones((N, N), dtype=np.int32) * INF
    for i in range(N-1):
        e[i, i+1] = 1
        e[i+1, i] = 1
    e[X, Y] = 1
    e[Y, X] = 1

    c = [0 for i in range(N)]

    for i in range(N):
        for j in range(i+1, N):
            if j <= X or Y <= i:
                e[i, j] = j - i
            else:
                e[i, j] = min(abs(j-i), abs(X-i) + 1 + abs(Y-j))
    
    for i in range(N):
        for j in range(i+1, N):
            if e[i, j] < INF:
                c[e[i, j]] += 1

    for i in range(1, N):
        print(c[i])

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


Fixed submission:
def read():
    N, X, Y = list(map(int, input().split()))
    return N, X, Y

def solve(N, X, Y):
    INF = N + N
    X -= 1
    Y -= 1
    e = [[INF for j in range(N)] for i in range(N)]
    for i in range(N-1):
        e[i][i+1] = 1
        e[i+1][i] = 1
    e[X][Y] = 1
    e[Y][X] = 1

    c = [0 for i in range(N)]

    for i in range(N):
        for j in range(i+1, N):
            if j <= X or Y <= i:
                e[i][j] = j - i
            else:
                e[i][j] = min(abs(j-i), abs(X-i) + 1 + abs(Y-j))
    
    for i in range(N):
        for j in range(i+1, N):
            if e[i][j] < INF:
                c[e[i][j]] += 1

    for i in range(1, N):
        print(c[i])

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)
Buggy python submission (verdict: Runtime Error):
import itertools

def read():
    N = str(input().strip())
    K = int(input().strip())
    return N, K

def nCk(n, k):
    return len(list(itertools.combinations(range(n), k)))

def count_nonzero(L, H, K):
    """
    [0-H][0-9]{L-1}にマッチするL桁の数字から、非ゼロがK個のものを数え上げ
    L: 桁数
    H: 上位1桁目の数字
    K: 範囲内に含まれるゼロでない数字の数
    """
    count = 0
    factor = [1, 9, 81, 729]
    count += nCk(L-1, K) * factor[K]
    for h in range(1, H+1):
        count += nCk(L-1, K-1) * factor[K-1]
    return count



def solve(N, K):
    L = len(N)
    intN = [int(N[i]) for i in range(L)]
    count = 0
    # 最上位桁が[0-(intN[0]-1)]のものをカウント
    if K >= 1:
        count += count_nonzero(L, intN[0]-1, K)
    # 最上位桁がintN[0]、2桁目が[0-(intN[1]-1)]のものをカウント
    if K >= 2:
        count += count_nonzero(L-1, intN[1]-1, K-1)
    # 上位桁がintN[0]intN[1]、3桁目が[0-(intN[2]-1)]のものをカウント
    if K >= 3:
        count += count_nonzero(L-2, intN[2]-1, K-2)
    # 上位桁がintN[0]intN[1]intN[2]のものをカウント (自分自身)
    count += 1
    return count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Fixed submission:
import itertools

def read():
    N = str(input().strip())
    K = int(input().strip())
    return N, K

def solve(N, K):
    L = len(N)
    D = [int(N[i]) for i in range(L)]
    dp0 = [[0 for k in range(K+1)] for i in range(L+1)]
    dp1 = [[0 for k in range(K+1)] for i in range(L+1)]
    
    dp0[0][0] = 1
    for i in range(L):
        for k in range(K+1):
            if k < K and D[i] > 0:
                dp0[i+1][k+1] += dp0[i][k]
                for d in range(1, D[i]):
                    dp1[i+1][k+1] += dp0[i][k]
            if D[i] == 0:
                dp0[i+1][k] += dp0[i][k]
            else:
                dp1[i+1][k] += dp0[i][k]
            if k < K:
                for d in range(1, 10):
                    dp1[i+1][k+1] += dp1[i][k]
            dp1[i+1][k] += dp1[i][k]
    return dp0[L][K] + dp1[L][K]


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))
Buggy python submission (verdict: Runtime Error):
import numpy as np


def read():
    H, N = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return H, N, A, B


def solve(H, N, A, B, INF=10**9):
    BMAX = max(B)
    dp = np.empty(H + BMAX + 1, dtype=np.int32)
    dp[:] = INF
    dp[0] = 0
    for h in range(0, H + BMAX + 1, A[0]):
        dp[h] = dp[h-A[0]] + b[0]
    
    for h in range(0, H + BMAX + 1):
        for i in range(N):
            if h - A[i] >= 0:
                dp[h] = min(dp[h], dp[h - A[i] + B[i])
    return dp[H]


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))


Fixed submission:
from collections import deque


def read():
    H, N = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return H, N, A, B


def solve(H, N, A, B, INF=10**9):
    BMAX = max(B)
    dp = [[INF for i in range(N)] for h in range(H + BMAX + 1)]
    for i in range(0, N):
        dp[0][i] = 0
    for h in range(0, H + BMAX + 1):
        for i in range(N):
            if i == 0:
                if h - A[i] >= 0:
                    dp[h][i] = dp[h - A[i]][i] + B[i]
            else:
                if h - A[i] >= 0:
                    dp[h][i] = min(dp[h][i-1], dp[h - A[i]][i] + B[i])
                else:
                    dp[h][i] = dp[h][i-1]
    min_b = INF
    for h in range(H, H + BMAX + 1):
        for i in range(N):
            min_b = min(min_b, dp[h][i])
    return min_b


if __name__ == "__main__":
    inputs = read()
    print("%s" % solve(*inputs))
Buggy python submission (verdict: Runtime Error):
import math
import collections


def modinv(n, p):
    """
    逆元のmod pを求める
    """
    if n >= p:
        raise ValueError('p must be larger than n')
    return pow(n, p-2, p)


def prime_sieve(n):
    """
    n以下の素数を昇順に列挙する
    エラトステネスの篩 計算量O(Nlog(log(N)))
    """
    is_prime = [True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return [i for i in range(2, n+1) if is_prime[i]]


def prime_factorization(it):
    """
    数値の素因数分解をリストで返すイテレータ
    エラトステネスの篩を応用する 計算量O(A+Nlog(log(N)))
    """
    n = max(it)
    factor = [1 for i in range(n+1)]
    factor[0] = 0
    factor[1] = 1
    for i in range(2, n+1):
        if factor[i] == 1:
            for j in range(i, n+1, i):
                factor[j] = i
    for a in it:
        if a < 2:
            yield list()
        else:
            prime_factors = list()
            while a != factor[a]:
                prime_factors.append(factor[a])
                a //= factor[a]
            prime_factors.append(factor[a])
            yield list(sorted(prime_factors))


def lcm(x, p=-1):
    """
    配列xに対する最小公倍数 LCM(x_1, x_2, ..., x_n) を求める
    p > 0のときはLCM mod pを返す
    """
    max_prime_counts = dict()
    for prime in prime_sieve(max(x)):
        max_prime_counts[prime] = 0
    pfs = prime_factorization(x)
    for pf in pfs:
        prime_count = collections.Counter(pf)
        for prime in prime_count.keys():
            max_prime_counts[prime] = max(max_prime_counts[prime], prime_count[prime])
    lcm_value = 1
    for prime, factor in max_prime_counts.items():
        if p > 0:
            lcm_value *= pow(prime, factor, p)
            lcm_value %= p
        else:
            lcm_value *= pow(prime, factor)
    return lcm_value


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A, MOD=1000000007):
    bsum = 0
    for i in range(N):
        bsum += modinv(A[i], MOD)
        bsum %= MOD
    bsum *= lcm(A, p=MOD)
    bsum %= MOD
    return bsum


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Fixed submission:
def read():
    N, M = list(map(int, input().strip().split()))
    return N, M

def solve(N, M):
    return 'Yes' if N == M else 'No'


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))
Buggy python submission (verdict: Time Limit Exceeded):
import math

def read():
    X = int(input().strip())
    return X,


def solve(X):
    A = [100 ,101, 102, 103, 104, 105]
    NA = 6
    dp = [[False for j in range(X+1)] for i in range(NA+1)]
    for i in range(NA+1):
        dp[i][0] = True
    for i in range(NA):
        for x in range(0, X+1):
            j = 0
            while x - j * A[i] >= 0:
                if dp[i][x - j * A[i]]:
                    dp[i+1][x] = True
                j += 1
    return 1 if dp[NA][X] else 0
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Fixed submission:
import math

def read():
    X = int(input().strip())
    return X,


def solve(X):
    if X >= 2000:
        return 1
    A = [100 ,101, 102, 103, 104, 105]
    NA = 6
    dp = [[False for j in range(X+1)] for i in range(NA+1)]
    for i in range(NA+1):
        dp[i][0] = True
    for i in range(NA):
        for x in range(0, X+1):
            j = 0
            while x - j * A[i] >= 0:
                if dp[i][x - j * A[i]]:
                    dp[i+1][x] = True
                j += 1
    return 1 if dp[NA][X] else 0
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S

def dig(S, T, N):
    for i in range(N):
            if S[i] == T[0]:
                for j in range(i+1, N):
                    if S[j] == T[1]:
                        for k in range(j+1, N):
                            if S[k] == T[2]:
                                return True
    return False


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for p in range(1000):
        T = '{:03d}'.format(p)
        count += 1 if dig(S, T, N) else 0
        
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)


Fixed submission:
import bisect
import collections

def read():
    N = int(input().strip())
    S = str(input().strip())
    return N, S


def solve(N, S):
    d = [collections.deque() for i in range(10)]
    count = 0
    for i in range(N):
        s = int(S[i])
        d[s].append(i)
    for p in range(1000):
        T = '{:03d}'.format(p)
        p0 = int(T[0])
        p1 = int(T[1])
        p2 = int(T[2])
        k0 = 0
        if len(d[p0]) > k0:
            idx0 = d[p0][k0]
            k1 = bisect.bisect_left(d[p1], idx0+1)
            if len(d[p1]) > k1:
                idx1 = d[p1][k1]
                k2 = bisect.bisect_left(d[p2], idx1+1)
                if len(d[p2]) > k2:
                    idx2 = d[p2][k2]
                    if  S[idx0] + S[idx1] + S[idx2] == T:
                        count += 1
    return count
    
if __name__ == '__main__':
    inputs = read()
    output = solve(*inputs)
    print("%d" % output)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import bisect

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    x = 0
    t = [0 for _ in range(N)]

    t[0] = 0
    t[1] = 0
    t[2] = 1 if L[2] < L[0] + L[1] else 0
    for i in range(3, N):
        t[i] = t[i-1]
        for a, b in itertools.combinations(L[:i], 2):
            t[i] += (L[i] < a + b)
    return t[-1]

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Fixed submission:
import itertools
import bisect

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    x = 0
    t = [0 for _ in range(N+1)]
    for i in range(N):
        for j in range(i+1, N):
            k = bisect.bisect_left(L, L[i] + L[j])
            if j < k:
                x += (k - j - 1)
    return x

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    count = 0
    for a, b, c in itertools.combinations(L, 3):
        if c < a + b:
            count += 1
    return count

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Fixed submission:
import itertools
import bisect

def read():
    N = int(input().strip())
    L = list(map(int, input().strip().split()))
    return N, L

def solve(N, L):
    L.sort()
    x = 0
    t = [0 for _ in range(N+1)]
    for i in range(N):
        for j in range(i+1, N):
            k = bisect.bisect_left(L, L[i] + L[j])
            if j < k:
                x += (k - j - 1)
    return x

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))