ZhenlongDai/ACPR huggingface dataset:
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

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

l.sort()

ans = 0

print(l)
for i in range(n):
    for j in range(i+1, n):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)

Failing test case input:
3
1 1010 1

Expected output:
0


Actual output:
[1, 1, 1010]
0


Fixed submission (verdict: Accepted):
import bisect

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

l.sort()

ans = 0

for i in range(n):
    for j in range(i+1, n):
        q = l[i]+l[j]
        p = bisect.bisect_left(l, q)
        ans += (p - j - 1)

print(ans)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if item > list[-1]:
        return high
    while low <= high:
        mid = (low + high) 
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    return mid-1
ans = 0
for i in range(N-1):
    for j in range(i,N-1):
        ans += max(0,binary_search(l,l[i] + l[j+1]-1)-(j+1))
print(ans)

Failing test case input:
7
218 1140 704 233 645 728 389

Expected output:
14


Actual output:
7


Fixed submission (verdict: Accepted):
N = int(input())
l = [int(x) for x in input().split()]
l.sort()
def binary_search(list, item):
    low = 0
    high = len(list) - 1
    if item > list[-1]:
        return high
    while low <= high:
        mid = (low + high) 
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1
    if list[mid] > item:
        return mid - 1
    else:
        return mid
ans = 0
for i in range(N-1):
    for j in range(i,N-1):
        b = binary_search(l,l[i] + l[j+1]-1)
        while True:
            if b == len(l)-1:
                break
            elif l[b] == l[b+1]:
                b = b+1
            else:
                break
        ans += max(0,b-(j+1))
print(ans)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

import itertools as it

def main():
    N=ii()
    L=lmis()
    ans=0
    for a,b,c in it.combinations(L,3):
        if a+b<c: continue
        if a+c<b: continue
        if b+c<a: continue
        ans+=1
    print(ans)


if __name__ == "__main__":
    main()

Failing test case input:
4
6 4 2 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

import itertools as it

def main():
    N=ii()
    L=sorted(lmis(),reverse=True)

    ans=0
    for i in range(N-2):
        a=L[i]
        j=i+1
        k=N-1
        while j<k:
            if a<L[j]+L[k]:
                j+=1
                ans+=k-j+1
            else:
                k-=1
    
    print(ans)


if __name__ == "__main__":
    main()

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def sort_list(list_n):
    ans = 0
    n_lst = tuple(sorted(list_n, reverse=True))
    for idx in range(len(list_n)-2):
        for diff_idx in range(idx+1, len(list_n)-1):
            diff = n_lst[idx] - n_lst[diff_idx]
            for search in range(diff_idx+1, len(list_n)):
                if n_lst[search] <= diff:
                    search -= 1
                    break
            ans += search - diff_idx
    return ans


def main():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = sort_list(K)
    print(ans)


Failing test case input:
7
329 7220 638 14 121 152 9

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
import bisect


def sort_list():
    _ = input()
    K = [int(x) for x in input().split()]
    ans = 0

    len_k = len(K)
    n_lst = sorted(K)

    for idx in reversed(range(2, len_k)):
        for diff_idx in range(1, idx):
            diff = n_lst[idx] - n_lst[diff_idx]
            insert_index = bisect.bisect_right(n_lst, diff)
            if insert_index < diff_idx:
                
                ans += diff_idx - insert_index
    print(ans)


if __name__ == "__main__":
    sort_list()

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
l = len(LS)
print(LS)
for i in range(l):
  for j in range(l):
    if i < j:
      for k in range(j+1,l):
        if LS[i]+LS[j] > LS[k]:
          ans += 1
        else:
          break
print(ans)


Failing test case input:
7
153 7220 2149 14 121 152 9

Expected output:
3


Actual output:
[9, 14, 121, 152, 153, 2149, 7220]
3


Fixed submission (verdict: Accepted):
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
l = len(LS)
for i in range(l):
  for j in range(l):
    if i < j:
      k = bisect.bisect_left(LS,LS[i]+LS[j])
      ans += k-j-1
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from bisect import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
print(l)
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - max(j+1, bisect(l,left)))
print(ans)

Failing test case input:
7
153 7220 2149 14 121 152 9

Expected output:
3


Actual output:
[9, 14, 121, 152, 153, 2149, 7220]
3


