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()))

ans = 0

l.sort()
print(l)

for i in range(n):
    for j in range(i+1, n):
        gap = l[i] + l[j]
        index = bisect.bisect_right(l, gap)

        ans += max(0, index-j-1)

print(ans)

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

Expected output:
12


Actual output:
[49, 218, 487, 551, 660, 890, 1140]
12


Fixed submission (verdict: Accepted):
import bisect

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

ans = 0

l.sort()

for i in range(n):
    for j in range(i+1, n):
        gap = l[i] + l[j]
        index = bisect.bisect_left(l, gap)

        ans += max(0, index-j-1)

print(ans)

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


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
print(L)
for i in range(N - 1):
    a = L[i]
    for j in range(i, N - 2):
        b = L[j + 1]
        index = bisect.bisect_left(L[j + 2:], a + b)
        for k in range(0, index):
            
            c = (L[j + 2:])[k]
            if b + c > a and a + c > b:
                num += 1

print(num)

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

Expected output:
0


Actual output:
[9, 14, 121, 152, 329, 638, 7220]
0


Fixed submission (verdict: Accepted):
import bisect


N = int(input())
str_l = input()
num = 0
L = []
for v in str_l.split(' '):
    L.append(int(v))

L.sort()
for i in range(N - 1):
    a = L[i]
    for j in range(i, N - 2):
        b = L[j + 1]
        index = bisect.bisect_left(L[j + 2:], a + b)
        num += index
        
        
        
        

print(num)

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

import bisect

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):
        k = bisect.bisect_left(L,L[i]+L[j])
        l = bisect.bisect_right(L,L[j])
        count += k - l 
print(count)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

import bisect

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):
        k = bisect.bisect_left(L,L[i]+L[j])
        count += k - j - 1 
        
print(count)
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
    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 < j and l_list[index] + b > a:
            count += (j-index)

print(count)

Failing test case input:
7
170 163 107 95 129 145 196

Expected output:
35


Actual output:
20


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import bisect
from heapq import heappop, heappush

import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
l = sorted(LIST(), reverse = True)
res = 0

for i in range(n-2):
    flag = False
    for j in range(i+1, n-1):
        if flag:
            break
        for k in range(j+1, n):
            if l[i] >= l[j] + l[k]:
                flag = True
                break
            res += 1
    

print(res)





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

Expected output:
12


Actual output:
8


Fixed submission (verdict: Accepted):
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import bisect
from heapq import heappop, heappush

import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
l = sorted(LIST())
res = 0

for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        index = bisect.bisect_left(l,a+b)
        res += max(index-j-1,0)

print(res)
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-2):
    a = L[i]
    for j in range(i+1, n-1):
        b = L[j]
        k = bisect.bisect_left(L, a+b)
        if L[k - 1] > b:
            ans += k - j - 1
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())
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 (Python (3.4.3), verdict: Wrong Answer):
import bisect
N= int(input())
L = list(map(int, input().split()))

L.sort(reverse=True)

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

print(count)

Failing test case input:
7
116 3264 995 11 248 232 18

Expected output:
2


Actual output:
[3264, 995, 248, 232, 116, 18, 11]
2


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

L.sort(reverse=True)


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

print(count)

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


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


ans = 0

for ib in range(0,N-2):
    for ic in range(ib+2, N):
        if L[ic] - L[ib] <= 0:
            continue
        if L[ic] - L[ib] > L[ib]:
            l = bisect_right(L, L[ic] - L[ib], lo=ib, hi=ic)
        else:
            l = bisect_left(L, L[ib], lo=ib, hi=ic) + 1

        
        ans += max(ic - l , 0)

print(ans)


Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


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


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):
        l = L[j] - L[i]
        r = L[j] + L[i]

        il = bisect_right(L, l, j)
        ir = bisect_left(L, r, j)

        if il == N-1:
            break

        ans += ir - il - 1

print(ans)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from bisect import bisect_right
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

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

print(res)


Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
from bisect import bisect_left
N = int(input())
L = sorted([int(i) for i in input().split()])

res = 0

for i in range(N):
    for j in range(i+1, N):
        r = bisect_left(L, L[i]+L[j])
        res += max(r-(j+1), 0)

print(res)

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n = int(input())
l = [int(x) for x in input().split()]

