Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



N,M=list(map(int,input().split()))
uf=UnionFind(N)
for _ in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    uf.union(a,b)

L=set(uf.roots())
Ls=uf.all_group_members()
ans=0
for k in L:
    ans=max(ans,len(Ls[k]))
print(ans)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]


N,M=list(map(int,input().split()))
uf=UnionFind(N)
for _ in range(M):
    a,b=list(map(int,input().split()))
    a-=1
    b-=1
    uf.union(a,b)

L=set(uf.roots())
ans=0
for k in L:
    ans=max(ans,uf.size(k))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from itertools import product
H, W, M = list(map(int, input().split()))
h = [0]*M
w = [0]*M
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))
hc = Counter(h)
wc = Counter(w)
hmax = max(hc.values())
wmax = max(wc.values())
lh = [k[0] for k in hc.items() if k[1] == hmax]
lw = [k[0] for k in wc.items() if k[1] == wmax]
# print(lh,lw)
S = set(product(lh, lw))
# print(S)

for i in range(M):
    if (h[i], w[i]) in S:
        S -= {(h[i], w[i])}
if S:
    print(hmax+wmax)
else:
    print(hmax+wmax-1)

Fixed submission:
from collections import Counter
H, W, M = list(map(int, input().split()))
h = [0]*M
w = [0]*M
for i in range(M):
    h[i], w[i] = list(map(int, input().split()))
hc = Counter(h)
wc = Counter(w)
hmax = max(hc.values())
wmax = max(wc.values())
lh = {k[0] for k in hc.items() if k[1] == hmax}
lw = {k[0] for k in wc.items() if k[1] == wmax}

ct = 0
for i in range(M):
    if h[i] in lh and w[i] in lw:
        ct += 1
if ct >= len(lh)*len(lw):
    print(hmax+wmax-1)
else:
    print(hmax+wmax)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
countW = S.count('W')
if countW==0:
	print(0)
	exit()
if countW==N:
	print(0)
	exit()
leftW = S[:countW].count('W')
rightR = S[countW:].count('R')
print(max(leftW, rightR))

Fixed submission:
X=int(input())
if X>=30:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(500000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

Fixed submission:
#ABC_174_C_Respect_review.py

K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())  # ぜんぜんちがう
ans = -1
 
def moduloseven(K):
	for i in range(1000000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
		else:
			ans = K-1
	return(ans)
 
if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)

Fixed submission:
#ABC_174_C_Respect_review.py

K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)

Buggy python submission (verdict: Runtime Error):
K = int(input())  # ぜんぜんちがう
ans = -1

def moduloseven(K):
	for i in range(1000):
		sev = int(str(7)*(i+1))
		if sev % K == 0:
			ans = i+1
			break
	return(ans)


if K % 2 != 0:
	if K % 5 != 0:
		ans = moduloseven(K)
print(ans)


Fixed submission:
#ABC_174_C_Respect_review.py

K = int(input())
ans = 1

if K % 2 == 0:
	print(-1)
	exit()
if K % 5 == 0:
	print(-1)
	exit()

temp = 7
for i in range(1*10**6):
	if temp % K == 0:
		print(ans)
		exit()
	res = temp % K
	temp = res*10 + 7
	ans += 1
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	leftW = S[:i+1].count('W')
	rightR = S[i+1:].count('R')
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)


Fixed submission:
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  # rightR:decrease
		rightR -= 1
	else:          # leftW:increase
		leftW += 1
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
while True:
	if S.count('R') == 0:
			break
	if S[0] == 'R':
		S=S.lstrip('R')
	else:
		count += 1
		Rpos = S.rfind('R')
		S = S[1:Rpos]
print(count)


Fixed submission:
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  # rightR:decrease
		rightR -= 1
	else:          # leftW:increase
		leftW += 1
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
while True:
	if S.count('R') == 0:
			break
	if S[0] == 'R':
		S=S.lstrip('R')
	else:
		count += 1
		S = S[1:]
		Rpos = S.rfind('R')
		S = S[:Rpos]
print(count)


Fixed submission:
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  # rightR:decrease
		rightR -= 1
	else:          # leftW:increase
		leftW += 1
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
count = 0
while True:
	if S == "":
		break
	if S[0] == 'R':
		S = S[1:]
	else:
		if S.count('R') == 0:
			break
		else:
			count += 1
			S = S[1:]
			Rpos = S.rfind('R')
			S = S[:Rpos]+S[Rpos+1:]
