Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i]) 
    ans = ans + (x-1+C)//C 
    if T[N-1]<t+K:
        y = N-i
    else:
        for j in range(i+((x-1+C)//C-1)*C,N):
            if T[j]>t+K:
                y = j-i
                break
 
    y=min(C,y)
    i = i + y 

print(ans)

Fixed submission:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0
time =0
p = 0

for i in range(N):
 
    if  p==0 or p ==C:
        ans = ans+1
        p =1
        time =T[i]+K
    elif p<C :
        if T[i]<=time:
            p +=1
        elif T[i]>time:
            ans =ans+1
            time=T[i]+K
            p =1

print(ans)

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

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i+((x-1+C)//C-1)*C,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Fixed submission:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0
time =0
p = 0

for i in range(N):
 
    if  p==0 or p ==C:
        ans = ans+1
        p =1
        time =T[i]+K
    elif p<C :
        if T[i]<=time:
            p +=1
        elif T[i]>time:
            ans =ans+1
            time=T[i]+K
            p =1

print(ans)

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

T.sort()
i = 0
ans = 0

while i < N:
    t = T[i]
    x = T.count(T[i])
    ans = ans + (x-1+C)//C
    for j in range(i,N):
        if T[j]>t+K:
            y = j-i
            break
        y = N-i
            
    y=min(C,y)
    i = i + y 

print(ans)

Fixed submission:
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()
i = 0
ans = 0
time =0
p = 0

for i in range(N):
 
    if  p==0 or p ==C:
        ans = ans+1
        p =1
        time =T[i]+K
    elif p<C :
        if T[i]<=time:
            p +=1
        elif T[i]>time:
            ans =ans+1
            time=T[i]+K
            p =1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))

cnt=1

for i in range(1,N):
    a=min(A)
    A.remove(min(A))
    b=min(A)
    A.remove(min(A))
    if 2*a>=b:
        cnt+=1
    else:
        cnt=1
    A.append(a+b)

print(cnt)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))

su=sum(A)
cnt=1
for i in range(N-1,0,-1):
    if (su-A[i])*2<A[i]:
        break
    else:
        cnt+=1
        su=su-A[i]

print(cnt)

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

A.sort(reverse=True)

cnt=1

for i in range(1,N):
    a=A.pop()
    b=A.pop()
    if 2*a>=b:
        cnt+=1
    else:
        cnt=1
    A.append(a+b)
    A.sort(reverse=True)

print(cnt)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))

su=sum(A)
cnt=1
for i in range(N-1,0,-1):
    if (su-A[i])*2<A[i]:
        break
    else:
        cnt+=1
        su=su-A[i]

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
count = 0

for a in range(K+1):
    for b in range(K+1):
        for c in range(K+1):
            if a+b+c == S:
                count =count +1

print(count)

Fixed submission:
K,S = map(int,input().split())
count = 0
for a in range(K+1):
    for b in range(K+1):
        x = S - (a+b)
        if x <= K and  x >= 0:
            count = count + 1
                
print(count)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
mod=10**9+7
a=[]
for i in range(M):
    a.append(int(input()))


DP=[1]*(N+1)

if 1 in a:
    DP[1]=0

for i in range(2,N+1):
    if i in a:
        DP[i]=0
        if DP[i-1]==0:
            print(0)
            exit()
    else:
        DP[i]=DP[i-1]+DP[i-2]
        DP[i]=DP[i]%mod

print(DP[N])


Fixed submission:
import collections

N=int(input())
A_data=list(map(int,input().split()))
mod=10**9+7

A=collections.Counter(A_data)

