Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=input()
A=[ input() for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)





Fixed submission:
import sys


N=input()
A=[  int(sys.stdin.readline()) for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)

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

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

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	for i in range(n):
		K.append(-2)
	K.append(-1)
	K.append(1)
	for i in range(n):
		K.append(2)
else:
	n=(N-2)/2

	## Pattern 1
	for i in range(n):
		K.append(-2)
	K.append(-1)
	K.append(-1)
	for i in range(n+1):
		K.append(2)
	## End

	## Pattern 2
	for i in range(n+1):
		K2.append(-2)
	K2.append(1)
	K2.append(1)
	for i in range(n):
		K2.append(2)
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)


Fixed submission:
import sys


N=input()
A=[  int(sys.stdin.readline()) for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)

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

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

A.sort()

q=deque(A)
q2=deque()

cnt=0
while q:
	cnt+=1

	if cnt==1:
		v=q.popleft()
		q2.append(v)
	else:
		if cnt%2==0:
			v=q.pop()
		else:
			v=q.popleft()			

		begin=q2[0]
		end=q2[-1]

		if abs(begin-v)>=abs(end-v):
			q2.appendleft(v)
		else:
			q2.append(v)

l=list(q2)

ans=0
for i in range(N-1):
	ans+=abs(l[i+1]-l[i])

print ans


Fixed submission:
import sys


N=input()
A=[  int(sys.stdin.readline()) for i in range(N) ] 

A.sort()

K=[]
K2=[]

if N%2==0:
	n=(N-2)/2
	K=[ -2 for i in range(n) ]+[-1,1]+[ 2 for i in range(n) ]
else:
	n=(N-2)/2

	## Pattern 1
	K=[ -2 for i in range(n) ]+[-1,-1]+[ 2 for i in range(n+1) ]
	## End

	## Pattern 2
	K2=[ -2 for i in range(n+1) ]+[1,1]+[ 2 for i in range(n) ]
	## End

ans=0

t1=0
for x, y in zip(A,K):
	t1+=x*y

t2=0
for x, y in zip(A,K2):
	t2+=x*y


print max(t1,t2)
Buggy python submission (verdict: Runtime Error):
N=input()
if N==1:
  	print "Hello World"
else:
  	A=input()
    B=input()
   	print A+B

Fixed submission:
N=input()
if N==1:
	print "Hello World"
else:
	A=input()
	B=input()
	print A+B
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n=input()
A=map(int,raw_input().split())

M0=[]
M1=[]

for i in range(n):
	if i%2==0: M0.append(A[i])
	else: M1.append(A[i])

C0=Counter(M0)
C1=Counter(M1)

l0=len(C0)
l1=len(C1)

ans=0
if l0>1:
	L=sorted(C1.items(), key=lambda x:x[1])
	ans=0
	for i in range(l0-1):
		ans+=L[i][1]

if l1>1:
	L=sorted(C1.items(), key=lambda x:x[1])
	ans=0
	for i in range(l1-1):
		ans+=L[i][1]

print ans


Fixed submission:
from collections import Counter
n=input()
A=map(int,raw_input().split())

M0=[]
M1=[]

for i in range(n):
	if i%2==0: M0.append(A[i])
	else: M1.append(A[i])

C0=Counter(M0)
C1=Counter(M1)

L0=sorted(C0.items(), key=lambda x:x[1], reverse=True)
L1=sorted(C1.items(), key=lambda x:x[1], reverse=True)

a0=None
a1=None

if L0[0][0]!=L1[0][0]:
	a0=L0[0][0]
	a1=L1[0][0]
	b0=L0[0][0]
	b1=L1[0][0]
elif L0[0][0]==L1[0][0]:
	a0=L0[0][0]
	if len(L1)==1:
		a1=-1
	else:
		a1=L1[1][0]

	b1=L1[0][0]
	if len(L0)==1:
		b0=-1
	else:
		b0=L0[1][0]

ans0=0
ans1=0
for x in M0:
	if x!=a0:
		ans0+=1

