Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k,x = map(str, input().split())
x.count("ABC")

Fixed submission:
n = int(input())
s = str(input())
cnt = 0
# s.count("ABC")
for i in range(n):
#   print(s[i:i+3].find("ABC"))
  if s[i:i+3].find("ABC") ==0:
    cnt = cnt+1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 1
i_before = a[0]
for i in a[1:]:
    ans *= (i - i_before)
    i_before=i

if ans ==0:
    print('NO')
else:
    print('YES')

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
import collections
a_c = collections.Counter(a)
if sum(a_c.values()) == len(a_c.values()):
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

ans = 1 #i=1は絶対満たす
for i in range(1,n):
    if p[i] == min(p[:(i+1)]):
        ans += 1
    
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 1 #i=1は絶対満たす
now_min = p[0]
for i in range(1,n):
    if p[i] <= now_min:
        ans+=1
        now_min = p[i]
print(ans)

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

ans = 1 #i=1は絶対満たす
for i in range(1,n):
    tmp = 1
    for j in range(0,i):
        if p[i] > p[j]:
            tmp = 0
            break
    ans += tmp
print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 1 #i=1は絶対満たす
now_min = p[0]
for i in range(1,n):
    if p[i] <= now_min:
        ans+=1
        now_min = p[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k,s = map(int, input().split())
if s==1:
    xx = 2
else:
    for i in range(2,s//2):
        if s%i != 0:
            xx = i
            break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))

Fixed submission:
n,k,s = map(int, input().split())
if s<5:
    xx = 1 + s
else:
    for i in range(2,s):
        if s%i != 0:
            xx = i
            break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
n,k,s = map(int, input().split())
for i in range(2,s//2):
    if s%i != 0:
        xx = i
        break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))

Fixed submission:
n,k,s = map(int, input().split())
if s<5:
    xx = 1 + s
else:
    for i in range(2,s):
        if s%i != 0:
            xx = i
            break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))

Buggy python submission (verdict: Runtime Error):
n,k,s = map(int, input().split())
for i in s//2:
    if s%i == 0:
        xx = i
        break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))

Fixed submission:
n,k,s = map(int, input().split())
if s<5:
    xx = 1 + s
else:
    for i in range(2,s):
        if s%i != 0:
            xx = i
            break
ans = [xx]* n
for i in range(k):
    ans[i] = s
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
wa = 0
ac = 0
ac_list = []
if m==0:
    print(0,0)
else:
    for i in range(m):
        p,s = input().split()
        if s=='WA' & ac_list.count(p) ==0:
            wa += 1
        elif ac_list.count(p) ==0:
            ac_list.append(p)
            ac += 1
        else:
            pass
    print(ac, wa)

Fixed submission:
n,m = map(int, input().split())
wa = 0
ac_list = {'AC':{}, 'WA':{}}
if m==0:
    print(0,0)
else:
    for i in range(m):
        p,s = input().split()
        ac_list[s][p] = ac_list[s].get(p, 0) + 1* int(not(p in ac_list['AC'].keys()))
    kyotu_key = list(set(ac_list['AC'].keys()) & set(ac_list['WA'].keys()))
    wa_list = [ac_list['WA'][p] for p in kyotu_key]
    print(len(ac_list['AC'].keys()), sum(wa_list))

Buggy python submission (verdict: Runtime Error):
wa = 0
ac = 0
ac_list = []
if m==0:
    print(0,0)
else:
    for i in range(m-1:
        p,s = input().split()
        if s=='WA':
            wa += 1
        elif ac_list.count(p) ==0:
            ac_list.append(p)
            ac += 1
        else:
            pass

Fixed submission:
n,m = map(int, input().split())
wa = 0
ac_list = {'AC':{}, 'WA':{}}
if m==0:
    print(0,0)
else:
    for i in range(m):
        p,s = input().split()
        ac_list[s][p] = ac_list[s].get(p, 0) + 1* int(not(p in ac_list['AC'].keys()))
    kyotu_key = list(set(ac_list['AC'].keys()) & set(ac_list['WA'].keys()))
    wa_list = [ac_list['WA'][p] for p in kyotu_key]
    print(len(ac_list['AC'].keys()), sum(wa_list))
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
ans = max([a,b])
while True:
    if (ans%a + ans%b) == 0:
        print(ans)
        break
    ans += 1

Fixed submission:
ab = list(map(int, input().split()))
a = max(ab)
b = min(ab)
r = a%b
while r!=0:
    a = b
    b = r
    r = a%b
print(int(max(ab) * min(ab)/b))

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
ans = 1
while True:
    if (ans%a + ans%b) == 0:
        print(ans)
        break
    ans += 1

Fixed submission:
ab = list(map(int, input().split()))
a = max(ab)
b = min(ab)
r = a%b
while r!=0:
    a = b
    b = r
    r = a%b
print(int(max(ab) * min(ab)/b))

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input())
ans = 1
while True:
    if (ans%a + ans%b) == 0:
        print(ans)
        break
    ans += 1