Fixed submission (verdict: Accepted):
from bisect import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - max(j+1, bisect(l,left)))
print(ans)

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
for x in itertools.combinations(LS, 2):
  if x[0] > x[1]:
    x[0], x[1] = x[1], x[0]
  il = bisect.bisect_right(LS, x[1])
  ir = bisect.bisect_left(LS,x[0]+x[1])
  ans += ir-il
print(ans)


Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import itertools
import bisect
N = int(input())
L = list(map(int, input().split()))
ans = 0
LS = sorted(L)
l = len(LS)
for i in range(l):
  for j in range(l):
    if i < j:
      k = bisect.bisect_left(LS,LS[i]+LS[j])
      ans += k-j-1
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
L = sorted(list(map(int,input().split())),reverse = False)
print(L)
cnt = 0
for a in range(0,N-2):
    A = L[a]
    for b in range(a+1,N-1):
        B = L[b]
        for c in range(b+1,N):
            C = L[c]
            if(A+B > C):
                cnt += 1
print(cnt)          

Failing test case input:
7
116 1499 551 40 806 890 529

Expected output:
8


Actual output:
[40, 116, 529, 551, 806, 890, 1499]
8


Fixed submission (verdict: Accepted):
from bisect import bisect_left
N = int(input())
L = sorted(list(map(int,input().split())),reverse = False)
cnt = 0
for a in range(0,N-2):
    A = L[a]
    for b in range(a+1,N-1):
        B = L[b]
        cnt += bisect_left(L,A+B)-b-1
print(cnt)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

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

L.sort()
print(L)
ans = 0
for ai in range(N):
    for bi in range(ai+1, N):
        ci = bisect.bisect_left(L, L[ai]+L[bi])
        print(ai, bi, ci)
        if ci > bi:
            ans += ci - bi - 1
            print(ci - bi - 1)
        else:
            pass

print(ans)

Failing test case input:
7
218 1140 1051 31 636 890 389

Expected output:
10


Actual output:
[31, 218, 389, 636, 890, 1051, 1140]
0 1 2
0
0 2 3
0
0 3 4
0
0 4 5
0
0 5 6
0
0 6 7
0
1 2 3
0
1 3 4
0
1 4 6
1
1 5 7
1
1 6 7
0
2 3 5
1
2 4 7
2
2 5 7
1
2 6 7
0
3 4 7
2
3 5 7
1
3 6 7
0
4 5 7
1
4 6 7
0
5 6 7
0
10


Fixed submission (verdict: Accepted):


import bisect
 
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
ans = 0
for ai in range(N):
    for bi in range(ai+1, N):
        ci = bisect.bisect_left(L, L[ai]+L[bi])
        if ci > bi:
            ans += ci - bi - 1
        else:
            pass
 
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import bisect

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

L.sort()
value = 0


for i in range(0, len(L)-2):
    for j in range(i, len(L)-1):
        index = bisect.bisect_left(L[j+1:], L[i]+L[j])
        value+=max(0, index)

print(value)

Failing test case input:
7
116 1499 551 40 806 890 487

Expected output:
7


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0
for i in range(n):
  for j in range(i+1, n):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()

if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_left(L,L[i]+L[j],j+1)
        print(index)
        ans += (index - 1) - (j + 1) + 1
print(ans)

Failing test case input:
7
540 7220 638 14 121 152 4

Expected output:
2


Actual output:
2
3
4
5
6
3
4
5
6
4
6
6
6
6
6
2


Fixed submission (verdict: Accepted):
import sys
import bisect
N = int(input())
L = [i for i in map(int, input().split())]
ans = 0

L.sort()

if N == 3:
    if L[0] + L[1] > L[2]:
        print("1")
        sys.exit()

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        index = bisect.bisect_left(L,L[i]+L[j],j+1)
        
        ans += (index - 1) - (j + 1) + 1
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
import bisect

n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

l. sort()
ans = 0
for i in range(len(l) - 1):
    for j in range(i + 1, len(l)):
        a = l[i]
        b = l[j]
        ab = a + b
        left = bisect.bisect_right(l, b)
        right = bisect.bisect_left(l, ab)
        ans += (right - left)

print(ans)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import sys
import bisect

n = int(input())
l = list(map(int, sys.stdin.readline().strip().split()))

l. sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        a = l[i]
        b = l[j]
        ab = a + b
        right = bisect.bisect_left(l, ab) - 1
        ans += (right - j)

print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left

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

l.sort()
ans = 0
for i in reversed(range(2,n)):
  for j in reversed(range(1,i)):
    s = l[i]-l[j]
    ans += len(l[:j])-bisect_left(l[:j],s)
print(ans)

Failing test case input:
4
5 4 2 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import bisect_left

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):
    s = l[i]+l[j]
    ans += bisect_left(l,s,j+1)-j-1
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N = int(input())
L = list(map(int, input().split(" ")))
L.sort() 
print(L)
counter = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j], 0, N)
    counter = counter + index - j - 1
       
print(counter)

Failing test case input:
7
218 1140 1051 233 636 71 389

Expected output:
6


Actual output:
[71, 218, 233, 389, 636, 1051, 1140]
6


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
L = list(map(int, input().split(" ")))
L.sort() 
counter = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    index = bisect.bisect_left(L, L[i]+L[j], 0, N)
    counter = counter + index - j - 1
       
print(counter)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
count = 0

for i in range(N-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)


Failing test case input:
7
540 1452 638 24 121 152 4

Expected output:
2


Actual output:
20


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
A.sort()
count = 0

for i in range(N-1,0,-1):
    l = 0
    r = i -1
    while(l< r):
        if (A[l] + A[r] >A[i]):
            count += (r-l)
            r -= 1
        else:
            l += 1
print(count)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    c += bisect.bisect_right(l,l[j]+l[i]-1) - bisect.bisect_left(l,l[j])-1
print(c)

Failing test case input:
4
8 2 2 1

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    c += bisect.bisect_right(l,l[j]+l[i]-1) - bisect.bisect_left(l,l[j],j+1)
print(c)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0


for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    for b in range(a+1, N):
        if b >= current_min:
            break
        for c in range(b+1,N):
            c_idx = current_min
            bc = Ln[b] + Ln[c_idx]
            if a_l < bc:
                count += (current_min - b)
                break
            current_min -= 1
print(count)

Failing test case input:
7
218 1140 551 40 660 890 487

Expected output:
12


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())
Ln = list(map(int,input().split(' ')))
Ln.sort(reverse=True)

count = 0
for a in range(N):
    a_l = Ln[a]
    current_min = N-1
    b = a +1
    while b <= current_min:
        c_idx = current_min
        bc = Ln[b] + Ln[c_idx]
        if a_l < bc:
            count += (current_min - b)
            b += 1
            continue
        current_min -= 1
    
print(count)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(2, n):
    j = i - 1
    while j and a[j - 1] + a[j] > a[i]:
        r += j - bisect_right(a, i - j, 0, j)
        j -= 1
print(r)


Failing test case input:
7
116 1632 1217 7 129 232 12

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(2, n):
    j = i - 1
    while j and a[j - 1] + a[j] > a[i]:
        r += j - bisect_right(a, a[i] - a[j], 0, j)
        j -= 1
print(r)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(1,n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if i==j+k and j==i+k and k==i+j:
                print(ans)
print(ans)

Failing test case input:
7
116 1499 551 40 806 890 487

Expected output:
7


Actual output:
0


Fixed submission (verdict: Accepted):
from bisect import bisect_left
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
    for j in range(i+1,n):
        r =bisect_left(l,l[i]+l[j])
        ans+=max((r-j-1),0)
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      if l[i]+l[j]<=l[k]:
        ans+=k-j-1
        break
print(ans)
      
        
        


Failing test case input:
7
218 613 704 233 645 890 389

Expected output:
20


Actual output:
8


Fixed submission (verdict: Accepted):
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0
ans1=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+ans1,n):
      ans1=0
      if l[i]+l[j]>l[-1]:
        ans+=n-j-1
        break
      elif l[i]+l[j]<=l[k] :
        ans+=k-j-1
        ans1+=k-j-1
        break
      
      
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


Failing test case input:
7
116 1632 609 65 129 214 487

Expected output:
4


Actual output:
0 1 3 1
0 2 3 0
0 3 4 0
0 4 5 0
0 5 6 0
0 6 7 0
1 2 4 1
1 3 4 0
1 4 5 0
1 5 6 0
1 6 7 0
2 3 4 0
2 4 6 1
2 5 6 0
2 6 7 0
3 4 6 1
3 5 6 0
3 6 7 0
4 5 6 0
4 6 7 0
5 6 7 0
4