for x in M1:
	if x!=a1:
		ans0+=1

ans1=0
for x in M0:
	if x!=b0:
		ans1+=1

for x in M1:
	if x!=b1:
		ans1+=1

print min(ans0, ans1)
Buggy python submission (verdict: Time Limit Exceeded):
T=input()
for i in range(T):
	A,B,C,D=map(int,raw_input().split())
	if A<B:
		print "No"
	elif B>D:
		print "No"
	elif abs(B-C)==1:
		print "Yes"
	else:
		A=A%B

		while A<=B:
			if (D-B)%B==0:
				if A>C and A<B:
					print "No"
					break
				else:
					print "Yes"
					break
			elif (D-B)%B==1:
					print "No"
					break

			A+=(D-B)%B
			if A>C and A<B:
				print "No"
				break
		else:
			print "Yes"

Fixed submission:
import fractions

def func(A,B,C,D):
#	print "A,B,C,D::",A,B,C,D

	if A<B:
		print "No"
	elif B>D:
		print "No"
	elif B<=C:
		print "Yes"

	else:
		A%=B
		g=fractions.gcd(B,D)
		if g==B:
			if A>C:
				print "No"
			else:
				print "Yes"
		elif B-g>C:
			print "No"
		else:
			print "Yes"
T=input()

for i in range(T):
	a,b,c,d=map(int, raw_input().split())
	func(a,b,c,d)

Buggy python submission (verdict: Time Limit Exceeded):
T=input()
for i in range(T):
	A,B,C,D=map(int,raw_input().split())
	if A<B:
		print "No"
	elif B>D:
		print "No"
	else:
		A=A%B

		while A<=B:
			if (D-B)%B==0:
				if A>C and A<B:
					print "No"
					break
				else:
					print "Yes"
					break

			A+=(D-B)%B
			if A>C and A<B:
				print "No"
				break
		else:
			print "Yes"

Fixed submission:
import fractions

def func(A,B,C,D):
#	print "A,B,C,D::",A,B,C,D

	if A<B:
		print "No"
	elif B>D:
		print "No"
	elif B<=C:
		print "Yes"

	else:
		A%=B
		g=fractions.gcd(B,D)
		if g==B:
			if A>C:
				print "No"
			else:
				print "Yes"
		elif B-g>C:
			print "No"
		else:
			print "Yes"
T=input()

for i in range(T):
	a,b,c,d=map(int, raw_input().split())
	func(a,b,c,d)
Buggy python submission (verdict: Time Limit Exceeded):
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)

C=[]
for x,y in zip(A,B):
	C.append(x-y)

K=set(C)
L=list(K)
L.append(0)
L.sort()

h=len(L)
l=0


ans=float("inf")

for j in range(1000):
	m=(h+l)/2
	x=L[m]
	t=0
	for y in C:
		t+=abs(-1*x+y)

	if t<ans:
		ans=t
		h=m
	else:
		l=m
	ans=min(ans,t)

print ans

Fixed submission:
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)
 
C=[]
for x,y in zip(A,B):
	C.append(x-y)

C.sort()

m=0
if len(C)%2==1:
	m=C[len(C)/2]
else:
	m=(C[len(C)/2-1]+C[len(C)/2])/2

	
t=0
for x in C:
	t+=abs(-1*m+x)
print t

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)

C=[]
for x,y in zip(A,B):
	C.append(x-y)

K=set(C)


ans=float("inf")
for x in K:
	t=0
	for y in C:
		t+=abs(-1*x+y)
	ans=min(ans, abs(t))

print ans

Fixed submission:
N=input()
A=map(int, raw_input().split())
B=range(1,N+1)
 
C=[]
for x,y in zip(A,B):
	C.append(x-y)

C.sort()

m=0
if len(C)%2==1:
	m=C[len(C)/2]
else:
	m=(C[len(C)/2-1]+C[len(C)/2])/2

	
t=0
for x in C:
	t+=abs(-1*m+x)
print t
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(101000)

N=input()

