Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

ans=0
if l>2:
	for i in range(1,l-1):
		s=L[i][0]
		if s=="L":
			L[i][0]="R"
			K-=1
			if K==0:
				break

	lcnt=0
	now=None
	for i,t in enumerate(L):
		s=t[0]
		cnt=t[1]
		if i==0:
			now=s
			lcnt+=cnt
		else:
			if now==s:
				lcnt+=cnt
			elif now!=s:
				#print s,lcnt
				ans+=max(0,(lcnt-1))
				lcnt=cnt
				now=s
	else:
		ans+=(lcnt-1)

	print ans

else:
	if K<=1:
		print N-1
	else:
		for s,cnt in L:
			ans+=max(0,(lcnt-1))
		print ans

Fixed submission:
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print ans

Buggy python submission (verdict: Runtime Error):
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

ans=0
if l>2:
	for i in range(1,l-1):
		s=L[i][0]
		if s=="L":
			L[i][0]="R"
			K-=1
			if K==0:
				break
	lcnt=0
	for i,t in enumerate(L):
		s=t[0]
		cnt=t[1]
		if i==0:
			now=s
		else:
			if now==s:
				lcnt+=cnt
			elif now!=s:
				ans+=max(0,(lcnt-1))
				lcnt=cnt
				now=s
	else:
		ans+=(lcnt-1)

	print ans

else:
	if K<=1:
		print N-1
	else:
		for s,cnt in L:
			ans+=max(0,(lcnt-1))
		print ans

Fixed submission:
N,K=map(int, raw_input().split())
S=list(raw_input())

L=[]

now=None
for i,s in enumerate(S):
	if i==0:
		now=s
		cnt=1
	elif now==s:
		cnt+=1
	elif now!=s:
		L.append([now,cnt])
		cnt=1
		now=s
else:
	L.append([now,cnt])	

l=len(L)

for i in range(1,min(K*2,l),2):
	s=L[i][0]
	if s=="L": L[i][0]="R"
	elif s=="R": L[i][0]="L"


ans=0
prev=None
for t in L:
	s=t[0]
	cnt=t[1]
	if prev is None:
		prev=s
		lcnt=cnt
	else:
		if prev==s:
			lcnt+=cnt
		elif prev!=s:
			ans+=(lcnt-1)
			lcnt=cnt
		prev=s
else:
	ans+=(lcnt-1)
	
print ans
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from numpy import arange

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	if x==0 and y==0: continue
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


ans=0
for d_kouho in arange(0.0,360.1,0.01):
	ans_kouho=0
	for d,l in L:
		#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
		ans_kouho+=l*math.cos(math.radians(d-d_kouho))
	ans=max(ans,ans_kouho)

print ans


Fixed submission:
S=raw_input()
T=raw_input()

ans=0
for s,t in zip(S,T):
	if s==t: ans+=1

print ans
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),x,y) )

N=len(L)
L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math
from numpy import arange

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	if x==0 and y==0: continue
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


ans=0
for d_kouho in arange(0.0,360.1,0.01):
	ans_kouho=0
	for d,l in L:
		#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
		ans_kouho+=l*math.cos(math.radians(d-d_kouho))
	ans=max(ans,ans_kouho)

print ans


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


d_kouho=45	#角度の候補

ans=0
for d,l in L:
	#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
	ans+=l*math.cos(math.radians(d-d_kouho))
print ans


Fixed submission:
# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
N,Q=map(int, sys.stdin.readline().split())

al=[ [] for _ in range(N+1) ]	#隣接リスト
for _ in range(N-1):
	u,v=map(int, sys.stdin.readline().split())
	al[u].append(v)
	al[v].append(u)

increment=[ 0 for _ in range(N+1) ]
for _ in range(Q):
    p,x=map(int, sys.stdin.readline().split())
    increment[p]+=x

socre=[ 0 for _ in range(N+1) ] #各頂点のカウンターの値を記録
visit=[ 0 for _ in range(N+1) ] #0なら未訪問、1なら訪問済み
point=0
def dfs(par,cur):
    visit[cur]=1
    global point
    point+=increment[cur]
    socre[cur]+=point       #各頂点のカウンターの値を記録
    old=point   #拡張点が子孫に遷移する前のカウンターの値を記録
    for to in al[cur]:
        if visit[to]==0:
            dfs(cur,to)
            point=old   #子孫に遷移し、増えたカウンターの値を自分の時の点数に戻す
dfs(-1,1)

for i in range(1,N+1):
    print socre[i],

