Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        ans =0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    #print(calc(-1))
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    
    if i<0 or j<0:
        print(0)
    elif i==0 and j==0:
        print(0)
    else:
        print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()

Fixed submission:
#ABC145D
def main():
    import sys, math
    X, Y = map(int, sys.stdin.readline().split())
    '''
    i +2*j ==X
    2*i +j ==Y
    '''
    if (2*Y-X)%3==0:
        i = (2*Y-X)//3
        j = Y-2*i
    else:
        i,j=0,0
    #print(i, j)
    mod = 10**9+7
    def calc(n):
        ans = 1
        for i in range(n, 1, -1):
            ans *= i
            ans %= mod
        return ans
    
    ans = calc(i+j)
    #print(calc(-1))
    #print(ans)
    
    #calc2(calc(i), mod-2)
    gg1 = pow(calc(i), mod-2, mod)
    gg2 = pow(calc(j), mod-2, mod)
    
    if i<0 or j<0:
        print(0)
    elif i==0 and j==0:
        print(0)
    else:
        print(ans*gg1*gg2%mod)

if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#AGC040A
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for i in range(n+1)]
f = False
while (f==False):
    f = True
    for i in range(n):
        if s[i] =='<' and not L[i+1] >L[i]:
            L[i+1] = L[i]+1
            f = False
        elif s[i] == '>' and not L[i] > L[i+1]:
            L[i] = L[i+1] +1
            f = False
#print(*L)
print(sum(L))


Fixed submission:
#AGC040
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for _ in range(n+1)]

for i in range(n):
    if s[i] == '<':
        L[i+1] = L[i] +1

#print(L)

for i in range(n-1,-1,-1):
    if s[i] == '>':
        L[i] = max(L[i], L[i+1]+1)

#print(L)

print(sum(L))

Buggy python submission (verdict: Time Limit Exceeded):
#AGC040A
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for i in range(n+1)]
f = False
while (f==False):
    f = True
    for i in range(n):
        if s[i] =='<' and not L[i+1] >L[i]:
            L[i+1] = L[i]+1
            f = False
        elif s[i] == '>' and not L[i] > L[i+1]:
            L[i] = L[i+1] +1
            f = False
#print(*L)
print(sum(L))

Fixed submission:
#AGC040
import sys
s = sys.stdin.readline().rstrip()
n = len(s)
L = [0 for _ in range(n+1)]

for i in range(n):
    if s[i] == '<':
        L[i+1] = L[i] +1

#print(L)

for i in range(n-1,-1,-1):
    if s[i] == '>':
        L[i] = max(L[i], L[i+1]+1)

#print(L)

print(sum(L))
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
A, B = map(int, sys.stdin.readline().split())

a, b = deque([]), deque([])
for i in range(A, 0, -1):
    if A%i ==0:
        a.append(i)
    
for i in range(B, 0, -1):
    if B%i ==0:
        b.append(i)

a,b = set(a), set(b)
L = a&b
#print(L)
cnt =0
for l in L:
    tmp = 0
    for i in range(l-1, 1, -1):
        if l%i==0:
            tmp +=1
            break
    if tmp ==0:
        cnt+=1
print(cnt)

Fixed submission:
import sys

n = int(sys.stdin.readline())
odd =0
for i in range(1, n+1):
    if i %2 ==1:
        odd +=1
print(odd/n)
Buggy python submission (verdict: Runtime Error):
import sys
n = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip()


dp = [[0 for i in range(n)] for j in range(n)]
#初期条件
for j in range(1, n):
    if S[0] == S[j]:
        dp[0][j] = 1
    else:
        dp[0][j] = 0

#print(dp)

