Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in l:
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Fixed submission:
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in range(A, B + 1):
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
l = [int(x) for x in range(A, B + 1)]
if 2 * K > B - A + 1:
	for i in l:
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Fixed submission:
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in range(A, B + 1):
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
l = [int(x) for x in range(A, B + 1)]
ans = set()
if K > len(l):
	for i in l:
		print(i)
else:
	for i in range(K):
		ans.add(l[i])
	l.reverse()
	for j in range(K):
		ans.add(l[j])
	ans = list(ans)
	ans.sort()
	for k in ans:
		print(k)

Fixed submission:
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in range(A, B + 1):
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
l = [int(x) for x in range(A, B + 1)]
ans = []
for i in range(K):
	ans.append(l[i])
l.reverse()
for j in range(K):
	ans.append(l[j])
ans.sort()
for k in ans:
	print(k)

Fixed submission:
A, B, K = map(int, input().split())
if 2 * K > B - A + 1:
	for i in range(A, B + 1):
		print(i)
else:
	for i in range(A, A + K):
		print(i)
	for j in range(B - K + 1, B + 1):
		print(j)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
  temp = 0
  for j in range(N - i):
    temp += A[i][j]
  temp += A[1][j]
  if ans < temp:
    ans = temp
print(ans)

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
for i in range(N):
	temp = 0
	for j in range(i+1):
		temp += A[0][j]
	for j in range(i, N): 
		temp += A[1][j]
	ans = max(ans, temp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for i in range(1, N + 1):
	if i ** 2 <= N and i ** 2 >= ans:
		ans = i * i
print(ans)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, 32000):
	if i ** 2 <= N and i ** 2 >= ans:
		ans = i * i
print(ans)
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
A.sort()
C.sort()
for i in range(len(B)):
	a_cand = 0
	c_cand = 0
	for j in range(len(A)):
		if A[j] < B[i]:
			a_cand += 1
		if B[i] < C[j]:
			c_cand += 1
	ans += a_cand * c_cand
print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
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()
C.sort()
for b in B:
	a_cand = bisect_left(A, b)
	c_cand = N - bisect_right(C, b)
	ans += a_cand * c_cand
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a)):
	b.append(a[i])
	b = b[::-1]
for i in range(len(b)):
	print(b[i], end = ' ')

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b_1 = []
b_2 = []
b = []
for i in reversed(range(len(a))):
	if i % 2 != 0:
		b_1.append(a[i])
	else:
		b_2.append(a[i])
if len(a) % 2 == 0:
	b_2.reverse()
	b.extend(b_1)
	b.extend(b_2)
else:
	b_1.reverse()
	b.extend(b_2)
	b.extend(b_1)
for b_num in b:
	print(b_num, end = ' ')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b_1 = []
b_2 = []
b = []
for i in reversed(range(len(a))):
	if i % 2 != 0:
		b_1.append(a[i])
	else:
		b_2.append(a[i])
if len(a) % 2 == 0:
	b_2.reverse()
	b.extend(b_1)
	b.extend(b_2)
else:
	b_1.reverse()
	b.extend(b_2)
	b.extend(b_1)
for b_num in b:
	print("".join(b))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b_1 = []
b_2 = []
b = []
for i in reversed(range(len(a))):
	if i % 2 != 0:
		b_1.append(a[i])
	else:
		b_2.append(a[i])
if len(a) % 2 == 0:
	b_2.reverse()
	b.extend(b_1)
	b.extend(b_2)
else:
	b_1.reverse()
	b.extend(b_2)
	b.extend(b_1)
for b_num in b:
	print(b_num, end = ' ')
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
ans = len(str(N))
for A in range(1, int(math.sqrt(N)) + 1):
	if N % A == 0:
		B = N // A
		ans = min(ans, max(len(str(A)), len(str(B))))
print(ans)

Fixed submission:
A, B = map(int, input().split())
if A + B < 24:
  print(A + B)
else:
  print(A + B - 24)
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
ans = pow(10, 9)
for t in range(X + 1):
  if t*(t+1) / 2 >= X and t < ans:
    ans = t
print(ans)

Fixed submission:
X = int(input())
ans = pow(10, 9)
for t in range(X + 1):
  if t*(t+1) / 2 >= X and t < ans:
    ans = t
    break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 1