l.sort()

ans = 0
for a in range(n - 1):
    for b in range(a + 1, n):
        c = bisect.bisect(l, l[a] + l[b])
        if b < c:
            ans += c - (b + 1)

print(ans)

Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


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

l.sort()

ans = 0
for a in range(n):
    for b in range(a + 1, n):
        c = bisect.bisect_left(l, l[a] + l[b])
        if b < c:
            ans += c - (b + 1)

print(ans)

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

    L = sorted(L, reverse=True)

    ans = 0
    for i in range(N-2):

        
        

        if (L[i] + L[i+1]) > L[i+2] and (L[i] + L[i+2]) > L[i+1] and (L[i+1] + L[i+2]) > L[i]:
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()



Failing test case input:
7
218 410 704 233 449 890 389

Expected output:
18


Actual output:
5


Fixed submission (verdict: Accepted):
import bisect

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

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

l.sort()
result =0
for i in range(n-2):
    a =l[i]
    for j in range(i+1,n-1):
        b=l[j]
        k = bisect_left(l,a+b-1)
        result += k-j-1

print(result)




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

Expected output:
2


Actual output:
1


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

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

l.sort()
result =0
for i in range(n-2):
    a =l[i]
    for j in range(i+1,n-1):
        b=l[j]
        k = bisect_left(l,a+b)
        result += k-j-1

print(result)
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

print(l_list)
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
540 6479 638 24 121 152 4

Expected output:
2


Actual output:
[4, 24, 121, 152, 540, 638, 6479]
0


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 (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+=p-k
print(cnt)


Failing test case input:
4
8 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):
n = int(input())
 
l = list(map(int, input().split()))
l.sort()
a = 0
 
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j >= l[i]+l[j]:
            a+=1
        
 
print(a)

Failing test case input:
4
5 4 3 1

Expected output:
1


Actual output:
0


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

for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a+=s


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

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

L = sorted(L)
print(L)
for c in reversed(range(2, N)):
	for b in reversed(range(1, c)):
		a = bisect.bisect_left(L, L[c]-L[b])
		if a<b:
			s += b-a
print(s)

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

Expected output:
15


Actual output:
[218, 233, 389, 449, 890, 1051, 1140]
15


Fixed submission (verdict: Accepted):
import bisect

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

L = sorted(L)

for c in reversed(range(2, N)):
	for b in reversed(range(1, c)):
		a = bisect.bisect_right(L, L[c]-L[b])
		if a<b:
			s += b-a
print(s)

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

N = int(input())
D = input().split(' ')

D.sort(reverse=True)

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(N - j - 1):
            
            if int(D[i]) < int(D[j]) + int(D[N - k - 1]):
                
                count += 1


print(count)
    

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

Expected output:
17


Actual output:
29


Fixed submission (verdict: Accepted):
from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

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

print(count)

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

N = int(input())
L = sorted(map(int, input().split(' ')))

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

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())
L = sorted(map(int, input().split(' ')))