Fixed submission:
ab = list(map(int, input().split()))
a = max(ab)
b = min(ab)
r = a%b
while r!=0:
    a = b
    b = r
    r = a%b
print(int(max(ab) * min(ab)/b))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

Fixed submission:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    i = 1
    a_l = a_l[a_l.index(i)+1:]
    i += 1
    while True:
        if a_l.count(i) > 0:
            a_l = a_l[a_l.index(i)+1:]
            i += 1
        else:
            break
    print(n - (i-1))

Fixed submission:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    i = 1
    a_l = a_l[a_l.index(i)+1:]
    i += 1
    while True:
        if a_l.count(i) > 0:
            a_l = a_l[a_l.index(i)+1:]
            i += 1
        else:
            break
    print(n - (i-1))

Fixed submission:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
else:
    i = 1
    a_l = a_l[a_l.index(i)+1:]
    i += 1
    while True:
        if a_l.count(i) > 0:
            a_l = a_l[a_l.index(i)+1:]
            i += 1
        else:
            break
print(n - (i-1))

Fixed submission:
n = int(input())
a_l = list(map(int, input().split()))
if min(a_l) !=1:
    print(-1)
    exit()
else:
    ans = 1
    for i in a_l:
        if i == ans:
            ans += 1
print(n-ans+1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input()))
ans = []
for i in range(n):
    for j in range(i+1,n):
        ans.append(nums[i] * nums[j])
print(sum(ans))

Fixed submission:
n = int(input())
nums = list(map(int, input().split()))
ans = []
for i in range(n):
    for j in range(i+1,n):
        ans.append(nums[i] * nums[j])
print(sum(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans+=bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)  

Fixed submission:
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
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)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = sorted(list(map(int, input().split())))
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 += 1
            else:
                break
print(ans)

Fixed submission:
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
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)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))
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]) & ((l[j]+l[k]) > l[i]) & ((l[k]+l[i]) > l[j]):
                ans += 1 
print(ans)

Fixed submission:
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
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)
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

print(np.sum(h>=k))

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
print(len([i for i in h if i>=k]))
Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
def make_soinsu(n):
    ans_val = [1]
    while n %2 == 0:
        ans_val.append(2)
        n /= 2
    s = 3
    while (n!=1):
        if n % s == 0:
            ans_val.append(s)
            n /= s
            s = 3
        else:
            s += 2
    ans_val = set(ans_val) #ダブりは削除。ダブりを残す場合は消す(4の場合は1,2となり、2は二つでない。)
    return ans_val
a_list = make_soinsu(a)
b_list = make_soinsu(b)
ans = 0
for i in a_list:
    if i in b_list:
        ans+=1
print(ans)

Fixed submission:
a,b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
import collections
a_list = collections.Counter(prime_factorize(a)).keys()
b_list = collections.Counter(prime_factorize(b)).keys()
ans = 0
for i in a_list:
    if i in b_list:
        ans+=1
print(ans+1) #1が入っていないから

Buggy python submission (verdict: Time Limit Exceeded):
a,b = map(int, input().split())
def make_soinsu(n):
    ans_val = [1]    
    s = 2
    while (n!=1):
        if n % s == 0:
            ans_val.append(s)
            n /= s
            s = 2
        else:
            s += 1
    ans_val = set(ans_val) #ダブりは削除。ダブりを残す場合は消す(4の場合は1,2となり、2は二つでない。)
    return ans_val
a_list = make_soinsu(a)
b_list = make_soinsu(b)
ans = 0
for i in a_list:
    if i in b_list:
        ans+=1
print(ans)

