Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

l = [1]
i = 0
while (True):
    if a[l[i]-1] in l:
        p = l.index(a[l[i]-1])
        break

    l.append(a[l[i]-1])
    i += 1

if k < p:
    print(l[k])
else:
    k -= p
    x = k % (len(l)-p)
    print(l[x+p])



Fixed submission:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

q = [0 for i in range(n)]
l = [1]
i = 0
while (True):
    if q[a[l[i]-1]-1] == 1:
        p = l.index(a[l[i]-1])
        break
    
    q[a[l[i]-1]-1] = 1
    l.append(a[l[i]-1])
    i += 1

if k < p:
    print(l[k])
else:
    k -= p
    x = k % (len(l)-p)
    print(l[x+p])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
k = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def main():
    ans = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            for l in range(1, k+1):
                ans += gcd(i, j, l)
    print(ans)

main()




    


Fixed submission:
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
k = int(input())
#n, k = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def main():
    ans = 0
    for i in range(1, k+1):
        for j in range(1, k+1):
            if gcd(i, j) == 1:
                ans += k
                continue
            for l in range(1, k+1):
                ans += gcd(i, j, l)
    print(ans)

main()
Buggy python submission (verdict: Runtime Error):
import sys
import math
import collections
from collections import deque
#n = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#x = list(map(int, sys.stdin.readline().split()))

a = math.factorial(n) // (math.factorial(n - 2) * 2)
b = math.factorial(m) // (math.factorial(m - 2) * 2)

print(a+b)


Fixed submission:
import sys
import math
import collections
from collections import deque
#n = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#x = list(map(int, sys.stdin.readline().split()))

if n <= 1:
    a = 0
else:
    a = math.factorial(n) // (math.factorial(n - 2) * 2)

if m <= 1:
    b = 0
else:
    b = math.factorial(m) // (math.factorial(m - 2) * 2)

print(a+b)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
 
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
 
c = 0
for i in range(n):
    b = ans // a[i]
    c += b
 
print(c % mod)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
 
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
 
c = 0
for i in range(n):
    b = ans // a[i]
    c += b
 
print(c % mod)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
#a, b = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])

c = 0
for i in range(n):
    b = ans // a[i]
    c += b
    c %= mod

print(c)

Fixed submission:
import fractions
n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
 
ans = a[0]
for i in range(1, n):
    ans = ans * a[i] // fractions.gcd(ans, a[i])
 
c = 0
for i in range(n):
    b = ans // a[i]
    c += b
 
print(c % mod)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())

if s != 10 ** 9
    for i in range(n):
        if i < k:
            print(s, end=" ")
        else:
            if s+1
            print(s+1, end=" ")

else:
    for i in range(n):
        if i < k:
            print(s, end=" ")
        else:
            if s+1
            print(s-1, end=" ")
        


Fixed submission:
n, k, s = map(int, input().split())

if s != 10 ** 9:
    for i in range(n):
        if i < k:
            print(s, end=" ")
        else:
            print(s+1, end=" ")

else:
    for i in range(n):
        if i < k:
            print(s, end=" ")
        else:
            print(s-1, end=" ")
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


x, y = map(int, input().split())
if x  > 2 * y:
    print("0")
    sys.exit()
elif y  > 2 * x:
    print("0")
    sys.exit()
elif (x + y) % 3 != 0:
    print("0")
    sys.exit()


z = x + y
a = z / 3
n = a
b = 2 * a
r = 0
while (True):
    if a == x and b == y:
        break
    a += 1
    b -= 1
    r += 1
    
print(combinations_count(n, r) % (10 ** 9 + 7))
    
        



        


    







        



Fixed submission:
import math
import sys
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10 ** 9 + 7
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

    
x, y = map(int, input().split())
if x  > 2 * y:
    print("0")
    sys.exit()
elif y  > 2 * x:
    print("0")
    sys.exit()
elif (x + y) % 3 != 0:
    print("0")
    sys.exit()


z = x + y
a = int(z / 3)
n = a
b = 2 * a
r = 0
ans = 1
while (True):
    if a == x and b == y:
        break
    a += 1
    b -= 1
    r += 1



print(cmb(n, r, mod))
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))

l = sorted(l, reverse = True)
count = 1
same = []
two = []
ans = 0
for i in range(n-1):
    if l[i] == l[i+1]:
        count += 1
        if l[i] not in same:
            same.append(l[i])
    else:
        if count >= 2:
            two.append(l[i])
        count = 1
    