print(count)


Fixed submission:
N = int(input())
S = input()
part = 0
leftW = 0
rightR = S.count('R')
moves = [rightR]

for i in range(N):
	if S[i] == 'R':  # rightR:decrease
		rightR -= 1
	else:          # leftW:increase
		leftW += 1
	moves.append(max(leftW, rightR))
# print(moves)
ans = min(moves[i] for i in range(N+1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

N,K=list(map(int, input().split()))
P=list(map(int, input().split()))
ans=float('INF')
L=list(combinations(range(N),K))
for a in L:
    sums=0
    for i in range(K):
        sums+=P[a[i]]
    # print(sums)
    ans=min(ans,sums)
print(ans)

Fixed submission:
N,K=list(map(int, input().split()))
P=list(map(int, input().split()))
P.sort()
L=P[:K]
print(sum(L))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
B=dict(Counter(A))
for k in B.keys():
    L[k]=B[k]
# print(L)

C=set(B)
sum = 0
for k in B.keys():
    sum += k*B[k]
for i in range(q):
    x=Q[i][0]
    y=Q[i][1]
    if L[x]==0:
        print(sum)
        continue
    L[y]+=L[x]
    L[x]=0
    C.add(y)
    C.remove(x)
    sum=0
    for k in C:
        sum+=k*L[k]
    print(sum)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
S=0
for i in range(N):
    L[A[i]]+=1
    S+=A[i]

for i in range(q):
    S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
    L[Q[i][1]]+=L[Q[i][0]]
    L[Q[i][0]]=0
    # print(L)
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]
# print(Q)

B=dict(Counter(A))
# print(B)

sum = 0
for k in B.keys():
    sum += k*B[k]
# print(B[2])
for i in range(q):
    x=Q[i][0]
    y=Q[i][1]
    if x not in B:
        print(sum)
        continue
    else:
        v = B[x]
        if y in B:
            B[y] += v
        else:
            B[y]=v
        del B[x]
        sum = 0
        for k in B.keys():
            sum += k*B[k]
        print(sum)


Fixed submission:
N=int(input())
A=list(map(int, input().split()))
q=int(input())
Q=[list(map(int, input().split())) for _ in range(q)]

L=[0]*(10**5+1)
S=0
for i in range(N):
    L[A[i]]+=1
    S+=A[i]

for i in range(q):
    S+=L[Q[i][0]]*(Q[i][1]-Q[i][0])
    L[Q[i][1]]+=L[Q[i][0]]
    L[Q[i][0]]=0
    # print(L)
    print(S)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
S=A[0]
for i in range(N-1):
  S=S^A[i+1]
L=[0]*N
for i in range(N):
  L[i]=A[i]^S
print(*L)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
S=A[0]
for i in range(N-1):
  S=S^A[i+1]
L=[0]*N
for i in range(N):
  L[i]=A[i]^S
print(*L)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N=int(input())
A=list(map(int, input().split()))
S=Counter(A)
T=set(S)
# print(S)
# print(T)
# 篩？
ct=0
L=list(S.keys())
L.sort()
# print(L)

for i in range(len(L)):
    a=L[i]
    if a not in T:
        continue
    T.remove(a)
    if S.get(a)==1:
        ct+=1
    tmp=T.copy()
    # print(tmp)
    for n in T:
        if n%a==0:
            tmp.difference_update({n,})
    T=tmp
print(ct)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m = max(A)
sieve = [True]*(m+1)
sieve[0] = False
ct = 0
for i in range(N):
    n = A[i]
    if sieve[n] == False:
        continue
    if i < N-1 and n == A[i+1]:
        sieve[n] = False
    if sieve[n] == True:
        ct += 1
    for k in range(n*2, m+1, n):
        sieve[k] = False
print(ct)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = list(map(int, input().split()))
S = set()
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    S.add((a, b))
    S.add((b, a))

parents = [-1]*N
parents[0] = 0
L = deque([0])
while L:
    k = L.pop()
    for l in S:
        if l[0] == k and parents[l[1]] < 0:
            L.appendleft(l[1])
            parents[l[1]] = k
    # print(L)

if -1 in parents:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(parents[i]+1)


Fixed submission:
from collections import deque
N, M = list(map(int, input().split()))
S = [set() for _ in range(N)]
for _ in range(M):
    a, b = list(map(int, input().split()))
    a -= 1
    b -= 1
    S[a].add(b)
    S[b].add(a)
# print(S)

parents = [-1]*N
parents[0] = 0
L = deque([0])
while L:
    k = L.pop()
    s=S[k]
    for l in s:
        if parents[l] < 0:
            L.appendleft(l)
            parents[l] = k
    # print(L)

if -1 in parents:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(parents[i]+1)
Buggy python submission (verdict: Runtime Error):
S,T=list(input())
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1)