memo={}
def dp(n):
	ret=float("inf")
	if n==0: return 0
	if n<0: return float("inf")
	if n in memo: return memo[n]

	for k in range(1,8):
		t=min(dp(n-6**k)+1,dp(n-9**k)+1,dp(n-1)+1)
		ret=min(ret,t)
	
	memo[n]=ret
	return ret

#print dp(8)
#print dp(12)
#print dp(83)
#print dp(N)
dp(N)
print memo[N]


Fixed submission:
import copy
N=input()

def nine(m):
	if m<9: return m
	for i in range(1000):
		t=9**i
		if t>m:
			t1=9**(i-1)
			return m-t1
def six(m):
	if m<6: return m
	for i in range(1000):
		t=6**i
		if t>m:
			t2=6**(i-1)
			return m-t2


Z=15
k=1<<Z

b=set()
for i in range(k):

	n=copy.deepcopy(N)
	ans=0
	for j in range(Z):
		if n<6:
			b.add(ans+n)
			break
		if i&(1<<j)!=0:
			#9
			n=nine(n)
			ans+=1
		else:
			#6
			n=six(n)
			ans+=1


print min(b)
Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,l+1):
	for i in range(l):
		a.add(s[i:i+diff])
b=list(a)
b.sort()

print b[K-1]

Fixed submission:
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,5+1):
	for i in range(l):
		a.add(s[i:i+diff])

b=list(a)
b.sort()

print b[K-1]

Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,l+1):
	for i in range(l):
		a.add(s[i:i+diff])
b=list(a)
b.sort()

print b[K-1]


Fixed submission:
s=raw_input()
K=input()
l=len(s)

a=set()
for diff in range(1,5+1):
	for i in range(l):
		a.add(s[i:i+diff])

b=list(a)
b.sort()

print b[K-1]
Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans


Fixed submission:
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	T={}

	for i in range(N):
		for j in range(N):
			T[(i,j)]=S[(i+A)%N][(j+B)%N]

	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			if T[ (i,j) ]==T[ (j,i) ]:
				pass
			else:
				flag=-1
				break
	else:
		ans+=1*N


print ans

Fixed submission:
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	T={}

	for i in range(N):
		for j in range(N):
			T[(i,j)]=S[(i+A)%N][(j+B)%N]

	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			if T[ (i,j) ]==T[ (j,i) ]:
				pass
			else:
				flag=-1
				break
	else:
		ans+=1*N


print ans


Fixed submission:
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans

Buggy python submission (verdict: Time Limit Exceeded):
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	T=[ ["" for j in range(N)] for i in range(N)]

	for i in range(N):
		for j in range(N):
			T[i][j]=S[(i+A)%N][(j+B)%N]

	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			if T[i][j]==T[j][i]:
				pass
			else:
				flag=-1
				break
	else:
		ans+=1*N


print ans


Fixed submission:
N=input()
S=[ list(raw_input()) for i in range(N)]

A=0
ans=0
for B in range(N):
	flag=0
	for i in range(N):
		if flag==-1: break
		for j in range(N):
			x1=(N+i-A)%N
			y1=(N+j-B)%N

			x2=(N+j-A)%N
			y2=(N+i-B)%N

			#print i,j,x1,y1,x2,y2
			if S[x1][y1]==S[x2][y2]:
				pass
			else:
				flag=-1
				#break
	else:
		ans+=1*N


print ans
Buggy python submission (verdict: Time Limit Exceeded):
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )

c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append( (comb(c,a[i]),a[i]) )

print c,sorted(d, key=lambda x:x[0],reverse=True)[0][1]


Fixed submission:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()


c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append(a[i])

d.sort()
d.reverse()

print c,d[0]

Buggy python submission (verdict: Runtime Error):
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	#return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )
	if N-R>=R: t=R
	else:	t=N-R

	bunbo=1
	bunshi=1
	for i in range(1,t+1):
		bunbo*=(N-i+1)
		bunshi*=i
	return bunbo/bunshi


l=1
r=n-1
c=a[0]
for i in range(20):
	if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
		r=(l+r*2)/3
	else:
		l=(l*2+r)/3


