Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K=map(int,input().split())
x=list(map(int,input().split()))
#print(x)

list1=[]
list2=[]
for i in range(len(x)):
    if x[i]<0:
        list2.append(x[i])
    else:
        list1.append(x[i])
list2.sort(reverse=True)
#print(list1)
#print(list2)
if N==1:
    print(abs(x[0]))
else:
    
    list3=[]
    for j in range(1,K):
        if len(list1)-j>=K-1:
            list3.append(list1[K-1])
        elif len(list1)-j>=0:
            list3.append(list1[len(list1)-j]*2+list2[K-2-len(list1)+j]*(-1))
            list3.append(list1[len(list1)-j]+list2[K-2-len(list1)+j]*(-2))
        elif list2[K-len(list1)+J]<=len(list2)-1 :
            list3.append(list2[K-1]*(-1))
            break
        else:
            break
        #print(j)
    #print(list3)
    print(min(list3))
            

Fixed submission:
N,K=map(int,input().split())
x=list(map(int,input().split()))
#print(x)

list1=[]
for i in range(N-K+1):
    if x[i+K-1]<=0:
        list1.append(x[i]*(-1))
    elif x[i]>=0:
        list1.append(x[i+K-1])
    else:
        list1.append(x[i+K-1]*2-x[i])
        list1.append(x[i+K-1]-x[i]*2)
#print(list1)
print(min(list1))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
for i in range(1,N):
    B.append(A[i]+B[i-1])
#print(B)

ans=10**20
for x in range(2,N-1):
    #print(x)
    Q=[]
    q1=B[bisect.bisect_left(B,B[x-1]/2)]
    q2=B[x-1]-q1
    q3=B[bisect.bisect_left(B,B[x-1]/2)-1]
    q4=B[x-1]-q3
    if abs(q1-q2)<abs(q3-q4):
        Q.append(q1)
        Q.append(q2)
    else:
        Q.append(q3)
        Q.append(q4)
    q5=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)]-B[x-1]
    q6=B[N-1]-q5-B[x-1]
    q7=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)-1]-B[x-1]
    q8=B[N-1]-q7-B[x-1]
    
    if abs(q5-q6)<abs(q7-q8):
        Q.append(q5)
        Q.append(q6)
    else:
        Q.append(q7)
        Q.append(q8)
    if (max(Q)-min(Q))<ans:
        ans=(max(Q)-min(Q))
    #print(Q)
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[A[0]]
for i in range(1,N):
    B.append(A[i]+B[i-1])
#print(B)

ans=10**20
for x in range(2,N-1):
    #print(x)
    Q=[]
    q1=B[bisect.bisect_left(B,B[x-1]/2)]
    q2=B[x-1]-q1
    q3=B[bisect.bisect_left(B,B[x-1]/2)-1]
    q4=B[x-1]-q3
    if abs(q1-q2)<abs(q3-q4):
        Q.append(q1)
        Q.append(q2)
    else:
        Q.append(q3)
        Q.append(q4)
    q5=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)]-B[x-1]
    q6=B[N-1]-q5-B[x-1]
    q7=B[bisect.bisect_left(B,(B[N-1]+B[x-1])/2)-1]-B[x-1]
    q8=B[N-1]-q7-B[x-1]
    
    if abs(q5-q6)<abs(q7-q8):
        Q.append(q5)
        Q.append(q6)
    else:
        Q.append(q7)
        Q.append(q8)
    if (max(Q)-min(Q))<ans:
        ans=(max(Q)-min(Q))
    #print(Q)
print(ans)
Buggy python submission (verdict: Runtime Error):

N=int(input())

if N>=1000:
    print("ABD")
else:
    print("ABC")

Fixed submission:
list1=[1]
for i in range(2,1000):
    list1.append(list1[i-2]+i)
    
#print(list1[0:5])

line=input()
line=line.rstrip().split(" ")
a=int(line[0])
b=int(line[1])