f=True
if N%2==1:
    if not A[0]==1:
        ans=0
    else:
        for i in range(2,N,2):
            if not A[i]==2:
                ans=0
                f=False
                break
        if f==True:
            ans=2**((N-1)//2)%mod
elif N%2==0:
    for i in range(1,N,2):
        if not A[i]==2:
            ans=0
            f=False
            break
    if f==True:
        ans=2**(N//2)%mod

print(ans)

Buggy python submission (verdict: Runtime Error):
import collections

N=int(input())
A_data=list(map(int,input().split()))
mod=10**9+7

A=collections.Counter(A_data)

if N%2==1:
    if not A[0]==1:
        ans=0
    else:
        for i in range(2,N,2):
            if not A[i]==2:
                ans=0
                break
        if ans!=0:
            ans=2**((N-1)//2)%mod
elif N%2==0:
    for i in range(1,N,2):
        if not A[i]==2:
            ans=0
            break
    if ans!=0:
        ans=2**(N//2)%mod

print(ans)

Fixed submission:
import collections

N=int(input())
A_data=list(map(int,input().split()))
mod=10**9+7

A=collections.Counter(A_data)

f=True
if N%2==1:
    if not A[0]==1:
        ans=0
    else:
        for i in range(2,N,2):
            if not A[i]==2:
                ans=0
                f=False
                break
        if f==True:
            ans=2**((N-1)//2)%mod
elif N%2==0:
    for i in range(1,N,2):
        if not A[i]==2:
            ans=0
            f=False
            break
    if f==True:
        ans=2**(N//2)%mod

print(ans)
Buggy python submission (verdict: Runtime Error):
W,H,N = map(int,input().split())
x=[]
y=[]
a=[]

A1=[]
A2=[]
A3=[]
A4=[]

for n in range(N):
    i,j,k = map(int,input().split())
    x.append(i)
    y.append(j)
    a.append(k)
a1,a2,a3,a4 = 0,0,0,0

for n in range(N):
    if a[n] == 1:
        A1.append(x[n])
        a1 = a1 + 1
    elif a[n] == 2:
        A2.append(x[n])
        a2 = a2 + 1
    elif a[n] == 3:
        A3.append(y[n])
        a3 = a3 + 1
    else:
        A4.append(y[n])
        a4 = a4 + 1

if a1 == 0 and a2 == 0:
    width = W
elif a1 == 0:
    width = min(A2)
elif a2 == 0:
    width = W - max(A1)
else:
    width = min(A2) - max(A1)
    if width <0:
        width = 0

if a3 == 0 and a4 == 0:
    height == H
elif a3 == 0:
    height =min(A4)
elif a4 ==0:
    height = H-max(A3)
else:
    height =min(A4) - max(A3)
    if width <0:
        width = 0

print(height*width)


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

wl = 0
wr = W
hu = H
hl = 0

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > wl:
        wl = x
    elif a == 2 and x < wr:
        wr = x
    elif a == 3 and y > hl:
        hl =y
    elif a == 4 and y < hu:
        hu = y
    
if wl>wr or hl>hu:
    print(0)
else:
    print((wr-wl)*(hu-hl))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    t=T[i]
    a=A[i]
    tempans=(t+a+ans-1)//(t+a)*(t+a)
    while True:
        tempT=tempans*t//(t+a)
        tempA=tempans*a//(t+a)
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=t+a
print(ans)



Fixed submission:
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]


for i in range(1,N):
    t=T[i]
    a=A[i]
    t1=(Tnow+t-1)//t*t
    a1=t1//t*a
    a2=(Anow+a-1)//a*a
    t2=a2//a*t
    if a1<Anow:
        Tnow=t2
        Anow=a2
    elif t2<Tnow:
        Tnow=t1
        Anow=a1
    elif t1+a1<=t2+a2:
        Tnow=t1
        Anow=a1
    else:
        Tnow=t2
        Anow=a2
print(Tnow+Anow)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    tempans=(T[i]+A[i]+ans-1)//(T[i]+A[i])*(T[i]+A[i])
    while True:
        tempT=tempans*T[i]//(T[i]+A[i])
        tempA=tempans*A[i]//(T[i]+A[i])
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=T[i]+A[i]
print(ans)



Fixed submission:
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]


for i in range(1,N):
    t=T[i]
    a=A[i]
    t1=(Tnow+t-1)//t*t
    a1=t1//t*a
    a2=(Anow+a-1)//a*a
    t2=a2//a*t
    if a1<Anow:
        Tnow=t2
        Anow=a2
    elif t2<Tnow:
        Tnow=t1
        Anow=a1
    elif t1+a1<=t2+a2:
        Tnow=t1
        Anow=a1
    else:
        Tnow=t2
        Anow=a2
print(Tnow+Anow)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]
ans=Tnow+Anow

for i in range(1,N):
    tempans=(T[i]+A[i]+ans-1)//(T[i]+A[i])*(T[i]+A[i])
    while True:
        tempT=tempans*T[i]//(T[i]+A[i])
        tempA=tempans*A[i]//(T[i]+A[i])
        if tempT>=Tnow and tempA>=Anow:
            ans=tempans
            Tnow=tempT
            Anow=tempA
            break
        else:
            tempans+=T[i]+A[i]
print(ans)



Fixed submission:
N=int(input())
T=[]
A=[]
for i in range(N):
    t,a=map(int,input().split())
    T.append(t)
    A.append(a)

Tnow=T[0]
Anow=A[0]


for i in range(1,N):
    t=T[i]
    a=A[i]
    t1=(Tnow+t-1)//t*t
    a1=t1//t*a
    a2=(Anow+a-1)//a*a
    t2=a2//a*t
    if a1<Anow:
        Tnow=t2
        Anow=a2
    elif t2<Tnow:
        Tnow=t1
        Anow=a1
    elif t1+a1<=t2+a2:
        Tnow=t1
        Anow=a1
    else:
        Tnow=t2
        Anow=a2
print(Tnow+Anow)
Buggy python submission (verdict: Time Limit Exceeded):
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])
A2.pop(0)
for i in range(1,L):
    A1.append(A2[0])
    A2.pop(0)
    if len(A1)>=2 and A1[-2]=="S" and A1[-1]=="T":
        A1.pop(-1)
        A1.pop(-1)
print(len(A1))

Fixed submission:
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and A2[i]=="T":
        A1.pop(-1)
    else:
        A1.append(A2[i])

print(len(A1))

Buggy python submission (verdict: Time Limit Exceeded):
X=list(input())

L=len(X)
cnt=0
i=0
while cnt<=L//2 and i<len(X)-1:
    if X[i]=="S" and X[i+1]=="T":
        X.pop(i+1)
        X.pop(i)
        cnt+=1
        i=-1
    i+=1

print(len(X))

Fixed submission:
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and A2[i]=="T":
        A1.pop(-1)
    else:
        A1.append(A2[i])

print(len(A1))

Buggy python submission (verdict: Runtime Error):
X=input()

S=0

for i in range(L):
    if X[-(1+i)]=="S":
        S+=1
    else:
        break
print(2*S)



Fixed submission:
A2=list(input())
A1=[]
L=len(A2)
A1.append(A2[0])

for i in range(1,L):
    if len(A1)>=1 and A1[-1]=="S" and A2[i]=="T":
        A1.pop(-1)
    else:
        A1.append(A2[i])

print(len(A1))
Buggy python submission (verdict: Runtime Error):
s=list(input())
K=int(input())

abc="bcdefghijklmnopqrstuvwxyza"

cnt=K
for i in range(len(s)):
    temp=25-abc.index(s[i])
    if cnt>=temp:
        s[i]="a"
        cnt-=temp

if cnt!=0:
    if abc.index(s[-1])+cnt>25:
        s[-1]=abc[abc.index(s[-1])+cnt-26]
    else:
        s[-1]=abc[abc.index(s[-1])+cnt]

print("".join(s))


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

abc="bcdefghijklmnopqrstuvwxyza"

cnt=K
for i in range(len(s)):
    temp=25-abc.index(s[i])
    if cnt>=temp:
        s[i]="a"
        cnt-=temp

if cnt!=0:
    s[-1]=abc[(abc.index(s[-1])+cnt)%26]

print("".join(s))
Buggy python submission (verdict: Runtime Error):
SA = input()
SB = input()
SC = input()

ca,cb,cc = 0,0,0
t = "a"
while ca < len(SA) and cb < len(SB) and cc < len(SC):
    if t == "a":
        answer = "A"
        t = SA[ca]
        ca = ca + 1      
    elif t == "b":
        answer = "B"
        t = [cb]
        cb = cb + 1
    else:
        answer ="C"
        t = SC[cb]
        cb = cb +1
print(answer)

Fixed submission:
SA = input()
SB = input()
SC = input()

ca,cb,cc = 0,0,0
t = "a"
while ca <= len(SA) and cb <= len(SB) and cc <= len(SC):
    if t == "a":
        if ca == len(SA):
            print("A")
            exit()
        t = SA[ca]
        ca = ca + 1
        
    elif t == "b":
        if cb == len(SB):
            print("B")
            exit()
        t = SB[cb]
        cb = cb + 1
    else:
        if cc == len(SC):
            print("C")
            exit()
        t = SC[cc]
        cc = cc +1
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[0]*N
DP=[0]*N

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

DP[0]=A[0]//2
DP[1]=max(A[0]//2+A[1]//2,min(A[0],A[1]))

for i in range(2,N):
    DP[i]=max(DP[i-2]+A[i-1]//2+A[i]//2,DP[i-2]+min(A[i-1],A[i]))

print(DP[N-1])

Fixed submission:
N=int(input())

ans=0
co=0
for i in range(N):
    a=int(input())
    ans+=(a+co)//2
    if a==0:
        co=0
    else:
        co=(a+co)%2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
ST = input()
ST = ST[::-1]

# NUM1 =
# NUM2 =
popcnt = 0

for i in range(N):
    popcnt += ST[i] == '1'

NUM1 = 0
NUM2 = 0
pop_1 = popcnt-1
pop_2 = popcnt+1
for i in range(N):
    if ST[i] == '1':
        if pop_1 >= 0:
            NUM1 += pow(2, i, pop_1)
            NUM1 %= pop_1
        if pop_2 <= N:
            NUM2 += pow(2, i, pop_2)
            NUM2 %= pop_2

# print(pop_1, pop_2)
# print(NUM1, NUM2)

for i in range(N):
    cnt = 1
    i = N-i-1
    if ST[i] == '1':
        # print("A")
        value = NUM1 - pow(2, i, pop_1)
        value %= pop_1
        while value:
            value %= bin(value).count("1")
            cnt += 1
        print(cnt)
    else:
        # print("B")
        value = NUM2 + pow(2, i, pop_2)
        value %= pop_2
        while value:
            value %= bin(value).count("1")
            cnt += 1
        print(cnt)


Fixed submission:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
ST = input()
ST = ST[::-1]

# NUM1 =
# NUM2 =
popcnt = 0

for i in range(N):
    popcnt += ST[i] == '1'

NUM1 = 0
NUM2 = 0
pop_1 = popcnt-1
pop_2 = popcnt+1
for i in range(N):
    if ST[i] == '1':
        if pop_1 > 0:
            NUM1 += pow(2, i, pop_1)
            NUM1 %= pop_1
        if pop_2 <= N:
            NUM2 += pow(2, i, pop_2)
            NUM2 %= pop_2

# print(pop_1, pop_2)
# print(NUM1, NUM2)

for i in range(N):
    cnt = 1
    i = N-i-1
    if ST[i] == '1':
        # print("A")
        if pop_1 != 0:
            value = NUM1 - pow(2, i, pop_1)
            value %= pop_1
            while value:
                value %= bin(value).count("1")
                cnt += 1
            print(cnt)
        else:
            print(0)
    else:
        # print("B")
        value = NUM2 + pow(2, i, pop_2)
        value %= pop_2
        while value:
            value %= bin(value).count("1")
            cnt += 1
        print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
AS = LI()
DP = {}
DP[(0, 0)] = 0

mm = -(10**18)
for i in range(N):
    NX = {}
    for ((cnt, isUsed), value) in DP.items():
        if isUsed:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
        else:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
            if cnt >= (i // 2 - 5):
                NX[(cnt+1, 1)] = max(value + AS[i],
                                     NX.get((cnt+1, 1)) or mm)
    DP = NX

res = -(10**18)
for ((cnt, _), value) in DP.items():
    if cnt == N//2:
        res = max(res, value)
print(res)


Fixed submission:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


N = II()
AS = LI()
DP = {}
DP[(0, 0)] = 0

mm = -(10**18)
for i in range(N):
    NX = {}
    for ((cnt, isUsed), value) in DP.items():
        if isUsed:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
        else:
            if cnt >= (i // 2 - 5):
                NX[(cnt, 0)] = max(value, NX.get((cnt, 0)) or mm)
            if cnt >= (i // 2 - 5):
                NX[(cnt+1, 1)] = max(value + AS[i],
                                     NX.get((cnt+1, 1)) or mm)
    DP = NX
    # print(NX)

res = -(10**18)
for ((cnt, _), value) in DP.items():
    if cnt == N//2:
        res = max(res, value)
print(res)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import heapq
import bisect

sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N,M=LI()
As=LI()
As.sort()
len_As = len(As)
Acum=[As[0]]
for i in range(1, len_As):
    Acum.append(Acum[i-1]+As[i])
# print(As)
# print(Acum)

ok = 0
ng = 2*max(As)+1

pat = 0
sm = 0
while ng - ok > 1:
    mid_sum = (ok + ng)//2
    pat = 0
    sm = 0
    for A in As:
        A2 = mid_sum - A
        # print(A2)
        lft = bisect.bisect_left(As, A2)
        pat += len_As - lft
        sm += Acum[len_As-1] - (lft and Acum[lft-1]) + (len_As - lft)*A
    # print(pat, M, ok, ng)

    if pat < M: ng = mid_sum
    else: ok = mid_sum

pat = 0
sm = 0
for A in As:
    A2 = ok - A
    # print(A2)
    lft = bisect.bisect_left(As, A2)
    pat += len_As - lft
    sm += Acum[len_As-1] - (lft and Acum[lft-1]) + (len_As - lft)*A

# print("lo:{} hi:{} pat:{} sum:{}".format(ok, ng, pat, sm))

print(sm - (pat-M)*ok)


Fixed submission:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

S,T=LS()
print(T+S)