Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    n=ii()
    a=ll()
    i=n-1;
    while(i):
        print(a[i],end=" ")
        i-=2
    for i in range(n%2,n,2):
        print(a[i],end=" ")

Fixed submission:
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    n=ii()
    a=ll()
    i=n-1;
    while(i>-1):
        print(a[i],end=" ")
        i-=2
    for i in range(n%2,n,2):
        print(a[i],end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    ans = [0 for _ in range(n)]
    for x in range(1, n):
        for y in range(x, n):
            for z in range(y, n):
                tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
                log(tmp)
                if tmp > n:
                    break
                if x == y == z:
                    ans[tmp - 1] = 1
                elif x == y or y == z or z == x:
                    ans[tmp - 1] = 3
                else:
                    ans[tmp - 1] = 6
    for v in ans:
        print(v)


if __name__ == '__main__':
    main()


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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    ans = [0 for _ in range(n)]
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
                if tmp > n:
                    break
                # if x == y == z:
                #     ans[tmp - 1] = 1
                # elif x == y or y == z or z == x:
                #     ans[tmp - 1] = 3
                # else:
                #     ans[tmp - 1] = 6
                ans[tmp - 1] += 1
    for v in ans:
        print(v)


if __name__ == '__main__':
    main()

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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    ans = [0 for _ in range(n)]
    for x in range(1, n):
        for y in range(x, n):
            for z in range(y, n):
                tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
                log(tmp)
                if tmp > n:
                    break
                if x == y == z:
                    ans[tmp - 1] = 1
                elif x == y or y == z or z == x:
                    ans[tmp - 1] = 3
                else:
                    ans[tmp - 1] = 6
    for v in ans:
        print(v)


if __name__ == '__main__':
    main()


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


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input().rstrip())
    ans = [0 for _ in range(n)]
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                tmp = pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + z * x
                if tmp > n:
                    break
                # if x == y == z:
                #     ans[tmp - 1] = 1
                # elif x == y or y == z or z == x:
                #     ans[tmp - 1] = 3
                # else:
                #     ans[tmp - 1] = 6
                ans[tmp - 1] += 1
    for v in ans:
        print(v)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
from math import factorial
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    x, y = map(int, input().rstrip().split())
    # 全部 i + 1, j + 2が最初だったとする
    # a + 2b = x, 2a + b = y
    # =>
    # a = x - 2b
    # b = y - 2a
    # =>
    # b = y - 2x + 4b
    # 3b = 2x - y
    # b = (2x - y) / 3
    # a = (2y - x) / 3
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        return
    a = (2 * x - y) // 3
    b = (2 * y - x) // 3
    # (a + b) C min(a, b)
    # => (a + b)! / (min(a, b) ! * (a + b - min(a, b)) !
    mod = 10**9 + 7
    ans = ((factorial(a + b) % mod) * pow(factorial(min(a, b)), mod - 2, mod)
           * pow(factorial(a + b - min(a, b)), mod - 2, mod)) % mod
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from math import factorial
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    x, y = map(int, input().rstrip().split())
    # 全部 i + 1, j + 2が最初だったとする
    # a + 2b = x, 2a + b = y
    # =>
    # a = x - 2b
    # b = y - 2a
    # =>
    # b = y - 2x + 4b
    # 3b = 2x - y
    # b = (2x - y) / 3
    # a = (2y - x) / 3
    if (2 * x - y) % 3 != 0 or (2 * y - x) % 3 != 0:
        print(0)
        return
    a = (2 * x - y) // 3
    b = (2 * y - x) // 3
    if a < 0 or b < 0:
        print(0)
        return
    # (a + b) C min(a, b)
    # => (a + b)! / (min(a, b) ! * (a + b - min(a, b)) !
    mod = 10**9 + 7
    ans = (factorial_mod(a + b, mod) * pow(factorial_mod(min(a, b), mod), mod - 2, mod)
           * pow(factorial_mod(a + b - min(a, b), mod), mod - 2, mod)) % mod
    print(ans)