print(list1[b-a-1]-b)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

S=input()

#print(S)

list1=[]

for i in range(N):
    E=S[:i].count("W")
    W=S[i+1:].count("E")
    list1.append(E+W)
    
print(min(list1))

Fixed submission:

N=int(input())
S=input()

#print(S)
#print(S[1:])
list1=[]

ST=S[1:].count("E")
list1.append(ST)
#print(list1)

for i in range(1,N):
    if S[i]=="E":
        ST=ST-1
    if S[i-1]=="W":
        ST=ST+1
    list1.append(ST)
#print(list1)
print(min(list1))
Buggy python submission (verdict: Time Limit Exceeded):

num=input()
num=int(num)

list1=[]
list2=[]
for i in range(num):
    n=input()
    n=int(n)
    list1.append(n)
    list2.append(n)
    
count=0
for j in range(num):
    for k in range(list1.index(num-j)+1):
        if list1[k]>list1[list1.index(num-j)]:
            #print(str(list1[list1.index(num-j)])+" "+str(k))
            del list1[list1.index(num-j)]
            list1.insert(0,num-j)
            #print(list1)
            count=count+1
            break
        else:
            k+=1
#print(count)

count2=0
for j in range(1,num+1):
    for k in range(list2.index(j),num):
        if list2[k]<list2[list2.index(j)]:
            #print(str(list1[list1.index(j)])+" "+str(k))
            del list2[list2.index(j)]
            list2.insert(num-1,j)
            #print(list2)
            count2=count2+1
            break
        else:
            k+=1
#print(count2)
if count<=count2:
    print(count)
else:
    print(count2)
    

Fixed submission:
import bisect

N=int(input())

A=[int(input())for i in range(N)]
#print(A)

L=[0 for i in range(N+1)]

for i in range(N):
    if L[A[i]-1]>0:
        L[A[i]]=(L[A[i]-1]+1)
    else:
        L[A[i]]=1
print(N-max(L))
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
K=int(input())
K-=1
D={}
for s in range(len(S)):
    for e in range(s,len(S)):
        D[S[s:e+1]]=1
        #print(S[s:e+1])
D=list(D)
D.sort()
print(D[K])

Fixed submission:
s = input()
K =input()

list1=[]
for i in range(len(s)):
    if s[0:i].count(s[i])==0:
        list1.append(s[i])
        i +=1
    else:
        i+=1

i=0
for i in range(len(s)):
    if s[i:i+2] not in list1:
        list1.append(s[i:i+2])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+3] not in list1:
        list1.append(s[i:i+3])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+4] not in list1:
        list1.append(s[i:i+4])
    else:
        i+=1
i=0
for i in range(len(s)):
    if s[i:i+5] not in list1:
        list1.append(s[i:i+5])
    else:
        i+=1

list1=sorted(list1)
print(list1[int(K)-1])
Buggy python submission (verdict: Runtime Error):
15 10000000000
400000000 1000000000
800000000 1000000000
1900000000 1000000000
2400000000 1000000000
2900000000 1000000000
3300000000 1000000000
3700000000 1000000000
3800000000 1000000000
4000000000 1000000000
4100000000 1000000000
5200000000 1000000000
6600000000 1000000000
8000000000 1000000000
9300000000 1000000000
9700000000 1000000000

Fixed submission:
N,C=map(int,input().split())

L=[]
for i in range(N):
    x,y=map(int,input().split())
    L.append([x,y])
    
l=L[::-1]
L=[[0,0]]+L
R=[]

for i in range(N):
    R.append([C-l[i][0],l[i][1]])
R=[[0,0]]+R


#print(L)
#print(R)
TS=[0]
TW=[0]
RS=[0]
RW=[0]