Fixed submission:
import sys
from collections import deque

N,Q=map(int, sys.stdin.readline().split())

 
al=[ [] for i in range(N+1) ]
 
for _ in range(N-1):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	al[b].append(a)

Visit=[ None for i in range(N+1) ] 
score=[ 0 for i in range(N+1) ] 

for _ in range(Q):
	p,x=map(int, sys.stdin.readline().split())
	score[p]+=x


q=deque()
q.append(1)

while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to] is None:
			score[to]+=score[fro]
			q.append(to)


for i,ans in enumerate(score):
	if i==0:	continue
	print ans,

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
N,Q=map(int, sys.stdin.readline().split())

al=[ [] for _ in range(N+1) ]	#隣接リスト
for _ in range(N-1):
	u,v=map(int, sys.stdin.readline().split())
	al[u].append(v)
	al[v].append(u)

increment=[ 0 for _ in range(N+1) ]
for _ in range(Q):
    p,x=map(int, sys.stdin.readline().split())
    increment[p]+=x

socre=[ 0 for _ in range(N+1) ] #各頂点のカウンターの値を記録
visit=[ 0 for _ in range(N+1) ] #0なら未訪問、1なら訪問済み
point=0
def dfs(par,cur):
    visit[cur]=1
    global point
    point+=increment[cur]
    socre[cur]+=point       #各頂点のカウンターの値を記録
    old=point   #拡張点が子孫に遷移する前のカウンターの値を記録
    for to in al[cur]:
        if visit[to]==0:
            dfs(cur,to)
            point=old   #子孫に遷移し、増えたカウンターの値を自分の時の点数に戻す
dfs(-1,1)

for i in range(1,N+1):
    print socre[i],

Fixed submission:
import sys
from collections import deque

N,Q=map(int, sys.stdin.readline().split())

 
al=[ [] for i in range(N+1) ]
 
for _ in range(N-1):
	a,b=map(int, sys.stdin.readline().split())
	al[a].append(b)
	al[b].append(a)

Visit=[ None for i in range(N+1) ] 
score=[ 0 for i in range(N+1) ] 

for _ in range(Q):
	p,x=map(int, sys.stdin.readline().split())
	score[p]+=x


q=deque()
q.append(1)

while q:
	fro=q.popleft()
	Visit[fro]=1
	for to in al[fro]:
		if Visit[to] is None:
			score[to]+=score[fro]
			q.append(to)


for i,ans in enumerate(score):
	if i==0:	continue
	print ans,
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter
from collections import defaultdict

N=input()

fact= [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact.append(fact_tmp) 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n]/fact[r]/fact[n-r])

C=defaultdict(lambda: 0) 
for i in range(N):
	s=sys.stdin.readline().strip()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=ncr(i,2)

print ans


Fixed submission:
import sys
from collections import Counter
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0) 
for i in range(N):
	s=sys.stdin.readline().strip()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=i*(i-1)/2

print ans

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from collections import defaultdict

N=input()

fact= [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact.append(fact_tmp) 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n]/fact[r]/fact[n-r])

C=defaultdict(lambda: 0) 
for i in range(N):
	s=raw_input()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=ncr(i,2)

print ans


Fixed submission:
import sys
from collections import Counter
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0) 
for i in range(N):
	s=sys.stdin.readline().strip()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=i*(i-1)/2

print ans
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heappush, heappop, heapify
from collections import defaultdict

N,M=map(int, sys.stdin.readline().split())

reward=defaultdict(lambda: []) 

hq=[]
for _ in range(N):
	a,b=map(int, sys.stdin.readline().split())
	reward[a].append(-1*b)


hq=[]
ans=0
for day in range(M-1,-1,-1):
	hq+=reward[M-day]
	heapify(hq)
	if hq:
		t=heappop(hq)
		ans+=t*-1

print ans

Fixed submission:
import sys
from heapq import heappush, heappop, heapify
from collections import defaultdict

N,M=map(int, sys.stdin.readline().split())

reward=defaultdict(lambda: []) 

hq=[]
for _ in range(N):
	a,b=map(int, sys.stdin.readline().split())
	reward[a].append(-1*b)


hq=[]
ans=0
for day in range(M-1,-1,-1):
	for r in reward[M-day]:
		heappush(hq,r)
	if hq:
		t=heappop(hq)
		ans+=t*-1

print ans
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

s=sum(A)
n=int(s**0.5)

#約数のリスト
cd=[]