if count >= 2:
    two.append(l[i])

         
for i in range(len(same)):
    l = [j for j in l if j != same[i]]
    l.append(same[i])


l = sorted(l, reverse = True)
for i in range(len(l)-2):
    for j in range(len(l)-2-i):
        if l[i] > 2 * l[i+j+1]:
            break
        for k in range(len(l)-2-i-j):
            if l[i] < l[i+j+1] + l[i+j+k+2]:
                ans += 1
            else:
                break

for i in range(len(two)):
    for j in range(len(l)):
        if 2 * l[two[i]] > l[j] > int(l[two[i]] / 2):
            ans += 1
print(ans)

            

        
            
        
    
        




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

l.sort(reverse=True)
ans = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while (j < k):
        if l[i] - l[j] - l[k] < 0:
            ans += k - j
            j += 1
        else:
            k -= 1

print(ans)

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

l = sorted(l, reverse = True)

ans = []
for i in range(len(l)-2):
    for j in range(len(l)-2-i):
        if l[i] > 2 * l[i+j+1]:
            break
        for k in range(len(l)-2-i-j):
            if l[i] < l[i+j+1] + l[i+j+k+2]:
                if [l[i], l[i+j+1], l[i+j+k+2]] not in ans:
                    ans.append([l[i], l[i+j+1], l[i+j+k+2]])
            else:
                break

print(len(ans))
    

         
        
        
    

        
            
        
    
        




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

l.sort(reverse=True)
ans = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while (j < k):
        if l[i] - l[j] - l[k] < 0:
            ans += k - j
            j += 1
        else:
            k -= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
h, w, a, b = map(int, input().split())

ans = []
for i in range(b):
    l = [1 for j in range(w)]
    ans.append(l)

for i in range(h-b):
    l = [0 for j in range(w)]
    ans.append(l)
    

for i in range(int(h/2)+1):
    if sum(ans[2*i]) != a or sum(ans[2*i]) != w-a:
        for j in range(min(abs(sum(ans[2*i])-a), abs(sum(ans[2*i])-w+a))):
            ans[2*i][j] = 1 - ans[2*i][j]
            if 2 * i + 1 != h:
                ans[2*i+1][j] = 1 - ans[2*i+1][j]

for i in range(len(ans)):
    for j in range(len(ans[i])):
        print(ans[i][j], end="")
    print()
        



    










 

 


                                        




    




        


    







        



Fixed submission:
h, w, a, b = map(int, input().split())

ans = []
for i in range(b):
    l = [1 for j in range(w)]
    ans.append(l)

for i in range(h-b):
    l = [0 for j in range(w)]
    ans.append(l)

if h % 2 == 0:
    m = int(h/2)
else:
    m = int(h/2) + 1

for i in range(m):
    if sum(ans[2*i]) != a or sum(ans[2*i]) != w-a:
        for j in range(min(abs(sum(ans[2*i])-a), abs(sum(ans[2*i])-w+a))):
            ans[2*i][j] = 1 - ans[2*i][j]
            if i != int(h/2):
                ans[2*i+1][j] = 1 - ans[2*i+1][j]
                
for i in range(len(ans)):
    for j in range(len(ans[i])):
        print(ans[i][j], end="")
    print()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
for i in range(n):
    ans += i

print(ans)



 

 


                                        




    




        


    







        



Fixed submission:
n = int(input())

