Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
mod = 10**9+7
x = 10**10
count = 0
c=[]
for i in range(n):
    if a[i]!=x:
        if i != 0:
            c.append([x,count])
        x=a[i]
        count = 1
    else:
        count += 1
    
    if i==n-1:
        c.append([x,count])

fact = [1]*(n+1)
inv_fact = [1]*(n+1)
for i in range(n):
    fact[i+1] = fact[i]*(i+1)
    fact[i+1] %= mod
for i in range(n,0,-1):
    if i == n:
        inv_fact[i] = pow(fact[i],mod-2,mod)
    else:
        inv_fact[i] = inv_fact[i+1]*(i+1)
        inv_fact[i] %= mod
        
sum_min = 0
sum_max = 0
b = 0
for i,j in c:
    if n-b < k:
        break
    b += j
    for l in range(max(1,k-n+b),min(k,j)+1):
        d = i*fact[j]*inv_fact[j-l]*inv_fact[l]%mod
        d *= fact[k-j]*fact[n-b]*inv_fact[n-b-k+l]*inv_fact[k-l]%mod
        sum_min += d
        sum_min %= mod
b = 0
for i,j in c[::-1]:
    if n-b < k:
        break
    b += j
    for l in range(max(1,k-n+b),min(k,j)+1):
        d = i*fact[j]*inv_fact[j-l]*inv_fact[l]%mod
        d *= fact[k-j]*fact[n-b]*inv_fact[n-b-k+l]*inv_fact[k-l]%mod
        sum_max += d
        sum_max %= mod
        
print((sum_max-sum_min)%mod)

Fixed submission:
import math
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
point = []
r = 0
for i in range(n-1):
    x1,y1=xy[i]
    for j in range(i+1,n):
        x2,y2=xy[j]
        d = ((x1-x2)/2)**2+((y1-y2)/2)**2
        if r**2 > d:
            if y1-y2 != 0:
                a = -(x1-x2)/(y1-y2)
                x = math.sqrt((r**2-d)/(a**2+1))//10**(-6)*10**(-6)
                point.append([(x1+x2)/2+x,(y1+y2)/2+a*x])
                point.append([(x1+x2)/2-x,(y1+y2)/2-a*x])
            else:
                x = math.sqrt(r**2-d)//1//10**(-6)*10**(-6)
                point.append([(x1+x2)/2,(y1+y2)/2+x])
                point.append([(x1+x2)/2,(y1+y2)/2-x])
        elif r**2 == d:
            point.append([(x1+x2)/2,(y1+y2)/2])

r_o = 800
r_i = 0
while r_o-r_i > 10**(-8):
    judge = 0
    while point:
        x,y = point.pop()
        c = 0
        for i,j in xy:
            if (x-i)**2+(y-j)**2 > r**2:
                c = 1
                break
        if c == 0:
            judge = 1
            break
            
    if judge == 1:
        r_o = r
    else:
        r_i = r
    r = (r_o+r_i)/2
    point = []
    for i in range(n-1):
        x1,y1=xy[i]
        for j in range(i+1,n):
            x2,y2=xy[j]
            d = ((x1-x2)/2)**2+((y1-y2)/2)**2
            if r**2 > d:
                if y1-y2 != 0:
                    a = -(x1-x2)/(y1-y2)
                    x = math.sqrt((r**2-d)/(a**2+1))//10**(-6)*10**(-6)
                    point.append([(x1+x2)/2+x,(y1+y2)/2+a*x])
                    point.append([(x1+x2)/2-x,(y1+y2)/2-a*x])
                else:
                    x = math.sqrt(r**2-d)//10**(-6)*10**(-6)
                    point.append([(x1+x2)/2,(y1+y2)/2+x])
                    point.append([(x1+x2)/2,(y1+y2)/2-x])
            elif r**2 == d:
                point.append([(x1+x2)/2,(y1+y2)/2])
    
print(r)
Buggy python submission (verdict: Runtime Error):
A, B, C, K = input().split()
# A=1 B=0 C=-1 K
ans = 0

for a in range(int(K)):
    if int(A) == int(K):
        ans = A
        break
    elif int(A) <= int(K):
        ans = A

    elif int(B) <= int(K):
        ans = A

    elif int(C) <= int(K):
        ans = (-1 * C)
        break