for i in range(1,n+2):
	if s%i==0:
		cd.append(i)
		cd.append(s/i)

cd.sort(reverse=True)

def check(t):
	A_temp=[]
	for x in A:
		A_temp.append(x%t)

	A_temp.sort()

	#Aの配列をmod tした配列A_tempの累積和
	A_temp_sum=[]

	for i,x in enumerate(A_temp):
		if i==0: A_temp_sum.append(x)
		else: A_temp_sum.append(A_temp_sum[-1]+x)

	#配列の前半は、数字をマイナスしていく
	p1=bisect_left(A_temp_sum,K)
	if A_temp_sum[p1]<=K:
		k1=A_temp_sum[p1]
	else:
		p1-=1
		k1=A_temp_sum[p1]

	#配列の後半で、数字をどれだけプラスする必要があるか
	k2=t*(N-p1-1)-(A_temp_sum[-1]-A_temp_sum[p1])

	#プラスする量が、マイナスする量より少なければ成立
	if k2<=k1:
		return True
	else:
		return False

for x in cd:
	if check(x):
		print x
		quit()


Fixed submission:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left, bisect_right

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

s=sum(A)
n=int(s**0.5)

#約数のリスト
cd=[]

for i in range(1,n+2):
	if s%i==0:
		cd.append(i)
		cd.append(s/i)

cd.sort(reverse=True)

def check(t):
	if t==1: return True
	A_temp=[]
	for x in A:
		A_temp.append(x%t)

	A_temp.sort()

	#Aの配列をmod tした配列A_tempの累積和
	A_temp_sum=[]

	for i,x in enumerate(A_temp):
		if i==0: A_temp_sum.append(x)
		else: A_temp_sum.append(A_temp_sum[-1]+x)

	#配列の前半は、数字をマイナスしていく
	p1=min(bisect_left(A_temp_sum,K),N-2)
	if A_temp_sum[p1]<=K:
		k1=A_temp_sum[p1]
	else:
		#配列の項数p1の値がKを超えている場合は、p1の1個手前の値をとる
		p1-=1
		k1=A_temp_sum[p1]


	#配列の後半で、数字をどれだけプラスする必要があるか
	k2=t*(N-p1-1)-(A_temp_sum[-1]-A_temp_sum[p1])

	#プラスする量が、マイナスする量より少なければ成立
	if k2<=k1:
		return True
	else:
		return False

for x in cd:
	if check(x):
		print x
		quit()
Buggy python submission (verdict: Time Limit Exceeded):
N=input()
A=[ input()  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])


Fixed submission:
import sys
N=input()
A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])

Buggy python submission (verdict: Runtime Error):
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])


Fixed submission:
import sys
N=input()
A=[ int(sys.stdin.readline().strip())  for _ in range(N) ]

L=[]
for i,a in enumerate(A):
	if i==0:
		L.append(a)
	else:
		L.append( max(L[-1], a) )

R=[]
for i,a in enumerate(A[::-1]):
	if i==0:
		R.append(a)
	else:
		R.append( max(R[-1], a) )

R=R[::-1]


for i in range(N):
	if i==0:
		print R[i+1]
	elif i==N-1:
		print L[i-1]
	else:
		print max( R[i+1], L[i-1])
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N=input()
A=map(int, raw_input().split())

C=Counter(A)

if len(C)%3==0:
	a,b,c=C.keys()
	if N%3==0:
		if a^b==c:
			print "Yes"
		else:
			print "No"
else:
	if len(C)==1:
		if C.keys()==[0]:
			print "Yes"
		else:
			print "No"
	else:
		print "No"


Fixed submission:
from collections import Counter

N=input()
A=map(int, raw_input().split())

for i,x in enumerate(A):
	if i==0:
		t=x
	else:
		t^=x

if t==0:
	print "Yes"
else:
	print "No"
Buggy python submission (verdict: Runtime Error):
import sys
L,R=map(int, sys.stdin.readline().split())
sho1=L/2019
sho2=R/2019
if 1<=sho2-sho1:
    print 0
else:
    ans=float("inf")
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans=min(ans,i*j%2019)

print ans

Fixed submission:
L,R=map(int, raw_input().split())
a=L%2019
b=R%2019

T=[]
ans=float("inf")
if a<b:
	T=range(a,b+1)
	if R-L>2018:
		print 0
		quit()
	else:
		l=len(T)
		for i in range(l):
			for j in range(i+1,l):
				ans=min(ans, (T[i]*T[j])%2019 )

		print ans