for i in range(1, n-1):
    for j in range(i+1, n):
        if S[i] ==S[j]:
            dp[i][j] = min(dp[i-1][j-1] +1, n//2)
        else:
            dp[i][j] = 0

maxp = 0
for i in range(1, n-1):
    for j in range(i+1, n):
        if maxp < dp[i][j]:
            maxp = dp[i][j]
#print(dp)
print(maxp)

Fixed submission:
#import sys
S = input()
#L = ["Sunny", "Cloudy", "Rainy"]

if S == "Sunny":
    print("Cloudy")
elif S =="Cloudy":
    print("Rainy")
elif S == "Rainy":
    print("Sunny")

Buggy python submission (verdict: Runtime Error):
import sys
S = sys.stdin.readline().rstrip()
L = ['Sunny', 'Cloudy', 'Rainy']
if S ==L[0]:
    print(L[1])
elif S ==L[1]:
    print(L[2])
elif S ==L[2]:
    printf(L[0])


Fixed submission:
#import sys
S = input()
#L = ["Sunny", "Cloudy", "Rainy"]

if S == "Sunny":
    print("Cloudy")
elif S =="Cloudy":
    print("Rainy")
elif S == "Rainy":
    print("Sunny")

Buggy python submission (verdict: Runtime Error):
import sys
S = sys.stdin.readline().rstrip()
L = ['Sunny', 'Cloudy', 'Rainy']
if S ==L[0]:
    print(L[1])
elif S ==L[1]:
    print(L[2])
elif S ==L[2]:
    printf(L[0])

Fixed submission:
#import sys
S = input()
#L = ["Sunny", "Cloudy", "Rainy"]

if S == "Sunny":
    print("Cloudy")
elif S =="Cloudy":
    print("Rainy")
elif S == "Rainy":
    print("Sunny")
Buggy python submission (verdict: Time Limit Exceeded):
#141D bisect
def main():
    import sys, bisect
    #from collections import deque
    
    N,M =map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    A.sort()
    #print(A)
    while M:
        tmp = A.pop()
        bisect.insort(A, tmp//2)
        M-=1
    print(sum(A))
   

if __name__=='__main__':
    main()


Fixed submission:
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    heapq.heappush(A ,int(A[0]/2))
    heapq.heappop(A)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    A[0] = int(A[0]/2)
    heapq.heapify(A)

print(-sum(A))

Fixed submission:
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    heapq.heappush(A ,int(A[0]/2))
    heapq.heappop(A)

print(-sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
for i in range(n):
    A[i] = -A[i]
heapq.heapify(A)
#(A)
for j in range(m):
    A[0] = int(A[0]/2)
    #print(A)
    heapq.heapify(A)

print(-sum(A))

Fixed submission:
import sys
import heapq
n, m = map(int, sys.stdin.readline().split())
A = list(map(lambda x:-int(x), sys.stdin.readline().split()))
heapq.heapify(A)

for j in range(m):
    heapq.heappush(A ,int(A[0]/2))
    heapq.heappop(A)

print(-sum(A))
Buggy python submission (verdict: Runtime Error):
import sys
n, k = map(int, sys.stdin.readline().split())
S = sys.stdin.readline()

score = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        score+=1
#print(S)
idx = []
for i in range(n):
    if S[i] == 'R':
        idx.append(i)
idx.append(-10)

s =-1
e =-1
ten = []
for i in range(len(idx)-1):
    if s ==-1:
        s = idx[i]
    if idx[i]+1 != idx[i+1]:
        e = idx[i]
        if e-s == n-1:
            pass
        elif s ==-1 or e==-1:
            pass
        elif s ==0 or e ==n-1:
            ten.append(1)
        else:
            ten.append(2)
        s =-1
ten = sorted(ten, reverse=True)
#print(score, ten)
print(score+ sum(ten[0:k]))

Fixed submission:
import sys
import itertools
n = int(sys.stdin.readline())
L = [i for i in range(1,n+1)]
a = list(itertools.product(L, repeat=3))
print(len(a))
Buggy python submission (verdict: Runtime Error):
import sys
import itertools
n, K = map(int, input().split())
S = list(input())

def main(S, score):
    L =[]
    for i in range(n):
        if S[i] =='R':
            L.append(i)
    L = list(itertools.combinations(L, 2))
    cnt = 0
    m = []
    for l in L:
        if cnt < S[l[0]:l[1]+1].count('R'):
            cnt = S[l[0]:l[1]+1].count('R')
            m = l
    M = S[m[0]:m[1]+1:]
    M = M[::-1]
    for i in range(len(M)):
        if M[i] == 'R':
            M[i] = 'L'
        elif M[i] == 'L':
            M[i] = 'R'
    S = S[0:m[0]] + M + S[m[1]+1:]

    ten = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            ten+=1
    if score < ten:
        score = ten
    return S, score
score = 0
for k in range(K):
    S, score = main(S, score)
    #print(S)
print(score)

Fixed submission:
import sys
import re
n, k = map(int, sys.stdin.readline().split())
S = sys.stdin.readline()

ptnr = 'R+'
ptnr = re.compile(ptnr)
ptnl = 'L+'
ptnl = re.compile(ptnl)

if len(ptnl.findall(S)) <=len(ptnr.findall(S)):
    f = 'L'
else:
    f = 'R'

score = 0
for i in range(len(S)-1):
    if S[i]==S[i+1]:
        score+=1

idx = []
for i in range(n):
    if S[i] == f:
        idx.append(i)
idx.append(-10)

s =-1
e =-1
ten = [0]
for i in range(len(idx)-1):
    if s ==-1:
        s = idx[i]
    if idx[i]+1 != idx[i+1]:
        e = idx[i]
        if s==0 and e ==n-1:
            pass
        elif s ==-1 or e==-1:
            pass
        elif s ==0 or e ==n-1:
            ten.append(1)
        else:
            ten.append(2)
        s =-1
ten = sorted(ten, reverse=True)
print(score+ sum(ten[0:k]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline())
total = 0
for i in range(1, n):
    total +=i
print(total)

Fixed submission:
import sys
n = int(sys.stdin.readline())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
hL = list(map(int, input().split()))
flag = 'Yes'
for i in range(n-1):
    for j in range(i+1, n) :
        if hL[i] -hL[j]>=2:
            flag = 'No'
            break
    if flag =='No':
        break
print(flag)

Fixed submission:
import sys
input = sys.stdin.readline
limit, nowl, addl = map(int, input().split())
print(max(0, nowl+addl-limit))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
for i in range(n):
    if A[i] == max(A):
        print(tmp[-2])
    else:
        print(max(A))

Fixed submission:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]

for i in range(n):
    if A[i] == max(A):
        tmp = sorted(A)
        print(tmp[-2])
    else:
        print(max(A))

Fixed submission:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]

for i in range(n):
    if A[i] == max(A):
        tmp = A.pop(i)
        print(max(A))
        A.insert(i, tmp)
    else:
        print(max(A))

Fixed submission:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
A = deque(A)
for i in range(n):
    tmp = A.popleft()
    print(max(A))
    A.append(tmp)

Fixed submission:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]

for i in range(n):
    #print(A)
    tmp = A.pop(i)
    print(max(A))
    A.insert(i, tmp)

Fixed submission:
import sys
n = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(n)]
tmp = sorted(A)
maxa = max(A)
for i in range(n):
    if A[i] == maxa:
        print(tmp[-2])
    else:
        print(maxa)