Fixed submission:
a,b = map(int, input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
import collections
a_list = collections.Counter(prime_factorize(a)).keys()
b_list = collections.Counter(prime_factorize(b)).keys()
ans = 0
for i in a_list:
    if i in b_list:
        ans+=1
print(ans+1) #1が入っていないから
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k,q = map(int, input().split())
a = [int(input()) for _ in range(q)]
point_list  = np.array([k] * n)

for i in a:
    point_list -= 1
    point_list[i-1] += 1

for i in point_list:
    if i >0:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q = map(int, input().split())
a = [int(input()) for _ in range(q)]
point_list  = [k-q] * n 
for i in a:
    point_list[i-1] += 1
for i in point_list:
    if i >0:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Runtime Error):
import numpy as np
n,k,q = map(int, input().split())
a = [input() for _ in range(q)]
point_list  = np.array([k] * n)

for i in a:
    print(point_list)
    point_list -= 1
    point_list[i-1] += 1

for i in point_list:
    if i >0:
        print('Yes')
    else:
        print('No')

Fixed submission:
n,k,q = map(int, input().split())
a = [int(input()) for _ in range(q)]
point_list  = [k-q] * n 
for i in a:
    point_list[i-1] += 1
for i in point_list:
    if i >0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(m):
    a.sort(reverse=True)
    a[0] = a[0]//2

print(sum(a))

Fixed submission:
import heapq
n,m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))

heapq.heapify(a)#ヒープ化
for i in range(m):
    tmp_max = heapq.heappop(a)
    heapq.heappush(a,tmp_max - tmp_max//2) #プッシュ
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[n-1]]
for i in range(n-2):
    a.append(min(b[i:i+2]))
print(sum(a))

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
a = [b[0], b[n-2]]
for i in range(n-2):
    a.append(min(b[i:i+2]))
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
if n==1:
    print(0)
else:
    print(sum([i for i in range(n)]))

Fixed submission:
n = int(input())
print((n-1)*n//2)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append([ba_tmp[1], [ba_tmp[0]])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Fixed submission:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append(ba_tmp[::-1])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
b_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append([ba_tmp[1], ba_tmp[0]])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Fixed submission:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append(ba_tmp[::-1])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Buggy python submission (verdict: Runtime Error):
n = int(input())
b_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append([ba_tmp[1], [ba_tmp[0]])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Fixed submission:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append(ba_tmp[::-1])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int, input().split())
ans_1 = w*h/2
ans_2 = 0
if (x==w/2) and (h == y/2):
    ans_2 = 1
print(" ".join([ans_1,ans_2]))

Fixed submission:
w,h,x,y = map(int, input().split())
ans_1 = w*h/2
ans_2 = 0
if (x==(w/2)) and (y == (h/2)):
    ans_2 = 1
print(" ".join(map(str, [ans_1,ans_2])))

Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int, input().split())
ans_1 = w*h/2
ans_2 = 0
if (x==w/2) and (h == y/2):
    ans_2 = 1
print("".join(map(str, ans_1,ans_2)))

Fixed submission:
w,h,x,y = map(int, input().split())
ans_1 = w*h/2
ans_2 = 0
if (x==(w/2)) and (y == (h/2)):
    ans_2 = 1
print(" ".join(map(str, [ans_1,ans_2])))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
array = list(map(int, input().split()))

sum = 0
max = 0
max_index = K

for i in range(K):
    sum += array[i]
    max = sum

for i in range(K, N):
    sum += array[i] - array[i - K]
    if sum > max:
        max = sum
        max_index = i

E = [(array[x] + 1) / 2 for x in range(max_index - K + 1, max_index + 1)]

sum2 = 0
for x in E:
    sum2 += x

print(sum2)

Fixed submission:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
array = list(map(int, input().split()))

sum = 0
max = 0

for i in range(K):
    sum += array[i]
    max = sum

for i in range(K, N):
    sum += array[i] - array[i - K]
    if sum > max:
        max = sum

E = (max + K) / 2
print(E)
Buggy python submission (verdict: Time Limit Exceeded):
INF = float('inf')
N, X, Y = map(int, input().split())
G = [[0 if i == j else INF for j in range(N)] for i in range(N)]
for i in range(N-1):
  G[i][i+1] = G[i+1][i] = 1