ans = 0
for i in range(len(L)):
    for j in range(i + 1, len(L)):
        a = L[i]
        b = L[j]
        ans += max(0, bisect.bisect_right(L, a + b - 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 = sorted(L)
ct = 0

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_right(L, a+b)
        ct += up_bound - (j+1)

print(ct)


Failing test case input:
4
6 4 2 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import bisect

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_left(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 1










print(ans/ 3)




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

Expected output:
10


Actual output:
10.0


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from bisect import bisect_left, bisect_right
n = getN()

nums = getList()
nums.sort()

ans = 0
for i, num1 in enumerate(nums):
    for j , num2 in enumerate(nums[i+1:]):
        tmp = num1 + num2
        idx_min = bisect_left(nums, tmp)
        idx_max = bisect_right(nums, num2 - num1)
        
        ans += idx_min - idx_max - 2
        if num2 >= num1 * 2:
            ans += 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()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b
    else:
      i=i
print(i)

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

Expected output:
1


Actual output:
22


Fixed submission (verdict: Accepted):
import bisect
N=int(input())
L=list(map(int,input().split()))
i=0
L=sorted(L)
for a in range(N):
  for b in range(a+1,N):
    c=bisect.bisect_left(L,L[a]+L[b])
    if c>b:
      i+=c-b-1
    else:
      i=i
print(i)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
N=int(input())
L=map(int,input().split())
l=list(L)
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)

Failing test case input:
7
116 1632 609 48 129 214 24

Expected output:
3


Actual output:
24


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
import bisect
n=int(input())
List = [int(i) for i in input().split()]
List2=sorted(List)
ans = 0

for i in range(0,n-1): 
  for j in range(i+1,n):
    
    tmp1 = List2[i]
    tmp2 = List2[j]
    
    a=bisect.bisect_right(List2,tmp1+tmp2) -j-1
    ans += a
    
print(ans)


Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
import bisect
n=int(input())
List = [int(i) for i in input().split()]
List2=sorted(List)
ans = 0

for i in range(0,n-1): 
  for j in range(i+1,n):
    
    tmp1 = List2[i]
    tmp2 = List2[j]
    
    a=bisect.bisect_left(List2,tmp1+tmp2)
    ans += a -j-1
    
print(ans)

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

N = int(input())
L = sorted([int(n) for n in input().split()])



total = 0

for i in range(len(L)):
    for j in range(i):
        a = L[i]
        b = L[j]

        right_index = bisect.bisect_left(L, a + b)
        left_index = bisect.bisect_right(L, abs(a - b))

        total += right_index - left_index
        
        
        
        
        



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

Expected output:
6


Actual output:

Fixed submission (verdict: Accepted):
import bisect

N = int(input())
L = [int(n) for n in input().split()]
L = sorted(L)

total = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        right_endpoint = bisect.bisect_left(L, a+b, j)
        total += right_endpoint - j - 1

print(total)

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

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

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

Expected output:
1


Actual output:
71


Fixed submission (verdict: Accepted):
N = int(input())
L = list(map(int,input().split()))
import bisect
 
L.sort()
ans = 0
 
for i in range(N-2):
  for j in range(i+1,N-1):
    ans += bisect.bisect_left(L,L[i]+L[j])-(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()
count=0
for i in range(N-2):
    for j in range(i+1,N-1):
        a=L[i]
        b=L[j]
        count+=bisect.bisect_left(L,a+b)-bisect.bisect_right(L,b)
print(count)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import bisect
N=int(input())
L=list(map(int,input().split()))
L.sort()
count=0
for i in range(N-2):
    for j in range(i+1,N-1):
        a=L[i]
        b=L[j]
        count+=bisect.bisect_left(L,a+b)-(j+1)
print(count)
Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
l = sorted(list(map(int, input().split())))
 
from bisect import bisect_left, bisect_right

cnt = 0
for i in range(N):
    a = l[i]
    for j in range(i+1, N):
        b = l[j]
        start = bisect_right(l, b)
        end = bisect_left(l, a+b)
        cnt += len(l[start:end])
print(cnt)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


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

cnt = 0
for i in range(N):
    a = l[i]
    for j in range(i+1, N):
        b = l[j]
        cnt += bisect_left(l[j+1:], a+b)
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()

ans=0
for a in range(n):
    for b in range(a+1,n):
        ans+=bisect.bisect_right(l,l[a]+l[b])-b
        
print(ans)

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

Expected output:
1


Actual output:
22


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

ans=0
for a in range(n-2):
    for b in range(a+1,n-1):
        ans+=max(0,bisect_left(l, l[a] + l[b])-b-1)
        
        
print(ans)

Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
L = list(map(int,input().split()))
L.sort()
print(L)
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)
    print(count)
    ans += max(0, count-j-1)
    print(ans)
print(ans)

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

Expected output:
3


Actual output:
[9, 14, 121, 152, 153, 638, 7220]
2
0
3
0
5
1
5
1
6
1
7
1
3
1
5
2
5
2
6
2
7
2
5
3
5
3
6
3
7
3
5
3
6
3
7
3
6
3
7
3
7
3
3


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 (Python (3.4.3), verdict: Wrong Answer):
import bisect

N = int(input())
L = [int(n) for n in input().split()]
L = sorted(L)



total = 0

for i in range(len(L)):
    for j in range(i):
        a = L[i]
        b = L[j]

        right_index = bisect.bisect_left(L, a + b)
        left_index = bisect.bisect_right(L, abs(a - b))

        total += right_index - left_index
        
        
        
        
        



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

Expected output:
6


Actual output:

Fixed submission (verdict: Accepted):
import bisect

N = int(input())
L = [int(n) for n in input().split()]
L = sorted(L)

total = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        right_endpoint = bisect.bisect_left(L, a+b, j)
        total += right_endpoint - j - 1

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

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:], ia):
        print(L, a+b, bisect_left(L, a+b) - ib - 2)
        ans += bisect_left(L, a+b) - ib - 2