else:
	print 0
	quit()
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import array
from numpy.linalg import solve
import sys

N=int(input())
#A=list(map(int, input().split())) 
A=list(map(int, sys.stdin.readline().split())) 

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print (int(ans)*2, end=" ")


Fixed submission:
import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x

Buggy python submission (verdict: Runtime Error):
from numpy import array
from numpy.linalg import solve

N=int(input()) 
A=list(map(int, input().split())) 

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print (int(ans)*2, end=" ")


Fixed submission:
import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import array
from numpy.linalg import solve

N=int(input()) 
A=list(map(int, input().split())) 

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print (int(ans)*2, end=" ")


Fixed submission:
import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x

Buggy python submission (verdict: Runtime Error):
from numpy import array
from numpy.linalg import solve
import sys

N=input()
A=map(int, sys.stdin.readline().split())

L=[]
for i in range(N-1):
	L.append ([0]*i+[1,1]+[0]*(N-i-2)) 

L.append([1]+[0]*(N-2)+[1])


a=array(L) 
b=array(A)       
L=solve(a,b) 

for ans in L:
	print int(ans)*2,


Fixed submission:
import sys
from collections import deque

N=input()
A=map(int, sys.stdin.readline().split())
A=map(lambda x: x*2, A)

a=sum(A)/2

for i in range(1,N):
	if i%2==1:
		a-=A[i]

#a
print a,

prev=a
for x in A[:-1]:
	x-=prev
	print x,
	prev=x
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import itertools
N,K=map(int, sys.stdin.readline().split())
cnt=(N-1)*(N-2)/2 #距離2の組み合わせができる最大の通り数
if cnt<K:
    print -1
    quit()
L=list( itertools.combinations(range(1,N+1),2) )

M=N-1+cnt-K
print M
for i in range(N-1):
    print L[i][0],L[i][1]

if N,K==100,0:
    for i in range(N,N+cnt-K-1):
            print L[i][0],L[i][1]
else:
    for i in range(N,N+cnt-K):
            print L[i][0],L[i][1]


Fixed submission:
N,K=map(int, raw_input().split())

torisu=(N-1)*(N-2)/2

if torisu<K:
	print -1
	quit()

print N-1+(torisu-K)

for i in range(2,N+1):
	print 1, i

cnt=0
for i in range(2,N+1):
	for j in range(i+1,N+1):
		if cnt==torisu-K:
			quit()
		print i,j
		cnt+=1

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import itertools
N,K=map(int, sys.stdin.readline().split())
cnt=(N-1)*(N-2)/2 #距離2の組み合わせができる最大の通り数
if cnt<K:
    print -1
    quit()
L=list( itertools.combinations(range(1,N+1),2) )

M=N-1+cnt-K
print M
for i in range(N-1):
    print L[i][0],L[i][1]

for i in range(N,N+cnt-K):
    print L[i][0],L[i][1]


Fixed submission:
N,K=map(int, raw_input().split())

torisu=(N-1)*(N-2)/2

if torisu<K:
	print -1
	quit()

print N-1+(torisu-K)

for i in range(2,N+1):
	print 1, i

cnt=0
for i in range(2,N+1):
	for j in range(i+1,N+1):
		if cnt==torisu-K:
			quit()
		print i,j
		cnt+=1

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import sys
import itertools
N,K=map(int, sys.stdin.readline().split())
cnt=(N-1)*(N-2)/2 #距離2の組み合わせができる最大の通り数
if cnt<K:
    print -1
    quit()
L=list( itertools.combinations(range(1,N+1),2) )

for i in range(N-1):
    print L[i][0],L[i][1]

for i in range(N,N+cnt-K):
    print L[i][0],L[i][1]


Fixed submission:
N,K=map(int, raw_input().split())

torisu=(N-1)*(N-2)/2

if torisu<K:
	print -1
	quit()

print N-1+(torisu-K)

for i in range(2,N+1):
	print 1, i

cnt=0
for i in range(2,N+1):
	for j in range(i+1,N+1):
		if cnt==torisu-K:
			quit()
		print i,j
		cnt+=1
Buggy python submission (verdict: Time Limit Exceeded):
import sys

N,M=map(int, sys.stdin.readline().split())
S=[None]+map(int, sys.stdin.readline().split())
T=[None]+map(int, sys.stdin.readline().split())

dp=[ [ 0 for m in range(M+1) ] for n in range(N+1) ]

for m in range(M+1): dp[0][m]=1	
for n in range(n+1): dp[n][0]=1	