def factorial_mod(a, mod):
    ans = 1
    for v in range(1, a + 1):
        ans *= v
        ans %= mod
    return ans


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
chr = input("")
num = len(s)

if chr[num-1] == "s":
  print(chr + "es")
else:
  print(chr + "s")
  
  

Fixed submission:
chr = input("")
num = len(chr)

if chr[num-1] == "s":
  print(chr + "es")
else:
  print(chr + "s")
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
max = a*c

if max > bd:
  print(max)
else:
  print(bd)


Fixed submission:
a,b,c,d = map(int,input().split())
val = [None]*4
val = [a*c,a*d,b*c,b*d]

top = a*c

for i in range(1,4):
    if top < val[i]:
        top = val[i]

print(top)
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input(""))
val = list(map(int,input().split()))
val_sum = 0
mod = 10**9 + 7

for i in range(num):
    for j in range(i+1,num):
        val_sum = val_sum + val[i]*val[j]
        
print(val_sum%mod)

Fixed submission:
num = int(input(""))
val = list(map(int,input().split()))
val_sum = sum(val)
ans = 0
mod = 10**9 + 7

for i in range(num):
    val_sum = val_sum - val[i]
    ans     = val[i] * val_sum + ans
        
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        if b in unique_val:
            unique_val[b] = unique_val[b] + unique_val.pop(a)
        else:
            unique_val[b] = unique_val.pop(a)
        print(unique_val)
        
    print(sum_val)
    q -= 1

print(sum_val)

Fixed submission:
x = int(input())
ar = list(map(int, input().split()))
sum_val = sum(ar)

unique_val = dict()

for i in ar:
    if i in unique_val:
        unique_val[i] += 1
    else:
        unique_val[i] = 1

q = int(input())
while(q):
    a, b = map(int, input().split())
    if a in unique_val:
        value = (b-a)*unique_val[a]
        sum_val += value
        if b in unique_val:
            unique_val[b] = unique_val[b] + unique_val.pop(a)
        else:
            unique_val[b] = unique_val.pop(a)
        #print(unique_val)
        
    print(sum_val)
    q -= 1
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
# uf = UnionFind(6)
# print(uf.parents)
# # [-1, -1, -1, -1, -1, -1]

# print(uf)

# print(uf.group_count())

n, m = map(int, input().split())

uf = UnionFind(n)

# print(n, m)
for _ in range(m):
    a, b = map(int, input().split())
    # print(a, b)
    uf.union(a, b)
    
# print(uf.group_count())
print(n - uf.group_count())

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
# uf = UnionFind(6)
# print(uf.parents)
# # [-1, -1, -1, -1, -1, -1]

# print(uf)

# print(uf.group_count())

n, m = map(int, input().split())

uf = UnionFind(n)

# print(n, m)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    # print(a, b)
    uf.union(a, b)
    
# print(uf.group_count())
print(uf.group_count() - 1)
Buggy python submission (verdict: Runtime Error):
import sympy

n = int(input())

sum_v = 0
for i in range(1, n):
    v = (n - 1) // i
    sum_v += v

print(sum_v)

Fixed submission:
n = int(input())

sum_v = 0
for i in range(1, n):
    v = (n - 1) // i
    sum_v += v

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

n = int(input())
a_l = list(map(int, input().split()))


ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        v1 = a_l[i]
        v2 = a_l[j]
        
        ans += v1 * v2
        ans = ans % (10 ** 9 + 7)

print(ans)

Fixed submission:
n = int(input())
a_list = input().split()

a_list_reverse = a_list[::-1]
# print(a_list_reverse)

rusekiwa = [0] * (len(a_list_reverse) - 1)
sum_v = 0
for i in range(len(a_list_reverse) - 1):
    sum_v += int(a_list_reverse[i])
    rusekiwa[i] = sum_v
