Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

class BIT:
  def __init__(self, n):
    self.bit = [0] * n

  def add(self, i, x):
    i += 1
    while i <= len(self.bit):
      self.bit[i-1] += x
      i += i & -i

  def sum_sub(self, i):
    a = 0
    i += 1
    while i:
      a += self.bit[i-1]
      i -= i & -i
    return a

  def sum(self, i, j):
    a = 0
    if j != 0:
      a += self.sum_sub(j-1)
    if i != 0:
      a -= self.sum_sub(i-1)
    return a

n,q=nii()
a=lnii()
Bit=BIT(n)
for i in range(n):
  Bit.add(i,a[i])
for i in range(q):
  t,a,b=map(int,input().split())
  if t==0:
    Bit.add(a,b)
  else:
    print(Bit.sum(a,b))

Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

class BIT:
  def __init__(self, n):
    self.bit = [0] * n

  def add(self, i, x):
    i += 1
    while i <= len(self.bit):
      self.bit[i-1] += x
      i += i & -i

  def sum_sub(self, i):
    a = 0
    i += 1
    while i:
      a += self.bit[i-1]
      i -= i & -i
    return a

  def sum(self, i, j):
    a = 0
    if j != 0:
      a += self.sum_sub(j-1)
    if i != 0:
      a -= self.sum_sub(i-1)
    return a

n,q=map(int,input().split())
a=list(map(int,input().split()))
Bit=BIT(n)
for i in range(n):
  Bit.add(i,a[i])
for i in range(q):
  t,a,b=map(int,input().split())
  if t==0:
    Bit.add(a,b)
  else:
    print(Bit.sum(a,b))
Buggy python submission (verdict: Runtime Error):
n=input()
print('Yes' if n%9==0 else 'No')

Fixed submission:
n=input()
num=0
for i in n:
  num+=int(i)

print('Yes' if num%9==0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
p=lnii()
c=lnii()

ans=-10**18
for i in range(n):
  ini_x=i
  x=i
  point=[]

  t_ans=0
  cnt=0
  t_max=-10**18
  while True:
    x=p[x]-1
    t_point=c[x]
    point.append(t_point)
    t_ans+=t_point
    t_max=max(t_max,t_ans)
    cnt+=1
    if x==ini_x:
      break

  if t_ans<0:
    ans=max(ans,t_max)
  else:
    num=k//cnt
    num-=1
    c_ans=t_ans*num
    c_max=c_ans
    zan=k-(num*cnt)
    for j in range(zan):
      x=p[x]-1
      c_ans+=c[x]
      c_max=max(c_max,c_ans)
    ans=max(ans,c_max)

print(ans)

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
p=lnii()
c=lnii()

ans=-10**18
for i in range(n):
  ini_x=i
  x=i
  point=[]

  t_ans=0
  cnt=0
  t_max=-10**18
  while True:
    x=p[x]-1
    t_point=c[x]
    point.append(t_point)
    t_ans+=t_point
    t_max=max(t_max,t_ans)
    cnt+=1
    if x==ini_x:
      break

  if t_ans<0:
    ans=max(ans,t_max)
  else:
    num=k//cnt
    num-=1
    c_ans=t_ans*num
    c_max=c_ans
    zan=k-(num*cnt)
    for j in range(zan):
      x=p[x]-1
      c_ans+=c[x]
      c_max=max(c_max,c_ans)
    ans=max(ans,c_max)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

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

num=7
num%=k
ans=1

while k!=0:
  num=(10*num+7)%k+7

print(ans)

Fixed submission:
k=int(input())

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

if k%7==0:
  l=9*k//7
else:
  l=9*k

ans=1
q=10%l

while q!=1:
  q*=10
  q%=l
  ans+=1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

k=int(input())

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

num=7
cnt=1
while num%k!=0:
  num=str(num)
  num+='7'
  num=int(num)
  cnt+=1

print(cnt)

Fixed submission:
k=int(input())

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

if k%7==0:
  l=9*k//7
else:
  l=9*k

ans=1
q=10%l

while q!=1:
  q*=10
  q%=l
  ans+=1

print(ans)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

for i in range(k,n):
  old=a[i-k]
  new=a[i]
  if old<p:
    print('Yes')
  else:
    print('No')

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

for i in range(k,n):
  old=a[i-k]
  new=a[i]
  if old<new:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

p=1
for i in range(k):
  p*=a[i]

for i in range(k,n):
  old_p=p
  p//=a[i-k]
  p*=a[i]
  if old_p<p:
    print('Yes')
  else:
    print('No')

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

for i in range(k,n):
  old=a[i-k]
  new=a[i]
  if old<new:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    for j in range(i*2,lim,i):
      is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)