for i in range(N):
    TS.append(TS[i]-L[i+1][0]+L[i][0]+L[i+1][1])
    TW.append(TW[i]-2*(L[i+1][0]-L[i][0])+L[i+1][1])
    RS.append(RS[i]-R[i+1][0]+R[i][0]+R[i+1][1])
    RW.append(RW[i]-2*(R[i+1][0]-R[i][0])+R[i+1][1])
    
MTS=[0]
MRS=[0]
for i in range(1,N+1):
    MTS.append(max(MTS[i-1],TS[i]))
    MRS.append(max(MRS[i-1],RS[i]))

ans=0
for i in range(N+1):
    if i>0 and L[i-1][0]*2>C:
        break
    else:
        if ans<TW[i] + MRS[N-i]:
            ans=TW[i] + MRS[N-i]
            
for i in range(N+1):
    if i>0 and R[i-1][0]*2>C:
        break
    else:
        if ans<RW[i]+MTS[N-i]:
            ans=RW[i]+MTS[N-i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

#print(b)
for j in range(len(b)):
    b1=[]
    for i in range(len(b)):
        if j ==i:
            i +=1
        else:
            b1.append(int(b[i]))
            i +=1
    b1 = sorted(b1)
    print(b1[int(a/2)-1])

Fixed submission:
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

bi =[]
for i in range(len(b)):
    bi.append(int(b[i]))
    i+=1
    
#print(bi)
bs =sorted(bi)
#print(bs)
for j in range(int(a)):
    if bi[j]>=bs[int(len(bs)/2)]:
        print(bs[int(len(bs)/2-1)])
        j+=1
    else:
        print(bs[int(len(bs)/2)])
        j+=1

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

#print(b)

b1=[]
for i in range(len(b)):
    b1.append(int(b[i]))
    i +=1
    
#print(b1)

list2=[]
for j in range(len(b1)):
    list1=[]
    for k in range(len(b1)):
        if j == k :
            k +=1
        else:
            list1.append(b1[k])
            k+=1
    list3=sorted(list1)
    list2.append(list3)
    j +=1
#print(list2)

for l in range(int(a)):
    print(list2[l][int(a/2)-1])
    l+=1

Fixed submission:
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

bi =[]
for i in range(len(b)):
    bi.append(int(b[i]))
    i+=1
    
#print(bi)
bs =sorted(bi)
#print(bs)
for j in range(int(a)):
    if bi[j]>=bs[int(len(bs)/2)]:
        print(bs[int(len(bs)/2-1)])
        j+=1
    else:
        print(bs[int(len(bs)/2)])
        j+=1
Buggy python submission (verdict: Time Limit Exceeded):
num =int(input())
line = input()
line = line.rstrip().split(" ")
linei = []
for i in range(len(line)):
    linei.append(int(line[i]))
#print(max(linei))

for j in range(max(linei)):
    if linei.count(int(max(linei)/2)+j)>=1:
        if int(max(linei)/2)+j==max(linei):
            print(str(max(linei))+" 0")
            break
        else:
            print(str(max(linei))+" "+str(int(max(linei)/2)+j))
            break
    elif linei.count(int(max(linei)/2)-j)>=1:
        print(str(max(linei))+" "+str(int(max(linei)/2)-j))
        break
    else:
        j+=1

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

MAX=max(a)
Harf=MAX/2

cnt=10**20
ans=0
for i in range(n):
    if MAX==a[i]:
        continue
    elif abs(Harf-a[i])<cnt:
        ans=a[i]
        cnt=abs(Harf-a[i])
print(MAX,ans)
Buggy python submission (verdict: Runtime Error):
mojiretu = input()

a = mojiretu.count(a)
b = mojiretu.count(b)
c = mojiretu.count(c)

if int(a)+int(b)+int(c)==3:
    print("Yes")
else:
    print("No")

Fixed submission:
mojiretu = input()

a = mojiretu.count("a")
b = mojiretu.count("b")
c = mojiretu.count("c")

if int(a) ==1 and int(b) ==1 and int(c)==1:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
Q=int(input())
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        A,B=B,A
    M=A*B-1
    CNT=B
    cnt=0
    for i in range(A,B):
        if CNT<=A:
            break
        if A<M//i<CNT:
            cnt+=1
            CNT=M//i
        elif M//i>=CNT and CNT-1>A:
            cnt+=1
            CNT-=1
        else:
            break
    print(cnt+(A-1)*2)

Fixed submission:
Q=int(input())
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        A,B=B,A
    if A==B:
        print((A-1)*2)
    elif A+1==B:
        print((A-1)*2)
    else:
        SQ=int(pow(A*B,0.5))
        if SQ**2==A*B:
            print((SQ-1)*2-1)
        elif SQ*(SQ+1)<A*B:
            print((SQ-1)*2+1)
        else:
            print((SQ-1)*2)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

N,M=map(int,input().split())
V=list(map(int,input().split()))

P=[i for i in range(N)]
size=[1 for i in range(N)]

def find(x):
    if x==P[x]:
        return x
    else:
        return find(P[x])
    
def union(y,z):
    Y=find(y)
    Z=find(z)
    if size[y]>=size[z]:
        P[Z]=P[Y]
        size[Y]+=size[Z]
    else:
        P[Y]=P[Z]
        size[Z]+=size[Y]

for i in range(M):
    x,y=map(int,input().split())
    if find(x)!=find(y):
        union(x,y)
#print(P)
S=[]
for i in range(N):
    S.append(find(i))
#print(S)
D={}
O={}
for i in range(N):
    if S[i] not in D:
        D[S[i]]=V[i]
        O[S[i]]=1
    else:
        O[S[i]]+=1
        if D[S[i]]>V[i]:
            D[S[i]:V[i]]
#print(D,O)
One=0
#print("S",S)
for i in O:
    #print(O[i])
    if O[i]==1:
        One+=1
#print("One",One)
if (One-1)*2>N:
    print("Impossible")
    exit()
W=[]
for i in range(N):
    W.append([V[i],S[i]])
W.sort()
#print(W)
ans=sum(D.values())
#print(ans)
#print(D)
if len(D)==1:
    print(0)
    exit()
for i in range(len(D)-1):
    if W[i][1] in D:
        if D[W[i][1]]==W[i][0]:
            continue
        else:
            ans+=W[i][0]
    else:
        ans+=W[i][0]
print(ans)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
P=[i for i in range(N)]
size=[1 for i in range(N)]

def find(a):
    if a==P[a]:
        return a
    else:
        return find(P[a])
        
def union(b,c):
    B=find(b)
    C=find(c)
    if size[B]>=size[C]:
        P[C]=P[B]
        size[B]+=size[C]
    else:
        P[B]=P[C]
        size[C]+=size[B]
for i in range(M):
    x,y=map(int,input().split())
    if find(x)!=find(y):
        union(x,y)
        
p=[]
for i in range(N):
    p.append([A[i],find(P[i])])
#print(p)
p.sort()
ANS1=[]
ANS2=[]
d={}
for i in range(N):
    if p[i][1] in d:
        ANS2.append(p[i][0])
    else:
        d[p[i][1]]=1
        ANS1.append(p[i][0])
#print(ANS1,ANS2)
if (len(ANS1)+len(ANS1)-2)>N:
    print("Impossible")
elif len(ANS1)==1:
    print(0)
else:
    ANS=sum(ANS1)+sum(ANS2[:len(ANS1)-2])
    print(ANS)
Buggy python submission (verdict: Time Limit Exceeded):
list1=[2]
list2=[]
for i in range(3,100000,2):
    flag=0
    for j in range(3,318):
        if i<j**2:
            break
        elif i%j==0:
            flag=1
            break
    #print(i,flag)
    if flag==0:
        list1.append(i)
        if (int((i+1)/2) in list1):
            list2.append(i)
#print(list1)
#print(list2)


N=int(input())
for k in range(N):
    A=input()
    A=A.rstrip().split(" ")
    A1=int(A[0])
    A2=int(A[1])
#print(A1,A2)
    cnt=0
    for l in list2:
        if A1<= l <=A2 :
            cnt+=1
    print(cnt)
    

Fixed submission:
listS=[1]*100005
listS[0]=0
listS[1]=0
for i in range(2,100003):
    if listS[i]==1:
        for j in range(2*i,100000,i):
            listS[j]=0
list2017=[0]
for k in range(1,100001):
    if listS[k]==1 and listS[int((k+1)/2)]==1:
        list2017.append(list2017[k-1]+1)
    else:
        list2017.append(list2017[k-1])

N=int(input())
for x in range(N):
    l,m=map(int,input().split())
    print(list2017[m]-list2017[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
list1=[2,3,5,7,11,13,17,19]
for i in range(21,100000,2):
    flag=0
    for j in range(3,318):
        if i%2==0:
            flag=1
            break
        elif i<j**2:
            break
        elif i%j==0:
            flag=1
            break
    #print(i,flag)
    if flag==0:
        list1.append(i)
#print(list1)

N=int(input())
for k in range(N):
    A=input()
    A=A.rstrip().split(" ")
    A1=int(A[0])
    A2=int(A[1])
#print(A1,A2)
    cnt=0
    for l in list1:
        if A1<= l <=A2 and (int((l+1)/2) in list1) :
            cnt+=1
    print(cnt)
    

Fixed submission:
listS=[1]*100005
listS[0]=0
listS[1]=0
for i in range(2,100003):
    if listS[i]==1:
        for j in range(2*i,100000,i):
            listS[j]=0
list2017=[0]
for k in range(1,100001):
    if listS[k]==1 and listS[int((k+1)/2)]==1:
        list2017.append(list2017[k-1]+1)
    else:
        list2017.append(list2017[k-1])

N=int(input())
for x in range(N):
    l,m=map(int,input().split())
    print(list2017[m]-list2017[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
list1=[2,3,5,7,11,13,17,19]
for i in range(20,100000):
    flag=0
    for j in range(3,318):
        if i%2==0:
            flag=1
            break
        elif i<j**2:
            break
        elif i%j==0:
            flag=1
            break
    #print(i,flag)
    if flag==0:
        list1.append(i)
#print(list1)

N=int(input())
for k in range(N):
    A=input()
    A=A.rstrip().split(" ")
    A1=int(A[0])
    A2=int(A[1])
#print(A1,A2)
    cnt=0
    for l in list1:
        if A1<= l <=A2 and (int((l+1)/2) in list1) :
            cnt+=1
    print(cnt)
    

Fixed submission:
listS=[1]*100005
listS[0]=0
listS[1]=0
for i in range(2,100003):
    if listS[i]==1:
        for j in range(2*i,100000,i):
            listS[j]=0
list2017=[0]
for k in range(1,100001):
    if listS[k]==1 and listS[int((k+1)/2)]==1:
        list2017.append(list2017[k-1]+1)
    else:
        list2017.append(list2017[k-1])

N=int(input())
for x in range(N):
    l,m=map(int,input().split())
    print(list2017[m]-list2017[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=list(map(int,input().split()))
l=set(L)
ls=list(l)
#print(len(l))
ans=0
for i in range(len(l)):
    if L.count(ls[i])>ls[i]:
        ans+=L.count(ls[i])-ls[i]
    elif L.count(ls[i])<ls[i]:
        ans+=L.count(ls[i])
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
cnt=0
L=[0 for i in range(100005)]
for i in range(N):
    if A[i]<=100000:
        L[A[i]]+=1
    else:
        cnt+=1
    
for j in range(100002):
    
    if L[j]==j:
        pass
    elif L[j]<j:
        cnt+=L[j]
    elif L[j]>j:
        cnt+=L[j]-j
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=input()
a=a.rstrip().split(" ")
list1=[]
for i in range(N):
    list1.append(int(a[i]))
#print(list1)
lists=[]
for k in range(len(list1)):
    if list1[k] in lists:
        pass
    else:
        lists.append(list1[k])
#print(lists)
cnt=0
for j in range(len(lists)):
    if lists[j]>list1.count(lists[j]):
        cnt+=list1.count(lists[j])
    elif lists[j]<list1.count(lists[j]):
        cnt+=list1.count(lists[j])-lists[j]
print(cnt)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
cnt=0
L=[0 for i in range(100005)]
for i in range(N):
    if A[i]<=100000:
        L[A[i]]+=1
    else:
        cnt+=1
    
for j in range(100002):
    
    if L[j]==j:
        pass
    elif L[j]<j:
        cnt+=L[j]
    elif L[j]>j:
        cnt+=L[j]-j
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
L=[]
for i in range(N):
    s,d=map(int,input().split())
    L.append([s,d])

High=10**30
Low =0
for i in range(300):
    Mid=(High + Low)/2
    cnt=0
    for j in range(N):
        cnt+=max(0,1+(Mid - L[j][0])//L[j][1])
    if cnt>=K:
        High = Mid
    elif cnt<K:
        Low = Mid
    #print(Mid)
import math
print(math.ceil(Mid))

Fixed submission:
import sys
input=sys.stdin.readline
N,K=map(int,input().split())
L=[]
for i in range(N):
    s,d=map(int,input().split())
    L.append([s,d])

High=10**20
Low =0
while High - Low >1:
    Mid=(High + Low)//2
    cnt=0
    for j in range(N):
        if Mid-L[j][0]<0:
            continue
        else:
            cnt+=max(0,1+(Mid - L[j][0])//L[j][1])
    if cnt>=K:
        High = Mid
    else:
        Low = Mid
    #print(High , Low)
Mid=int(Mid)
ans=0
for j in range(N):
    ans+=max(0,1+(Mid - L[j][0])//L[j][1])
if ans>=K:
    print(Mid)
else:
    print(Mid+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
L=[]
for i in range(N):
    s,d=map(int,input().split())
    L.append([s,d])

High=10**30
Low =0
for i in range(500):
    Mid=(High + Low)/2
    cnt=0
    for j in range(N):
        cnt+=max(0,1+(Mid - L[j][0])//L[j][1])
    if cnt>=K:
        High = Mid
    elif cnt<K:
        Low = Mid
    #print(Mid)
import math
print(math.ceil(Mid))

Fixed submission:
import sys
input=sys.stdin.readline
N,K=map(int,input().split())
L=[]
for i in range(N):
    s,d=map(int,input().split())
    L.append([s,d])

High=10**20
Low =0
while High - Low >1:
    Mid=(High + Low)//2
    cnt=0
    for j in range(N):
        if Mid-L[j][0]<0:
            continue
        else:
            cnt+=max(0,1+(Mid - L[j][0])//L[j][1])
    if cnt>=K:
        High = Mid
    else:
        Low = Mid
    #print(High , Low)
Mid=int(Mid)
ans=0
for j in range(N):
    ans+=max(0,1+(Mid - L[j][0])//L[j][1])
if ans>=K:
    print(Mid)
else:
    print(Mid+1)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0

for i in range(N):
    cntA=0
    cntC=0
    for j in range(N):
        if B[i]>A[j]:
            cntA+=1
        if B[i]<C[j]:
            cntC+=1
    ans+=cntA*cntC
print(ans)

Fixed submission:
import bisect
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

ans=0
A.sort()
B.sort()
C.sort()

for i in range(len(B)):
    ans+=bisect.bisect_left(A,B[i])*(len(C)-bisect.bisect_right(C,B[i]))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

for h in range(1,3501):
    for n in range(h,3501):
        if (4*h*n-N*n-N*h)==0:
            pass
        elif (N*h*n)/(4*h*n-N*n-N*h)==int((N*h*n)/(4*h*n-N*n-N*h)):
            if int((N*h*n)/(4*h*n-N*n-N*h))>0:
                print(h,n,int((N*h*n)/(4*h*n-N*n-N*h)))
                exit()

Fixed submission:
N=int(input())

for a in range(1,3501):
    for b in range(1,3501):
        if (4*a*b-N*a-N*b)>0:
            c=N*a*b/(4*a*b-N*a-N*b)
            if c==int(c):
                if 4*a*b*c==N*(a*b+b*c+c*a):
                    print(a,b,int(c))
                    exit()
Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,K=map(int,input().split())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    if a<=K:
        L.append([a,b])

#print(L)
k=[]
num=copy.deepcopy(K)
for i in range(30):
    if num//(2**(29-i))==1:
        k.append(1)
        num%=(2**(29-i))
    else:
        k.append(0)
        num%=(2**(29-i))
        
ans=0
for a,b in L:
    f=0
    for i in range(30):
        if a//(2**(29-i))==1 and k[i]==0:
            f=1
            break
        else:
            a%=(2**(29-i))
    if f==0:
        ans+=b
NUM=0

for i in range(29):
    if k[i]==1:
        cnt=0
        NUM+=2**(29-i)
        for a,b in L:
            if a<NUM:
                A=copy.deepcopy(a)
                A%=(2**(30-i))
                if A//(2**(29-i))==0:
                    cnt+=b
        if ans<cnt:
            ans=cnt
        #print(cnt,NUM)
    else:
        l=[]
        for a,b in L:
            A=copy.deepcopy(a)
            A%=2**(30-i)
            if A//(2**(29-i))==0:
                l.append([a,b])
        L=l
print(ans)
#print(k)

Fixed submission:
import copy
N,K=map(int,input().split())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    if a<=K:
        L.append([a,b])

#print(L)
k=[]
num=copy.deepcopy(K)
for i in range(30):
    if num//(2**(29-i))==1:
        k.append(1)
        num%=(2**(29-i))
    else:
        k.append(0)
        num%=(2**(29-i))
        
ans=0
for a,b in L:
    if K|a==K:
        ans+=b
NUM=0
for i in range(30):
    if k[i]==1:
        cnt=0
        NUM+=2**(29-i)
        for a,b in L:
            if K-2**(29-i)|a<NUM:
                cnt+=b
        if ans<cnt:
            ans=cnt
        #print(cnt,i,K-2**(29-i))
    
print(ans)
#print(k)

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
import copy
import sys
input=sys.stdin.readline
D=dict()
D[(0,0)]=1

for i in range(N):
    a,b=map(int,input().split())
    d=dict()
    for j in D:
        d[j]=1
        d[(j[0]|a,j[1]+b)]=1
    D=copy.deepcopy(d)
#print(D)
ans=0
for i in D:
    if i[1]>ans and i[0]<=K:
        ans=i[1]
print(ans)

Fixed submission:
import copy
N,K=map(int,input().split())
L=[]
for i in range(N):
    a,b=map(int,input().split())
    if a<=K:
        L.append([a,b])

#print(L)
k=[]
num=copy.deepcopy(K)
for i in range(30):
    if num//(2**(29-i))==1:
        k.append(1)
        num%=(2**(29-i))
    else:
        k.append(0)
        num%=(2**(29-i))
        
ans=0
for a,b in L:
    if K|a==K:
        ans+=b
NUM=0
for i in range(30):
    if k[i]==1:
        cnt=0
        NUM+=2**(29-i)
        for a,b in L:
            if K-2**(29-i)|a<NUM:
                cnt+=b
        if ans<cnt:
            ans=cnt
        #print(cnt,i,K-2**(29-i))
    
print(ans)
#print(k)