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

Fixed submission:
n, m, x = map(int, input().split())
sL = [0]*m
bL = []
for i in range(n):
    book = list(map(int, input().split()))
    bL.append(book)


def fullS(currentL, index, allP):
    if index >= len(bL):
        if min(currentL) >= x:
            return allP
        else:
            return -1
    else:
        if min(currentL) >= x:
            return allP
        else:
            op1 = fullS(currentL, index+1, allP)
            newP = 0
            newL = []
            for i in range(len(bL[index])):
                if i == 0:
                    newP = allP+bL[index][i]
                else:
                    newL.append(currentL[i-1]+bL[index][i])
            op2 = fullS(newL, index+1, newP)
            if op1 == -1 and op2 == -1:
                return -1
            elif op1 == -1:
                return op2
            elif op2 == -1:
                return op1
            else:
                return min(op1, op2)
                


print(fullS(sL, 0, 0))

Buggy submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
sL = [0]*m
bL = []
for i in range(n):
    book = list(map(int, input().split()))
    bL.append(book)


def fullS(currentL, index, allP):
    if index > len(currentL):
        if min(currentL) >= x:
            return allP
        else:
            return -1
    else:
        if min(currentL) >= x:
            return allP
        else:
            op1 = fullS(currentL, index+1, allP)
            newP = 0
            newL = []
            for i in range(len(bL[index])):
                if i == 0:
                    newP = allP+bL[index][i]
                else:
                    newL.append(currentL[i-1]+bL[index][i])
            op2 = fullS(newL, index+1, newP)
            if op1 == -1 and op2 == -1:
                return -1
            elif op1 == -1:
                return op2
            elif op2 == -1:
                return op1
            else:
                return min(op1, op2)
                


print(fullS(sL, 0, 0))
Problem p02995 (python)

Fixed submission:
import fractions
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//fractions.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))

Buggy submission (verdict: Runtime Error):
import math
a, b, c, d = map(int, input().split())
cCan = b//c-(a-1)//c
dCan = b//d-(a-1)//d
cdSK = c*d//math.gcd(c, d)
cdCan = b//cdSK-(a-1)//cdSK
print(int(b-(a-1)-cCan-dCan+cdCan))
Problem p03062 (python)

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

index=0
count=0
plSum=0
miSum=0
miniO=10000000
while index < len(listA):
    if listA[index] < 0:
        count+=1
        miSum-=listA[index]
    else:
        plSum+=listA[index]
    if abs(listA[index]) < miniO:
        miniO = abs(listA[index])
    index+=1
if count%2==0:
    print(plSum+miSum)
else:
    print(plSum+miSum-2*miniO)

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

sum1=0
index=0
while index < len(listA):
    sum1+=listA[index]
    index+=1

if len(listA)%2==0:
    leng = len(listA)-1
else:
    leng = len(listA)-2
while leng > 1:
    index=0
    max1 = 0
    startI=0
    endI=0
    while index < len(listA)-leng+1:
        if sum(listA[index:index+leng+1]) <= 0 and max1 < sum(listA[index:index+leng+1])*-2:
            max1 = -2*(sum(listA[index:index+leng+1]))
            startI = index
            endI = index+leng
        index+=1
    if max1!=0:
        sum1+=max1
        index2=startI
        while index2 < endI+1:
            listA[index2]*=-1
            index2+=1
    leng-=1

print(sum1)
Problem p03089 (python)

Fixed submission:
n = int(input())
listB = list(map(int, input().split()))
listA = []

flag=1
while flag:
    index=len(listB)-1
    while index > -1:
        if listB[index] == index+1:
            listA.append(listB[index])
            del listB[index]
            break
        index-=1
    if index == -1:
        print(-1)
        flag=0
        break
    if listB == []:
        break
listA.reverse()
if flag:
    for ans in listA:
        print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