Fixed submission (verdict: Accepted):






def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






def sol(n,l):
    import bisect
    l.sort()
    a = []
    
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


Failing test case input:
7
153 3264 1874 14 248 232 5

Expected output:
1


Actual output:
15


Fixed submission (verdict: Accepted):






def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

def bi_search(array, target):
    l, r = 0, len(array)
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid+1
    return l

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list, b-a)
        if index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Failing test case input:
7
116 1632 609 65 129 214 487

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0


for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], a-b)
        
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n = int(input())
ln = list(map(int, input().split()))
ln.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        a = ln[i]
        b = ln[j]
        index = bisect.bisect_left(ln, a+b)-1
        print(i,j, index)
        print(a, b, ln[index-1])
        ans += index - j
print(ans)

Failing test case input:
7
91 574 704 384 645 728 374

Expected output:
25


Actual output:
0 1 2
91 374 374
0 2 2
91 384 374
0 3 4
91 574 574
0 4 6
91 645 704
0 5 6
91 704 704
1 2 6
374 384 704
1 3 6
374 574 704
1 4 6
374 645 704
1 5 6
374 704 704
2 3 6
384 574 704
2 4 6
384 645 704
2 5 6
384 704 704
3 4 6
574 645 704
3 5 6
574 704 704
4 5 6
645 704 704
25


Fixed submission (verdict: Accepted):
import bisect
n = int(input())
ln = list(map(int, input().split()))
ln.sort()
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        a = ln[i]
        b = ln[j]
        index = bisect.bisect_left(ln, a+b)-1
        ans += index - j
print(ans)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input=sys.stdin.readline
n = int(input())



A = list(map(int,input().split()))



d = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a = A[i]
            b = A[j]
            c = A[k]
            if c < a+b:
                d += 1
print(d)

Failing test case input:
7
218 1140 1051 233 74 890 389

Expected output:
10


Actual output:
30


Fixed submission (verdict: Accepted):
import sys
input=sys.stdin.readline
from bisect import bisect_left
N = int(input())



A = list(map(int,input().split()))



d = 0
A.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        s = A[i]+A[j]
        dex = bisect_left(A,s)
        if dex > j:
          d += dex -j -1
print(d)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0

for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], b-a)
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)


Failing test case input:
7
218 1140 205 40 636 890 389

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
import sys

def bi_search(array, target):
    l, r = -1, len(array)-1
    while r-l > 1:
        mid = int((r+l)/2)
        if array[mid] > target:
            r = mid
        else:
            l = mid
    return r

N = int(sys.stdin.readline().strip())
l_list = list(sorted(list(map(int, sys.stdin.readline().strip().split(" ")))))
count = 0


for i in reversed(range(N)):
    a = l_list[i]
    for j in reversed(range(i)):
        b = l_list[j]
        index = bi_search(l_list[:j], a-b)
        
        if index > -1 and index < j and l_list[index] + b > a:
            count += (j-index)

print(count)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






def sol(n,l):
    import bisect
    l.sort()
    a = []
    print(l)
    for i in range(n-2):
        for j in range(i+2,n):
            ind = bisect.bisect_left(l,j-i+1,lo=i+1,hi=j+1)
            print(i,j,ind)
            a.append(ind)
    return len(a)


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


Failing test case input:
7
218 554 380 233 449 890 389

Expected output:
22


Actual output:
[218, 233, 380, 389, 449, 554, 890]
0 2 1
0 3 1
0 4 1
0 5 1
0 6 1
1 3 2
1 4 2
1 5 2
1 6 2
2 4 3
2 5 3
2 6 3
3 5 4
3 6 4
4 6 5
15


Fixed submission (verdict: Accepted):






def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import bisect
 
N = int(input())
Ls = list(map(int, input().split(" ")))
Ls.sort()
 
ans = 0
 
for i in range(0,N-2):
  for j in range(i+1,N-1):
    k = bisect.bisect_left(Ls,Ls[i]+Ls[j])
    l = bisect.bisect_right(Ls,Ls[j])
    ans += k - l
       
print(ans)

Failing test case input:
4
8 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
 
N = int(input())
Ls = list(map(int, input().split(" ")))
Ls.sort()
 
