Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

n=int(input())
s=input()
d=set([])
t=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        if i in t: break
        for k in range(j+1,n):
            d.add(s[i]+s[j]+s[k])
    t.append(i)
print(len(d))

Fixed submission:
n=int(input())
s=input()
d=[set([]) for i in range(10)]
for i in range(n):
    x=int(s[i])
    d[x].add(i)
ans=0
#print(d)
#exit()
for i in range(1000):
    a=b=c=-1
    x=i//100
    y=(i%100)//10
    z=i%10
    if len(d[x])>0:
        a=min(d[x])
    if len(d[z])>0:
        c=max(d[z])
    if a!=-1 and c!=-1:
        for j in range(a+1,c):
            #print(a,c)
            if j in d[y]:
                ans+=1
                break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
d=set([])
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            d.add(s[i]+s[j]+s[k])
print(len(d))

Fixed submission:
n=int(input())
s=input()
d=[set([]) for i in range(10)]
for i in range(n):
    x=int(s[i])
    d[x].add(i)
ans=0
#print(d)
#exit()
for i in range(1000):
    a=b=c=-1
    x=i//100
    y=(i%100)//10
    z=i%10
    if len(d[x])>0:
        a=min(d[x])
    if len(d[z])>0:
        c=max(d[z])
    if a!=-1 and c!=-1:
        for j in range(a+1,c):
            #print(a,c)
            if j in d[y]:
                ans+=1
                break
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(i) for i in range(n)]
ans=chk=p=0
w=[]
for i in range(n):
    x,y=map(int,input().split())
    w.append((x,y))
for i in list(itertools.permutations(l,n)):
    chk=0
    for j in range(n-1):
        chk+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5
    ans+=chk
    p+=1

print(ans/p)

Fixed submission:
import itertools
def sol():
    n=int(input())
    d=list(itertools.permutations([i for i in range(n)]))
    w=[]
    for i in range(n):
        x,y=map(int,input().split())
        w.append((x,y))
    ans=chk=0
    for i in d:
        for j in range(len(i)-1):
            ans+=((w[i[j]][0]-w[i[j+1]][0])**2+(w[i[j]][1]-w[i[j+1]][1])**2)**0.5
    print(ans/len(d))

if __name__=="__main__":
    sol()
Buggy python submission (verdict: Runtime Error):
import heapq
n,m=map(int,input().split())
q=[]
a=[-int(i) for i in input().split()]
for i in a:
    heapq.heappush(q,(i,i,0))
