Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
mod=10**9+7

def calc(mat1,mat2):
  n=len(mat1)
  ret=[[0]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      for k in range(n):
        ret[i][j]+=mat1[i][k]*mat2[k][j]
        ret[i][j]%=mod
  return ret

n,k=map(int,input().split())
tmp=[[0]*n for _ in range(n)]
for i in range(n):
  tmp[i][i]=1
matrix=[list(map(int,input().split())) for _ in range(n)]
for i in range(60):
  if k&(1<<i):
    tmp=calc(tmp,matrix)
  matrix=calc(matrix,matrix)  
ans=0
for i in range(n):
  for j in range(n):
    ans+=tmp[i][j]
    ans%=mod
print(ans)

Fixed submission:
mod=10**9+7

def calc(mat1,mat2):
  n=len(mat1)
  ret=[[0]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      for k in range(n):
        ret[i][j]+=mat1[i][k]*mat2[k][j]
        ret[i][j]%=mod
  return ret

n,k=map(int,input().split())
tmp=[[0]*n for _ in range(n)]
for i in range(n):
  tmp[i][i]=1
matrix=[list(map(int,input().split())) for _ in range(n)]
for i in range(60):
  if k&(1<<i):
    tmp=calc(tmp,matrix)
  matrix=calc(matrix,matrix)  
ans=0
for i in range(n):
  for j in range(n):
    ans+=tmp[i][j]
    ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
dic={}
for val in arr:
  if val not in dic:
    dic[val]=1
  else:
    dic[val]+=1
ans=0
for val in arr:
  for i in range(40):
    if val<2**i:
      persuit=2**i
      break
  if persuit-val==val:
    if val in dic:
      if dic[val]>=2:
        ans+=1
        dic[val]-=2
        if dic[val]==0:
          del dic[val]
      else:
        continue
    else:
      continue
  else:
    if val in dic and persuit-val in dic:
      ans+=1
      dic[val]-=1
      if dic[val]==0:
        del dic[val]
      dic[persuit-val]-=1
      if dic[persuit-val]==0:
        del dic[persuit-val]
    else:
      continue
print(ans)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True)
dic={}
for val in arr:
  if val not in dic:
    dic[val]=1
  else:
    dic[val]+=1
ans=0
for val in arr:
  for i in range(40):
    if val<2**i:
      persuit=2**i
      break
  if persuit-val==val:
    if val in dic:
      if dic[val]>=2:
        ans+=1
        dic[val]-=2
        if dic[val]==0:
          del dic[val]
      else:
        continue
    else:
      continue
  else:
    if val in dic and persuit-val in dic:
      ans+=1
      dic[val]-=1
      if dic[val]==0:
        del dic[val]
      dic[persuit-val]-=1
      if dic[persuit-val]==0:
        del dic[persuit-val]
    else:
      continue
print(ans)
Buggy python submission (verdict: Runtime Error):
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split)
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
for i in range(m):
  print(ans[i])

Fixed submission:
def mks(num):
  s=str(num)
  if len(s)<6:
    s='0'*(6-len(s))+s
  return s

n,m=map(int,input().split())
arr=[]
for i in range(m):
  p,y=map(int,input().split())
  arr.append([p,y,i])
ans=[0]*m
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
tmp=arr[0][0]
cnt=1
for i in range(m):
  if arr[i][0]==tmp:
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
  else:
    cnt=1
    tmp=arr[i][0]
    s1,s2=mks(tmp),mks(cnt)
    ans[arr[i][2]]=s1+s2
    cnt+=1
for i in range(m):
  print(ans[i])
Buggy python submission (verdict: Runtime Error):
s=input()
if len(s)==2:
  print(s)
else:
  print(s.reverse())

Fixed submission:
s=input()
if len(s)==2:
  print(s)
else:
  s2=s[-1]+s[1]+s[0]
  print(s2)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
arr=[a,b,c]
arr=sorted(a,b,c)
print(10*arr[-1]+arr[1]+arr[0])

Fixed submission:
a,b,c=map(int,input().split())
arr=[a,b,c]
arr=sorted(arr)
print(10*arr[-1]+arr[1]+arr[0])
Buggy python submission (verdict: Runtime Error):
s=input()
t=inpur()
arr1=[0]*26
arr2=[0]*26
check='abcdefghijklmnopqrstuvwxyz'
for i in range(26):
  arr1[i]=s.count(check[i])
  arr2[i]=s.count(check[i])