if int(A) == int(K):
    print(K)
else:
    print(int(A) + int(B) - int(C))

Fixed submission:
S = input()
T = input()

if S == T[0:-1] and len(S) + 1 == len(T):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import re

S = input()
P = re.compile()

if P.match(S):
    print("Yes")
else:
    print("No")

Fixed submission:
import re

S = input()
A = re.compile(r'^([^L][^R])*[^L]?$')

if A.match(S):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
list1 = [int(a) for a in input().split()]
list1_0 = list1[0] #AB
list1_1 = list1[1] #BC
list1_2 = list1[2] #CA

if (list1_0 * list1_1 // 2) > 1:
    print(list1_0 * list1_1 // 2)
else:
    print(list1)

Fixed submission:
list1 = [int(a) for a in input().split()]
list1_0 = list1[0] #A
list1_1 = list1[1] #B

if (list1_1 % list1_0) == 0:
    print(list1_0 + list1_1)
else:
    print(list1_1 - list1_0)
Buggy python submission (verdict: Runtime Error):
# Rows and columns(行と列)
rac_count = 3
rac_all = [input().split() for a in range(rac_count)]

rac_0 = rac_all[0]
rac_1 = rac_all[1]
rac_2 = rac_all[2]

rac_0.extend(rac_1)
rac_0.extend(rac_2)

print(str(rac_0[0] + rac_0[4] + rac_0[8]))

Fixed submission:
# Rows and columns(行と列)
rac_count = 3
rac_all = [input() for a in range(rac_count)]

rac_0 = rac_all[0]
rac_1 = rac_all[1]
rac_2 = rac_all[2]

rac_0_0 = list(rac_0)
rac_1_1 = list(rac_1)
rac_2_2 = list(rac_2)

rac_0_0.extend(rac_1_1)
rac_0_0.extend(rac_2_2)

print(str(rac_0_0[0] + rac_0_0[4] + rac_0_0[8]))

Buggy python submission (verdict: Runtime Error):
# Rows and columns(行と列)
rac_count = 3
rac_all = [input().split() for a in range(rac_count)]

rac_0 = rac_all[0]
rac_1 = rac_all[1]
rac_2 = rac_all[2]

rac_0.extend(rac_1)
rac_0.extend(rac_2)

print(str(rac_0[0] + rac_0[4] + rac_0[8]))

Fixed submission:
# Rows and columns(行と列)
rac_count = 3
rac_all = [input() for a in range(rac_count)]

rac_0 = rac_all[0]
rac_1 = rac_all[1]
rac_2 = rac_all[2]

rac_0_0 = list(rac_0)
rac_1_1 = list(rac_1)
rac_2_2 = list(rac_2)

rac_0_0.extend(rac_1_1)
rac_0_0.extend(rac_2_2)

print(str(rac_0_0[0] + rac_0_0[4] + rac_0_0[8]))
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())

for i in range(100): # 繰り返し処理したい、とりあえず100回以上の繰り返しはないから100回繰り返す
    c -= b # 青木くんの体力cから高橋くんの攻撃力bぶん引く
#    print('c', c) # 残り体力確認用
    if c <= 0>: # 青木くん体力が0以下になったら
        print('Yes') # 高橋くんの勝ちなのでYes
        break # 体力が0になったら繰り返しも終了

    a -= d # 次に高橋くんの体力aから青木くんの攻撃力dを引く
 #   print('a',a) # 残り体力確認用
    if a < 1: # 高橋くん体力が0以下になったら
        print('No') # 青木くん勝利でNo
        break # 体力が0になったら繰り返しも終了
# どちらの体力も残ってたら次の繰り返し

Fixed submission:
a,b,c,d = map(int, input().split())

for i in range(100):
    c -= b
#    print('c', c)
    if c < 1:
        print('Yes')
        break

    a -= d
 #   print('a',a)
    if a < 1:
        print('No')
        break
Buggy python submission (verdict: Runtime Error):
weather = input()

if weather == 'Sunny':
    print 'Cloudy'

if weather == 'Cloudy':
    print 'Rainy'
    
if weather == 'Rainy':
    print 'Sunny'

Fixed submission:
weather = input()

if weather == 'Sunny':
    print('Cloudy')

if weather == 'Cloudy':
    print('Rainy')

if weather == 'Rainy':
    print('Sunny')

Buggy python submission (verdict: Runtime Error):
weather = input()

if (weather == 'Sunny'):
    print 'Cloudy'

if (weather == 'Cloudy'):
    print 'Rainy'
    
if (weather == 'Rainy'):
    print 'Sunny'

Fixed submission:
weather = input()

if weather == 'Sunny':
    print('Cloudy')

if weather == 'Cloudy':
    print('Rainy')

if weather == 'Rainy':
    print('Sunny')

Buggy python submission (verdict: Runtime Error):
weather = input()

if (weather == 'Cloudy'):
    print 'Rainy'

if (weather == 'Cloudy'):
    print 'Rainy'
    
if (weather == 'Cloudy'):
    print 'Rainy'

Fixed submission:
weather = input()

if weather == 'Sunny':
    print('Cloudy')

if weather == 'Cloudy':
    print('Rainy')

if weather == 'Rainy':
    print('Sunny')

Buggy python submission (verdict: Runtime Error):
weather = imput()

if (weather == 'Sunny')
    print 'Cloudy'
if (weather == 'Cloudy')
    print 'Rainy'
if (weather == 'Rainy')
    print 'Sunny'

Fixed submission:
weather = input()

if weather == 'Sunny':
    print('Cloudy')

if weather == 'Cloudy':
    print('Rainy')

if weather == 'Rainy':
    print('Sunny')
Buggy python submission (verdict: Runtime Error):
data = input()

dataa,datab,datac,datad = data.split(' ')

dataa = int(dataa)
datab = int(datab)
datac = int(datac)
datad = int(datad)

length1 = dataa - datab
length2 = datab - datac
length11 = abs(length1) + abs(length2)
length3 = dataa - datac

if abs(length1) <>= datad:
    print('Yes')
elif abs(length2) <= datad:
    print('Yes')
elif abs(length11) <= datad:
    print('Yes')
else:
    print('No')

Fixed submission:
data = input()
data1,data2,data3,data4 = data.split()
data1 = int(data1)
data2 = int(data2)
data3 = int(data3)
data4 = int(data4)


if abs(data1 - data3) <= data4:
    print('Yes')
elif abs(data1 - data2) <= data4 and abs(data2 - data3) <= data4:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

flg = 1
for i in range(q):
    t = input()
    if t == "1":
        if flg:
            flg = 0
        else:
            flg = 1
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]
            if flg:
                s = c + s
            else:
                s += c
        elif f == "2":
            c = t[4]
            if flg:
                s += c
            else:
                s = c + s