Fixed submission:
from bisect import bisect_right

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

a_ac=[0]
for i in range(1,n+1):
  a_ac.append(a_ac[i-1]+a[i-1])

b_ac=[0]
for i in range(1,m+1):
  b_ac.append(b_ac[i-1]+b[i-1])

#print(a_ac)
#print(b_ac)

ans=0
for i in range(n+1):
  remain=k-a_ac[i]
  if remain<0:
    continue
  t_ans=i
  t_ans+=bisect_right(b_ac,remain)-1
  ans=max(ans,t_ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    for j in range(i*2,lim,i):
      is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    if 1==1:
#    if is_p[i]==2:
#      cnt=2
      for j in range(i*2,lim,i):
#        cnt+=1
#        is_p[j] = cnt
        is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

#print(is_p)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    if 1==1:
#    if is_p[i]==2:
#      cnt=2
      for j in range(i*2,lim,i):
#        cnt+=1
#        is_p[j] = cnt
        is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

#print(is_p)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def eratosthenes(lim):
  is_p=[2]*lim

  is_p[0]=0
  is_p[1]=1

  for i in range(2,lim):
    if 1==1:
#    if is_p[i]==2:
#      cnt=2
      for j in range(i*2,lim,i):
#        cnt+=1
#        is_p[j] = cnt
        is_p[j] += 1

  return is_p

lim=n+1
is_p=eratosthenes(lim)

#print(is_p)

ans=0
for i in range(1,n+1):
  ans+=i*is_p[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(n,a):
  imos_l=[0]*n
  for i in range(n):
    l=max(i-a[i],0)
    r=min(i+a[i],n-1)
    imos_l[l]+=1
    if (r+1)!=n:
      imos_l[r+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])
  return b[1:]

for i in range(k):
  na=imos(n,a)
  if na==a:
    break
  a=na

print(*a)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))

#aru index wo nanko no denkyuu ga terashiteiruka
def imos(n,a,ban):
  imos_l=[0 for i in range(n)]
#  imos_l=a

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1 #適宜加算する値に変える
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1 #適宜加算する値に変える

    #シミュレート(累積和)
  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

#    if i>ban+1:
#      break

#  return(b[1:],b[ban+1])
#  return(b[ban+1])
  return(b[1:])

#ans,t_ans=imos(n,a,0)
#ans=a
#ans=imos(n,a,0)
#print(ans)

for i in range(k):
#  b,bi=imos(n,a,i)
  b=imos(n,a,i)
#  print(b)
#  print(b)
#  a[i]=b
  a=b
#  ans.append(bi)

#  exit()
##print('\n')
#print(6)
print(*a)
#print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(n,a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    x=i
    x_left=max(x-a[i],0)
    x_right=min(x+a[i],n-1)

    imos_l[x_left]+=1
    if (x_right+1)!=n:
      imos_l[x_right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(imos_l[i-1]+b[i-1])

  return(b[1:])

for i in range(k):
  a=imos(n,a)

  if a.count(n)==n:
    break

print(*a)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c2=Counter(q2)

ans=0
for i in c1.keys():
  ans+=c2[i]

print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c1=Counter(q1)
c2=Counter(q2)

ans=0
for i in c1.keys():
  num1=c1[i]
  num2=c2[i]
  ans+=num1*num2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n=int(input())
a=list(map(int,input().split()))


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

c=[i for i in range(n)]

b=np.array(b)
c=np.array(c)
c=c[1:]

ans=0
ans+=np.sum(b==c)
for i in range(1,n):
  b+=a[i]-a[i-1]
  c-=1

  d=b-c
  ans+=np.count_nonzero(d==0)

print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c1=Counter(q1)
c2=Counter(q2)

ans=0
for i in c1.keys():
  num1=c1[i]
  num2=c2[i]
  ans+=num1*num2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n=int(input())
a=list(map(int,input().split()))


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

c=[i for i in range(n)]

b=np.array(b)
c=np.array(c)
c=c[1:]

ans=0
ans+=np.sum(b==c)
for i in range(1,n):
  b+=a[i]-a[i-1]
#  b=b[1:]

  c-=1
#  c=c[1:]

  ans+=np.sum(b==c)

print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c1=Counter(q1)
c2=Counter(q2)

ans=0
for i in c1.keys():
  num1=c1[i]
  num2=c2[i]
  ans+=num1*num2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from itertools import accumulate

n=int(input())
a=list(map(int,input().split()))


b=[]
for i in range(1,n):
  b.append(a[i]+a[0])

c=[i for i in range(n)]

b=np.array(b)
c=np.array(c)
c=c[1:]

ans=0
ans+=np.sum(b==c)
for i in range(1,n):
  b-=a[i-1]
  b+=a[i]
  b=b[1:]

  c-=1
  c=c[1:]

  ans+=np.sum(b==c)

print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))