print(ans)


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

Expected output:
3


Actual output:
[5, 14, 149, 153, 248, 1874, 3264] 19 0
[5, 14, 149, 153, 248, 1874, 3264] 154 1
[5, 14, 149, 153, 248, 1874, 3264] 158 0
[5, 14, 149, 153, 248, 1874, 3264] 253 0
[5, 14, 149, 153, 248, 1874, 3264] 1879 0
[5, 14, 149, 153, 248, 1874, 3264] 3269 0
[5, 14, 149, 153, 248, 1874, 3264] 163 1
[5, 14, 149, 153, 248, 1874, 3264] 167 0
[5, 14, 149, 153, 248, 1874, 3264] 262 0
[5, 14, 149, 153, 248, 1874, 3264] 1888 0
[5, 14, 149, 153, 248, 1874, 3264] 3278 0
[5, 14, 149, 153, 248, 1874, 3264] 302 1
[5, 14, 149, 153, 248, 1874, 3264] 397 0
[5, 14, 149, 153, 248, 1874, 3264] 2023 0
[5, 14, 149, 153, 248, 1874, 3264] 3413 0
[5, 14, 149, 153, 248, 1874, 3264] 401 0
[5, 14, 149, 153, 248, 1874, 3264] 2027 0
[5, 14, 149, 153, 248, 1874, 3264] 3417 0
[5, 14, 149, 153, 248, 1874, 3264] 2122 0
[5, 14, 149, 153, 248, 1874, 3264] 3512 0
[5, 14, 149, 153, 248, 1874, 3264] 5138 0
3


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

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:], ia):
        ans += bisect_left(L, a+b) - ib - 2

print(ans)

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

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

    print(L)

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

if __name__ == '__main__':
    solve()


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

Expected output:
21


Actual output:
[218, 233, 389, 449, 554, 704, 890]
21


Fixed submission (verdict: Accepted):
import bisect

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

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

if __name__ == '__main__':
    solve()
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
 
l = list(map(int, input().split()))
 
a = 0
 
for i in range(len(l)):
    for j in range(i+1,len(l)):
        if j > l[i]+l[j]:
            a+=1
        
 
print(a)

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

Expected output:
5


Actual output:
0


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

for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a+=s


print(a)

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


print(a)

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()
a = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        s = bisect.bisect_left(l,l[i]+l[j])-j-1
        a+=s


print(a)

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()
result=0
for i in range(N-2):
    for j in range(N-1):
        result+=bisect_left(L,L[i]+L[j])-j-1
print(result)

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

Expected output:
8


Actual output:
42


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

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

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def find(edges):
    import bisect
    edges=sorted(edges)
    ans=0
    for i in range(len(edges)):
        for j in range(i+1,len(edges)):
            temp=edges[i]+edges[j]
            pos=bisect.bisect_left(edges,temp)
            ans+=max(0,pos-1-j)
            print(edges[i],edges[j],max(0,pos-1-j))
    return ans

input()
print(find(list(map(int,input().strip().split(" ")))))

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

Expected output:
1


Actual output:
7 12 0
7 116 0
7 129 0
7 232 0
7 1217 0
7 1632 0
12 116 0
12 129 0
12 232 0
12 1217 0
12 1632 0
116 129 1
116 232 0
116 1217 0
116 1632 0
129 232 0
129 1217 0
129 1632 0
232 1217 0
232 1632 0
1217 1632 0
1


Fixed submission (verdict: Accepted):
def find(edges):
    import bisect
    edges=sorted(edges)
    ans=0
    for i in range(len(edges)):
        for j in range(i+1,len(edges)):
            temp=edges[i]+edges[j]
            pos=bisect.bisect_left(edges,temp)
            ans+=max(0,pos-1-j)
            
    return ans

input()
print(find(list(map(int,input().strip().split(" ")))))
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_right(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)


Failing test case input:
4
5 4 3 1

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect

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