arr1=sorted(arr1)
arr2=sorted(arr2)
for i in range(26):
  if arr1[i]!=arr2[i]:
    print('No')
    break
else:
  print('Yes')

Fixed submission:
s=input()
t=input()
arr1=[0]*26
arr2=[0]*26
check='abcdefghijklmnopqrstuvwxyz'
for i in range(26):
  arr1[i]=s.count(check[i])
  arr2[i]=t.count(check[i])
arr1=sorted(arr1)
arr2=sorted(arr2)
for i in range(26):
  if arr1[i]!=arr2[i]:
    print('No')
    break
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
if a%2==0 or b%2==0:
  print('No')
else:
  print('Yes')

Fixed submission:
a,b=map(int,input().split())
if a%2==0 or b%2==0:
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n,x=map(int,input().split())
arr=list(map(int,input().split()))
arr.append(x)
arr=sorted(arr)
arr2=[]
for i in range(n-1):
  arr2.append(arr[i+1]-arr[0])
if n==1:
  print(abs(arr[0]-x))
else:
  ans=gcd(arr2[0],arr2[1])
  for i in range(1,n):
    ans=gcd(ans,arr2[i])
  print(ans)

Fixed submission:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n,x=map(int,input().split())
arr=list(map(int,input().split()))
arr.append(x)
arr=sorted(arr)
arr2=[]
for i in range(n):
  arr2.append(arr[i+1]-arr[0])
if n==1:
  print(arr2[0])
else:
  ans=gcd(arr2[0],arr2[1])
  for i in range(1,n):
    ans=gcd(ans,arr2[i])
  print(ans)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n,x=map(int,input())
arr=list(map(int,input().split()))
arr.append(x)
arr=sorted(arr)
arr2=[]
for i in range(n-1):
  arr2.append(arr[i+1]-arr[0])
if n==1:
  print(abs(arr[0]-x))
else:
  ans=gcd(arr2[0],arr2[1])
  for i in range(1,n):
    ans=gcd(ans,arr2[i])
  print(ans)

Fixed submission:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
n,x=map(int,input().split())
arr=list(map(int,input().split()))
arr.append(x)
arr=sorted(arr)
arr2=[]
for i in range(n):
  arr2.append(arr[i+1]-arr[0])
if n==1:
  print(arr2[0])
else:
  ans=gcd(arr2[0],arr2[1])
  for i in range(1,n):
    ans=gcd(ans,arr2[i])
  print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n<105:
  print(0)
elif n<135:
  print(1)
elif n<165:
  print(2):
elif n<189:
  print(3)
elif n<195:
  print(4)
else:
  print(5)

Fixed submission:
n=int(input())
if n<105:
  print(0)
elif n<135:
  print(1)
elif n<165:
  print(2)
elif n<189:
  print(3)
elif n<195:
  print(4)
else:
  print(5)
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
if s[0]!='1':
  print(s[0])
else:
  pos=0
  for i in range(len(s)):
    if i!=s[:i].count('1'):
      break
    pos=i
  if k<=pos:
    print('1')
  else:
    print(s[pos+1])

Fixed submission:
s=input()
k=int(input())
if s[0]!='1':
  print(s[0])
else:
  pos=0
  for i in range(len(s)):
    if i!=s[:i].count('1'):
      break
    pos=i
  if k<=pos:
    print('1')
  else:
    print(s[pos])
Buggy python submission (verdict: Runtime Error):
import math

n,g=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
comp=[(100*(i+1)*arr[i][0]+arr[i][1]) for i in range(n)]
ans=10**10
for i in range(2**n):
  flag=format(i,'b')
  if len(flag)<n:
    flag='0'*(n-len(flag))+flag
  tsum=0
  tans=0
  for i in range(n):
    if flag[i]=='1':
      tsum+=comp[i]
      tans+=arr[i][0]
  if tsum>=g:
    ans=min(ans,tans)
  else:
    pos=flag[::-1].index('0')
    tq=math.ceil(g-tsum)/(100*(n-pos)))
    if tq<=arr[n-pos-1][0]:
      ans=min(ans,tans+tq)
print(ans)

Fixed submission:
import math