Buggy python submission (verdict: Time Limit Exceeded):
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        for i in range(b):
            total +=a
            m -=1
            if m==0:
                print(total)
                break


Fixed submission:
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        total +=a*m
        print(total)
        break

Buggy python submission (verdict: Time Limit Exceeded):
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        for i in range(b):
            total +=a
            m -=1
            if m==0:
                print(total)
                break

Fixed submission:
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        total +=a*m
        print(total)
        break
Buggy python submission (verdict: Runtime Error):
import math
a,b,k =map(int, input().split())
c = math.gcd(a,b)
cnt = 0
for i in range(c, 0, -1):
    if a%i==0 and b%i==0:
        cnt +=1
    if cnt ==k:
        print(i)
        break

Fixed submission:
a,b,k =map(int, input().split())
c = min(a, b)
cnt = 0
for i in range(c, 0, -1):
    if a%i==0 and b%i==0:
        cnt +=1
    if cnt ==k:
        print(i)
        break
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ls = len(s)
while True:
    f = False
    for i in range(len(s)-1):
        if (s[i] =='0' and s[i+1] =='1') or (s[i] =='1' and s[i+1] =='0'):
            s = s[0:i] + s[i+2:]
            f = True
            break
    if f == False:
        break
print(ls-len(s))

Fixed submission:
s = list(input())
print(min(s.count('1'), s.count('0'))*2)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int, list(input())))
ls = len(s)
while True:
    f = False
    for i in range(len(s)-1):
        if (s[i] ==0 and s[i+1] ==1) or (s[i] ==1 and s[i+1] ==0):
            del s[i:i+2]
            f = True
            break
    if f == False:
        break