ans = 0
 
for i in range(0,N-2):
  for j in range(i+1,N-1):
    k = bisect.bisect_left(Ls,Ls[i]+Ls[j])
    ans += k - (j + 1)
       
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n=int(input())
l=[int(x) for x in input().split()]
l.sort()
ans=0

print(l)
for i in range(n):
  for j in range(i+1,n):
    k=bisect.bisect_left(l, l[i]+l[j])-1
    ans+=k-j
    
print(ans)

Failing test case input:
7
153 3264 2149 14 248 149 5

Expected output:
3


Actual output:
[5, 14, 149, 153, 248, 2149, 3264]
3


Fixed submission (verdict: Accepted):
import bisect
n=int(input())
L=[int(x) for x in input().split()]
L.sort()
ans=0

for i in range(n):
  for j in range(i+1,n):
    k=bisect.bisect_left(L, L[i]+L[j])-j-1
    ans+=k
    
    
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

N = int(input())
L = [int(l) for l in input().split()]
L.sort()
S = 0
n = 0
print(L)
S = 0
for i in range(N - 2):
    
    for j in range(i + 1, N - 1):
        
        l = L[i] + L[j]
        s = bisect.bisect_left(L, l)
        
        S += bisect.bisect_left(L, L[i] + L[j]) - j - 1

print(S)

Failing test case input:
7
91 574 704 384 645 728 374

Expected output:
25


Actual output:
[91, 374, 384, 574, 645, 704, 728]
25


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
L = [int(l) for l in input().split()]
L.sort()
S = 0
n = 0
S = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        l = L[i] + L[j]
        s = bisect.bisect_left(L, l)
        S += bisect.bisect_left(L, L[i] + L[j]) - j - 1

print(S)

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline

n = int(input())
l = list(map(int,input().split()))
l.sort()
mx = l[-1]+l[-2]

length = [0]*(mx+1)
for i in range(n):
    for j in range(i+1,n):
        length[l[i]+l[j]] -= 1
        length[l[j]-l[i]+1] += 1

for i in range(1,mx+1):
    length[i] += length[i-1]

minus = [0]*n
for i in range(n):
    a = i
    for j in range(i+1,n):
        if l[i]*2 - 1 >= l[j]:
            a += 1
    minus[i] = a


ans = 0
for i in range(n):
    ans += length[l[i]+1] - minus[i]

ans 
if ans < 0:
    ans = 0
print(ans)

Failing test case input:
7
116 1632 609 65 129 190 487

Expected output:
5


Actual output:
15


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline

n = int(input())
l = list(map(int,input().split()))
l.sort()
mx = l[-1]+l[-2]

length = [0]*(mx+1)
for i in range(n):
    for j in range(i+1,n):
        length[l[i]+l[j]] -= 1
        length[l[j]-l[i]+1] += 1

for i in range(1,mx+1):
    length[i] += length[i-1]

minus = [0]*n
for i in range(n):
    a = i
    for j in range(i+1,n):
        if l[i]*2 - 1 >= l[j]:
            a += 1
    minus[i] = a


ans = 0
for i in range(n):
    ans += length[l[i]] - minus[i]


print(ans

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0

print(l)
for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
print(cnt)




Failing test case input:
7
153 3264 1874 14 248 149 5

Expected output:
3


Actual output:
[5, 14, 149, 153, 248, 1874, 3264]
3


Fixed submission (verdict: Accepted):
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0

for i in range(n - 1, 0, -1):
    for j in range(i - 1, -1, -1):
        base = l[i] - l[j]
        idx = bisect.bisect_right(l, base)
        cnt += max(j - idx, 0)
print(cnt)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-1):
    for j in range(i+1,n):
        k=bisect.bisect_left(l,l[j]+1)
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-k,0)
print(cnt)


Failing test case input:
4
5 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
n=int(input())
l=sorted(list(map(int,input().split())))

cnt=0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        p=bisect.bisect_right(l,l[i]+l[j]-1)
        cnt+=max(p-j-1,0)
print(cnt)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    


Failing test case input:
7
218 786 704 271 645 728 389

Expected output:
24


Actual output:
32


Fixed submission (verdict: Accepted):
import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
listl = [int(i) for i in input().split()]

listl.sort(reverse=True)


ans=0