Fixed submission:
S,T=input().split()
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1)

Buggy python submission (verdict: Runtime Error):
S,T=list(input())
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1

Fixed submission:
S,T=input().split()
s,t=list(map(int, input().split()))
U=input()
if U==S:
  print(s-1,t)
else:
  print(s,t-1)
Buggy python submission (verdict: Runtime Error):
A=list(map(int, input().split()))
n=len(A)
A.sort()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    exit()
else:
  print('YES')

Fixed submission:
N=int(input())
A=list(map(int, input().split()))
A.sort()
if N==1:
  print('YES')
  exit()
for i in range(N-1):
  if A[i]==A[i+1]:
    print('NO')
    exit()
else:
  print('YES')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

for i in range(1, N+1):
    if i not in A:
        j = i-1
        break
    k = A.index(i)
    A = A[k+1:]

if j == 0:
    print(-1)
else:
    print(N-j)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
j=0
for i in range(N):
    if A[i]==j+1:
        j+=1

if j == 0:
    print(-1)
else:
    print(N-j)
Buggy python submission (verdict: Runtime Error):
# ABC_147_C_HonestOrUnkind2.py

N=int(input())
A=[]
for i in range(N):
    a=int(input())
    xy=[list(map(int, input().split())) for _ in range(a)]
    A.append([a,xy])
# print(A)

# 下からi桁目のbitが1->人iは正直
# 下からi桁目のbitが0->人iは不親切

ans=0
for i in range(2**N):
    for j in range(N):
        for k in range(A[j][0]):
            flag=0
            if (i >> j) & 1 != A[j][1][k][1]:
                flag=1
                break
        if flag==1:
                break
    else:
        # print(bin(i))
        ct=0
        for l in range(N):
            ct+=((i>>l)&1)
        ans=max(ans,ct)

print(ans)

Fixed submission:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    xy = [list(map(int, input().split())) for _ in range(a)]
    A.append([a, xy])
# print(A)

# 下からi桁目のbitが1->人iは正直
# 下からi桁目のbitが0->人iは不親切
# 不親切な人の証言は無視して良い

ans = 0
for i in range(2**N):
    for j in range(N):
        flag = 0
        if (i >> j) & 1:
            for k in range(A[j][0]):
                l = A[j][1][k][0]
                m=A[j][1][k][1]
                # print(i,j,k,(l,m),(i >> (l-1)))
                if not (i >> (l-1)) & 1 == A[j][1][k][1]:
                    flag = 1
                    break
            if flag == 1:
                break
    else:
        # print(bin(i))
        ct = 0
        for l in range(N):
            ct += ((i >> l) & 1)
        ans = max(ans, ct)
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()
date=[SUN,MON,TUE,WED,THU,FRI,SAT]
i=date.index(S)
print(7-i)

Fixed submission:
S=input()
date=['SUN','MON','TUE','WED','THU','FRI','SAT']

i=date.index(S)
print(7-i)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
n=N//2
for i in range(m):
  if S[i]!=S[n+i]:
	print('No')
else:
  print('Yes')

Fixed submission:
N=int(input())
S=input()
if N%2==1:
  print('No')
  exit()
n=N//2
for i in range(n):
  if S[i]!=S[n+i]:
    print('No')
    break
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
A = [0]*(len(S)+1)
for i in range(len(S)+1):
    L = S[:i]
    R = S[i:]
    # print('L=', L)
    # print('R=', R)
    l = 0
    r = 0
    if L != '':
        T = len(L)
        for k in range(T):
            if L[T-k-1] != '<':
                l = k
                break
        else:
            l = T
    if R != '':
        U = len(R)
        for j in range(U):
            if R[j] != '>':
                r = j
                break
        else:
            r = len(R)
    A[i] = max(l, r)
# print(A)
print(sum(A))