print(ls-len(s))

Fixed submission:
s = list(input())
print(min(s.count('1'), s.count('0'))*2)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(map(int, list(input())))
ls = len(s)
while True:
    f = False
    for i in range(len(s)-1):
        if (s[i] ==0 and s[i+1] ==1) or (s[i] ==1 and s[i+1] ==0):
            s[i], s[i+1] = '', ''
            f = True
    while '' in s:
        s.remove('')
    if f == False:
        break
print(ls-len(s))

Fixed submission:
s = list(input())
print(min(s.count('1'), s.count('0'))*2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000100)
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

ans = []
def frog(pnt, pos):
    if pos ==n-1:
        ans.append(pnt)
    elif pos ==n-2:
        frog(pnt + abs(H[pos+1]-H[pos]), pos+1)
    else:
        frog(pnt + abs(H[pos+1]-H[pos]), pos+1)
        frog(pnt + abs(H[pos+2]-H[pos]), pos+2)
        
frog(0, 0)
print(min(ans))

Fixed submission:
import sys
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

P =[0 for _ in range(n)]
P[1] = abs(H[1]-H[0])
for pos in range(2, n):
    a = abs(H[pos]-H[pos-1])
    b = abs(H[pos]-H[pos-2])
    P[pos] = min((P[pos-1] + a), (P[pos-2] + b))