for i in range(n-2):
	for j in range(i+1,n-1):
		for k in range(j+1,n):
			print(listl[i],listl[j],listl[k])
			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
	

Failing test case input:
7
218 1140 551 25 636 890 487

Expected output:
11


Actual output:
1140 890 636
1140 890 551
1140 890 487
1140 890 218
1140 636 551
1140 636 487
1140 551 487
1140 487 218
1140 218 25
890 636 551
890 636 487
890 636 218
890 551 487
890 551 218
890 487 218
890 218 25
636 551 487
636 551 218
636 551 25
636 487 218
636 487 25
636 218 25
551 487 218
551 487 25
551 218 25
487 218 25
11


Fixed submission (verdict: Accepted):
n=int(input())
listl = [int(i) for i in input().split()]


from bisect import bisect_right				 
listl.sort()

ans=0

for i in range(n-1,1,-1):
	a=listl[i]
	for j in range(i-1,0,-1):
		b=listl[j]
		c=bisect_right(listl,a-b)
		
		num = j-c
		if num>0:
			ans+=num
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

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

L.sort(reverse=True)

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        idx=bisect.bisect_left(L,L[i]-L[j])
        ans+=idx-j
print(ans)

Failing test case input:
7
218 1140 1051 233 449 890 389

Expected output:
15


Actual output:
-14


Fixed submission (verdict: Accepted):
import bisect

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

L.sort()

ans=0
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        temp=L[i]-L[j]
        idx=bisect.bisect_right(L,temp)
        ans+=max(0,j-idx)
print(ans)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
wa = 0
for i in range(N):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if(L[i] < L[j]+L[k]):
                wa += N-k
                break
            
print(wa)

Failing test case input:
7
159 613 704 233 645 890 389

Expected output:
19


Actual output:
25


Fixed submission (verdict: Accepted):
N = int(input())
L = list(map(int, input().split()))
L.sort()
wa = 0
import bisect
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        diff = L[i]-L[j]
        k = bisect.bisect_right(L, diff)
        wa += j-k if j-k > 0 else 0           
            
print(wa)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
sticks = list(map(int, input().split()))

sticks.sort(reverse = True)
count = 0
fj = False
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if fj:
            fj=False
            break
        else:
            for k in range(j+1,N):
                
                if sticks[i]<sticks[j]+sticks[k]:
                    count += 1
                else:
                    fj = True
                    break
print(count)

Failing test case input:
7
218 554 380 233 449 890 389

Expected output:
22


Actual output:
16


Fixed submission (verdict: Accepted):
N = int(input())
sticks1 = list(map(int, input().split()))


sticks = sorted(sticks1, reverse=True)

count = 0
jmax = N-2
kmax = N-1
i=0
while i<N-2:
    j= i+1
    while j<jmax+1:
        k=kmax
        while j<k:
            
            if sticks[i]<sticks[j]+sticks[k]:
                count += k-j
                kmax = k
                break
            else:
                k -= 1
                continue
        jmax = kmax-1
        j += 1
    kmax = N-1
    jmax = N-2
    i += 1
      
print(count)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(2, n):
    j = i - 1
    while j >=0 and a[j - 1] + a[j] > a[i]:
        r += j - bisect_right(a, i - j, 0, j)
        j -= 1
print(r)


Failing test case input:
7
540 1452 60 24 75 304 3

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
from bisect import bisect_right

n = int(input())
a = sorted(map(int, input().split()))
r = 0
for i in range(2, n):
    j = i - 1
    while j and a[j - 1] + a[j] > a[i]:
        r += j - bisect_right(a, a[i] - a[j], 0, j)
        j -= 1
print(r)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

N = int(input())
lst =list(map(int, input().split()))
lst.sort()
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        n = lst[i] + lst[j]
        ret += max(0, bisect.bisect_right(lst, lst[i] + lst[j] + 1) - bisect.bisect_right(lst, lst[j] + 1))
print(ret)

Failing test case input:
7
116 1632 609 7 129 232 12

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import bisect

N = int(input())
lst =list(map(int, input().split()))
lst.sort()
ret = 0
for i in range(N):
    for j in range(i + 1, N):
        n = lst[i] + lst[j]
        idx = bisect.bisect_left(lst, n)
        ret += max(0, idx - j - 1)