Fixed submission:
S=input()
N=len(S)+1
L=[0]*N
R=[0]*N
ans=[0]*N
for i in range(1,N):
    if S[i-1]=='<':
        L[i]=L[i-1]+1
    if S[N-i-1]=='>':
        R[N-i-1]=R[N-i]+1
for i in range(N):
    ans[i]=max(L[i], R[i])
print(sum(ans))

Buggy python submission (verdict: Runtime Error):
S = input()
A = [0]*(len(S)+1)
for i in range(len(S)+1):
    L = S[:i]
    R = S[i:]
    print('L=', L)
    print('R=', R)
    l = 0
    r = 0
    if L != '':
        T = len(L)
        for k in range(T):
            if L[T-k-1] != '<':
                l = k
                break
        else:
            l = T
    if R != '':
        U = len(R)
        for j in range(U):
            if R[j] != '>':
                r = j
                break
        else:
            r = len(R)
    A[i] = max(l, r)
# print(A)
print(sum(A))

Fixed submission:
S=input()
N=len(S)+1
L=[0]*N
R=[0]*N
ans=[0]*N
for i in range(1,N):
    if S[i-1]=='<':
        L[i]=L[i-1]+1
    if S[N-i-1]=='>':
        R[N-i-1]=R[N-i]+1
for i in range(N):
    ans[i]=max(L[i], R[i])
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
a,b=list(map(int,input.split()))
print(max(a+b,a-b,a*b))

Fixed submission:
a,b=list(map(int,input().split()))
print(max(a+b,a-b,a*b))
Buggy python submission (verdict: Runtime Error):
A,B,C=list(map(int, input().split()))
print(max(C-(A-B)),0)

Fixed submission:
A,B,C=list(map(int, input().split()))
print(max(C-(A-B),0))
Buggy python submission (verdict: Runtime Error):
L,R=list(map(int, input().split()))
M=2019
if R-L=1:
  print(((R%M)*(L%M))%M)
  exit()
L=L%M
if R%M<=L:
  R=(R%M)+M
else:
  R=R%M
ans=M
for i in range(L,R+1):
  for j in range(i+1,R+1):
    ans=min(ans,(i*j)%M)
print(ans)


Fixed submission:
L,R=list(map(int, input().split()))
M=2019
if R-L==1:
  print(((R%M)*(L%M))%M)
  exit()
if L//M!=R//M:
  print(0)
  exit()
L=L%M
R=R%M
ans=M
for i in range(L,R+1):
  for j in range(i+1,R+1):
    ans=min(ans,(i*j)%M)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W = list(map(int, input().split()))
maps = [[None]*(W+2) for _ in range(H+2)]
maps[0] = ['#']*(W+2)
for i in range(H):
    maps[i+1] = ['#']+list(input())+['#']
maps[H+1] = ['#']*(W+2)
# pprint.pprint(maps)
# L[i][j]:それぞれ該当マスから上下左右に'.'が続く数
ans = 0
L = [[[0]*4 for _ in range(W+2)] for _ in range(H+2)]
for i in range(1, H+1):
    for j in range(1, W+1):
        if maps[i][j] == '.':
            L[i][j][0] = L[i-1][j][0]+1
            L[i][j][2] = L[i][j-1][2]+1
        if maps[H+1-i][W+1-j] == '.':
            L[H+1-i][W+1-j][1] = L[H+2-i][W+1-j][1]+1
            L[H+1-i][W+1-j][3] = L[H+1-i][W+2-j][3]+1
for i in range(H+2):
    for j in range(W+2):
        ans = max(ans, sum(L[i][j])-3)
print(ans)


Fixed submission:
H, W = list(map(int, input().split()))
maps = [['']*(W+2) for _ in range(H+2)]
maps[0] = ['#']*(W+2)
for i in range(H):
    maps[i+1] = ['#']+list(input())+['#']
maps[H+1] = ['#']*(W+2)