print(P[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
#DP B
import sys
N, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

dp = [0 for _ in range(N)]
#print(dp)
#print(H)
dp[1] = abs(H[1]-H[0])
#print(dp)

for i in range(2, N):
    for k in range(1, K+1):
        if i-k>=0:
            tmp = abs(H[i]-H[i-k]) + dp[i-k]
            if dp[i] ==0 or tmp < dp[i]:
                dp[i] = tmp
    #print(dp)
print(dp[-1])

Fixed submission:
import sys
n, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

p = [float('inf') for _ in range(n)]
p[0] = 0
for i in range(1, n):
    for k in range(1, K+1):
        if i-k >=0:
            tmp = abs(H[i]-H[i-k]) + p[i-k]
            if p[i] > tmp:
                p[i] = tmp

print(p[-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

p = [float('inf') for _ in range(n)]
p[0] = 0
for i in range(1, n):
    for k in range(1, K+1):
        if i-k >=0:
            tmp = abs(H[i]-H[i-k]) + p[i-k]
            if p[i] > tmp:
                p[i] = tmp

print(p[-1])

Fixed submission:
import sys
n, K = map(int, sys.stdin.readline().split())
H = list(map(int, sys.stdin.readline().split()))

p = [float('inf') for _ in range(n)]
p[0] = 0
for i in range(1, n):
    for k in range(1, K+1):
        if i-k >=0:
            tmp = abs(H[i]-H[i-k]) + p[i-k]
            if p[i] > tmp:
                p[i] = tmp

print(p[-1])
Buggy python submission (verdict: Runtime Error):
#DP C
import sys
N = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
#print(L)

dp = [[0,0,0] for _ in range(N)]
dp[0] = L[0].copy()
for i in range(1, N):
    dp[i][0] = L[i][0] + max(dp[i-1][1], dp[i-1][2])
    dp[i][1] = L[i][1] + max(dp[i-1][0], dp[i-1][2])
    dp[i][2] = L[i][2] + max(dp[i-1][0], dp[i-1][1])
    #print(dp)
print(max(dp[-1]))

Fixed submission:
import sys
n = int(sys.stdin.readline())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

p = [[0 for _ in range(3)] for _ in range(n)]

p[0] = L[0].copy()
#print(p)
#print(L)

for d in range(1, n):
    for i in range(3):
        if i ==0:
            p[d][0] = max(p[d-1][1], p[d-1][2]) + L[d][0]
        elif i ==1:
            p[d][1] = max(p[d-1][0], p[d-1][2]) + L[d][1]
        elif i==2:
            p[d][2] = max(p[d-1][0], p[d-1][1]) + L[d][2]

print(max(p[-1]))
Buggy python submission (verdict: Runtime Error):
    L[0]+=2
  elif L[2]-L[1]>=2:
    L[1]+=2
  elif L[0] !=L[1] or L[1] !=L[2]:
    L[0]+=1
    L[1]+=1
  cnt+=1
  L.sort()
  if L[0]==L[1]==L[2]:
    break
print(cnt) 
    
    


Fixed submission:
import sys
L=list(map(int,sys.stdin.readline().split()))
cnt=0
while True:
  if L[0]==L[1]==L[2]:
    break
  L.sort()
  if L[2]-L[0]>=2:
    L[0]+=2
  elif L[2]-L[1]>=2:
    L[1]+=2
  elif L[0] !=L[1] or L[1] !=L[2]:
    L[0]+=1
    L[1]+=1
  cnt+=1
  
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
#ABC077C
def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))
    
    A.sort()
    B.sort()
    C.sort()
    #print(A, B, C)
    ans = 0
    for i in range(N):
        idxB = bisect.bisect_right(B, A[i])
        for j in range(idxB, N):
            idxC = bisect.bisect_right(C, B[j])
            #print(A[i],B[j], (N-idxC))
            ans +=(N-idxC)
    print(ans)


if __name__=='__main__':
    main()


Fixed submission:
#ABC077C
def main():
    import sys, bisect
    N = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    B = list(map(int, sys.stdin.readline().split()))
    C = list(map(int, sys.stdin.readline().split()))
    
    A.sort()
    B.sort()
    C.sort()
    #print(A, B, C)
    ans = 0
    #Bを起点
    for i in range(N):
        idxA = bisect.bisect_left(A, B[i])
        idxC = bisect.bisect_right(C, B[i])
        #print(idxA, idxC)
        ans +=idxA*(N-idxC)
    print(ans)

if __name__=='__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#063 C Bugged
import sys
n = int(sys.stdin.readline())
S = [int(sys.stdin.readline()) for _ in range(n)]
#print(S)

ans=[]
def saiki(total, i):
    if i==n:
        #print(total)
        ans.append(total)
    else:
        saiki(total + S[i], i+1)
        saiki(total, i+1)



saiki(0, 0)
ans.sort(reverse=True)
for a in ans:
    if a%10!=0:
        print(a)
        break
else:
    print(0)

Fixed submission:
#063 C Bugged
#動的計画法(DP)で解く
import sys
n = int(sys.stdin.readline())
S = [int(sys.stdin.readline()) for _ in range(n)]
#print(S)

dp =[[0 for _ in range(sum(S)+1)] for _ in range(n)]
dp[0][0]=1
dp[0][S[0]]=1
for i in range(1, n):
    for j in range(sum(S)+1):
        if dp[i-1][j]==1:
            dp[i][j] = 1
            dp[i][j+S[i]] = 1
    dp[i][S[i]]=1

L=[]   
for i, p in enumerate(dp[n-1]):
    if p!=0:
        L.append(i)
L.sort(reverse=True)

for l in L:
    if l%10 !=0:
        print(l)
        break
else:
    print(0)