if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
	print c,a[(l*2+r)/3]
else:
	print c,a[(l+r*2)/3]
	 

Fixed submission:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()


c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append(a[i])

d.sort()
d.reverse()

print c,d[0]

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()

def comb(N,R):
	return math.factorial(N)/( math.factorial(N-R)*math.factorial(R) )



l=1
r=n-1
c=a[0]
for i in range(20):
	if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
		r=(l+r*2)/3
	else:
		l=(l*2+r)/3


if comb(c,a[(l*2+r)/3]) > comb(c,a[(l+r*2)/3]):
	print c,a[(l*2+r)/3]
else:
	print c,a[(l+r*2)/3]
	 

Fixed submission:
import math
n=input()
a=map(int, raw_input().split())
a.sort()
a.reverse()


c=a[0]

b=[0 for i in range(n)]
for i in range(1,n):
	b[i]=abs(a[i]-c/2)

min_b=min(b[1:])

d=[]
for i in range(1,n):
	if b[i]==min_b:
		d.append(a[i])

d.sort()
d.reverse()

print c,d[0]
Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)
d=len(l)

if d/2>=K:
	for i in l[:K]:
		print i
	for i in l[-1*K:]:
		print i
elif d/2<K and K<d:
	for i in l[:K]:
		print i
	for i in l[ K-d:]:
		print i
else:
	for i in l:
		print i

Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-1*K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ K-len(l):]:
		print i
else:
	for i in l:
		print i


Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
#elif len(l)/2<K and K<len(l):
#	for i in l[:K]:
#		print i
#	for i in l[ K-len(l):]:
#		print i
else:
	for i in l:
		print i

Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ K-len(l):]:
		print i
else:
	for i in l:
		print i

Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ ( K-(2*K-len(l)) )*-1:]:
		print i
else:
	for i in l:
		print i


Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i

Buggy python submission (verdict: Runtime Error):
A,B,K=map(int, raw_input().split())
l=range(A,B+1)

if len(l)/2>=K:
	for i in l[:K]:
		print i
	for i in l[-K:]:
		print i
elif len(l)/2<K and K<len(l):
	for i in l[:K]:
		print i
	for i in l[ ( K-(2*K-len(l)) )*-1:]:
		print i
elif len(l)/2<K and K>=len(l):
	for i in l:
		print i
	

Fixed submission:
A,B,K=map(int, raw_input().split())
c=set()
for i in range(A,min(B+1,A+K)):
	c.add(i)

for i in range(B,max(A-1,B-K),-1):
	c.add(i)


a=list(c)
a.sort()
for i in a:
	print i
Buggy python submission (verdict: Runtime Error):
N=input()

if N==3:
	print "2 5 63"
	quit()
elif N==4:
	print "2 5 20 63"
	quit()

#N>=5
#For 2 and 3
S=[2,3,4]
N-=3


x=N/4	# N=4x+b
b=N%4

for i in range(1,x+1):
	S.append(6*i)
	S.append(6*i+2)
	S.append(6*i+3)
	S.append(6*i+4)

if x%2==0:
	if b==0:
		pass
	elif b==1:
		S.append(6*(x+1)+3)
	elif b==2:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
		S.append(6*(x+1)+6)
else:
	if b==0:
		S.remove(6*x+3)
		S.remove(6*x+6)
	elif b==1:
		S.append(6*(x+1))
	elif b==2:
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)	

for i in S:
	print i,


Fixed submission:
N=input()

if N==3:
	print "2 5 63"
	quit()
elif N==4:
	print "2 5 20 63"
	quit()

#N>=5
#For 2 and 3
S=[2,3,4]
N-=3


x=N/4	# N=4x+b
b=N%4

for i in range(1,x+1):
	S.append(6*i)
	S.append(6*i+2)
	S.append(6*i+3)
	S.append(6*i+4)


if x%2==0:
	if b==0:
		S.remove(6*x+3)
		S.append(6*x+6)
	elif b==1:
		S.append(6*(x+1)+3)
	elif b==2:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+3)
		S.append(6*(x+1)+6)