print(ret)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
A.sort()
from bisect import bisect_left
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        ans += bisect_left(A, A[i] + A[j]) - bisect_left(A, A[j]) - 1
print(ans)


Failing test case input:
4
8 2 2 1

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
A.sort()
from bisect import bisect_left, bisect_right
ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        ans +=bisect_left(A, A[i] + A[j]) - (j + 1)
print(ans)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect

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

L.sort()
print(L)

ans=0
for i in range(N-1,-1,-1):
  for j in range(i-1,-1,-1):
    if L[i]>=2*L[j]:
      break
    
    ans+=j-bisect.bisect(L,L[i]-L[j])
print(ans)

Failing test case input:
7
540 1452 638 24 75 152 3

Expected output:
1


Actual output:
[3, 24, 75, 152, 540, 638, 1452]
1


Fixed submission (verdict: Accepted):
import bisect

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

L.sort()


ans=0
for i in range(N-1,-1,-1):
  for j in range(i-1,-1,-1):
    if L[i]>=2*L[j]:
      break
    
    ans+=j-bisect.bisect(L,L[i]-L[j])
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
L = list(map(int,input().split()))
L.sort()
count = 0
for k in range(N-1,1,-1):
  for j in range(0,k-1):
    if L[k] < L[j] + L[j+1]:
      count = count + (len(L[j:k])*len(L[j+1:k]))
      j = k-2
print(count)

Failing test case input:
7
218 1140 704 233 645 728 389

Expected output:
14


Actual output:
20


Fixed submission (verdict: Accepted):
N = int(input())
L = list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i in range(N):
  for j in range(i+1, N):
    sum = L[i]+L[j]
    count = bisect_left(L, sum)
    ans += max(0, count-j-1)
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
total = 0

for i in range(n-1, -1, -1):
    l = 0
    r = i - 1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += 1
            r -= 1
        else:
            l += 1
print(total)

Failing test case input:
7
218 554 380 233 449 890 389

Expected output:
22


Actual output:
10


Fixed submission (verdict: Accepted):
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
total = 0

for i in range(n-1, -1, -1):
    l = 0
    r = i - 1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += r - l
            r -= 1
        else:
            l += 1
print(total)

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from bisect import bisect_left

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

l.sort()

ans = 0

for i in range(n-2):
    for j in range(n-1):
        ans += bisect_left(l, l[i]+l[j]) - j - 1

print(ans)


Failing test case input:
7
116 3264 995 11 129 232 12

Expected output:
1


Actual output:
25


Fixed submission (verdict: Accepted):
from bisect import bisect_left

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

l.sort()

ans = 0

for i in range(n):
    for j in range(i+1, n):
        tmp = bisect_left(l, l[i]+l[j]) - 1
        ans += tmp - j

print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0







print(Edges)

import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
[1, 2, 2, 6]
1


Fixed submission (verdict: Accepted):
N=int(input())
Edges = list(map(int,input().split()))

Edges=sorted(Edges)
cnt =0









import bisect

for a in range(N-2):
    for b in range(a+1,N-1):
        ab = Edges[a] + Edges[b]

        idx = bisect.bisect_left(Edges,ab)

        cnt += max(0,idx-b-1)


print(cnt)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
count = 0
List = sorted(list(map(int, input().split())))
print(List)
for i in range(N-2):
  for j in range(N-i-2):
    a = List[i]
    b = List[i+j+1]
    index = [i for i, x in enumerate(List) if x >= a+b]
    if index == []:
      index = [N]
    count += index[0]-i-j-2
print(count)

Failing test case input:
7
218 786 704 271 645 728 389

Expected output:
24


Actual output:
[218, 271, 389, 645, 704, 728, 786]
24


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
count = 0
List = sorted(list(map(int, input().split())))
for i in range(N-2):
  for j in range(N-i-2):
    a = List[i]
    b = List[i+j+1]
    index = bisect.bisect_left(List, a+b)
    count += index-i-j-2
print(count)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
L=map(int,input().split())
l=list(L)
result=0
for i in range(0,len(l)-1):
  for j in range(0,len(l)-1):
    for k in range(0,len(l)-1):
      if l[i]>(l[j]+l[k]):
        result+=1

print(result)

Failing test case input:
7
116 1632 609 65 129 190 487

Expected output:
5


Actual output:
44