for i in range(N-1):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        up_bound = bisect.bisect_left(L, a+b)
        ct += max(0, up_bound - (j+1))

print(ct)

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

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

L.sort()

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

print(ans)    


Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


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

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

L.sort()

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

print(ans)

Problem: p02888
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from bisect import *

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        lower = bisect_right(l, b)
        upper = bisect_left(l, a+b)
        cnt += upper - lower
print(cnt)

Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


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

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

cnt = 0

for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        k = bisect_left(l, a+b)
        cnt += k-(j+1)
print(cnt)

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

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

Expected output:
1


Actual output:
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 5 0
1 5 6 0
1 6 7 0
2 3 4 0
2 4 5 0
2 5 6 0
2 6 7 0
3 4 6 1
3 5 6 1
3 6 7 1
4 5 6 1
4 6 7 1
5 6 7 1
1


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i+1, N):
        t = L[i] + L[j]
        idx = bisect.bisect_left(L, t)
        ans += max(0, idx-j-1)
print(ans)
Problem: p02888
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()

Failing test case input:
4
5 4 2 1

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            k = bisect.bisect_left(l, l[i]+l[j])
            res += max(k-(j+1), 0)
    print(res)
    return 0

if __name__ == "__main__":
    solve()

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(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i]+1)-bisect.bisect(ls1,ls[j]-ls[i]-1)
print(ans)

Failing test case input:
4
5 4 3 1

Expected output:
1


Actual output:
3


Fixed submission (verdict: Accepted):
import bisect
N = int(input())
ls = list(map(int,input().split()))
ls.sort()
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ls1 = ls[j+1:]
        ans += bisect.bisect_left(ls1,ls[j]+ls[i])-bisect.bisect(ls1,ls[j]-ls[i])
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)
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)


 

 


                                        




    




        


    







        



Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
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)
Problem: p02888
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
count = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        index = bisect.bisect_right(l,l[i]+l[j],j)
       
        count += index-j-1
print(count)

Failing test case input:
4
5 4 2 1

Expected output:
1


Actual output:
2


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

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

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


import bisect

N = int(input())
L_list = list(map(int, input().split()))
L_list = sorted(L_list)
count = 0

for a in range(N-2):
    for b in range(a + 1, N-1):
        c_min = max(L_list[a] - L_list[b], L_list[b] - L_list[a], L_list[b])
        c_max = L_list[a] + L_list[b]
        count_c = bisect.bisect_right(L_list, c_max) - bisect.bisect_right(L_list, c_min)
        count += count_c

print(count)

Failing test case input:
4
8 2 1 1

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):


import bisect

N = int(input())
L_list = list(map(int, input().split()))
L_list = sorted(L_list)
count = 0

for a in range(N-2):
    for b in range(a + 1, N-1):
        c_min = L_list[b + 1]
        c_max = L_list[a] + L_list[b]
        c_max_idx = bisect.bisect_left(L_list, c_max)
        c_count = c_max_idx - (b + 1)
        count += c_count

print(count)

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

listl.reverse()

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

			if listl[i]<listl[j]+listl[k]:
				ans=ans+1
			else:
				break	
print(ans)
				 
		

Failing test case input:
7
116 3264 1874 11 248 232 18

Expected output:
2


Actual output:
23


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):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]+l[j]>l[k]:
        ans+=1
        
    
print(ans)

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

Expected output:
3


Actual output:
34


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 (Python (3.4.3), verdict: Wrong Answer):
import sys
import heapq


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())), reverse=True)
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            for k in range(j+1, N):
                if L[i] < L[j] + L[k]:
                    print(L[i], L[j], L[k])
                    cnt += 1
    print(cnt)


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

Expected output:
15


Actual output:
1140 1051 890
1140 1051 449
1140 1051 389
1140 1051 233
1140 1051 218
1140 890 449
1140 890 389
1051 890 449
1051 890 389
1051 890 233
1051 890 218
449 389 233
449 389 218
449 233 218
389 233 218
15


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


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    L = sorted(list(map(int, input().split())))
    cnt = 0
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            b = bisect.bisect_left(L, L[i]+L[j])
            cnt += b-j-1
    print(cnt)

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-2):
  for j in range(i+1,n-1):
    k=bisect.bisect_left(L, L[i]+L[j])-1
    ans+=k-j
    
    