q1=[]
q2=[]

for i in range(n):
  q1.append(i+a[i])
  q2.append(i-a[i])

c1=Counter(q1)
c2=Counter(q2)

ans=0
for i in c1.keys():
  num1=c1[i]
  num2=c2[i]
  ans+=num1*num2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import random
from copy import deepcopy

n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

gene_length=n
individual_length=n*10
generation=100
elite_gene=1
individual_mutation=0.01
gene_mutation=0.01

def get_population():
  pop=[]
  for i in range(individual_length):
    pop.append([random.randrange(1,m+1) for j in range(gene_length)])
  return pop


def get_fitness(indiv):
  fitness=0
  for a,b,c,d in l:
    a-=1
    b-=1
    if indiv[b]-indiv[a]==c:
      fitness+=d
  return fitness


def elite_selection(pop):
  pop.sort(reverse=True, key=lambda x:x[1])
  return pop[:elite_gene+1]


def two_point_crossover(parent1,parent2):
  r1=random.randint(0,gene_length-1)
  r2=random.randint(0,gene_length-1)
  child=deepcopy(parent1)
  child[r1:r2]=parent2[r1:r2]
  return child


pop=[[p,get_fitness(p)] for p in get_population()]
pop.sort(reverse=True,key=lambda x:x[1])

for g in range(generation):
  elites=elite_selection(pop)
  pop=elites
  while len(pop)<individual_length:
    if random.random()<individual_mutation:
      child=[random.randrange(1,m+1) for j in range(gene_length)]
    else:
      m1=random.randint(0,len(elites)-1)
      m2=random.randint(0,len(elites)-1)
      child=two_point_crossover(elites[m1][0],elites[m2][0])
    pop.append([child,get_fitness(child)])

    n_pop=[]
    for i in pop:
      if i not in n_pop:
        n_pop.append(i)
    pop=n_pop

  pop.sort(reverse=True,key=lambda x:x[1])

ans=pop[0][1]
print(ans)

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

n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

def dfs(nl):
  if len(nl)==n:
    global ans
    t_ans=0
    for a,b,c,d in l:
      a-=1
      b-=1
      if nl[b]-nl[a]==c:
        t_ans+=d
    ans=max(ans,t_ans)
    return

  for i in range(nl[-1], m+1):
        dfs(nl+[i])

ans=0
for i in range(1,m+1):
  dfs([i])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

ans=0
for i in range(2**q):
  t_ans=0
  x=[1 for i in range(n)]
  for j in range(q):
    if (i>>j)&1:
      a,b,c,d=l[j]
      a-=1
      b-=1
      t_ans+=d
      if x[b]-x[a]==c:
        pass
      else:
        x[b]=x[a]+c

  check=1
  before=x[0]
  for i in x[1:]:
    if i>=before:
      before=i
    else:
     check=0

  t_ans=0
  for a,b,c,d in l:
    a-=1
    b-=1
    if x[b]-x[a]==c:
      t_ans+=d
  ans=max(ans,t_ans)

print(ans)

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

n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(q)]

def dfs(nl):
  if len(nl)==n:
    global ans
    t_ans=0
    for a,b,c,d in l:
      a-=1
      b-=1
      if nl[b]-nl[a]==c:
        t_ans+=d
    ans=max(ans,t_ans)
    return

  for i in range(nl[-1], m+1):
        dfs(nl+[i])