listB = list(map(int, input().split()))
i = 1
if i == 1:
    listA = []
    index2 = len(listB)-1
    befI = len(listB)
    while index2 > -1:
        if listB[index2]!=1:
            pass
        else:
            if index2 != befI:
                newL = listB[index2:befI]
                newL.sort()
                listA.extend(newL)
                befI = index2
            else:
                listA.append(1)
        index2-=1
    listC = []
    index3=0
    while index3 < len(listA):
        if index3 == 0:
            if listA[index3] == 1:
                listC.append(listA[index3])
            else:
                listC.append(0)
        elif listA[index3] > index3+1:
            listC.append(0)
        else:
            if listA[index3]-1 <=  len(listC):
                listC.insert(listA[index3]-1, listA[index3])
            else:
                listC.append(0)
        index3+=1
    if index3 == len(listA):
        if listC == listB:
            for ans in listA:
                print(ans)
        else:
            print(a)
Problem p03231 (python)

Fixed submission:
n, m = map(int, input().split())
listS= list(input())
listT = list(input())


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


l = n*m // gcd(n, m)
a = l//n
b = l//m

if listS[0]!=listT[0]:
    print(-1)
else:
    checkI = a*b // gcd(a, b)
    if checkI > l:
        print(l)
    else:
        index=0
        flag=0
        while index < l//min(a, b):
            if index*checkI//a > len(listS)-1 or index*checkI//b > len(listT)-1:
                break
            elif listS[index*checkI//a] != listT[index*checkI//b]:
                print(-1)
                flag=1
                break
            else:
                index+=1
        if flag==0:
            print(l)

Buggy submission (verdict: Runtime Error):
import math
n, m = map(int, input().split())
listS = list(input())
listT = list(input())
listX = []

l= n*m // math.gcd(n, m)
a=l//n
b=l//m

if listS[0]!=listT[0]:
    print(-1)
else:
    index =0
    index2=0
    while index < l:
        while index2 < n:
            if index == index2*a:
                listX.append(listS[index2])
                index2+=1
                index+=1
            else:
                listX.append(0)
                index+=1
        index+=1
    index4=0
    flag=0
    while index4 < min(m, l//b):
        if listX[index4*b] == listT[index4] or listX[index4*b] == 0:
            index4+=1
        else:
            print(-1)
            flag=1
            break
    if flag!=1:
        print(l)
Problem p03260 (python)

Fixed submission:
list = list(map(int, input().split()))
a = list[0]
b = list[1]

if a%2!=0 and b%2!=0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
list1 = list(map(int, input().split()))
n = list1[0]
x = list1[1]
list2 = list(map(int, input().split()))
list2.append(x)
list2.sort()

list3 = []
length = len(list2)
index =1
while index < length:
    list3.append(list2[index]-list2[index-1])
    index+=1

list3.sort()
mimN = list3[0]
ans =0
index2 =mimN
if len(list3) ==1:
    print(mimN)
else:
    flag2 =0
    for number in list3:
       if number%mimN !=0:
           flag2 =1
    if flag2 ==0:
        print(mimN)
    else:
        while index2>=1:
            flag=1
            for number in list3:
                if number%index2 ==0:
                    flag =1
            if flag ==1:
                ans = index2
                break
            index2-=1
            
        print(ans)
Problem p03339 (python)

Fixed submission:
n = int(input())
listS = list(input())

listSeeWSum=[]
index=0
wSum=0
while index < n:
    if index==0:
        listSeeWSum.append(0)
    else:
        if listS[index-1] == "W":
            wSum+=1
        listSeeWSum.append(wSum)
    index+=1

listSeeESum=[]
listS.reverse()
index = 0
eSum = 0
while index < n:
    if index == 0:
        listSeeESum.append(0)
    else:
        if listS[index-1] == "E":
            eSum += 1
        listSeeESum.append(eSum)
    index += 1
listSeeESum.reverse()

listSum=[]
index=0
while index < n:
    listSum.append(listSeeESum[index]+listSeeWSum[index])
    index+=1

print(min(listSum))

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

listSeeWSum=[]
index=0
wSum=0
while index < n:
    if index==0:
        listSeeWSum.append(0)
    else:
        if listS[index-1] == "W":
            wSum+=1
        listSeeWSum.append(wSum)
    index+=1

listSeeESum=[]
listS.reverse()
index = 0
eSum = 0
while index < n:
    if index == 0:
        listSeeESum.append(0)
    else:
        if listS[index-1] == "E":
            eSum += 1
        listSeeESum.append(eSum)
    index += 1
listSeeESum.reverse()

listSum=[]
index=0
while index < n:
    listSum.append(listSeeESum[index]+listSeeWSum[index])
    index+=1

print(min(listSum))v
Problem p03761 (python)

Fixed submission:

n = int(input())
listForList = []

index = 0
while index < n:
    listI = list(input())
    listI.sort()
    listForList.append(listI)
    index += 1

if len(listForList) == 1:
    print("".join(listForList[0]))
else:
    index2 = 0
    pendingL = []
    while index2 < len(listForList)-1:
        if index2 == 0:
            for c in listForList[index2]:
                if c in listForList[index2+1]:
                    pendingL.append(c)
        else:
            newPL = []
            for ch in pendingL:
                if ch in listForList[index2+1]:
                    newPL.append(ch)
                    listForList[index2+1].remove(ch)
            pendingL = newPL
            if pendingL == []:
                print("")
                break
        index2 += 1

    if index2 == len(listForList)-1:
        print("".join(pendingL))

Buggy submission (verdict: Runtime Error):
n = int(input())
listForList=[]

index=0
while index < n:
    listI = list(input())
    listI.sort()
    listForList.append(listI)
    index+=1

if len(listForList)==1:
    print("".join(listForList[0]))
else:
    index2=1
    pendingL=listForList[0]
    while index2 < len(listForList):
        newPL=[]
        for ch in pendingL:
            if ch in listForList[index2]:
                newPL.append(ch)
        pendingL = newPL
        if pendingL==[]:
            print("")
            break
        index2+=1

if index2 == len(listForList):
    print("".join(pendingL))

Buggy submission (verdict: Runtime Error):
n = int(input())
listForList=[]

index=0
while index < n:
    listI = list(input())
    listI.sort()
    listForList.append(listI)
    index+=1

if len(listForList)==1:
    print("".join(listForList[0]))
else:
    index2=0
    pendingL=[]
    while index2 < len(listForList)-1:
        if index2 ==0:
            for c in listForList[index2]:
                if c in listForList[index2+1]:
                    pendingL.append(c)
        else:
            newPL=[]
            for ch in pendingL:
                if ch in listForList[index2+1]:
                    newPL.append(ch)
            pendingL = newPL
            if pendingL==[]:
                print("")
                break
        index2+=1

if index2 == len(listForList)-1:
    print("".join(pendingL))
Problem p02630 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for _ in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)

d=[0]*100001
for i in a:
    d[i]+=1

ans=sum(a)
for m,p in zip(b,c):
    minus=d[m]
    d[m]=0
    d[p]+=minus
    ans+=(p-m)*minus
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for _ in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)