ans=chk=0
while 1:
    f=1
    for i in range(m):
        x=heapq.heappop(q)
        j=-x[1]
        k=-q[0][1]
        if (i==m-1) or (j//(2**(i+1+x[2]))<k):
            f=0
            heapq.heappush(q,(-(j//(2**(i+1+x[2]))),x[1],x[2]+i+1))
            m-=(i+1)
            break
    if f:
        break
for i in q:
    ans+=-i[0]
print(ans)

Fixed submission:
import heapq
n,m=map(int,input().split())
q=[]
a=[-int(i) for i in input().split()]
for i in a:
    heapq.heappush(q,i)
ans=chk=0
for i in range(m):
    x=heapq.heappop(q)
    heapq.heappush(q,-(-x//2))
print(-sum(q))
exit()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
w=[[0]*n for i in range(n)]
ans=chk=0
for i in range(n-1,-1,-1):
    for j in range(n-1,-1,-1):
        if s[i]==s[j]:
            if i==n-1 or j==n-1:
                w[i][j]=1
            else:
                w[i][j]=w[i+1][j+1]+1
for i in range(1,n):
    for j in range(i):
        ans=max(ans,w[i][j]-[0,w[i][j]-(i-j-w[i][j]+1)][j+w[i][j]>=i+1])
print(ans)


Fixed submission:
n=int(input())
s=input()
w=[[0]*n for i in range(n)]
ans=chk=0
for i in range(n-1,-1,-1):
    for j in range(n-1,-1,-1):
        if s[i]==s[j]:
            if i==n-1 or j==n-1:
                w[i][j]=1
            else:
                w[i][j]=w[i+1][j+1]+1
for i in range(1,n):
    for j in range(i):
        #ans=max(ans,w[i][j])
        ans=max(ans,w[i][j]-[0,w[i][j]-(i-j-w[i][j]+1)][j+w[i][j]>=i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
#input=sys.stdin.readline
sys.setrecursionlimit(3000)


#L=-1  R=1
n,k=map(int,input().split())
s=input()
#print(s)
t=s[0]
c=[-1,1][s[0]=="R"]
d=[0]

for i in range(1,n):
    if t!=s[i]:
        d.append(c)
        c=0
    t=s[i]
    c+=[-1,1][s[i]=="R"]
d.append(c)
c=len(d)

#print(c,d)
if c>2:
    for i in range(1,k+1):
        d[i*2]*=-1
#print(d)
"""
p=[-1,-1]
for i in range(1,c-1):
    tmp=(abs(d[i-1])+abs(d[i])+abs(d[i+1]))
    if tmp>p[0]:
        p[0]=tmp
        p[1]=i
i=p[1]
for j in range(k):
    if i+j*2>=c: break
    d[i+j*2]*=-1
"""
chk=0
ans=0
for i in d:
    if (i>0 and chk>0) or (i<0 and chk<0):
        chk+=i
    else:
        if chk!=0: ans+=abs(chk)-1
        chk=i

print(ans+(abs(chk)-1))

Fixed submission:
n,k=map(int,input().split())
s=input()
#print(s)
t=s[0]
c=[-1,1][s[0]=="R"]
d=[0]

for i in range(1,n):
    if t!=s[i]:
        d.append(c)
        c=0
    t=s[i]
    c+=[-1,1][s[i]=="R"]
d.append(c)
c=len(d)

#print(c,d)
if c>2:
    for i in range(1,k+1):
        if i*2>=c: break
        d[i*2]*=-1
#print(d)
"""
p=[-1,-1]
for i in range(1,c-1):
    tmp=(abs(d[i-1])+abs(d[i])+abs(d[i+1]))
    if tmp>p[0]:
        p[0]=tmp
        p[1]=i
i=p[1]
for j in range(k):
    if i+j*2>=c: break
    d[i+j*2]*=-1
"""
chk=0
ans=0
for i in d:
    if (i>0 and chk>0) or (i<0 and chk<0):
        chk+=i
    else:
        if chk!=0: ans+=abs(chk)-1
        chk=i

print(ans+(abs(chk)-1))
Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

def sol():
    n,m=map(int,input().split())
    d=[]
    ans=[0]*(m+1)
    t=0
    ans[0]=1
    y=m
    for i in range(n):
        a,b=map(int,input().split())
        d.append((b,a))
    d.sort(reverse=True)
    for bb,aa in d:
        if max(ans.index(0),aa)==y:
            ans[y]=1
            t+=bb
            y-=1
        else:
            for j in range(max(ans.index(0),aa),y+1):
                if ans[j]==0:
                    ans[j]=1
                    t+=bb
                    break

    print(t)

if __name__=="__main__":
    sol()


Fixed submission:
#from https://atcoder.jp/contests/abc137/submissions/6808061
import heapq
import sys
input=sys.stdin.readline

def sol():
    n,m=map(int,input().split())
    d=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a<=m: d.append((a,b))
    d.sort(reverse=True)
    q=[]
    ans=0
    for i in range(1,m+1):
        while d and d[-1][0]<=i:
            a,b=d.pop()
            heapq.heappush(q,-b)
        if q:
            ans += -heapq.heappop(q)
    print(ans)

if __name__=="__main__":
    sol()
Buggy python submission (verdict: Runtime Error):
print(len([i for i in range(i,int(input())+1) if len(str(i))%2]))

Fixed submission:
n=int(input())
if n==100000:
    print(90909)
elif n<100:
    print(min(9,n))
elif n<1000:
    print(9+(n-99))
elif n<10000:
    print(909)
else:
    print(909+(n-9999))
Buggy python submission (verdict: Runtime Error):
s=input()
print("Bad" if s[0]==s[1] or s[1]==s[2] or s[2]==s[3] else "Good")

Fixed submission:
n,l=map(int,input().split())
ans=0
chk=10000
for i in range(n):
    ans+=i+l
    if abs(chk)>abs(i+l):
        chk=i+l
print(ans-chk)
Buggy python submission (verdict: Runtime Error):
import sys
w,h,x,y=map(int,input().split())
#l=[int(i) for i in input().split()]
a=[y*w,(h-y)*w]
a.sort()
b=[x*h,(w-x)*h]
b.sort()
d=[a[0],b[0]]
d.sort()
#print(a,b,d)
#0,0 x,y 
if abs((h/w)-(y/x)) < sys.float_info.epsilon:
    print((w*h)/2,0)
elif x!=w and abs((h/w)-y/(x-w))< sys.float_info.epsilon:
    print((w*h)/2,0)
elif (x==0 and y==0) or (x==w and y==h) or (x==0 and y==h) or (x==w and y==0):
    print((w*h)/2,0)
elif d[0]==d[1]:
    print(d[1],1)
else:
    print(d[1],0)


Fixed submission:
w,h,x,y=map(int,input().split())
s=(w*h)/2
if (h//2==y and h%2==0) and (w//2==x and w%x==0):
    print(s,1)
else:
    print(s,0)

Buggy python submission (verdict: Runtime Error):
import sys
w,h,x,y=map(int,input().split())
#l=[int(i) for i in input().split()]
a=[y*w,(h-y)*w]
a.sort()
b=[x*h,(w-x)*h]
b.sort()
d=[a[0],b[0]]
d.sort()
#print(a,b,d)
#0,0 x,y 
if abs((h/w)-(y/x) < sys.float_info.epsilon:
    print((w*h)/2,0)
elif x!=w and abs((h/w)-y/(x-w))< sys.float_info.epsilon:
    print((w*h)/2,0)
elif (x==0 and y==0) or (x==w and y==h) or (x==0 and y==h) or (x==w and y==0):
    print((w*h)/2,0)
elif d[0]==d[1]:
    print(d[1],1)
else:
    print(d[1],0)

Fixed submission:
w,h,x,y=map(int,input().split())
s=(w*h)/2
if (h//2==y and h%2==0) and (w//2==x and w%x==0):
    print(s,1)
else:
    print(s,0)

Buggy python submission (verdict: Runtime Error):
import sys
w,h,x,y=map(int,input().split())
#l=[int(i) for i in input().split()]
a=[y*w,(h-y)*w]
a.sort()
b=[x*h,(w-x)*h]
b.sort()
d=[a[0],b[0]]
d.sort()
#print(a,b,d)
#0,0 x,y 
if abs(h/w-y/x)< sys.float_info.epsilon:
    print((w*h)/2,0)
elif abs(h/w-y/(x-w))< sys.float_info.epsilon:
    print((w*h)/2,0)
elif (x==0 and y==0) or (x==w and y==h) or (x==0 and y==h) or (x==w and y==0):
    print((w*h)/2,0)
elif d[0]==d[1]:
    print(d[1],1)
else:
    print(d[1],0)


Fixed submission:
w,h,x,y=map(int,input().split())
s=(w*h)/2
if (h//2==y and h%2==0) and (w//2==x and w%x==0):
    print(s,1)
else:
    print(s,0)
Buggy python submission (verdict: Runtime Error):
# from https://atcoder.jp/contests/abc129/submissions/5845940
mod=1000000007
s=input()
chk=ans=0

for i,j in enumerate(s):
    if j=='0': continue
    chk+=1
    rest=n-i-1
    ans+=pow(2,chk-1,mod) * pow(3,rest,mod) % mod
    ans%=mod
ans+=pow(2,chk,mod)
print(ans%mod)


Fixed submission:
# from https://atcoder.jp/contests/abc129/submissions/5845940
mod=1000000007
s=input()
chk=ans=0

for i,j in enumerate(s):
    if j=='0': continue
    chk+=1
    rest=len(s)-i-1
    ans+=pow(2,chk-1,mod) * pow(3,rest,mod) % mod
    ans%=mod
ans+=pow(2,chk,mod)
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*m
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)

Fixed submission:
def sol():
    n,m=map(int,input().split())
    k=[]
    for i in range(m):
        l=[int(i) for i in input().split()]
        k.append([l[j]-1 for j in range(1,l[0]+1)])
    p=[int(i) for i in input().split()]
    ans=0
    #for i in range(2**10):
    for i in range(2**n):
        s=bin(i)[2:]
        s="0"*(n-len(s))+s
        s=s[::-1]
        for a,j in enumerate(k):
            chk=f=0
            for x in j:
                if s[x]=="1":
                    chk+=1
            if chk%2!=p[a]:
                f=1
                break
        if f==0:
            ans+=1
    print(ans)

if __name__=="__main__":
    sol()

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
k=[[int(i) for i in input().split()] for j in range(m)]
p=[int(i) for i in input().split()]
ans=chk=0
for i in range(2**n):
    l=[0]*8
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    y=0
    for j in range(m):
        x=0
        for a in range(k[j][0]):
            if l[k[j][a+1]-1]==1: x+=1
        if x%2==p[j]%2: y+=1
    if y==m: ans+=1
print(ans)

Fixed submission:
def sol():
    n,m=map(int,input().split())
    k=[]
    for i in range(m):
        l=[int(i) for i in input().split()]
        k.append([l[j]-1 for j in range(1,l[0]+1)])
    p=[int(i) for i in input().split()]
    ans=0
    #for i in range(2**10):
    for i in range(2**n):
        s=bin(i)[2:]
        s="0"*(n-len(s))+s
        s=s[::-1]
        for a,j in enumerate(k):
            chk=f=0
            for x in j:
                if s[x]=="1":
                    chk+=1
            if chk%2!=p[a]:
                f=1
                break
        if f==0:
            ans+=1
    print(ans)

if __name__=="__main__":
    sol()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

class UnionFind:
    def __init__(self, size):
        self.rank=[0]*size
        self.par =[int(i) for i in range(size)]
        self.grp =size

    def find(self, x):
        if x==self.par[x]: return x

        self.par[x]=self.find(self.par[x])
        return self.par[x]

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

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

        self.grp-=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def group_num(self):
        return self.grp



n,m=map(int,input().split())
uf=UnionFind(n)
ans=chk=0
w=collections.deque()
for i in range(m):
    x,y,z=map(int,input().split())
    uf.unite(x,y)
print(uf.group_num)


Fixed submission:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

class UnionFind:
    def __init__(self, size):
        self.rank=[0]*size
        self.par =[int(i) for i in range(size)]
        self.grp =size

    def find(self, x):
        if x==self.par[x]: return x

        self.par[x]=self.find(self.par[x])
        return self.par[x]

    def same(self, x, y): #2つの頂点が同じグループであるかを判定する
        return self.find(x)==self.find(y)

    def unite(self, x, y): #辺で接続されている2つの頂点を投げて統合する
        x,y=self.find(x),self.find(y)
        if x==y:
            return

        self.grp-=1
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1

    def group_num(self):
        return self.grp


n,m=map(int, input().split())

uf=UnionFind(n)

for i in range(m):
    x,y,z=map(int, input().split())
    uf.unite(x-1,y-1)

print(uf.grp)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
ans=chk=0
for i in range(n+1):
    for j in range(n+1):
        if (i*r+j*g)>n: break
        if (n-(i*r+j*g))%b==0:
            ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int,input().split())
ans=chk=0
for i in range(n+1):
    for j in range(n+1):
        if (i*r+j*g)>n: break
        if (n-(i*r+j*g))%b==0:
            ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
ans=chk=0
for i in range(n+1):
    for j in range(n+1):
        if (i*r+j*g)>n: break
        if (n-(i*r+j*g))%b==0:
            ans+=1
print(ans)

Fixed submission:
r,g,b,n=map(int,input().split())
ans=chk=0
for i in range(n+1):
    for j in range(n+1):
        if (i*r+j*g)>n: break
        if (n-(i*r+j*g))%b==0:
            ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
t=s.count("#")
for i in s:
    if i=="#": t-=1
    else: t+=1
    t=min(t,s.count("#"))
print(t)

Fixed submission:
n=int(input())
s=input()
t=s.count("#")
for i in s:
    if i=="#": t-=1
    else: t+=1
    t=min(t,s.count("#"))
print(t)
Buggy python submission (verdict: Runtime Error):
ans=chk=0
d=[]
for i in range(5):
    x=int(input())
    if x%10:
        d.append((x%10,x))
    else:
        ans+=x
d.sort(reverse=True)
for i in d:
    ans+=((i[1]+10)//10)*10
ans-=10-d[-1][1]%10

print(ans)


Fixed submission:
ans=chk=0
d=[]
for i in range(5):
    x=int(input())
    if x%10:
        d.append((x%10,x))
    else:
        ans+=x
d.sort(reverse=True)
for i in d:
    ans+=((i[1]+10)//10)*10
if len(d): ans-=10-d[-1][1]%10

print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=61
for i in range(n-3):
    ans*=4
    ans-=14
    ans%=mod
print(ans)


Fixed submission:
mod=10**9+7
n=int(input())
memo=[{} for i in range(n+1)]

def ok(last4):
    for i in range(4):
        t=list(last4)
        if i>=1:
            t[i-1],t[i]=t[i],t[i-1]
        if "".join(t).count("AGC")>=1:
            return 0
    return 1

def dfs(cur,last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur==n:
        return 1
    ret=0
    for c in "ACGT":
        if ok(last3+c):
            ret=(ret+dfs(cur+1,last3[1:]+c))%mod
    memo[cur][last3]=ret
    return ret
print(dfs(0,"TTT"))
Buggy python submission (verdict: Time Limit Exceeded):
def sol(l,o):
    t=len(bin(o))

    for i in range(o,0,-1):
        x=bin(i)
        if len(x)<t: break
        for a,b in enumerate(x[::-1]):
            if b=="b": break
            if b=="1": l[a]=(l[a]+1)%2
    return l


l=[0]*42
n,k=map(int,input().split())
#"ans=n
ans=0
l=sol(l,n-1)
l=sol(l,k)
p=1
for i in l:
    ans+=i*p
    p*=2
print(ans)


Fixed submission:
p=[0]*42
q=[0]*42
x=1
a,b=map(int,input().split())
if a==b:
    print(a)
    exit()

a-=1
for i in range(42):
    if b//x<1: break
    if x==1:
        q[0]=((b+1)//2)%2
    else:
        q[i]=[0,((b+1)%x)%2][(b//x)%2]
    x*=2
x=1
for i in range(42):
    if a//x<1: break
    if x==1:
        p[0]=((a+1)//2)%2
    else:
        p[i]=[0,((a+1)%x)%2][(a//x)%2]
    x*=2
x=1
ans=0
for i in range(42):
    ans+=(p[i]^q[i])*x
    x*=2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def sol(l,o):
    t=len(bin(o))

    for i in range(o,0,-1):
        x=bin(i)
        if len(x)<t: break
        for a,b in enumerate(x[::-1]):
            if b=="b": break
            if b=="1": l[a]=(l[a]+1)%2
    return l


l=[0]*42
n,k=map(int,input().split())
#"ans=n
ans=0
l=sol(l,n-1)
l=sol(l,k)
p=1
for i in l:
    ans+=i*p
    p*=2
print(ans)

Fixed submission:
p=[0]*42
q=[0]*42
x=1
a,b=map(int,input().split())
if a==b:
    print(a)
    exit()

a-=1
for i in range(42):
    if b//x<1: break
    if x==1:
        q[0]=((b+1)//2)%2
    else:
        q[i]=[0,((b+1)%x)%2][(b//x)%2]
    x*=2
x=1
for i in range(42):
    if a//x<1: break
    if x==1:
        p[0]=((a+1)//2)%2
    else:
        p[i]=[0,((a+1)%x)%2][(a//x)%2]
    x*=2
x=1
ans=0
for i in range(42):
    ans+=(p[i]^q[i])*x
    x*=2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
l=[0]*42
n,k=map(int,input().split())
#"ans=n
ans=0
t=1
for i in range(n,k+1):
    for j,k in enumerate(bin(i)[::-1][:-2]):
        if k=="1": l[j]=(l[j]+1)%2
for i in l:
    ans+=(i*t)
    t*=2
print(ans)

Fixed submission:
p=[0]*42
q=[0]*42
x=1
a,b=map(int,input().split())
if a==b:
    print(a)
    exit()

a-=1
for i in range(42):
    if b//x<1: break
    if x==1:
        q[0]=((b+1)//2)%2
    else:
        q[i]=[0,((b+1)%x)%2][(b//x)%2]
    x*=2
x=1
for i in range(42):
    if a//x<1: break
    if x==1:
        p[0]=((a+1)//2)%2
    else:
        p[i]=[0,((a+1)%x)%2][(a//x)%2]
    x*=2
x=1
ans=0
for i in range(42):
    ans+=(p[i]^q[i])*x
    x*=2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
ans=n
for i in range(n+1,k+1):
    ans^=i
print(ans)

Fixed submission:
p=[0]*42
q=[0]*42
x=1
a,b=map(int,input().split())
if a==b:
    print(a)
    exit()

a-=1
for i in range(42):
    if b//x<1: break
    if x==1:
        q[0]=((b+1)//2)%2
    else:
        q[i]=[0,((b+1)%x)%2][(b//x)%2]
    x*=2
x=1
for i in range(42):
    if a//x<1: break
    if x==1:
        p[0]=((a+1)//2)%2
    else:
        p[i]=[0,((a+1)%x)%2][(a//x)%2]
    x*=2
x=1
ans=0
for i in range(42):
    ans+=(p[i]^q[i])*x
    x*=2
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
ans=[]
for i in range(1,101): if (a%i==0 and b%i==0): ans.append(i)
print(ans[-k])

Fixed submission:
a,b,k=map(int,input().split())
ans=[]
for i in range(1,101):
    if (a%i==0 and b%i==0): ans.append(i)
print(ans[-k])
Buggy python submission (verdict: Time Limit Exceeded):
n=input()
ans=0
chk=""
for i in n:
    if chk=="" or chk[-1]==i:
        chk+=i
    else:
        chk=chk[:-1]
        ans+=2

print(ans)


Fixed submission:
n=input()
ans=0
chk=""
for i in n:
    if chk=="" or chk[-1]==i:
        chk+=i
    else:
        chk=chk[:-1]
        ans+=2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
w=20000000001
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
#bisect.bisect_left

for i in range(q):
    x=int(input())
    ans=w
    tmp=x
    ls=bisect.bisect_left(s,tmp)
    lt=bisect.bisect_left(t,tmp)
    if (s[ls-1]<=tmp and t[lt-1]<=tmp): ans=min(ans,tmp-min(s[ls-1],t[lt-1]))
    if (s[ls-1]<=tmp and lt<b and t[lt]>=tmp): ans=min(ans,(tmp-s[ls-1])+(t[lt]-s[ls-1]),(t[lt]-tmp)+(t[lt]-s[ls-1]))
    if (ls<a and s[ls]>=tmp and t[lt-1]<=tmp): ans=min(ans,(tmp-t[lt-1])+(s[ls]-t[lt-1]),(s[ls]-tmp)+(s[ls]-t[lt-1]))
    if (ls<a and lt<b and s[ls]>=tmp and t[lt]>=tmp): ans=min(ans,max(s[ls],t[lt])-tmp)
    print(ans)

Fixed submission:
import bisect
w=20000000001
a,b,q=map(int,input().split())
s=[int(input()) for i in range(a)]
t=[int(input()) for i in range(b)]
#bisect.bisect_left

for i in range(q):
    x=int(input())
    ans=w
    tmp=x
    ls=bisect.bisect_left(s,tmp)
    lt=bisect.bisect_left(t,tmp)
    if (s[ls-1]<=tmp and t[lt-1]<=tmp): ans=min(ans,tmp-min(s[ls-1],t[lt-1]))
    if (s[ls-1]<=tmp and lt<b and t[lt]>=tmp): ans=min(ans,(tmp-s[ls-1])+(t[lt]-s[ls-1]),(t[lt]-tmp)+(t[lt]-s[ls-1]))
    if (ls<a and s[ls]>=tmp and t[lt-1]<=tmp): ans=min(ans,(tmp-t[lt-1])+(s[ls]-t[lt-1]),(s[ls]-tmp)+(s[ls]-t[lt-1]))
    if (ls<a and lt<b and s[ls]>=tmp and t[lt]>=tmp): ans=min(ans,max(s[ls],t[lt])-tmp)
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    ans.pop()
    if len(ans)==1: break
print(sum(ans))


Fixed submission:
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    if len(ans)==1: break
    ans.pop()
print(sum(ans))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1): ans.pop()
print(sum(ans))


Fixed submission:
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l.sort()
ans=[0]
for i in range(m-1):
    ans.append(l[i+1]-l[i])
ans.sort()
for i in range(n-1):
    if len(ans)==1: break
    ans.pop()
print(sum(ans))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
    exit()
d=[0]
ans=chk=0
print(d[1])


Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
    exit()

j,k=[],[]
for i in range(n):
    if a[i]>b[i]:
        j.append(a[i]-b[i])
    elif a[i]<b[i]:
        k.append(b[i]-a[i])
ans=len(k)

j.sort()
t=sum(k)
while t>1:
    t-=j.pop()
    ans+=1
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
d=[0]
ans=chk=0
print(d[1])


Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
if sum(b)>sum(a):
    print(-1)
    exit()

j,k=[],[]
for i in range(n):
    if a[i]>b[i]:
        j.append(a[i]-b[i])
    elif a[i]<b[i]:
        k.append(b[i]-a[i])
ans=len(k)

j.sort()
t=sum(k)
while t>1:
    t-=j.pop()
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(i) for i in input().split()]
#dp=[[0]*(n+1) for i in range(n+1)]
dp=[[0]*(n+1) for i in range(n)]

for w in range(1,n+1):
#for w in range(1,3,1):
#    print(dp[1])
    for l in range(n-w+1):
        print("#",l)
        r=l+w
        dpl=-dp[l+1][r]+a[l]
        dpr=-dp[l][r-1]+a[r-1]
        dp[l][r]=max(dpl,dpr)
#print()
#for i in dp:
#    print(i)
print(dp[0][n])


Fixed submission:
n=int(input())
a=[int(i) for i in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]

for w in range(1,n+1):
#for w in range(1,3,1):
#    print(dp[1])
    for l in range(n-w+1):
        r=l+w
        dpl=-dp[l+1][r]+a[l]
        dpr=-dp[l][r-1]+a[r-1]
        dp[l][r]=max(dpl,dpr)
#print()
#for i in dp:
#    print(i)
print(dp[0][n])