G[X-1][Y-1] = G[Y-1][X-1] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      G[i][j] = min(G[i][j], G[i][k] + G[k][j])
for k in range(1, N):
  rk = 0
  for i in range(N):
    for j in range(N):
      if j <= i: continue
      if G[i][j] == k:
        rk += 1
  print(rk)

Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
R = [0 for j in range(N)]
for i in range(N-1):
  for j in range(N):
    if j <= i:
      continue
    xd = abs(i - X)
    yd = abs(j - Y)
    dist = min(
      j - i,
      xd + yd + 1
    )
    R[dist] += 1
for r in R[1:]:
  print(r)
Buggy python submission (verdict: Time Limit Exceeded):
S, Q = input(), int(input())
rev = False
for _ in range(Q):
  a = input().split(' ')
  if a[0] == '1':
    rev = not rev
  else:
    if (rev and a[1] == '1') or (not rev and a[1] != '1'):
      S = S + a[2]
    else:
      S = a[2] + S
if rev:
  print(S[::-1])
else:
  print(S)

Fixed submission:
S, Q = input(), int(input())
rev = False
st = []
ed = []
for _ in range(Q):
  a = input().split(' ')
  if a[0] == '1':
    rev = not rev
    continue
  if not rev:
    if a[1] == '1':
      st.append(a[2])
    else:
      ed.append(a[2])
  else:
    if a[1] == '1':
      ed.append(a[2])
    else:
      st.append(a[2])
if rev:
  print(''.join(reversed(ed)) + S[::-1] + ''.join(st))
else:
  print(''.join(reversed(st)) + S + ''.join(ed))
Buggy python submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
A = [int(x) for x in input().split(' ')]
r = sorted([A[i] * A[j] for i in range(N) for j in range(i+1, N)])
print(r[K-1])

Fixed submission:
N = int(input())
l = {}
for _ in range(N):
  s = input()
  l.setdefault(s, 0)
  l[s] += 1
l = sorted([(v, k) for k, v in l.items()])
c = l[-1][0]
r = []
for i in range(-1, -len(l)-1, -1):
  if l[i][0] < c:
    break
  r.append(l[i][1])
for x in reversed(r):
  print(x)
Buggy python submission (verdict: Runtime Error):
H A = [int(i) for i in input().split(' ')]
print(H // A + 1)

Fixed submission:
H, A = [int(i) for i in input().split(' ')]
print(H // A + min(H % A, 1))

Buggy python submission (verdict: Runtime Error):
H A = input().split(' ')
print(H // A + 1)

Fixed submission:
H, A = [int(i) for i in input().split(' ')]
print(H // A + min(H % A, 1))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if i in si:
    continue
  si.add(i)
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set([S[k] for k in range(j+1, N)]))
print(sum(dp.values()))

Fixed submission:
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if S[i] in si:
    continue
  si.add(S[i])
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set(S[j+1:]))
print(sum(dp.values()))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
dp = {}
for i in range(N-2):
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set([S[k] for k in range(j+1, N)]))
print(sum(dp.values()))

Fixed submission:
N = int(input())
S = input()
dp = {}
si = set()
for i in range(N-2):
  if S[i] in si:
    continue
  si.add(S[i])
  for j in range(i+1, N-1):
    if dp.get(S[i] + S[j], 0) > 0:
      continue
    dp[S[i] + S[j]] = len(set(S[j+1:]))
print(sum(dp.values()))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
from bisect import bisect_right
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += len(A[:ai]) * len(C[ci:])
print(r)

Fixed submission:
from bisect import bisect_left
from bisect import bisect_right
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += ai * (N - ci)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
def bin_search(itr, v, ret=None):
  l, r = 0, len(itr) - 1
  while l <= r:
    m = l + (r - l) // 2
    if itr[m] == v:
      if ret == 'smaller':
        r = m - 1
        continue
      if ret == 'bigger':
        l = m + 1
        continue
      return m
    elif itr[m] > v:
      r = m - 1
    else:
      l = m + 1
  if ret == 'smaller':
    return min(l, r)
  if ret == 'bigger':
    return max(l, r)
  return -1
N = int(input())
A = sorted(map(int, input().split()))
B = sorted(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bin_search(A, B[i], 'smaller')
  ci = bin_search(C, B[i], 'bigger')
  r += len(A[:ai+1]) * len(C[ci:])
print(r)

Fixed submission:
from bisect import bisect_left
from bisect import bisect_right
N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))
r = 0
for i in range(N):
  ai = bisect_left(A, B[i])
  ci = bisect_right(C, B[i])
  r += ai * (N - ci)
print(r)