# print(rusekiwa)

ans = 0
for i in range(len(a_list) - 1):
    v = int(a_list[i]) * rusekiwa[-1 - (i)]
    # print(v)
    # v = v % (10 ** 9 + 7)
    ans += v
    ans = ans % (10 ** 9 + 7)

# ans = ans % (10 ** 9 + 7)
print(ans)

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

n = int(input())
a_l = map(int, input().split())


ans = 0
for v1, v2 in itertools.combinations(a_l, 2):
    ans += v1 * v2
    ans = ans % (10 ** 9 + 7)
    
print(ans)

Fixed submission:
n = int(input())
a_list = input().split()

a_list_reverse = a_list[::-1]
# print(a_list_reverse)

rusekiwa = [0] * (len(a_list_reverse) - 1)
sum_v = 0
for i in range(len(a_list_reverse) - 1):
    sum_v += int(a_list_reverse[i])
    rusekiwa[i] = sum_v
# print(rusekiwa)

ans = 0
for i in range(len(a_list) - 1):
    v = int(a_list[i]) * rusekiwa[-1 - (i)]
    # print(v)
    # v = v % (10 ** 9 + 7)
    ans += v
    ans = ans % (10 ** 9 + 7)

# ans = ans % (10 ** 9 + 7)
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np

n, m ,x = map(int, input().split())

# l = list(range(0, n))
# print(l)

l = []
for i in range(n):
    l.append(list(map(int, input().split())))
    
# print(l)

value_list = []
min_value = -1
for v in itertools.permutations(l):
    lll = np.array([0] * (m + 1))
    for ll in v:
        # print(lll)
        # print(np.array(ll))
        # print(lll + np.array(ll))
        lll = lll + np.array(ll)
        # print(min(lll[1:]))
        if min(lll[1:]) >= x:
            # print(lll[0])
            value_list.append(lll[0])
            break

print(min(value_list))

Fixed submission:
import itertools
import numpy as np

n, m ,x = map(int, input().split())

# l = list(range(0, n))
# print(l)

ca_list = []
for _ in range(n):
    ca_list.append(list(map(int, input().split())))

l = [True, False]
    
# print(l)

value_list = []
for is_buy_list in itertools.product(l, repeat=n):
    sum_l = np.array([0] * (m + 1))
    for i in range(n):
        # print(ll[i])
        if is_buy_list[i]:
            sum_l += np.array(ca_list[i])
            # print(sum_l)

    # print(min(sum_l[1:]))
    if min(sum_l[1:]) >= x:
        # print(sum_l[0])
        value_list.append(sum_l[0])
# print(min(value_list))

if len(value_list) > 0:
    print(min(value_list))
else:
    print(-1)

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

n, m ,x = map(int, input().split())

# l = list(range(0, n))
# print(l)

l = []
for i in range(n):
    l.append(list(map(int, input().split())))
    
# print(l)

min_value = -1
for v in itertools.permutations(l):
    lll = [0] * (m + 1)
    for ll in v:
        # print(ll)
        for i in range(len(ll)):
            lll[i] += ll[i]
        # print(lll)
        
        flag = True
        for i in range(len(lll)):
            if i == 0:
                continue
            if lll[i] < x:
                flag = False
        if flag == True:
            # print(lll)
            
            if min_value == -1:
                min_value = lll[0]
            elif min_value > lll[0]:
                min_value = lll[0]
                
            break
        
print(min_value)

Fixed submission:
import itertools
import numpy as np

n, m ,x = map(int, input().split())

# l = list(range(0, n))
# print(l)

ca_list = []
for _ in range(n):
    ca_list.append(list(map(int, input().split())))

l = [True, False]
    
# print(l)

value_list = []
for is_buy_list in itertools.product(l, repeat=n):
    sum_l = np.array([0] * (m + 1))
    for i in range(n):
        # print(ll[i])
        if is_buy_list[i]:
            sum_l += np.array(ca_list[i])
            # print(sum_l)

    # print(min(sum_l[1:]))
    if min(sum_l[1:]) >= x:
        # print(sum_l[0])
        value_list.append(sum_l[0])