for i in range(1, N + 1):
	ans *= i
print(ans % (pow(10, 9) + 7))

Fixed submission:
import math
N = int(input())
ans = math.factorial(N)
print(ans % (pow(10, 9) + 7))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ans = 0
while N >= 1 and M >= 2:
	N -= 1
	M -= 2
	ans += 1
while M >= 4:
	M -= 4
	ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
n = min(N, M //2)
m = max((M - 2 * N) // 4, 0)
print(n + m)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
ans = 0
while N >= 1 and M >= 2:
	N -= 1
	M -= 2
	ans += 1
while M >= 4:
	M -= 4
	ans += 1
print(ans)

Fixed submission:
N, M = map(int, input().split())
n = min(N, M //2)
m = max((M - 2 * N) // 4, 0)
print(n + m)
Buggy python submission (verdict: Time Limit Exceeded):
K , S = map(int, input().split())
ans = 0
for i in range(K + 1):
	for j in range(K + 1):
		for k in range(K + 1):
			if i + j + k == S:
				ans += 1
print(ans)

Fixed submission:
K , S = map(int, input().split())
ans = 0
for i in range(K + 1):
	for j in range(K + 1):
			if 0 <= S - i - j <= K:
				ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = [ int(it) for it in input().split() ]
al = [ int(it) for it in input().split() ]
bl = [ int(it) for it in input().split() ]
cl = [ int(it) for it in input().split() ]

abl = [ a + b for a in al for b in bl]
abl.sort()
abl.reverse()
abl=abl[:k]

abcl = [ ab + c for ab in abl for c in cl]
abcl.sort()
abcl.reverse()
abcl=abcl[:k]
print ( "\n".join( [ str(it) for it in abcl ]) )






Fixed submission:
x,y,z,k = [ int(it) for it in input().split() ]
al = [ int(it) for it in input().split() ]
bl = [ int(it) for it in input().split() ]
cl = [ int(it) for it in input().split() ]

abl = [ a + b for a in al for b in bl]
abl.sort()
abl.reverse()
abl=abl[:k]

abcl = [ ab + c for ab in abl for c in cl]
abcl.sort()
abcl.reverse()
abcl=abcl[:k]
print ( "\n".join( [ str(it) for it in abcl ]) )

Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k = [ int(it) for it in input().split() ]
al = [ int(it) for it in input().split() ]
bl = [ int(it) for it in input().split() ]
cl = [ int(it) for it in input().split() ]

abl = [ a + b for a in al for b in bl]
abl.sort()
abl.reverse()
abl=abl[:k]

abcl = [ ab + c for ab in abl for c in cl]
abcl.sort()
abcl.reverse()
abcl=abcl[:k]
for it in abcl:
  print (it)





Fixed submission:
x,y,z,k = [ int(it) for it in input().split() ]
al = [ int(it) for it in input().split() ]
bl = [ int(it) for it in input().split() ]
cl = [ int(it) for it in input().split() ]

abl = [ a + b for a in al for b in bl]
abl.sort()
abl.reverse()
abl=abl[:k]

abcl = [ ab + c for ab in abl for c in cl]
abcl.sort()
abcl.reverse()
abcl=abcl[:k]
print ( "\n".join( [ str(it) for it in abcl ]) )
Buggy python submission (verdict: Runtime Error):
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]

comall = [-1,2,5,5,4,5,6,3,7,6]
com = [ (i,comall[i]) for i in li ]
com.sort( key=lambda x:-x[0])

dp = [-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  for j,c in com:
    if (c==-1):
      continue
    if ( i-c < 0 ):
      continue
    if ( dp[i-c] == -1 ):
      continue
    dp[i] = max( dp[i] , dp[i-c] + 1 )

match = N
keta = dp[N]
st = ""


for i in range( 10000 ):
  for j,c in com:
    if (keta-1==dp[match-c]):
      keta-=1
      match-=c
      st+=str(j)
      break
  if (match==0):
    break
print ( st )
    

Fixed submission:
N,M = [ int(it) for it in input().split() ]
li = [ int(it) for it in input().split() ]

comall = [-1,2,5,5,4,5,6,3,7,6]
com = [ (i,comall[i]) for i in li ]
com.sort( key=lambda x:-x[0])

dp = [-1]*(N+1)
dp[0] = 0

for i in range(N+1):
  for j,c in com:
    if (c==-1):
      continue
    if ( i-c < 0 ):
      continue
    if ( dp[i-c] == -1 ):
      continue
    dp[i] = max( dp[i] , dp[i-c] + 1 )

match = N
keta = dp[N]
st = ""


for i in range( 10000 ):
  for j,c in com:
    if (match-c<0):
      continue
    if (keta-1==dp[match-c]):
      keta-=1
      match-=c
      st+=str(j)
      break
  if (match==0):
    break
print ( st )
Buggy python submission (verdict: Runtime Error):
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na + nb - max(cb[0][1]+ca[1][1],ca[0][1]+cb[1][1])
    
print (s)
  


Fixed submission:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    p1 = cb[0][1]
    p2 = ca[0][1]
    if (len(ca)>1):
      p1+=ca[1][1]
    if (len(cb)>1):
      p2+=cb[1][1]
    s += na + nb - max(p1,p2)
    
print (s)

Buggy python submission (verdict: Runtime Error):
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif ( ca[0][1] < cb[0][1]   ):
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    s += na - ca[0][1] + nb - min(ca[1][1],cb[1][1])
print (s)
  

Fixed submission:
N = int(input())
li=[int(it) for it in input().split()]
lia=li[::2]
lib=li[1::2]

import collections
ca = list(collections.Counter(lia).items())
cb = list(collections.Counter(lib).items())
na = len(lia)
nb = len(lib)
ca.sort(key=lambda x:-x[1])
cb.sort(key=lambda x:-x[1])
s = 0
if ( ca[0][0] != cb[0][0] ):
  s += na - ca[0][1]
  s += nb - cb[0][1]
else:
  if ( ca[0][1] > cb[0][1]   ):
    s += na - ca[0][1]
    if ( len(cb)>1 ):
      s += nb - cb[1][1]
    else:
      s += nb
  elif (ca[0][1] < cb[0][1]) :
    s += nb - cb[0][1]
    if ( len(ca)>1 ):
      s += na - ca[1][1]
    else:
      s += na
  else:
    p1 = cb[0][1]
    p2 = ca[0][1]
    if (len(ca)>1):
      p1+=ca[1][1]
    if (len(cb)>1):
      p2+=cb[1][1]
    s += na + nb - max(p1,p2)
    
print (s)
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q = [ int(it) for it in input().split()]

grid = [ [0]*N for i in range(N) ]
gridsml = [ [0]*N for i in range(N) ]

for i in range(M):
  s,g = [ int(it)-1 for it in input().split()]
  grid[s][g]+=1

for i in range(N):
  gridsml[i][0]=grid[i][0]
  for j in range(1,N):
    gridsml[i][j]+=gridsml[i][j-1]+grid[i][j]


for i in range(Q):
  s,g = [ int(it)-1 for it in input().split()]
  m = 0
  for i in range(s,N):
    m += gridsml[i][g]
  print (m)

Fixed submission:
N,M,Q = [ int(it) for it in input().split()]

grid = [ [0]*N for i in range(N) ]
gridsml = [ [0]*N for i in range(N) ]

for i in range(M):
  s,g = [ int(it)-1 for it in input().split()]
  grid[s][g]+=1

for i in range(N):
  gridsml[i][0]=grid[i][0]
  for j in range(1,N):
    gridsml[i][j]+=gridsml[i][j-1]+grid[i][j]


for i in range(Q):
  s,g = [ int(it)-1 for it in input().split()]
  m = 0
  for i in range(s,N):
    m += gridsml[i][g]
  print (m)
Buggy python submission (verdict: Runtime Error):
D,G=[ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(D) ]

import itertools as ite
cmin = 100000000000000000
for cli in ite.product( *([[0,1]]*D) ):
  
  s = 0
  c = 0
  for i in range(D):
    if cli[i]==1:
      s +=  li[i][1] + (i+1)*100*li[i][0]
      c +=  li[i][0]
  
  ds = G-s
  
  for i in range(D-1,-1,-1):
    if (ds<=0):
      break
    if cli[i]==0:
      toku = (ds-1)//((i+1)*100)+1
      toku = min(toku,li[i][0])
      c += toku
      ds -= toku*(i+1)*100
    if (ds<=0):
      break
  if (ds<=0):
    cmin = min(cmin,c)
  else:
print (cmin)

Fixed submission:
D,G=[ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(D) ]

import itertools as ite
cmin = 100000000000000000
for cli in ite.product( *([[0,1]]*D) ):
  
  s = 0
  c = 0
  for i in range(D):
    if cli[i]==1:
      s +=  li[i][1] + (i+1)*100*li[i][0]
      c +=  li[i][0]
  
  ds = G-s
  
  for i in range(D-1,-1,-1):
    if (ds<=0):
      break
    if cli[i]==0:
      toku = (ds-1)//((i+1)*100)+1
      toku = min(toku,li[i][0])
      c += toku
      ds -= toku*(i+1)*100
    if (ds<=0):
      break
  if (ds<=0):
    cmin = min(cmin,c)
  else:
    pass
print (cmin)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
li = [ int(it) for it in input().split() ] 

keta = 0
p = max(li)
for i in range(100000):
  if (p>0):
    keta+=1
    p//=2
  else:
    break

bli = [ [0]*keta for i in range(N) ]

for i in range(len(li)):
  p = li[i]
  for j in range(100000):
    if (p>0):
      bli[i][j]=p%2
      p//=2
    else:
      break
      
sli = [ [0]*(N+1) for i in range(keta) ]
for k in range(keta):
  for i in range(N):
    sli[k][i+1] = sli[k][i] + bli[i][k] 


s = 0
for i in range(N):
  for j in range(i+1,N+1):
    flag = True
    for k in range(keta):
      if (sli[k][j] - sli[k][i] < 2):
        pass
      else:
        flag=False
        break
    if (flag):
      s += 1
    else:
      break
print (s)

Fixed submission:
N = int(input())
li = [ int(it) for it in input().split() ] 

keta = 0
p = max(li)
for i in range(100000):
  if (p>0):
    keta+=1
    p//=2
  else:
    break

bli = [ [0]*keta for i in range(N) ]

for i in range(len(li)):
  p = li[i]
  for j in range(100000):
    if (p>0):
      bli[i][j]=p%2
      p//=2
    else:
      break
      
sli = [ [0]*(N+1) for i in range(keta) ]
for k in range(keta):
  for i in range(N):
    sli[k][i+1] = sli[k][i] + bli[i][k] 


s = 0
x = 0
y = 1
gli=[]
for i in range(N*N):
    
    flag = True
    for k in range(keta):
      if (sli[k][y] - sli[k][x] < 2):
        pass
      else:
        flag=False


    if flag:
      if ( len(gli) > 0 ):
        if (gli[-1][0]==x):
          gli.pop()
      gli.append([x,y])    

    if (x==N-1 and y==N):
      break
     
    
    if (flag):
      y+=1
      if(y>N):
        x+=1
      y=min(y,N)
    else:
      x+=1
      y-=1
      x = min(N,x)

s=0
for a,b in gli:
  s+=b-a
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
import numpy as np
li = np.array([ int(it) for it in input().split()])
cs = np.cumsum(li)
import collections
cd = collections.Counter(cs)
sm = 0
for k,v in cd.items():
  p = v - 1 + (1 if k==0 else 0)
  sm += (p*(p+1))//2
print (sm)

Fixed submission:
n = int(input())
import numpy as np
li = np.array([ int(it) for it in input().split()])
cs = np.cumsum(li)
import collections
cd = collections.Counter(cs)
sm = 0
for k,v in cd.items():
  p = v - 1 + (1 if k==0 else 0)
  sm += (p*(p+1))//2
print (sm)
Buggy python submission (verdict: Runtime Error):
N = int(input())
lia=[int(it) for it in input().split()]
lib=[int(it) for it in input().split()]
lip=[lia[i]-lib[i] for i in range(N)]
sb = 0
for i in range(N):
  if (lip[i]>0):
    sb+=lip[i]
sa2 = 0
for i in range(N):
  if (lip[i]<0):
    sa2=(-lip[i])//2
sas-=sb*2
x = sum(lib)-sum(lia)
if (x<0):
  print ("No")
else:
  if (sa2>=sb):
    print ("Yes")
  else:
    print ("No")


Fixed submission:
N = int(input())
lia=[int(it) for it in input().split()]
lib=[int(it) for it in input().split()]
lip=[lia[i]-lib[i] for i in range(N)]
sb = 0
for i in range(N):
  if (lip[i]>0):
    sb+=lip[i]
sa2 = 0
for i in range(N):
  if (lip[i]<0):
    sa2+=(-lip[i])//2
x = sum(lib)-sum(lia)
if (x<0):
  print ("No")
else:
  if (sa2>=sb):
    print ("Yes")
  else:
    print ("No")
Buggy python submission (verdict: Runtime Error):
N,K = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(N) ]

kbit = []
k = K
for i in range(100000000):
  if (k == 0):
    break
  kbit.append( k%2 )
  k//=2
keta = len(kbit)

def chk(c):
  #print (c)
  s = 0
  for k,v in li:
    if ( (c^k)|c == c ):
      #print ( k,v,"ok" )
      s += v
  return s

ma = 0
ma = max(ma, chk( (1<<(keta-1))-1) )
ma = max(ma, chk ( K ) )

for i in range(keta):
  if ( kbit[keta-1-i] == 0 ):
    continue
  else:
    bit = [0]*(keta)
    for j in range(keta):
      if (i<j):
        bit[keta-1-j]=1
      elif (j<i):
        bit[keta-1-j]=kbit[keta-1-j]
      else:
        bit[keta-1-j]=0
    
    v = 0
    for j in range(keta):
      if (bit[j]==1):
        v += 2**(j)
    #print ( v , bit )
    ma = max(ma, chk ( v ) )
print ( ma )


Fixed submission:
N,K = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(N) ]

kbit = []
k = K
for i in range(100000000):
  if (k == 0):
    break
  kbit.append( k%2 )
  k//=2
keta = len(kbit)

def chk(c):
  #print (c)
  s = 0
  for k,v in li:
    if ( (c^k)|c == c ):
      #print ( k,v,"ok" )
      s += v
  return s

ma = 0

if (K<100):
  for i in range(K+1):
  	ma = max(ma, chk(i))
else:
  ma = max(ma, chk( 0 ))
  ma = max(ma, chk( 1 ))
  ma = max(ma, chk( 2 ))
  ma = max(ma, chk( 3 ))
  ma = max(ma, chk( 4 ))
  ma = max(ma, chk( (1<<(keta-1))-1) )
  ma = max(ma, chk ( K ) )

  for i in range(keta):
    if ( kbit[keta-1-i] == 0 ):
      continue
    else:
      bit = [0]*(keta)
      for j in range(keta):
        if (i<j):
          bit[keta-1-j]=1
        elif (j<i):
          bit[keta-1-j]=kbit[keta-1-j]
        else:
          bit[keta-1-j]=0

      v = 0
      for j in range(keta):
        if (bit[j]==1):
          v += 2**(j)
      #print ( v , bit )
      ma = max(ma, chk ( v ) )
print ( ma )
Buggy python submission (verdict: Runtime Error):
N,M = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(M) ]
li = [ (a-1,b-1,c) for a,b,c in li ]

dw = [ [] for i in range(N) ]


for a,b,c in li:
  dw[a].append( (b,c) )

NOT = 1e+10 -1 
  
cost = [NOT]*N
cost[0]=0
cosli = []
for i in range(1000):
  chk = [0]*N
  now = 0
  pop=[now]
  for i in range(N):
    now = pop.pop()
    chk[now]=1
    for b,c in dw[now]:
      if ( cost[b] == NOT ):
        cost[b] = cost[now] + c
      else:
        cost[b] = max(cost[now] + c,cost[b])
      if (chk[b]==0):
        pop.append(b)
  cosli.append( cost[N-1] )  

if ( cosli[-1] != cosli[-2] ):
  print ("inf")
else:
  print (cosli[-1])

Fixed submission:
N,M = [ int(it) for it in input().split() ]
li = [ [ int(it) for it in input().split() ] for i in range(M) ]
li = [ (a-1,b-1,c) for a,b,c in li ]

dw = [ [] for i in range(N) ]


for a,b,c in li:
  dw[a].append( (b,c) )

NOT = 1e+16 -1 
  
cost = [NOT]*N
cost[0]=0
cosli = []
for i in range(1000):
  chk = [0]*N
  now = 0
  pop=[now]
  for i in range(N):
    if (len(pop)==0):
      break
    now = pop.pop()
    chk[now]=1
    for b,c in dw[now]:
      if ( cost[b] == NOT ):
        cost[b] = cost[now] + c
      else:
        cost[b] = max(cost[now] + c,cost[b])
      if (chk[b]==0):
        pop.append(b)
  cosli.append( cost[N-1] )  

if ( cosli[-1] != cosli[-2] ):
  print ("inf")
else:
  print (cosli[-1])
Buggy python submission (verdict: Time Limit Exceeded):
class Union():
  def __init__(me,N):
    me.N = N
    me.up = [-1]*N
    me.down = [ [] for i in range(N) ]
  def union(me,a,b):
    ua = me.up[a] if me.up[a]!=-1 else a
    ub = me.up[b] if me.up[b]!=-1 else b
    if (ua == ub):
      return
    if ( len(me.down[ua]) < len(me.down[ub]) ):
      ub,ua = ua,ub
    for v in me.down[ub]:
      me.up[v] = ua
    me.down[ua].extend( me.down[ub] )
    me.down[ub] = []
    me.up[ub] = ua
    me.down[ua].append( ub )

N,K,L = [ int(it) for it in input().split() ]
uk = Union(N)
for a,b in [ [int(it)-1 for it in input().split()] for i in range(K) ]:
  uk.union(a,b)

ul = Union(N)
for a,b in [ [int(it)-1 for it in input().split()] for i in range(L) ]:
  ul.union(a,b)

for i in range(N):
  if ( uk.up[i] == -1 ):
    uk.down[i].append(i)
    uk.down[i] = set(uk.down[i])
  if ( ul.up[i] == -1 ):
    ul.down[i].append(i)
    ul.down[i] = set(ul.down[i])

li = [-1]*N
for i in range(N):
  if (li[i] != -1):
    continue
  ua = uk.up[i] if uk.up[i]!=-1 else i
  ub = ul.up[i] if ul.up[i]!=-1 else i
  uni = uk.down[ua] & ul.down[ub]
  for it in uni:
    li[i] = len(uni)

print ( " ".join( [ str(it) for it in li ]) )
    
    

Fixed submission:
class Union():
  def __init__(me,N):
    me.N = N
    me.up = [-1]*N
    me.down = [ [] for i in range(N) ]
  def union(me,a,b):
    ua = me.up[a] if me.up[a]!=-1 else a
    ub = me.up[b] if me.up[b]!=-1 else b
    if (ua == ub):
      return
    if ( len(me.down[ua]) < len(me.down[ub]) ):
      ub,ua = ua,ub
    for v in me.down[ub]:
      me.up[v] = ua
    me.down[ua].extend( me.down[ub] )
    me.down[ub] = []
    me.up[ub] = ua
    me.down[ua].append( ub )

N,K,L = [ int(it) for it in input().split() ]
uk = Union(N)
for a,b in [ [int(it)-1 for it in input().split()] for i in range(K) ]:
  uk.union(a,b)

ul = Union(N)
for a,b in [ [int(it)-1 for it in input().split()] for i in range(L) ]:
  ul.union(a,b)

pr = [0]*N
for i in range(N):
  ua = uk.up[i] if uk.up[i]!=-1 else i
  ub = ul.up[i] if ul.up[i]!=-1 else i
  pr[i] = (ua*N+ub,i)
pr.sort(key = lambda x:x[0])

li = [0]*N
de = pr[0][0]
s = [pr[0][1]]
for i in range(1,N):
  if (de!=pr[i][0]):
    for v in s:
      li[v] = len(s)
    s=[pr[i][1]]
    de = pr[i][0]
  else:
    s.append(pr[i][1])
for v in s:
  li[v] = len(s)

print ( " ".join( [ str(it) for it in li ]) )