Fixed submission (verdict: Accepted):
import bisect
N=int(input())
L=map(int,input().split())
l=list(L)
l.sort()

result=0
for i in range(0,N):
  for j in range(i+1,N):
    result += bisect.bisect_left(l,l[i]+l[j])-1-j

print(result)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_left,bisect_right
N = int(input(()))
L = list(map(int,input().split()))
count = 0
L.sort()

for i in range(N-2):
    for j in range(i+1,N-1):
            count += max(bisect_right(L,L[i]+L[j]-1)-j-1,0)

print(count)


Failing test case input:
7
292 833 32 31 128 304 3

Expected output:
4


Actual output:
()4


Fixed submission (verdict: Accepted):
from bisect import bisect_left,bisect_right
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()

for i in range(N-2):
    for j in range(i+1,N-1):
            count += max(bisect_right(L,L[i]+L[j]-1)-j-1,0)

print(count)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

while len(L) > 2:
    for i in range(2,len(L)):
        if L[i] > L[0] + L[1]:
            count += 1
    L.pop(0)

print(count)

Failing test case input:
7
116 1499 551 65 418 890 487

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):

from bisect import bisect_left

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

count = 0

for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        count += bisect_left(L,L[i]+L[j]) - j - 1
        
print(count)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


import bisect

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):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index)
        
print(ans)


Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
8


Fixed submission (verdict: Accepted):


import bisect

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):
        insert_index = bisect.bisect_left(l,l[i]+l[j])
        ans+=(insert_index-j-1)
        
print(ans)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
L = sorted([int(i) for i in input().split()],reverse=True)
from bisect import bisect_right
ans = 0
for i1,a in enumerate(L):
    L_temp = L[i1+1:]
    for i2,b in enumerate(L_temp):
        L_temp2 = L_temp[i2+1:]
        ans += len(L_temp2) - bisect_right(L_temp2,a-b)
print(ans)

Failing test case input:
7
540 7220 638 14 121 152 6

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
L = sorted([int(i) for i in input().split()])
from bisect import bisect_left
ans = 0
for i1,a in enumerate(L):
    L_temp = L[i1+1:]
    for i2,b in enumerate(L_temp):
        L_temp2 = L_temp[i2+1:]
        
        ans += bisect_left(L_temp2,a+b)
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools







INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d = na()

    d.sort()
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            l = bisect.bisect_right(d, d[i] + d[j])
            ans+=l-j-1
    print(ans)


if __name__ == '__main__':
    main()


Failing test case input:
4
5 4 2 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools







INF = sys.maxsize


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d = na()

    d.sort()
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            l = bisect.bisect_left(d, d[i] + d[j])
            ans+=l-j-1
    print(ans)


if __name__ == '__main__':
    main()

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(n-1, j+1, -1):
               if length[k] >= length[i]+length[j]:
                   pass
               else:
                   count += k-j+1
                   break
                
print(count)

Failing test case input:
7
218 1140 704 233 645 728 389

Expected output:
14


Actual output:
12


Fixed submission (verdict: Accepted):
import bisect
n = int(input())
length = list(map(int, input().split()))
length = sorted(length)
count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        insert_index = bisect.bisect_left(length, length[i]+length[j])
        count += insert_index-j-1               
print(count)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        print(i, j, k)
        if L[k-1] > b:
            ans += k - j - 1
print(ans)


Failing test case input:
7
116 1632 609 65 129 214 487

Expected output:
4


Actual output:
0 1 3
0 2 3
0 3 4
0 4 5
0 5 6
0 6 7
1 2 4
1 3 4
1 4 5
1 5 6
1 6 7
2 3 4
2 4 6
2 5 6
2 6 7
3 4 6
3 5 6
3 6 7
4 5 6
4 6 7
5 6 7
4


Fixed submission (verdict: Accepted):
import bisect

n = int(input())
L = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    a = L[i]
    for j in range(i+1, n):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if k > j:
            ans += k - j - 1
print(ans)

Problem: p02888
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()

from bisect import bisect_right
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_right(Ls, Ls[i]+Ls[j])
        ans += idx-j-1

print(ans)

Failing test case input:
4
5 4 3 1

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ls = list(mapint())
Ls.sort()

from bisect import bisect_left
ans = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(Ls, Ls[i]+Ls[j])
        ans += idx-1-j

print(ans)