if flg:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

flg = 1
for _ in range(q):
    t = input()
    if t == "1":
        flg = not flg
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]
            if flg:
                s.appendleft(c)
            else:
                s.append(c)
        elif f == "2":
            c = t[4]
            if flg:
                s.append(c)
            else:
                s.appendleft(c)

if flg:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    t = input()
    if t == "1":
        s = s[::-1]
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]            
            s = c + s
        elif f == "2":
            c = t[4]
            s += c

print(s)


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())

flg = 1
for _ in range(q):
    t = input()
    if t == "1":
        flg = not flg
    elif t[0] == "2":
        f = t[2]
        if f == "1":
            c = t[4]
            if flg:
                s.appendleft(c)
            else:
                s.append(c)
        elif f == "2":
            c = t[4]
            if flg:
                s.append(c)
            else:
                s.appendleft(c)

if flg:
    print(''.join(s))
else:
    print(''.join(reversed(s)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

l = list(range(1, 200001))
count = 0
for i in range(n):
    if a[i] == l[0]:
        l.remove(l[0])
        count += 1

if count == 0:
    print(-1)
else:
    print(n - count)


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

cnt = 0
for a in A:
	if a == cnt + 1:
		cnt += 1

if cnt == 0:
	print(-1)
else:
	print(n - cnt)

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

l = list(range(1, 200001))
count = 0
for i in range(n):
    if a[i] == l[0]:
        l.remove(l[0])
        count += 1

if count == 0:
    print(-1)
else:
    print(n - count)


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

cnt = 0
for a in A:
	if a == cnt + 1:
		cnt += 1

if cnt == 0:
	print(-1)
else:
	print(n - cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

n = len(s) + 1
ans = 0
# for i in range(n - 1):
i = 0
while i < n - 1:
    uCount = 0 # '<'
    dCount = 0 # '>'
    while s[i] == '<' and i < n - 1:
        uCount += 1
        if i == n - 2:
            break
        i += 1
    while s[i] == '>' and i < n - 1:
        dCount += 1
        if i == n - 2:
            i += 1
            break
        i += 1
    if uCount > dCount:
        ans += sum(range(0, uCount + 1))
        ans += sum(range(0, dCount))
    elif uCount <= dCount:
        ans += sum(range(0, dCount + 1))
        ans += sum(range(0, uCount))
    # if i == n - 2 and s[i] == '<':
    #     ans += 1
    #     i += 1
    # elif i == n - 2 and s[i] == '>':
    #     i += 1
print(ans)


Fixed submission:
s = input()

n = len(s) + 1
a = [0] * n
for i in range(n - 1):
    if s[i] == '<':
        a[i + 1] = a[i] + 1

for i in range(n - 2, - 1, -1):
    if s[i] == '>':
        if a[i] <= a[i + 1] + 1:
            a[i] = a[i + 1] + 1

print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))

Fixed submission:
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n))]

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))