print(int(n*(n-1)//2))
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input(9.split()))

print(n-k+1)                
        


    







        



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

print(n-k+1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [a, b, c, d, e]
u = []
v = []
ans = 0

for i in range(len(s)):
    if s[i] % 10 == 0:
        ans += s[i]
    else:
        u.append(s[i])
        v.append(s[i] % 10)

k = min(v)
for j in range(len(u)):
    ans += u[j] + 10 - v[j]
    
ans = ans - 10 + k
print(ans)



Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [a, b, c, d, e]
u = []
v = []
ans = 0

for i in range(len(s)):
    if s[i] % 10 == 0:
        ans += s[i]
    else:
        u.append(s[i])
        v.append(s[i] % 10)

if len(v) != 0:
    k = min(v)
    for j in range(len(u)):
        ans += u[j] + 10 - v[j]
        
    ans = ans - 10 + k
print(ans)

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [a, b, c, d, e]
u = []
v = []
ans = 0

for i in range(len(s)):
    if s[i] % 10 == 0:
        ans += s[i]
    else:
        u.append(s[i])
        v.append(s[i] % 10)

k = min(v)
for j in range(len(u)):
    ans += u[j] + 10 - v[j]
    
ans = ans - 10 + k
print(ans)



Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [a, b, c, d, e]
u = []
v = []
ans = 0

for i in range(len(s)):
    if s[i] % 10 == 0:
        ans += s[i]
    else:
        u.append(s[i])
        v.append(s[i] % 10)

if len(v) != 0:
    k = min(v)
    for j in range(len(u)):
        ans += u[j] + 10 - v[j]
        
    ans = ans - 10 + k
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
t = [[0 for i in range(2)] for j in range(q)]
for k in range(q):
    t[k][0], t[k][1] = map(int, input().split())

for l in range(q):
    count = 0
    for m in range(t[l][1] - t[l][0]):
        if s[t[l][0] - 1 + m] == "A" and s[t[l][0] + m] == "C":
            count += 1

    print(count)
            


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

t = [0 for i in range(len(s))]
count = 0
for j in range(len(s)-1):
    if s[j] == "A" and s[j+1] == "C":
        count += 1
    t[j+1] = count

for k in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
Buggy python submission (verdict: Runtime Error):
n, m, c = map(int, input().split())
a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
for i in range(m):
    b[i] = int(input())
for i in range(n):
    for j in range(m):
        a[i][j] = int(input())

count = 0
for i in range(n):
    x = 0
    for j in range(m):
        x += a[i][j] * b[j]
    x += c

    if x > 0:
        count += 1
            
print(count)


Fixed submission:
n, m, c = map(int, input().split())
a = []
b = list(map(int, input().split()))

for i in range(n):
    a.append(list(map(int, input().split())))

count = 0
for i in range(n):
    x = 0
    for j in range(m):
        x += a[i][j] * b[j]
    x += c

    if x > 0:
        count += 1
            
print(count)
Buggy python submission (verdict: Runtime Error):
s = int(input())

if s == 1 or s == 2:
    print(4)
elif:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        
    







        



Fixed submission:
s = int(input())

if s == 1 or s == 2:
    print(4)
else:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1

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

if s == 1 || s == 2:
    print(4)
elif:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        
    







        



Fixed submission:
s = int(input())

if s == 1 or s == 2:
    print(4)
else:
    for i in range(1000000):
        if s == 4:
            print(i + 4)
            break

            
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    tmp = 1
    for i in range(K):
        tmp *= A[i]

    for i in range(N-K):
        t = tmp // A[i]
        t *= A[i+K]
        if t > tmp:
            print('Yes')
        else:
            print('No')
        tmp = t


if __name__ == "__main__":
    main()


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

    for i in range(N-K):
        if A[i+K] > A[i]:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import random
import copy
import numpy as np


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    t = [0] * D

    # 貪欲法でまず求める
    penalty = np.array(c)
    for i in range(D):
        ind = 0
        tmp = 0
        for j in range(26):
            if penalty[j] + s[i][j] > tmp:
                tmp = penalty[j] + s[i][j]
                ind = j
        penalty[ind] = 0
        t[i] = ind + 1
        for j in range(26):
            penalty[j] += c[j]

    # 適当なtをスワップしてスコアが伸びればそれを採用する
    ans = calc(s, c, t)
    rand = list(range(365))
    for i in range(1000):
        swap = random.sample(rand, 2)
        t[swap[0]], t[swap[1]] = t[swap[1]], t[swap[0]]
        tmp = calc(s, c, t)
        if tmp < ans:
            # 元に戻す
            t[swap[0]], t[swap[1]] = t[swap[1]], t[swap[0]]

    return t


def output(t):
    for tt in t:
        print(tt)


def calc(s, c, t):
    d = [0] * 26

    ans = 0
    days = 0
    for tt in t:
        for i in range(26):
            d[i] += 1
        d[tt-1] = 0
        ans += s[days][tt-1]
        for i in range(26):
            ans -= d[i] * c[i]
        days += 1
        # print(ans)

    return ans


if __name__ == "__main__":
    t = main()
    output(t)


Fixed submission:
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    for i in range(D):
        print(1)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import random
import copy
import numpy as np


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    t = [0] * D

    # ペナルティが多い順にindexを並べる
    penalty = np.array(c)
    for i in range(D):
        ind = 0
        tmp = 0
        for j in range(26):
            if penalty[j] + s[i][j] > tmp:
                tmp = penalty[j] + s[i][j]
                ind = j
        penalty[ind] = 0
        t[i] = ind + 1
        for j in range(26):
            penalty[j] += c[j]

    for tt in t:
        print(tt)


def calc(s, c, t):
    d = [0] * 26

    ans = 0
    days = 0
    for tt in t:
        for i in range(26):
            d[i] += 1
        d[tt-1] = 0
        ans += s[days][tt-1]
        for i in range(26):
            ans -= d[i] * c[i]
        days += 1
        print(ans)

    return ans


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _ in range(D)]

    for i in range(D):
        print(1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor
from collections import defaultdict


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    # divisors.sort()
    return divisors


def main():
    N = int(input())
    divlist = defaultdict(int)

    ans = 0
    for i in range(1, N+1):
        ans += i/2 * floor(N/i) * floor(1+N/i)

    print(int(ans))


def test():
    ans = 0
    for i in range(1, 10000000):
        d = Calc_Divisors(i)
        print(len(d))
        ans += len(d) * i
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from math import floor
from collections import defaultdict


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    # divisors.sort()
    return divisors


def main():
    N = int(input())
    divlist = defaultdict(int)

    ans = 0
    for i in range(1, N+1):
        ans += i/2 * floor(N/i) * floor(1+N/i)

    print(int(ans))


def test():
    ans = 0
    for i in range(1, 10000000):
        d = Calc_Divisors(i)
        print(len(d))
        ans += len(d) * i
        print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from itertools import product
from collections import defaultdict


def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(q)]

    m_list = defaultdict(list)

    for i in range(1, m+1):
        m_list[i].append(0)

    for data in abcd:
        for i in range(1, m+1):
            for j in range(i+1, m+1):
                if j - i == data[2]:
                    if m_list[data[0]][0] == 0:
                        m_list[data[0]] = [i]
                    else:
                        m_list[data[0]].append(i)
                    if m_list[data[1]][0] == 0:
                        m_list[data[1]] = [j]
                    else:
                        m_list[data[1]].append(j)

    ll = list(product(*m_list.values()))

    ans = 0
    for l in ll:
        tmp = 0
        for data in abcd:
            if l[data[1]-1] - l[data[0]-1] == data[2]:
                tmp += data[3]
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from itertools import combinations_with_replacement
from collections import defaultdict


def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(q)]

    ll = list(combinations_with_replacement(range(1, m+1), n))

    ans = 0
    for l in ll:
        tmp = 0
        for data in abcd:
            if l[data[1]-1] - l[data[0]-1] == data[2]:
                tmp += data[3]
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
from itertools import product
from collections import defaultdict