d=[0]*10001
for i in a:
    d[i]+=1

for m,p in zip(b,c):
    minus=d[m]
    d[m]=0
    d[p]+=minus
    ans=0
    for i in range(len(d)):
        ans+=i*d[i]
    print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[]
c=[]
for _ in range(q):
    x,y=map(int,input().split())
    b.append(x)
    c.append(y)

d=[0]*10000
for i in a:
    d[i]+=1

for m,p in zip(b,c):
    minus=d[m]
    d[m]=0
    d[p]+=minus
    ans=0
    for i in range(len(d)):
        ans+=i*d[i]
    print(ans)
Problem p02678 (python)

Fixed submission:
from collections import deque

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

graph = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [0] * (n + 1)

d=deque()
d.append(1)

while d:
    v = d.popleft()
    
    for i in graph[v]:
        if not dist[i]:
            dist[i] = v
            d.append(i)

ans = dist[2:]
print('Yes')
print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
from collections import deque

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

graph = [[] for _ in range(n+1)]
for i in range(m):
    a,b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

print(graph)

dist = [-1] * (n + 1)
dist[0] = 0
dist[1] = 0

d=deque()
d.append(1)

while d:
    print(d)
    print(dist)
    v = d.popleft()
    
    for i in graph[v]:
        if dist[i] != -1:
            continue
        dist[i] = dist[v] + 1
        d.append(i)
        
ans = dist[2:]
print('Yes')
print(*ans,sep='\n')
Problem p02767 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
imax=int(max(x))
imin=int(min(x))
lis=[]
re=0
for k in range(imin,imax+1):
  for i in x:
    re=re+(i-k)**2
  lis.append(re)
  re=0
print(min(lis))