Fixed submission:
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for _ in range(n))
a.sort()

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))


Fixed submission:
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for _ in range(n))

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))


Fixed submission:
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for _ in range(n))

paper = []
for i in a:
    if i in paper:
        paper.remove(i)
    else:
        paper.append(i)
print(len(paper))


Fixed submission:
from collections import Counter

n = int(input())
a = [int(input()) for _ in range(n)]

a_c = Counter(a).most_common() 
ans = 0
for i in a_c: 
    if i[1] % 2 == 1:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

sum = a[0]
count = 0

if a[0] == 0:
    if a[1] > 0:
        sum -= 1
        count += 1
    elif a[1] < 0:
        sum += 1
        count += 1

for i in range(1, n):
    tmp = sum
    sum += a[i]
    while tmp > 0 and sum >= 0:
        sum -= 1
        count += 1
    while tmp < 0 and sum <= 0:
        sum += 1
        count += 1

print(count)


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

# +, -, +, -, ...
sum = 0
count = 0
for i in range(n):
    sum += a[i]
    if i % 2 == 0:
        if sum <= 0:
            count += abs(sum) + 1
            sum = 1
    else:
        if sum >= 0:
            count += abs(sum) + 1
            sum = -1

# -, +, -, +, ...
sum2 = 0
count2 = 0
for i in range(n):
    sum2 += a[i]
    if i % 2 == 0:
        if sum2 >= 0:
            count2 += abs(sum2) + 1
            sum2 = -1
    else:
        if sum2 <= 0:
            count2 += abs(sum2) + 1
            sum2 = 1

print(min(count, count2))
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())

ans = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans += math.gcd(math.gcd(a,b),c)

print(ans)

Fixed submission:
import math

K = int(input())

ans = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans += math.gcd(math.gcd(a,b),c)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split(' ')))

ans=1
thresh=10**18
for i in range(N):
    ans = ans * A[i]
if ans > thresh:
    ans=-1

print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split(' ')))

ans=1
thresh=10**18
A.sort()
for i in range(N):
    ans = ans * A[i]
    if ans > thresh:
        ans=-1
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split(' '))
A = list(map(int,input().split(' ')))

# 戻ってくるまでのリスト
R=[]
Now=1
cnt=0
for i in range(N):
    if Now in R:
        Start=R.index(Now)
        End = cnt
        break
    else:
        R.append(Now)
        Now=A[Now-1]
        cnt+=1

if K < End:
    ans=R[K]
else:
    key=Start+(K-Start)%(End-Start)
    ans=R[key]

print(ans)
#print(Start,End)
#print(R)
#Start+K(End-Start)

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