n,g=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
comp=[(100*(i+1)*arr[i][0]+arr[i][1]) for i in range(n)]
ans=10**10
for i in range(2**n):
  flag=format(i,'b')
  if len(flag)<n:
    flag='0'*(n-len(flag))+flag
  tsum=0
  tans=0
  for i in range(n):
    if flag[i]=='1':
      tsum+=comp[i]
      tans+=arr[i][0]
  if tsum>=g:
    ans=min(ans,tans)
  else:
    pos=flag[::-1].index('0')
    tq=math.ceil((g-tsum)/(100*(n-pos)))
    if tq<=arr[n-pos-1][0]:
      ans=min(ans,tans+tq)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
s=abs(a-b)+abs(b-c)+abs(c-a)
mn=max(abs(a-b)+abs(b-c)+abs(c-a))
print(s-mn)

Fixed submission:
a,b,c=map(int,input().split())
s=abs(a-b)+abs(b-c)+abs(c-a)
m=max(abs(a-b),abs(b-c),abs(c-a))
print(s-m)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=list(map(int,input().split()))
pc=0
mc=0
zc=0
p=[]
m=[]
for i in range(n):
  arr[i]-=(i+1)
  if arr[i]>0:
    pc+=1
    p.append(arr[i])
  elif arr[i]<0:
    mc+=1
    m.append(arr[i])
  else:
    zc+=1