# print(min(value_list))

if len(value_list) > 0:
    print(min(value_list))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = []
for _ in range(n):
    s = input()
    if not s in l:
        l.append(s)
        
print(len(l))

Fixed submission:
n = int(input())

d = {}
for _ in range(n):
    s = input()
    if not s in d:
        d[s] = 0
        
print(len(d.keys()))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

n = int(input())
a = list(map(int, input().split()))

import collections
c = collections.Counter(a)

# print(n)
# print(a)

l = [0] * (n + 1)
ll  = [0] * (n + 1)
# for i in range(n):
#     l[a[i]] += 1
#     ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
for key, value in c.items():
    l[key] = value
    ll[key] = int((value * (value - 1)) / 2)
    
# print(l)
# print(ll)
    
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(sum(ll) - (vv - vvv))

Fixed submission:
# coding: utf-8
# Your code here!

n = int(input())
a = list(map(int, input().split()))

import collections
c = collections.Counter(a)

# print(n)
# print(a)

# l = [0] * (n + 1)
# ll  = [0] * (n + 1)

l = {}
ll = {}

# for i in range(n):
#     l[a[i]] += 1
#     ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
# print(c)
    
for key, value in c.items():
    l[key] = value
    ll[key] = int((value * (value - 1)) / 2)
    
# print(l)
# print(ll)
    
# print(l)
# print(ll)

c_sum = sum(ll.values())
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(c_sum - (vv - vvv))

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

n = int(input())
a = list(map(int, input().split()))

# print(n)
# print(a)

l = [0] * (n + 1)
ll  = [0] * (n + 1)
for i in range(n):
    l[a[i]] += 1
    ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
# print(l)
# print(ll)
    
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(sum(ll) - (vv - vvv))

Fixed submission:
# coding: utf-8
# Your code here!

n = int(input())
a = list(map(int, input().split()))

import collections
c = collections.Counter(a)

# print(n)
# print(a)

# l = [0] * (n + 1)
# ll  = [0] * (n + 1)

l = {}
ll = {}

# for i in range(n):
#     l[a[i]] += 1
#     ll[a[i]] = int((l[a[i]] * (l[a[i]] - 1)) / 2)
    
# print(c)
    
for key, value in c.items():
    l[key] = value
    ll[key] = int((value * (value - 1)) / 2)
    
# print(l)
# print(ll)
    
# print(l)
# print(ll)

c_sum = sum(ll.values())
for i in range(n):
    v = l[a[i]]
    vv = ll[a[i]]
    vvv = int(((v - 1) * (v - 2)) / 2)
    # print(vvv)
    print(c_sum - (vv - vvv))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

# print(H)
H = sorted(H, reverse=True)
# print(H)

for _ in range(K):
    if len(H) == 0:
        break
    H.pop(0)

# print(H)

result = 0
for h in H:
    result += h
    
print(result)

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

# print(H)
# print(H)

if N <= K:
    print(0)
else:
    H = sorted(H, reverse=True)
    # for _ in range(K):
    #     if len(H) == 0:
    #         break
    #     H.pop(0)
    
    # print(H)
    
    result = 0
    for i in range(K, N):
        result += H[i]

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

n = int(input())
s = input()

# print(f"{n} {s}")

l = list(s)
# print(l)


set1 = set()
for v1, v2, v3 in itertools.combinations(l, 3):
    # print(f"{v1} {v2} {v3}")
    set1.add(int(v1 + v2 + v3))
    
print(len(set1))

Fixed submission:
import itertools

n = int(input())
s = input()

s_l = list(map(int, s))
# print(s_l)