else:
	if b==0:
		pass
	elif b==1:
		S.append(6*(x+1))
	elif b==2:
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)
	elif b==3:
		S.append(6*(x+1))
		S.append(6*(x+1)+2)
		S.append(6*(x+1)+4)	

for i in S:
	print i,
Buggy python submission (verdict: Runtime Error):
N=input()
a=[]
for i in range(2*N):
	x,y=map(int, raw_input().split())
	if i<N: a.append([x,y,"R"])
	else: a.append([x,y,"B"])

b=sorted(a, key=lambda x: x[0], reverse=True)


q=[]
ans=0
for i in b:
	x=i[1]
	type=i[2]
	if type=="B":
		q.append(x)
	elif type=="R" and len(q)>0:
		up=0
		tmp=[]
		for j in q:
			if x<=j:
				tmp.append(j)
				up=1
		else:
			ans+=up
		val=min(tmp)
		q.remove(val)

print ans

Fixed submission:
N=input()
a=[]
for i in range(2*N):
	x,y=map(int, raw_input().split())
	if i<N: a.append([x,y,"R"])
	else: a.append([x,y,"B"])

b=sorted(a, key=lambda x: x[0], reverse=True)


q=[]
ans=0
for i in b:
	x=i[1]
	type=i[2]
	if type=="B":
		q.append(x)
	elif type=="R" and len(q)>0:
		up=0
		tmp=[]
		for j in q:
			if x<=j:
				tmp.append(j)
				up=1
		ans+=up
		if len(tmp)>0:
			val=min(tmp)
			q.remove(val)

print ans
Buggy python submission (verdict: Time Limit Exceeded):
H,W,D=map(int,raw_input().split())
C={}
for i in range(H):
	A=map(int,raw_input().split())
	cnt=1
	for j in A:
		C[j]=(i+1,cnt)
		cnt+=1


Q=input()
memo={}
for i in range(Q):
	L,R=map(int,raw_input().split())

	if (L,R) in memo:
		print memo[(L,R)]
		continue
	ans=0
	for j in range(L,R,D):
		ans+=abs(C[j][0]-C[j+D][0])+abs(C[j][1]-C[j+D][1])
		memo[(j,j+D)]=abs(C[j][0]-C[j+D][0])+abs(C[j][1]-C[j+D][1])
	memo[(L,R)]=ans
	print ans


Fixed submission:
H,W,D=map(int,raw_input().split())
C={}
for i in range(H):
	A=map(int,raw_input().split())
	cnt=1
	for j in A:
		C[j]=(i+1,cnt)
		cnt+=1

dist=[ 0 for i in range(H*W+1) ]

for i in range(1,H*W+1):
	if i<=D:
		continue
	dist[i]=dist[i-D]+abs(C[i-D][0]-C[i][0])+abs(C[i-D][1]-C[i][1])
	

Q=input()
for i in range(Q):
	L,R=map(int,raw_input().split())
	print dist[R]-dist[L]

Buggy python submission (verdict: Time Limit Exceeded):
H,W,D=map(int,raw_input().split())
C={}
for i in range(H):
	A=map(int,raw_input().split())
	cnt=1
	for j in A:
		C[j]=(i+1,cnt)
		cnt+=1


Q=input()
for i in range(Q):
	L,R=map(int,raw_input().split())
	ans=0
	for j in range(L,R,D):
		ans+=abs(C[j][0]-C[j+D][0])+abs(C[j][1]-C[j+D][1])
	print ans

Fixed submission:
H,W,D=map(int,raw_input().split())
C={}
for i in range(H):
	A=map(int,raw_input().split())
	cnt=1
	for j in A:
		C[j]=(i+1,cnt)
		cnt+=1

dist=[ 0 for i in range(H*W+1) ]

for i in range(1,H*W+1):
	if i<=D:
		continue
	dist[i]=dist[i-D]+abs(C[i-D][0]-C[i][0])+abs(C[i-D][1]-C[i][1])
	