print(ans)

Failing test case input:
7
170 163 107 95 129 145 196

Expected output:
35


Actual output:
[95, 107, 129, 145, 163, 170, 196]
35


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 (Python (3.4.3), verdict: Wrong Answer):
import bisect

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

print(L)

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += N - bisect.bisect_left(L,L[m]+L[n])

print(count)


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

Expected output:
11


Actual output:
[40, 116, 487, 551, 806, 890, 1140]
24


Fixed submission (verdict: Accepted):
import bisect

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

count = 0
for n in range(N-2):
    for m in range(n+1,N-1):
        count += bisect.bisect_left(L,L[m]+L[n]) - (m + 1)

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

import math
import heapq
import bisect

MOD = 10**9+7

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

ans = 0
for a in range(N-2):
    for b in range(a+1,N-1):
        c = bisect.bisect_left(L,a+b)
        ans += c-b-1
            
print(ans)

Failing test case input:
7
116 1140 551 39 660 890 487

Expected output:
11


Actual output:
-70


Fixed submission (verdict: Accepted):

import math
import heapq
import bisect

MOD = 10**9+7

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

ans = 0
for a in range(N-2):
    for b in range(a+1,N-1):
        c = bisect.bisect_left(L,L[a]+L[b])
        ans += c-b-1
            
print(ans)

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

cnt = 0
for i in range(0, n):
    a = l[i]
    if i < len(l) - 1:
        b = l[i + 1]
    else:
        b = l[0]
    for j in range(0, n):
        if l[j] == a or l[j] == b:
            pass
        else:
            c = l[j]

            if a < b + c and b < c + a and c < a + b:
                cnt += 1
            else:
                continue
print(cnt)


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 = [x for x in map(int, input().split())]
l = sorted(l)

cnt = 0
for i in range(n - 2):
    a = l[i]
    k = i + 2
    for j in range(i + 1, n - 1):
        b = l[j]
        while(l[k] < a + b):
            k += 1
            if k == n:
                break
            else:
                pass

        k -= 1
        cnt += k - j
print(cnt)

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(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if i<j+k and j<k+i and k<i+j:
        ans += 1
print(ans)

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

Expected output:
3


Actual output:
7


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

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

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

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

N = int(input())
D = input().split(' ')

D.sort(reverse=True)

count = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if int(D[i]) < int(D[j]) + int(D[k]):
                count += 1


print(count)
    

Failing test case input:
7
153 5288 2149 14 416 149 5

Expected output:
2


Actual output:
14


Fixed submission (verdict: Accepted):
from bisect import bisect_right
N = int(input())
D = list(map(int, input().split()))
D.sort(reverse=False)

count = 0

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

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

import sys
import itertools

def solve(N: int, L: "List[int]"):
    ans = 0
    ls = list(set(L))
    from collections import Counter
    c = Counter(L)

    for x,y,z in list(itertools.combinations(ls, 3)):
        if(x < y+z and y < x+z and z < x+y):
            ans += c[x]*c[y]*c[z]

    print(ans)    

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = [int(next(tokens)) for _ in range(N)]  
    solve(N, L)

if __name__ == '__main__':
    main()


Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

import sys

from bisect import bisect_left, bisect_right



def solve(N: int, L: "List[int]"):
    ans = 0
    L.sort()

    for x in range(N):
        for y in range(x+1,N):
            ze = bisect_left(L, L[x]+L[y])            
            ans += (ze-y-1)
            
    print(ans)

    return
 



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = [int(next(tokens)) for _ in range(N)]  
    solve(N, L)

if __name__ == '__main__':
    main()

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

Failing test case input:
4
5 4 2 1

Expected output:
1


Actual output:
2


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

Problem: p02888
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
max_l = max(l_list)
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a = l_list[i]
        b = l_list[j]
        low = max((abs(a - b), a, b))
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        id2 = bisect_right(l_list, low)
        tmp = max(0, id1 - id2)
        ans += tmp
print(ans)


Failing test case input:
4
6 2 2 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
from bisect import *
ans = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        a = l_list[i]
        b = l_list[j]
        high = a + b
        id1 = bisect_right(l_list, high - 1)
        ans += max(0, id1 - (j + 1))
print(ans)