ans = 0
L = [[[0, 0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if maps[i+1][j+1] == '#':
            continue
        if j >= 1 and L[i][j-1][1] > 0:
            L[i][j][1] = L[i][j-1][1]
        else:
            u = j+1
            while maps[i+1][u] == '.':
                u += 1
            L[i][j][1] = u-j-1
        if i >= 1 and L[i-1][j][0] > 0:
            L[i][j][0] = L[i-1][j][0]
        else:
            u = i+1
            while maps[u][j+1] == '.':
                u += 1
            L[i][j][0] = u-i-1
        ans = max(ans, L[i][j][0]+L[i][j][1]-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
S = input()
C = 10**9+7


def answer(a):
    if a == '0' or a == '':
        return 1
    if a == '1':
        return 3
    if a[0] == '0':
        return answer(a[1:])
    else:
        b = a[1:]
        return (pow(3, (len(a)-1), C)+2*answer(b)) % C


print(answer(S))


Fixed submission:
S = input()
C = 10**9+7
T = S[::-1]
N = len(S)
dp = [0]*N
dp[0] = 1+2*(int(T[0]))

for i in range(1, N):
    if T[i] == '0':
        dp[i] = dp[i-1]
    else:
        dp[i] = (pow(3, i, C)+2*dp[i-1]) % C
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
S = input()
C = 10**9+7


def answer(a):
    if a == '0' or a == '':
        return 1
    if a == '1':
        return 3
    if a[0] == '0':
        return answer(a[1:])
    else:
        b = a[1:]
        return (pow(3, (len(a)-1), C)+2*answer(b)) % C


print(answer(S))

Fixed submission:
S = input()
C = 10**9+7
T = S[::-1]
N = len(S)
dp = [0]*N
dp[0] = 1+2*(int(T[0]))

for i in range(1, N):
    if T[i] == '0':
        dp[i] = dp[i-1]
    else:
        dp[i] = (pow(3, i, C)+2*dp[i-1]) % C
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
C = 10**9+7


def answer(a):
    if a == '0' or a == '':
        return 1
    if a == '1':
        return 3
    b = '{:b}'.format(int(a[1:], 2))
    return (pow(3, (len(a)-1), C)+2*answer(b)) % C


print(answer(S))

Fixed submission:
S = input()
C = 10**9+7
T = S[::-1]
N = len(S)
dp = [0]*N
dp[0] = 1+2*(int(T[0]))

for i in range(1, N):
    if T[i] == '0':
        dp[i] = dp[i-1]
    else:
        dp[i] = (pow(3, i, C)+2*dp[i-1]) % C
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
# print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cos

Fixed submission:
N, M = list(map(int, input().split()))
L = [tuple(map(int, input().split())) for i in range(N)]
L.sort()
# print(L)
ct = 0
cost = 0
i = 0
while ct < M:
    a = min(M-ct, L[i][1])
    ct += a
    cost += a*L[i][0]
    # print(ct,cost)
    i += 1
print(cost)
Buggy python submission (verdict: Runtime Error):
A,B=list(map(int, input().split()))
if A==B:
  print(A)
  exit()
a=A//4
b=B//4

def xorsum(L):
  if len(L)==1:
    return L[0]
  a=L[0]
  for i in range(1,len(L)):
    a^=L[i]
  return a

if a==b:
  L=[A+i for i in range(B-A+1)]
  print(xorsum(A))
  exit()
c=[a*4+i for i in range(4) if i>=A%4]
d=[b*4+i for i in range(4) if i<=B%4]
print(xorsum(c)^xorsum(d))

Fixed submission:
A,B=list(map(int, input().split()))
if A==B:
  print(A)
  exit()
a=A//4
b=B//4

def xorsum(L):
  if len(L)==1:
    return L[0]
  a=L[0]
  for i in range(1,len(L)):
    a^=L[i]
  return a

if a==b:
  L=[A+i for i in range(B-A+1)]
  print(xorsum(L))
  exit()
c=[a*4+i for i in range(4) if i>=A%4]
d=[b*4+i for i in range(4) if i<=B%4]
print(xorsum(c)^xorsum(d))
Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split()))
B=sort(A)
print(A[0]*A[1]/2)

Fixed submission:
A=list(map(int,input().split()))
B=list.sort(A)
print(A[0]*A[1]//2)
Buggy python submission (verdict: Runtime Error):
N=int(inpput())
H=list(map(int,input().split()))
ct=0
for i in range(N):
  t=H[i]
  for j in range(i+1,N):
    if H[j]==0:
      break
    H[j]=max(H[j]-t,0)
  ct+=t
print(ct)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

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


def need(L):
    if L == [] or max(L) == 0:
        return 0
    if min(L) > 0:
        l = [L[i]-1 for i in range(len(L))]
        return need(l)+1
    else:
        i = L.index(0)
        l = L[:i]
        m = L[i+1:]
        return need(l)+need(m)


print(need(H))