l = [i for i in range(10)]
ans = 0
for v1, v2, v3 in itertools.product(l, repeat=3):
    # print(f"{v1} {v2} {v3}")

    # print(v1) 
    if not v1 in s_l:
        continue
    else:
        index1 = s_l.index(v1)
    
    # print(f"index1 : {index1}")
    # print(s_l[index1 + 1:])
    
    s_l_1 = s_l[index1 + 1:]
        
    if not v2 in s_l_1:
        continue
    else:
        index2 = s_l_1.index(v2)
        
    s_l_2 = s_l_1[index2 + 1:]
        

    if not v3 in s_l_2:
        continue
    

    # print(f"{v1} {v2} {v3}")
    ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

# print(N)

ans = N
i = 1
while i < N:
    # print(i)
    
    div, mod = divmod(N, i)
    
    if mod == 0:
        # print(i)
        # print(div)
        # print(mod)
        
        ans = min(ans, ((i - 1) + (div - 1)))
    
    i += 1
    
print(ans)

Fixed submission:
N = int(input())

# print(N)

ans = N
i = 1
while i * i <= N:
    # print(i)
    
    div, mod = divmod(N, i)
    
    if mod == 0:
        # print(i)
        # print(div)
        # print(mod)
        
        ans = min(ans, ((i - 1) + (div - 1)))
    
    i += 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!

N = int(input())
L = list(map(int, input().split()))

# print(N)
# print(L)

L_sorted = sorted(L)
# print(L_sorted)

count = 0
for i in range(0, N - 2):
    # print(i)
    for j in range(i + 1, N - 1):
        # print(j)
        for k in range(j + 1, N):
            a = L_sorted[i]
            b = L_sorted[j]
            c = L_sorted[k]
            
            if a + b <= c:
                break
            # print('{}, {}, {}'.format(a, b, c))
            count += 1
        
print(count)        

Fixed submission:
# coding: utf-8
# Your code here!

import bisect

N = int(input())
L = list(map(int, input().split()))

# print(N)
# print(L)

L_sorted = sorted(L)
# print(L_sorted)

count = 0
for i in range(0, N - 2):
    # print(i)
    for j in range(i + 1, N - 1):
        a = L_sorted[i]
        b = L_sorted[j]
        # print(j)
        # for k in range(j + 1, N):
        #     a = L_sorted[i]
        #     b = L_sorted[j]
        #     c = L_sorted[k]
            
        #     if a + b <= c:
        #         break
        #     # print('{}, {}, {}'.format(a, b, c))
        #     count += 1
        
        # print('{}, {},'.format(a, b))
        index = bisect.bisect_left(L_sorted, a + b, i + 1, N)
        # print(index)
        # print((index - 1) - j)
        count += ((index - 1) - j)
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))

# print(N)
# print(L)

# print(range(N))
# print(range(1, N))
# print(range(2, N))

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if not(L[i] < L[j] + L[k]):
                continue
            if not(L[j] < L[i] + L[k]):
                continue
            if not(L[k] < L[i] + L[j]):
                continue
            # print('{}, {}, {}'.format(i, j, k))
            count += 1
            
print(count)

Fixed submission:
# coding: utf-8
# Your code here!

import bisect

N = int(input())
L = list(map(int, input().split()))

# print(N)
# print(L)

L_sorted = sorted(L)
# print(L_sorted)

count = 0
for i in range(0, N - 2):
    # print(i)
    for j in range(i + 1, N - 1):
        a = L_sorted[i]
        b = L_sorted[j]
        # print(j)
        # for k in range(j + 1, N):
        #     a = L_sorted[i]
        #     b = L_sorted[j]
        #     c = L_sorted[k]
            
        #     if a + b <= c:
        #         break
        #     # print('{}, {}, {}'.format(a, b, c))
        #     count += 1
        
        # print('{}, {},'.format(a, b))
        index = bisect.bisect_left(L_sorted, a + b, i + 1, N)
        # print(index)
        # print((index - 1) - j)
        count += ((index - 1) - j)
        
print(count)