def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(q)]

    m_list = defaultdict(list)

    for i in range(1,m+1):
        m_list[i].append(0)

    for data in abcd:
        for i in range(1, m+1):
            for j in range(i+1, m+1):
                if j - i == data[2]:
                    m_list[data[0]].append(i)
                    m_list[data[1]].append(j)

    ll = list(product(*m_list.values()))

    ans = 0
    for l in ll:
        tmp = 0
        for data in abcd:
            if l[data[1]-1] - l[data[0]-1] == data[2]:
                tmp += data[3]
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from itertools import combinations_with_replacement
from collections import defaultdict


def main():
    n, m, q = map(int, input().split())
    abcd = [list(map(int, input().split())) for _ in range(q)]

    ll = list(combinations_with_replacement(range(1, m+1), n))

    ans = 0
    for l in ll:
        tmp = 0
        for data in abcd:
            if l[data[1]-1] - l[data[0]-1] == data[2]:
                tmp += data[3]
        if tmp > ans:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
if __name__ == "__main__":
    n = int(input())

    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                tmp = gcd(i, j)
                tmp = gcd(tmp, k)
                ans += tmp

    print(ans)


Fixed submission:
from math import gcd
if __name__ == "__main__":
    n = int(input())

    ans = 0
    for i in range(1, n+1):
        for j in range(1, n+1):
            for k in range(1, n+1):
                tmp = gcd(i, j)
                tmp = gcd(tmp, k)
                ans += tmp

    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    L.reverse()

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            for k in range(j+1, N):
                if i != j and j != k and k != i:
                    if L[i] < L[j] + L[k] and L[j] < L[k] + L[i] and L[k] < L[i] + L[j]:
                        ans += 1
                        # print("{} {} {}".format(L[i], L[j], L[k]))

    print(ans)


Fixed submission:
from bisect import bisect_right

if __name__ == "__main__":
    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):
            k = bisect_right(L, L[i] + L[j] - 1)
            ans += max(k - j - 1, 0)

    print(ans)