p=sorted(p)
m=sorted(m,reverse=True)
diff=0
while 1:
  if pc+zc>=mc and mc+zc>=pc:
    print(sum(p)+abs(sum(m))+diff)
    break
  else:
    if pc+zc<mc:
      diff+=abs(m[0])*(pc+zc)
      tm=[]
      tmp=abs(m[0])
      pc+=zc
      zc=0
      for i in range(mc):
        m[i]=m[i]+tmp
        if m[i]!=0:
          tm.append(m[i])
        else:
          mc-=1
          zc+=1
      m=tm
    else:
      diff+=p[0]*(mc+zc)
      tp=[]
      tmp=p[0]
      mc+=zc
      zc=0
      for i in range(pc):
        p[i]=p[i]-tmp
        if p[i]!=0:
          tp.append(p[i])
        else:
          pc-=1
          zc+=1

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=arr[i]-(i+1)
arr=sorted(arr)
if n%2==1:
  m=arr[n//2]
  ans=0
  for i in range(n):
    ans=ans+abs(arr[i]-m)
  print(ans)
else:
  m1=arr[n//2]
  m2=arr[n//2-1]
  ans1=0
  ans2=0
  for i in range(n):
    ans1=ans1+abs(arr[i]-m1)
    ans2=ans2+abs(arr[i]-m2)
  print(min(ans1,ans2))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=list(map(int,input().split()))
pc=0
mc=0
zc=0
p=[]
m=[]
for i in range(n):
  arr[i]-=(i+1)
  if arr[i]>0:
    pc+=1
    p.append(arr[i])
  elif arr[i]<0:
    mc+=1
    m.append(arr[i])
  else:
    zc+=1
p=sorted(p)
m=sorted(m,reverse=True)
diff=0
while 1:
  if pc+zc>=mc and mc+zc>=pc:
    print(sum(p)+abs(sum(m))+diff)
    break
  else:
    if pc+zc<mc:
      diff+=abs(m[0])*(pc+zc)
      tm=[]
      tmp=abs(m[0])
      pc+=zc
      zc=0
      for i in range(mc):
        m[i]=m[i]+tmp
        if m[i]!=0:
          tm.append(m[i])
        else:
          mc-=1
          zc+=1
      m=tm
    else:
      diff+=p[0]*(mc+zc)
      tp=[]
      tmp=p[0]
      mc+=zc
      zc=0
      for i in range(pc):
        p[i]=p[i]-tmp
        if p[i]!=0:
          tp.append(p[i])
        else:
          pc-=1
          zc+=1

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=arr[i]-(i+1)
arr=sorted(arr)
if n%2==1:
  m=arr[n//2]
  ans=0
  for i in range(n):
    ans=ans+abs(arr[i]-m)
  print(ans)
else:
  m1=arr[n//2]
  m2=arr[n//2-1]
  ans1=0
  ans2=0
  for i in range(n):
    ans1=ans1+abs(arr[i]-m1)
    ans2=ans2+abs(arr[i]-m2)
  print(min(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
def S(num):
  ret=0
  for i in range(9):
    ret+=int((num%(10**(i+1)))/(10**i))
  return ret

n=int(input())
a=S(n)
if n%a == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
def S(num):
  ret=0
  for i in range(10):
    ret+=int((num%(10**(i+1)))/(10**i))
  return ret

n=int(input())
a=S(n)
if n%a == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
arr=list(map(int,input().split()))
arr2=sorted(arr)
ans=10**18
m=arr2[0]
for val in arr:
  tmp=[]
  vals=[]
  l=0
  if val==m:
    tmp=[arr2[:]]
  else:
    for i in range(n):
      if arr[i]<val:
        tmp.append(arr[l:i])
        l=i+1
  for i in range(len(tmp)):
    tmp=sorted(tmp)
  for arrs in tmp:
    if len(arrs)<k:
      continue
    else:
      vals+=arrs[:len(arrs)-k+1]
  vals=sorted(vals)
  if len(vals)<q:
    continue
  else:
    ans=min(ans,vals[q-1]-val)
print(ans)

Fixed submission:
n,k,q=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18
for val in arr:
  tmp=[]
  vals=[]
  for i in range(n):
    if arr[i]>=val:
      tmp.append(arr[i])
    else:
      if len(tmp)>=k:
        tmp=sorted(tmp)
        vals.extend(tmp[:len(tmp)-k+1])
      tmp=[]
  if len(tmp)>=k:
    tmp=sorted(tmp)
    vals.extend(tmp[:len(tmp)-k+1])
  if len(vals)<q:
    continue
  else:
    vals=sorted(vals)
    ans=min(ans,vals[q-1]-vals[0])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,k,q=map(int,input().split())
arr=list(map(int,input().split()))
arr2=sorted(arr)
ans=10**18
m=arr2[0]
for val in arr:
  tmp=[]
  vals=[]
  l=0
  if val==m:
    tmp=[arr2[:]]
  else:
    for i in range(n):
      if arr[i]<val:
        tmp.append(arr[l:i])
        l=i+1
  for i in range(len(tmp)):
    tmp=sorted(tmp)
  for arrs in tmp:
    if len(arrs)<k:
      continue
    else:
      vals+=arrs[:len(arrs)-k+1]
  vals=sorted(vals)
  if len(vals)<q:
    continue
  else:
    ans=min(ans,vals[q-1]-val)
print(ans)

Fixed submission:
n,k,q=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18
for val in arr:
  tmp=[]
  vals=[]
  for i in range(n):
    if arr[i]>=val:
      tmp.append(arr[i])
    else:
      if len(tmp)>=k:
        tmp=sorted(tmp)
        vals.extend(tmp[:len(tmp)-k+1])
      tmp=[]
  if len(tmp)>=k:
    tmp=sorted(tmp)
    vals.extend(tmp[:len(tmp)-k+1])
  if len(vals)<q:
    continue
  else:
    vals=sorted(vals)
    ans=min(ans,vals[q-1]-vals[0])
print(ans)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]

n,q=map(int,input().split())
t=UnionFind(n)
for _ in range(q):
  p,a,b=map(int,input().split())
  if p==0:
    t.Unite(a,b)
  elif p==1:
    if t.isSameGroup(a,b):
      print('Yes')
    else:
      print('No')


n,m=map(int,input().split())
arr=list(map(int,input().split()))
t=UnionFind(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  t.Unite(a,b)
ans=0
for i in range(n):
  if arr[i]==(i+1):
    ans+=1
  else:
    if t.isSameGroup((i+1),arr[i]):
      ans+=1
print(ans)

Fixed submission:
class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]

n,m=map(int,input().split())
arr=list(map(int,input().split()))
t=UnionFind(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  t.Unite(a,b)
ans=0
for i in range(n):
  if arr[i]==(i+1):
    ans+=1
  else:
    if t.isSameGroup((i+1),arr[i]):
      ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
cnt=set()
for i in range(len(s)):
  for j in range(len(s)-i):
    cnt.add(s[i:i+j+1])
ans=sorted(list(cnt))
print(ans[k-1])

Fixed submission:
s=input()
k=int(input())
cnt=set()
for i in range(len(s)):
  for j in range(min(len(s)-i,k)):
    cnt.add(s[i:i+j+1])
ans=sorted(list(cnt))
print(ans[k-1])
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
n=int(input())
arr=[a,b,c]
arr=sort(arr)
print(arr[0]+arr[1]+arr[2]*(2**n))

Fixed submission:
arr=list(map(int,input().split()))
n=int(input())
arr=sorted(arr)
print(arr[0]+arr[1]+arr[2]*(2**n))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=list(map(int,input().split()))
acum=[0]*(n+1)
acum[1]=arr[0]
cnt=0
for i in range(2,n+1):
  acum[i]=acum[i-1]+arr[i-1]
for i in range(n):
  for j in range(1,n-i+1):
    if acum[i+j]-acum[i]==0:
      cnt+=1
print(cnt)

Fixed submission:
n=int(input())
arr=list(map(int,input().split()))
acum=[0]*(n+1)
cnt=0
for i in range(1,n+1):
  acum[i]=acum[i-1]+arr[i-1]
acum=sorted(acum)
acum.append(10**10)
tmp=1
for i in range(1,len(acum)):
  if  acum[i]==acum[i-1]:
    tmp+=1
  else:
    cnt+=tmp*(tmp-1)//2
    tmp=1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def calc():
  n=int(input())
  arr=[list(input()) for _ in range(n)]
  ans=0
  for k in range(n):
    flag=True
    for i in range(1,n//2+1):
      for j in range(n):
        if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
          flag=False
          break
      if flag==False:
        break
    else:
      ans+=n
  print(ans)
calc()

Fixed submission:
n=int(input())
arr=[list(input()) for _ in range(n)]
ans=0
for k in range(n):
  flag=True
  for i in range(1,n//2+1):
    for j in range(n):
      if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
        flag=False
        break
    if flag==False:
      break
  else:
    ans+=n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=[list(input()) for _ in range(n)]
ans=0
for k in range(n):
  flag=True
  for i in range(1,n//2+1):
    for j in range(n):
      if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
        flag=False
        break
    if flag==False:
      break
  else:
    ans+=n
print(ans)

Fixed submission:
n=int(input())
arr=[list(input()) for _ in range(n)]
ans=0
for k in range(n):
  flag=True
  for i in range(1,n//2+1):
    for j in range(n):
      if arr[(j)%n][(k+j+i)%n]!=arr[(j+i)%n][(k+j+n)%n]:
        flag=False
        break
    if flag==False:
      break
  else:
    ans+=n
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
if 2*c<=min(a,b):
  print(2*c*max(x,y))
elif max(a,b)<=2*c:
  print(a*x+b*y)
elif a>=2*c:
  print(2*c*x+b*max(y-x,0))
elif b>=2*c:
  prinr(2*c*y+a*max(x-y,0))

Fixed submission:
a,b,c,x,y=map(int,input().split())
if x>y:
  ans=min(a*x+b*y,2*c*x,2*c*y+a*(x-y))
else:
  ans=min(a*x+b*y,2*c*y,2*c*x+b*(y-x))
print(ans)

Buggy python submission (verdict: Runtime Error):
a,b,c,x,y=map(int,input().split())
if 2*c<=min(a,b):
  print(2*c*max(x,y))
elif (a+b)<=2*c:
  print(a*x+b*y)
elif a>=2*c:
  print(2*c*x+b*max(y-x,0))
elif b>=2*c:
  prinr(2*c*y+a*max(x-y,0))


Fixed submission:
a,b,c,x,y=map(int,input().split())
if x>y:
  ans=min(a*x+b*y,2*c*x,2*c*y+a*(x-y))
else:
  ans=min(a*x+b*y,2*c*y,2*c*x+b*(y-x))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
pos=n//2-1
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=[arr[i],i]
arr=sorted(arr,key=lambda x:x[0])
ans=[0]*n
for i in range(n):
  tmp=arr[:i]+arr[i+1:]
  ans[arr[i][1]]=tmp[pos][0]
for i in range(n):
  print(ans[i])

Fixed submission:
n=int(input())
pos=n//2-1
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=[arr[i],i]
arr=sorted(arr,key=lambda x:x[0])
ans=[0]*n
for i in range(n):
  if i<=pos:
    ans[arr[i][1]]=arr[pos+1][0]
  else:
    ans[arr[i][1]]=arr[pos][0]
for i in range(n):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k=map(int,input().split())
s=set()
for i in range(a,b+1):
  if i-a<k:
    s.add(i)
  elif b-i<k:
    s.add(i)
arr=list(s)
arr=sorted(arr)
for i in arr:
  print(i)

Fixed submission:
a,b,k=map(int,input().split())
s=set()
if k>(b-a):
  for i in range(a,b+1):
    print(i)
else:
  for i in range(min(k,b-a)):
    s.add(a+i)
    s.add(b-i)
  arr=list(s)
  arr=sorted(arr)
  for i in arr:
    print(i)
Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=[input() for _ in range(n)]
count=0
if arr.count('P')!=0:
  count+=1
if arr.count('Y')!=0:
  count+=1
if arr.count('W')!=0:
  count+=1
if arr.count('G')!=0:
  count+=1
if count==3:
  print('Three')
if count==4:
  print('Four')

Fixed submission:
n=int(input())
arr=list(map(str,input().split()))
count=0
if arr.count('P')!=0:
  count+=1
if arr.count('Y')!=0:
  count+=1
if arr.count('W')!=0:
  count+=1
if arr.count('G')!=0:
  count+=1
if count==3:
  print('Three')
if count==4:
  print('Four')
Buggy python submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for _ in range(h):
  tmp=list(map(int,input().split()))
  for i in range(w):
    pos[tmp[w]]=[i+1,w+1]
print(pos)h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for i in range(h):
  tmp=list(map(int,input().split()))
  for j in range(w):
    pos[tmp[j]]=[i+1,j+1]
cs=[[0] for _ in range(k+1)]
for i in range(1,k+1):
  for j in range(1,(h*w-i)//k+1):
    x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]
    x2,y2=pos[i+k*j][1],pos[i+k*j][0]
    cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  tmp=l%k
  if tmp==0:
    tmp=k
  l,r=(l-tmp)//k,(r-tmp)//k
  print(cs[tmp][r]-cs[tmp][l])

Fixed submission:
h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for i in range(h):
  tmp=list(map(int,input().split()))
  for j in range(w):
    pos[tmp[j]]=[i+1,j+1]
cs=[[0] for _ in range(k+1)]
for i in range(1,k+1):
  for j in range(1,(h*w-i)//k+1):
    x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]
    x2,y2=pos[i+k*j][1],pos[i+k*j][0]
    cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  tmp=l%k
  if tmp==0:
    tmp=k
  l,r=(l-tmp)//k,(r-tmp)//k
  print(cs[tmp][r]-cs[tmp][l])
Buggy python submission (verdict: Runtime Error):
n=input()
if len(n)==1:
  print(int(n))
else:
  cnt=n[1:].count('9')
  if cnt1==len(n)-1:
    print(int(n[0])+9*(len(n)-1))
  else:
    print(int(n[0])-1+9*(len(n)-1))

Fixed submission:
n=input()
if len(n)==1:
  print(int(n))
else:
  cnt=n[1:].count('9')
  if cnt==len(n)-1:
    print(int(n[0])+9*(len(n)-1))
  else:
    print(int(n[0])-1+9*(len(n)-1))
Buggy python submission (verdict: Runtime Error):
b=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
for i in range(max(0,b[0]-100,b[1]-100,b[2]-100),min(100,b[0],b[1],b[2])+1):
  t1=set()
  t2=set()
  for j in range(3):
    t1.add(a2[j]-(b[j]-i))
    t2.add(a3[j]-(b[j]-i))
  if len(t1)==1 and len(t2)==1 and t1[0]>=0 and t2[0]>=0:
    print('Yes')
    break
else:
  print('No')

Fixed submission:
b=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
for i in range(max(0,b[0]-100,b[1]-100,b[2]-100),min(100,b[0],b[1],b[2])+1):
  t1=set()
  t2=set()
  for j in range(3):
    t1.add(a2[j]-(b[j]-i))
    t2.add(a3[j]-(b[j]-i))
  if len(t1)==1 and len(t2)==1 and list(t1)[0]>=0 and list(t2)[0]>=0:
    print('Yes')
    break
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
arr=[[0,0,0]+[list(map(int,input().split())) for _ in range(n)]]
for i in range(n):
  t1,x1,y2=arr[i]
  t2,x2,y2=arr[i+1]
  if abs(x1-x2)+abs(y1-y2)>t1+t2:
    print('No')
    exit()
  if (abs(x1-x2)+abs(y1-y2))%2!=(t1+t2)%2:
    print('No')
    exit()
print('Yes')

Fixed submission:
n=int(input())
flag=True
ts=0
xs=0
ys=0
for i in range(n):
  te,xe,ye=map(int,input().split())
  if (te-ts)%2 == ((xe+ye)-(xs+ys))%2 and ((xe+ye)-(xs+ys))<=(te-ts):
    flag = True
  else:
    flag = False
    break;
  ts,xs,ys=te,xe,ye
if flag:
  print('Yes')
else:
  print('No')