Buggy submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
imax=int(max(x))
imin=int(min(x))
lis=[]
re=0
for k in range(imin,imax+1):
  for i in x:
    re=re+(x[i]-k)**2
  lis.append(re)
  re=0
print(min(lis))
Problem p02772 (python)

Fixed submission:
N = int(input())
array = [int(x) for x in input().split()]
fl=True
for i in array:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 != 0:
        fl = False
if fl: print('APPROVED')
else:print('DENIED')

Buggy submission (verdict: Runtime Error):
N = int(input())
array = [int(x) for x in input().split()]
for i in array:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      fg = True
    else:
      fg = False
if fg: print('APPROVED')
else: print('DENIED')

Buggy submission (verdict: Runtime Error):
N = int(input())
array = [int(x) for x in input().split()]
for i in array:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      fg = True
    else:
      fg = False
      print('DENIED')
      break
if fg:
  print('APPROVED')

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
array = [int(x) for x in input().split()]
for i in array:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      fg = True
    else:
      fg = False
      print('DENIED')
      break
if fg:
  print('APPROVED')

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
array = list(map(int, input().strip().split()))
for i in array:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      fg = True
    else:
      fg = False
      print('DENIED')
      break
if fg:
  print('APPROVED')

Buggy submission (verdict: Runtime Error):
N = int(input().strip())
array = list(map(int, input().strip().split()))
for i in array:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      fg = True
    else:
      fg = False
      print('DENIED')
      break
if fg:
  print('APPROVED')
Problem p02817 (python)

Fixed submission:
s=input().split()
print(s[1]+s[0])

Buggy submission (verdict: Runtime Error):
a,b,k=(long(i)for i in input().split())
while 0<k:
    if 0<a:a=a-1
    elif 0<b:b=b-1
    k=k-1
print(a,b)
Problem p03105 (python)