# 戻ってくるまでのリスト
R=[]
Rs=set()
Now=1
cnt=0
for i in range(N):
    if Now in Rs:
        Start=R.index(Now)
        End = cnt
        break
    else:
        R.append(Now)
        Rs.add(Now)
        Now=A[Now-1]
        cnt+=1

if K < End:
    ans=R[K]
else:
    key=Start+(K-Start)%(End-Start)
    ans=R[key]

print(ans)
#print(Start,End)
#print(R)
#Start+K(End-Start)

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

# 戻ってくるまでのリスト
R=[]
Now=1
cnt=0
for i in range(N):
    if Now in R:
        Start=R.index(Now)
        End = cnt
        break
    else:
        R.append(Now)
        Now=A[Now-1]
        cnt+=1

if K < End:
    ans=R[K]
else:
    key=Start+(K-Start)%(End-Start)
    ans=R[key]

print(ans)
#print(Start,End)
#print(R)
#Start+K(End-Start)

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

# 戻ってくるまでのリスト
R=[]
Rs=set()
Now=1
cnt=0
for i in range(N):
    if Now in Rs:
        Start=R.index(Now)
        End = cnt
        break
    else:
        R.append(Now)
        Rs.add(Now)
        Now=A[Now-1]
        cnt+=1

if K < End:
    ans=R[K]
else:
    key=Start+(K-Start)%(End-Start)
    ans=R[key]

print(ans)
#print(Start,End)
#print(R)
#Start+K(End-Start)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())

ans=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            t=math.gcd(a,b)
            t=math.gcd(t,c)
            ans+=t

print(ans)

Fixed submission:
import math
K = int(input())

ans=0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            t=math.gcd(a,b)
            t=math.gcd(t,c)
            ans+=t

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

plist=prime_factorize(N)
ctr=pow(2,len(plist))
minctr=N
#print(plist)
for i in range(ctr):
    a=1
    b=1
    ctr_str=format(i,'0'+str(len(plist))+'b')
    #print(ctr_str)
    for j in range(len(ctr_str) ):
        if ctr_str[j] == '0':
            a=a*plist[j]
        else:
            b=b*plist[j]
    #print(a,b)
    minctr = min(minctr,a+b-2)

print(minctr)

Fixed submission:
import math
N = int(input())
mins = N
for i in range(1,math.ceil(math.sqrt(N))+1 ):
    b = N//i
    a = i
    if a*b == N:
        mins = min(mins,a+b-2)

print(mins)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

plist=prime_factorize(N)
ctr=pow(2,len(plist))
minctr=N
#print(plist)
for i in range(ctr):
    a=1
    b=1
    ctr_str=format(i,'0'+str(len(plist))+'b')
    #print(ctr_str)
    for j in range(len(ctr_str) ):
        if ctr_str[j] == '0':
            a=a*plist[j]
        else:
            b=b*plist[j]
    #print(a,b)
    minctr = min(minctr,a+b-2)

print(minctr)

Fixed submission:
import math
N = int(input())
mins = N
for i in range(1,math.ceil(math.sqrt(N))+1 ):
    b = N//i
    a = i
    if a*b == N:
        mins = min(mins,a+b-2)

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

L.sort()
#print(L)


cnt = 0
for i in range(N-2):
    highJ = 0
    for j in range(i+1,N-1):
        tmphighJ = max(j,highJ)
        for k in range(max(j+1,highJ+1),N):
            if L[k] < L[i]+L[j]:
                tmphighJ = k
            else:
                break
        highJ = max(j,tmphighJ)
        cnt+= tmphighJ - j
        #print(i,j,highJ,cnt)

print(cnt)
            

Fixed submission:
N = int(input())
L = list(map(int,input().split(' ')))

L.sort()
#print(L)

cnt = 0
order =0
for i in range(N-2):
    highJ = 0
    for j in range(i+1,N-1):
        tmphighJ = max(j,highJ)
        for k in range(max(j+1,highJ+1),N):
            order+=1
            if L[k] < L[i]+L[j]:
                tmphighJ = k
            else:
                break
        highJ = max(j,tmphighJ)
        cnt+= highJ - j
        #print(i,j,highJ,cnt)

print(cnt)
#print(order)