Q=input()
for i in range(Q):
	L,R=map(int,raw_input().split())
	print dist[R]-dist[L]
Buggy python submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,raw_input().split())
c=[]
for i in range(H):
	s=list(raw_input())
	for j in s:
		if j=="#":
			c.append(1)
		else:
			c.append(0)


nl=[ [] for i in range(H*W)]

p0=[-1,1,3]
p1=[-3,1,3]
p2=[-3,-1,3]
p3=[-3,-1,1]
p4=[-3,-1,1,3]
for i in range(H*W):
	if c[i]==0:
		if i==0:
			if c[i+1]==0:nl[i].append(i+1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W-1:
			if c[i-1]==0:nl[i].append(i-1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W*(H-1):
			if c[i-W]==0:nl[i].append(i-W)
			if c[i+1]==0:nl[i].append(i+1)		
		elif i==W*H-1:
			if c[i-W]==0:nl[i].append(i-W)
			if c[i-1]==0:nl[i].append(i-1)
		elif i<W-1:
			for j in p0:
				if c[i+j]==0:nl[i].append(i+j)			
		elif i%W==0:
			for j in p1:
				if c[i+j]==0:nl[i].append(i+j)	
		elif i%W==W-1:
			for j in p2:
				if c[i+j]==0:nl[i].append(i+j)
		elif i>W*(H-1):
			for j in p3:
				if c[i+j]==0:nl[i].append(i+j)
		else:
			for j in p4:
				if c[i+j]==0:nl[i].append(i+j)
				

V=[ None for i in range(H*W)]

def dfs(start):
	q = deque([]) 
	V[start]=1
	q.append(start)

	while len(q)!=0:
		v=q.pop()
		V[v]=1
		if H*W-1 in nl[v]:
			V[H*W-1]=1
			return

		for i in nl[v]:
			if V[i] is None:
				q.append(i)

dfs(0)
print len( filter(lambda x:x is None, V) ) - sum(c)




Fixed submission:
from collections import deque
H,W=map(int,raw_input().split())
c=[]
for i in range(H):
	s=list(raw_input())
	for j in s:
		if j=="#":
			c.append(1)
		else:
			c.append(0)


nl=[ [] for i in range(H*W)]

p0=[-1,1,W]
p1=[-W,1,W]
p2=[-W,-1,W]
p3=[-W,-1,1]
p4=[-W,-1,1,W]
for i in range(H*W):
	if c[i]==0:
		if i==0:
			if c[i+1]==0:nl[i].append(i+1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W-1:
			if c[i-1]==0:nl[i].append(i-1)
			if c[i+W]==0:nl[i].append(i+W)
		elif i==W*(H-1):
			if c[i-W]==0:nl[i].append(i-W)
			if c[i+1]==0:nl[i].append(i+1)		
		elif i==W*H-1:
			if c[i-W]==0:nl[i].append(i-W)
			if c[i-1]==0:nl[i].append(i-1)
		elif i<W-1:
			for j in p0:
				if c[i+j]==0:nl[i].append(i+j)			
		elif i%W==0:
			for j in p1:
				if c[i+j]==0:nl[i].append(i+j)	
		elif i%W==W-1:
			for j in p2:
				if c[i+j]==0:nl[i].append(i+j)
		elif i>W*(H-1):
			for j in p3:
				if c[i+j]==0:nl[i].append(i+j)
		else:
			for j in p4:
				if c[i+j]==0:nl[i].append(i+j)


V=[ None for i in range(H*W)]
d=[ float("inf") for i in range(H*W) ]

def bfs(start):
	q = deque([]) 
	V[start]=1
	d[start]=0
	q.append(start)

	while len(q)!=0:
		v=q.popleft()
		for i in nl[v]:
			if V[i] is None:
				V[i]=1
				q.append(i)
				d[i]=d[v]+1

bfs(0)

if V[H*W-1] is None:
	print -1
else:
	print H*W-(d[H*W-1]+1)-sum(c)