ans=0
for i in range(1,m+1):
  dfs([i])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd

k=int(input())

ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      t_gcd=gcd(i,j)
      ans+=gcd(t_gcd,l)

print(ans)

Fixed submission:
from math import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)

Fixed submission:
from math import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      t_gcd=gcd(i,j)
      ans+=gcd(t_gcd,l)
 
print(ans)

Fixed submission:
from math import gcd
 
k=int(input())
 
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1, k+1):
      ans+=gcd(gcd(i,j),l)
 
print(ans)
Buggy python submission (verdict: Runtime Error):
k=int(input())
l=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(l[k-1])

Fixed submission:
from collections import Counter

n=int(input())
s=input()

c=Counter(s)
ans1=c['B']*c['R']*c['G']

lim= n//2 if n%2==1 else n//2-1

for i in range(1,lim+1):
  for j in range(i,n-i):
    right=s[j-i]
    middle=s[j]
    left=s[j+i]
    if right!=middle and middle!=left and left!=right:
      ans1-=1
print(ans1)
Buggy python submission (verdict: Runtime Error):
k=int(input())

keta=1
total=9
while total<=k:
  keta+=1
  total*=3

if keta==1:
  print(k)
  exit()
ans=''
num=1
k-=9*3**(keta-2)
while k-(3**(keta-1))>0:
  k-=3**(keta-1)
  num+=1
else:
  ans+=str(num)
  keta-=1

while keta>0:
  san=ans[-1]
  for i in range(4):
    if k>=3**(keta-1):
      k-=3**(keta-1)
    else:
      ans+=str(int(san)+i-2)
      break

  keta-=1

print(int(ans))

Fixed submission:
k=int(input())

def dfs(keta, val):
  lunlun.append(val)

  if keta==10:
    return

  for i in range(-1,2):
    add=(val%10)+i
    if 0<=add<=9:
      dfs(keta+1, val*10+add)

lunlun=[]
for i in range(1,10):
  dfs(1, i)

lunlun.sort()
print(lunlun[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

n=int(input())
d1=divisore(n)
d1=d1[1::2]
d2=divisore(n-1)
d2=d2[1:]
d_l=set(d1+d2)

cnt=0
nn=n
for i in d_l:
  while nn>1:
    if nn%i==0:
      nn//=i
    else:
      nn-=i
  if nn==1:
    cnt+=1
  nn=n
print(cnt)

Fixed submission:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

ans_l=divisore(n-1)[1:]

d=divisore(n)
for i in d[1:]:
  nn=n
  while nn%i==0:
    nn//=i
  if nn%i==1:
    ans_l.append(i)

print(len(ans_l))
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from bisect import insort

x,y,a,b,c=nii()
p=lnii()
q=lnii()
r=lnii()

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

l=p[:x]+q[:y]
l.sort()

for i in r:
  insort(l,i)

l.sort(reverse=True)
print(sum(l[:x+y]))

Fixed submission:
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)

list=p[:x]+q[:y]

if len(list)<x+y:
  ll=len(list)
  for i in range((x+y)-len(list)):
    list.append(r[i])
  r=r[(x+y)-ll:]
list=sorted(list)

for i in range(len(r)):
  if list[i]<r[i]:
    list[i]=r[i]
  else:
    break
print(sum(list))
Buggy python submission (verdict: Runtime Error):
from collections import deque

s=deque(list(input()))
q=int(input())


rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
#    s.reverse()
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

s=list(s)
if rev%2==1:
  s.reversed()
print(''.join(s))

Fixed submission:
from collections import deque

s=deque(list(input()))
q=int(input())


rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
#    s.reverse()
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

s=list(s)
if rev%2==1:
  s.reverse()
print(''.join(s))

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

s=deque(list(input()))
q=int(input())

for i in range(q):
  l=list(input().split())
  if len(l)==1:
    s.reverse()
  else:
    t,f,c=l[0],l[1],l[2]
    if f=='1':
      s.appendleft(c)
    else:
      s.append(c)

s=list(s)
print(''.join(s))

Fixed submission:
from collections import deque

s=deque(list(input()))
q=int(input())


rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
#    s.reverse()
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

s=list(s)
if rev%2==1:
  s.reverse()
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
2
10000000 10000000

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print('YES' if len(list(set(a)))==n else 'NO')