Fixed submission:
a,b,c = map(int, input().split())
print(c) if a*c<=b else print(b//a)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
print(c) if a*c=<b else print(b//a)
Problem p03219 (python)

Fixed submission:
x,y = map(int, input().split())
print(x+(y//2))

Buggy submission (verdict: Runtime Error):
x,y = map(int, input().split())
print(x+(y//2)
Problem p03303 (python)

Fixed submission:
print(input()[::int(input())])

Buggy submission (verdict: Runtime Error):
print(input()[::int(input())]
Problem p02631 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

su = 0

for i in range(1, n):
    su ^= a[i]
    
ans = [su]

for i in range(n-1):
    su = su ^ a[i] ^ a[i+1]
    ans.append(su)
    
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

su = 0

for i in range(1, n):
    su ^= a[i]
    
ans = [su]

for i in range(n-1):
    su = su ^ a[i] ^ a[i+1]
    ans.append(su)
    
print(*su)
Problem p02642 (python)

Fixed submission:
#Ai/Aj not integer
#5
#24 11 8 3 16
#のときは、24は8,3があるからダメ　16も8があるからダメ
N=int(input())
A=[int(i) for i in input().split()]
D=set()
S=set()
for i in range(N):
    if A[i] in S:
        D.add(A[i])
    else:
        S.add(A[i])
M=max(S)
X=[1 for i in range(M+1)]
for a in S:
    if a in D:
        X[a]=0
    for i in range(2*a,M+1,a):
        X[i]=0
ans=0
for i in range(N):
    if X[A[i]]==1:
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

a.sort()

ans = 0

for i in range(n):
    
    x = a[i]

    l = 0; r = n # 二分探索時は探索範囲は取り得る値+-1しておく

    while l+1 < r:
        c = (l+r)//2
        if a[c] < int(x**0.5)+1:
            l = c
        else:
            r = c

    tmp = 1
    for j in range(c+1):
        if i != j and x%a[j] == 0:
            break
    else:
        ans += tmp

print(ans)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = tuple(map(lambda n: int(n) - 1, input().split()))

visited = [0] * n
next_town = 0
order = []

while True:
    if visited[next_town]:
        break
    order.append(next_town)
    visited[next_town] = 1
    next_town = a[next_town]

first_loop = len(order)
offset = order.index(next_town)
second_loop = first_loop - offset

if k < first_loop:
    print(order[k] + 1)
else:
    print(order[offset + (k - first_loop) % second_loop] + 1)

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

init = [1]
while True:
    nxt = a[init[-1]-1]
    if nxt in init:
        idx_nxt = init[nxt]
        loop = init[idx_nxt:]
        init = init[:idx_nxt]
        break
    else:
        init.append(nxt)

idx = (k-len(init))%len(loop)
print(loop[idx])
Problem p02813 (python)

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

import itertools

a = [i+1 for i in range(n)]

C = list(itertools.permutations(a))

idxs = []

for i, c in enumerate(C):
    l = list(c)
    if l == p:
        idxs.append(i)
    if l == q:
        idxs.append(i)

ans = idxs[1]-idxs[0]

print(ans)

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

import itertools

a = [i+1 for i in range(n)]

C = list(itertools.permutations(a))

idxs = []

for i, c in enumerate(C):
    l = list(c)
    if l == p or l == q:
        idxs.append(i)

ans = idxs[1]-idxs[0]

print(ans)
Problem p02818 (python)

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

if a <= k:
    k -= a
    a = 0
else:
    a -= k
    k = 0

if b <= k:
    b = 0
else:
    b -= k
    
print(a, b)

Buggy submission (verdict: Runtime Error):
a,b,k = list(map(int, input().split()))

if a =< k:
    k -= a
    a = 0
else:
    a -= k
    k = 0

if b =< k:
    b = 0
else:
    b -= k
    
print(a, b)
Problem p02850 (python)

Fixed submission:
"""dfs"""

n = int(input())
import sys
sys.setrecursionlimit(10**6)

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i)
    to[b].append(a); eid[b].append(i)

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
"""bfs"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*(n-1)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i) # to:nodeの繋がり、eid:edgeの色
    to[b].append(a); eid[b].append(i)

import queue

q = queue.Queue()
used = [0]*n
q.put(0)
used[0] = 1
while not q.empty():
    v = q.get()
    p = pre[v]
    c = -1
    for i in range(len(to[v])):
        u = to[v]; ei = eid[v]
        if used[u]: c = ans[ei]
    k = 1
    for i in range(len(to[v])):
        u = to[v]; ei = eid[v]
        if used[u]: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        q.put(u)
        used[u] = 1

mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
"""dfs"""

n = int(input())

to = [[] for _ in range(n)]
eid = [[] for _ in range(n)]
ans = [0]*n

def dfs(v, c=-1, p=-1):
    k = 1
    for i in range(len(to[v])):
        u = to[v][i]
        ei = eid[v][i]
        if u == p: continue
        if k == c: k += 1
        ans[ei] = k
        k += 1
        dfs(u,ans[ei],v)

for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1; b -= 1
    to[a].append(b); eid[a].append(i)
    to[b].append(a); eid[b].append(i)

dfs(0)
mx = 0
for i in range(n):
    mx = max(mx, len(to[i]))
print(mx)
for i in range(n-1):
    print(ans[i])
Problem p02888 (python)

Fixed submission:
"""二分探索"""

import sys
sys.setrecursionlimit(10**6)

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

L.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        l = j; r = n
        while l+1 < r:
            c = (l+r)//2
            if L[c] < L[i]+L[j]:
                l = c
            else:
                r = c
        ans += l-j
        
print(ans)

Buggy submission (verdict: Runtime Error):
"""
keyword: 二分探索

初めにLをソートして、a<b<cとしてa,bを決めたとき、a+b>cとなるようなcの個数を計算する
cの最大値を求めるには二分探索が高速
さらに、二分探索の探索範囲の左端は、前のループで求めたcの最大値で十分である（∵前のループのa+b <= 今ループのa+b）ことを考慮すれば、さらに高速化できる

pythonでTLE, pypyでAC
"""

import sys
sys.setrecursionlimit(10**6)

n = int(input())
L = list(map(int, input(s).split()))

L.sort()
ans = 0

for i in range(n-2):
    l_prev = 0 # 前のループで求めたcの最大値を覚えておく
    for j in range(i+1,n-1):
        ab = L[i]+L[j]
        if not l_prev:
            l = j; r = n
        else:
            l = l_prev; r = n
        while l+1 < r:
            c = (l+r)//2
            if L[c] < ab:
                l = c
            else:
                r = c
        ans += l-j
        l_prev = l
        
print(ans)