for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i]==T[j]:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]
		else:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
		

print dp[-1][-1]%(10**9+7)


Fixed submission:
import sys

N,M=map(int, sys.stdin.readline().split())
S=[None]+map(int, sys.stdin.readline().split())
T=[None]+map(int, sys.stdin.readline().split())

dp=[ [ 0 for m in range(M+1) ] for n in range(N+1) ]

for m in range(M+1): dp[0][m]=1	
for n in range(n+1): dp[n][0]=1	

mod=10**9+7
for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i]==T[j]:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]
		else:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
		dp[i][j]%=mod
		

print dp[-1][-1]%mod
Buggy python submission (verdict: Runtime Error):
import itertools

N=input()
XY=[ map(int, raw_input().split())  for _ in range(N) ]
XY.sort(key=lambda x:(x[0],x[1]) )

D={}

C=list( itertools.combinations( range(1,N+1), 2) )

for b1, b2 in C:
	x1=XY[b1-1][0]
	y1=XY[b1-1][1]
	x2=XY[b2-1][0]
	y2=XY[b2-1][1]

	dx=x2-x1
	dy= y2-y1
	if (dx,dy) not in D:
		D[(dx,dy)]=1
	else:
		D[(dx,dy)]+=1

print N-max( D.values() )


Fixed submission:
import itertools

N=input()
if N==1:
	print 1
	quit()

XY=[ map(int, raw_input().split())  for _ in range(N) ]
XY.sort(key=lambda x:(x[0],x[1]) )

D={}

C=list( itertools.combinations( range(1,N+1), 2) )

for b1, b2 in C:
	x1=XY[b1-1][0]
	y1=XY[b1-1][1]
	x2=XY[b2-1][0]
	y2=XY[b2-1][1]

	dx=x2-x1
	dy= y2-y1
	if (dx,dy) not in D:
		D[(dx,dy)]=1
	else:
		D[(dx,dy)]+=1

print N-max( D.values() )
Buggy python submission (verdict: Runtime Error):
import sys

N=input()
A=map(int, sys.stdin.readline().split())
A.sort()

L=[]
for i in range(N-1):
	if i==0:
		next=A[i]-A[i+1]
		L.append( (A[i], A[i+1]) )

	else:
		if i==N-2:
			if A[i+1]<next:
				ans=next-A[i+1]
				L.append( (next,A[i+1]) )
			else:
				ans=A[i+1]-next
				L.append( (A[i+1],next) )
		else:
			L.append( (next, A[i+1]) )
			next=next-A[i+1]
else:
	print ans
	for x, y in L:
		print x,y



Fixed submission:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
A.sort()
min_A=A[0]
max_A=A[-1]

L=[]
for i in range(1,N-1):
	v=A[i]
	if v<0:
		L.append( (max_A, v) )
		max_A-=v
	else:
		L.append( (min_A, v) )
		min_A-=v
else:
	L.append( (max_A,min_A) )
	print max_A-min_A
	for x,y in L:
		print x,y

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

N=input()
A=map(int, sys.stdin.readline().split())
A.sort()

L=[]
for i in range(N-1):
	if i==0:
		next=A[i]-A[i+1]
		L.append( (A[i], A[i+1]) )

	else:
		if i==N-2:
			L.append( (A[i+1],next) )
			ans=A[i+1]-next
		else:
			L.append( (next, A[i+1]) )
			next=next-A[i+1]
else:
	print ans
	for x, y in L:
		print x,y


Fixed submission:
import sys

N=input()
A=map(int, sys.stdin.readline().split())
A.sort()
min_A=A[0]
max_A=A[-1]

L=[]
for i in range(1,N-1):
	v=A[i]
	if v<0:
		L.append( (max_A, v) )
		max_A-=v
	else:
		L.append( (min_A, v) )
		min_A-=v
else:
	L.append( (max_A,min_A) )
	print max_A-min_A
	for x,y in L:
		print x,y
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=input()
	NG[a]=1

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

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod


Fixed submission:
import sys
N,M=map(int, raw_input().split())

NG=[ 0 for i in range(N+1) ]
for i in range(M):
	a=int( sys.stdin.readline().strip() )
	NG[a]=1

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

mod=10**9+7

for i in range(N):
	if i+1<=N and NG[i+1]==0:
		dp[i+1]+=dp[i]
		dp[i+1]%=mod
	if  i+2<=N and NG[i+2]==0:
		dp[i+2]+=dp[i]
		dp[i+2]%=mod

print dp[N]%mod