Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
C=0
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2=N:
    C=i**2
    break
  elif i**2>N:
    break
print(C)

Fixed submission:
N=int(input())
C=0
if N==1:
  print(1)
  exit()
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2==N:
    C=i**2
    break
  elif i**2>N:
    break
print(C)

Buggy python submission (verdict: Runtime Error):
N=int(input())
C=0
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2=N:
    C=i**2
    break
  elif i**2<N:
    break
print(C)

Fixed submission:
N=int(input())
C=0
if N==1:
  print(1)
  exit()
for i in range(1,N):
  if i**2<N:
    C=i**2
  elif i**2==N:
    C=i**2
    break
  elif i**2>N:
    break
print(C)
Buggy python submission (verdict: Runtime Error):
odd = list(map(str, input()))
even = list(map(str, input()))
L=len(odd)*2
li=[]

for i in range(1,L+1):
  if i%2==1:
    if i==1:
      li.append(odd[0])
    else:
      li.append(odd[i//2])
  else:
    li.append(even[i//2-1])
    
print(''.join(li))

Fixed submission:
odd = list(map(str, input()))
even = list(map(str, input()))
if len(odd)==len(even):
  L=len(odd)*2
else:
  L=len(odd)+len(even)
li=[]

for i in range(1,L+1):
  if i%2==1:
    if i==1:
      li.append(odd[0])
    else:
      li.append(odd[i//2])
  else:
    li.append(even[i//2-1])
    
print(''.join(li))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a=='H':
  print(b)
  exit()
else:
  if b=='H':
    print('D')
  else:
    print('H')

Fixed submission:
a,b=map(str,input().split())
if a=="H":
  print(b)
  exit()
else:
  if b=="H":
    print("D")
  else:
    print("H")
Buggy python submission (verdict: Runtime Error):
W,a,b=map(int,input().split())
if b>a:
  	if b-(a+W)==0:
  	print(0)
  	exit()
	print(b-(a+W))
else:
  if a-(b+W)==0:
  	print(0)
  	exit()
	print(a-(b+W))

Fixed submission:
W,a,b=map(int,input().split())
if b>a:
  if b-(a+W)<=0:
  	print(0)
  	exit()
  print(b-(a+W))
else:
  if a-(b+W)<=0:
  	print(0)
  	exit()
  print(a-(b+W))
Buggy python submission (verdict: Runtime Error):
s=list(map(str,input()))
if 'C' in s and 'F' in s:
  if s.index('C')<s.index('F'):
    print('Yes')
  else:
    s.remove(s[s.index('F')])
    if s.index('C')<s.index('F'):
      print('Yes')
    else:
      print('No')
else:
  print('No')
  exit()

Fixed submission:
s=str(input())
if 'C' in s and 'F' in s:
  if s.find('C')<s.rfind('F'):
    print('Yes')
  else:
    print('No')
else:
  print('No')
  exit()
Buggy python submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
la = [0]*(n+1)
lb = [0]*(n+1)
for i in range(n):
    la[a[i]] += 1
    lb[b[i]] += 1
for i in range(1,n+1):
    if la[i] > n//2 and lb[i] > n//2:
        print("No")
        quit()
print("Yes")
b = b[::-1]
s = 0
for i in range(n):
    if s == 0 and a[i] == b[i]:
        s = i+1
    if s > 0 and a[i] != b[i]:
        e = i+1
        break
if s == 0:
    print(*b)
    quit()
cl = a[s-1]
k = e-s
j = 0
for i in range(n):
    if s-1 <= i < e-1:
        continue
    if cl != b[i] and cl != a[i]:
        b[s-1+j] = b[i]
        b[i] = cl
        j += 1
    if j == k:
        break
print(*b)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
b = b[::-1]
s = 0
e = 0
for i in range(n):
    if s == 0 and a[i] == b[i]:
        s = i+1
    if s > 0 and a[i] != b[i]:
        e = i+1
        break
if s == 0:
    print("Yes")
    print(*b)
    quit()
cl = a[s-1]
k = e-s
j = 0
for i in range(n):
    if s-1 <= i < e-1:
        continue
    if cl != b[i] and cl != a[i]:
        b[s-1+j] = b[i]
        b[i] = cl
        j += 1
    if j == k:
        break
for i in range(n):
    if a[i] == b[i]:
        print("No")
        quit()
print("Yes")
print(*b)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = [i-1 for i in list(map(int,input().split()))]
c = list(map(int,input().split()))
ans = -float("inf")
for i in range(n):
    now = i
    cnt = [0]
    for j in range(n):
        nxt = p[now]
        cnt.append(cnt[j]+c[nxt])
        now = nxt
        if now == i:
            break
    m = len(cnt)-1
    if k <= m:
        s = max(cnt[1:(k+1)])
    elif cnt[-1] < 0:
        s = max(cnt[1:])
    else:
        t = k//m
        s = (t-1)*cnt[-1]+max(cnt[1:])
        s = max(s, t*cnt[-1]+max(cnt[:(k-t*m+1)]))
    ans = max(ans,s)
print(ans)

Fixed submission:
s = input()
if s == "RRS" or s == "SRR":
    print(2)
elif s == "RRR":
    print(3)
elif s == "SSS":
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = [i-1 for i in list(map(int,input().split()))]
c = list(map(int,input().split()))
ans = -float("inf")
for i in range(n):
    now = i
    cnt = [0]
    for j in range(n):
        nxt = p[now]
        cnt.append(cnt[j]+c[nxt])
        now = nxt
        if now == i:
            break
    m = len(cnt)-1
    if k <= m:
        s = max(cnt[1:(k+1)])
    elif cnt[-1] < 0:
        s = max(cnt[1:])
    else:
        t = k//m
        s = (t-1)*cnt[-1]+max(cnt[1:])
        s = max(s, t*cnt[-1]+max(cnt[:(k-t*m+1)]))
    ans = max(ans,s)
print(ans)

Fixed submission:
n,k = map(int,input().split())
p = [i-1 for i in list(map(int,input().split()))]
c = list(map(int,input().split()))
ans = -float("inf")
for i in range(n):
    now = i
    cnt = [0]
    for j in range(n):
        nxt = p[now]
        cnt.append(cnt[j]+c[nxt])
        now = nxt
        if now == i:
            break
    m = len(cnt)-1
    if k <= m:
        s = max(cnt[1:(k+1)])
    elif cnt[-1] < 0:
        s = max(cnt[1:])
    else:
        t = k//m
        s = (t-1)*cnt[-1]+max(cnt[1:])
        s = max(s, t*cnt[-1]+max(cnt[:(k-t*m+1)]))
    ans = max(ans,s)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*(n-k+1)
t = 1
for i in range(k):
    t *= a[i]
l[0] = t
for i in range(1,n-k+1):
    t = t//a[i-1]
    t = t*a[k+i-1]
    l[i] = t
for i in range(n-k):
    if l[i] < l[i+1]:
        print("Yes")
    else:
        print("No")

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n-k):
    if a[i] < a[i+k]:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [input() for _ in range(n)]
l = ["AC","WA","TLE","RE"]
for i in range(4):  print(l[i],"x",s.count(l[i]))

Fixed submission:
print((1000-int(input()))%1000)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
M = max(a)
cnt = [0]*(M+1)
ans = 0
for i in range(n):
    if cnt[a[i]]:
        continue
    j = a[i]
    if i == 0:
        if a[i] == a[i+1]:
            1
        else:
            ans += 1
    elif i == n-1:
        if a[i-1] == a[i]:
            1
        else:
            ans += 1
    elif a[i] == a[i+1] or a[i-1] == a[i]:
        1
    else:
        ans += 1
    while j <= M:
        cnt[j] = 1
        j += a[i]
print(ans)

Fixed submission:
from math import gcd
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n == 1:
    print(1)
    quit()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
M = max(a)
cnt = [0]*(M+1)
ans = 0
for i in range(n):
    if cnt[a[i]]:
        continue
    j = a[i]
    if i == 0:
        if a[i] == a[i+1]:
            1
        else:
            ans += 1
    elif i == n-1:
        if a[i-1] == a[i]:
            1
        else:
            ans += 1
    elif a[i] == a[i+1] or a[i-1] == a[i]:
        1
    else:
        ans += 1
    while j <= M:
        cnt[j] = 1
        j += a[i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n,k = map(int,input().split())
a = list(map(int,input().split()))

def sim(a):
    b = [0]*n
    for i in range(n):
        l = max(0,i-a[i])
        r = min(n-1,i+a[i])
        b[l] +=1
        if r+1<n:
            b[r+1] -= 1
    for i in range(1,n):
        b[i] += b[i-1]
    return b

for i in range(min(k,41)):
    a = copy.copy(sim(a))
print(*a)


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

def sim(a):
    b = [0]*n
    for i in range(n):
        l = max(0,i-a[i])
        r = min(n-1,i+a[i])
        b[l] +=1
        if r+1<n:
            b[r+1] -= 1
    for i in range(1,n):
        b[i] += b[i-1]
    return b

for i in range(min(k,41)):
    a = copy.copy(sim(a))
print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
t = input()
n = len(t)
t += "a"
ans = ""
for i in range(n):
    if t[i] == "?":
        ans += "D"
    else:
        ans += t[i]
print(ans)

Fixed submission:
t = input()
n = len(t)
t += "a"
ans = ""
for i in range(n):
    if t[i] == "?":
        ans += "D"
    else:
        ans += t[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])

Fixed submission:
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])

Buggy python submission (verdict: Runtime Error):
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(m)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
    print(memo)
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])

Fixed submission:
import copy
n,m = map(int,input().split())
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
memo = [0]*n
now = [[0,0]]
nxt = []
done = [False]*n
done[0] = True


while now:
    for l in now:
        for j in graph[l[1]]:
            if not done[j]:                
                done[j] = True
                nxt.append([l[1],j])
                memo[j] = l[1]+1
    now = copy.copy(nxt)
    nxt = []
for l in now:
    done[l[1]] = True
if False in done:
    print("No")
else:
    print("Yes")
    for i in range(1,n):
        print(memo[i])
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
mod = 998244353
ans = 0
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = mod
N = 10**6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
for i in range(0,k+1):
  ans += m*pow(m-1,n-1-i,mod)*cmb(n-1,i,p)
  ans %= mod
print(ans)

Fixed submission:
s = input()
t = input()
if len(t) != len(s)+1:
  print("No")
  quit()
if s == t[:len(s)]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
from collections import Counter
a = list(map(int,input().split()))
b = []
for i in range(n):
  b.append(a[i]-i-1)
b = Counter(b)
k = -a[0]-1
a.append(10**10)
ans = 0
for i in range(n):
  ans += b[k]
  k -= 1
  k += a[i]-a[i+1]
print(ans)

Fixed submission:
s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
def make_divisors(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
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
b = 0
for i in l:
  b = 0
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)

Fixed submission:
x = int(input())
def make_divisors(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
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
for i in l:
  b = 0
  a = b+i
  if (a**5-b**5)%10 != x%10:
    continue
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)
      quit()
print(l)

Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
def make_divisors(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
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
b = 0
for i in l:
  b = 0
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)

Fixed submission:
x = int(input())
def make_divisors(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
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
for i in l:
  b = 0
  a = b+i
  if (a**5-b**5)%10 != x%10:
    continue
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)
      quit()
print(l)
Buggy python submission (verdict: Runtime Error):
n,m,q = map(int,input().split())
abcd = [list(map(int,input().split())) for _ in range(q)]
ans = 0
for a in range(1,11):
  for b in range(a,11):
    for c in range(b,11):
      for d in range(c,11):
        for e in range(d,11):
          for f in range(e,11):
            for g in range(f,11):
              for h in range(g,11):
                for i in range(h,11):
                  for j in range(i,11):
                    lst = [0,a,b,c,d,e,f,g,h,i,j]
                    print(lst)
                    s = 0
                    for l in range(q):
                      s += abcd[l][3]*(lst[abcd[l][1]]-lst[abcd[l][0]]==abcd[l][2])
                    ans = max(ans, s)
print(ans)

Fixed submission:
k = int(input())
a,b = map(int,input().split())
if b//k-(a-1)//k >0:
  print("OK")
else:
  print("NG")
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
if n%2 == 1:
  for i in range(m):
    print(i+1,2*m-i)
else:
  ans = [[i+1] for i in range(m)]
  t = n
  for i in range(m):
    if t == i+1+n//2:
      t -= 1
    ans[i].append(t)
    t -= 1
print(ans)

Fixed submission:
n,m = map(int,input().split())
ans=[]
if m%2==1:
  for i in range(m//2):
    print(i+1,m-i)
  for i in range(m//2+1):
    print(m+1+i,2*m+1-i)
else:
  for i in range(m//2):
    print(i+1,m-i+1)
  for i in range(m//2):
    print(m+2+i,2*m+1-i)
Buggy python submission (verdict: Runtime Error):
import bisect
import sys
sys.setrecursionlimit(10**9)
n = int(input())
a = [0]+list(map(int,input().split()))
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
  u,v = map(int,input().split())
  tree[u].append(v)
  tree[v].append(u)
#print(tree)
d = [float("inf")]*(n+1)
ans = [0]*(n+1)

def dfs(now, pre):
  print(now,pre)
  i = bisect.bisect_left(d, a[now])
  tmp = d[i]
  d[i] = a[now]
  ans[now] = bisect.bisect_left(d, float("inf"))
  print(d)
  for nxt in tree[now]:
    if nxt == pre:
      continue
    dfs(nxt, now)
  d[i] = tmp
dfs(1,-1)

for i in ans[1:]:
  print(i)

Fixed submission:
import bisect
import sys
sys.setrecursionlimit(10**9)
n = int(input())
a = [0]+list(map(int,input().split()))
tree = [[] for _ in range(n+1)]
for _ in range(n-1):
  u,v = map(int,input().split())
  tree[u].append(v)
  tree[v].append(u)
#print(tree)
d = [float("inf")]*(n+1)
ans = [0]*(n+1)

def dfs(now, pre):
  i = bisect.bisect_left(d, a[now])
  tmp = d[i]
  d[i] = a[now]
  ans[now] = bisect.bisect_left(d, float("inf"))
  for nxt in tree[now]:
    if nxt == pre:
      continue
    dfs(nxt, now)
  d[i] = tmp
dfs(1,-1)

for i in ans[1:]:
  print(i)
Buggy python submission (verdict: Runtime Error):
from collections import Counter
s = input()
n = len(s)
dp = [0]*(n+1)
mod = 2019
for i in range(n-1,-1,-1):
    dp[i] = (dp[i+1]+int(s[i])*pow(10,n-i-1,mod))%mod
c = Counter(dp)
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)

Fixed submission:
s,w = map(int,input().split())
if w >= s:
  print("unsafe")
else:
  print("safe")

Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
if n < 4:
  quit()
l,r = 0,4
ans = [[[],[]] for _ in range(n+3)]
for i in range(4,8):
  l = 0
  while l+i <= n:
    if int(s[l:(l+i)])%2019 == 0:
      ans[l+1][0].append(l+i)
      ans[l+i+1][1].append(l+1)
    l += 1
final = 0
cnt = 1
for i in range(n+1):
  if ans[i][0] and ans[i][1]:
    cnt += 1
    final += cnt
  elif ans[i][0]:
    final += 1
    cnt = 1
print(final)

Fixed submission:
s,w = map(int,input().split())
if w >= s:
  print("unsafe")
else:
  print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
n = len(s)
dp = [0]*(n+1)
mod = 2019
for i in range(n-1,-1,-1):
    dp[i] = (dp[i+1]+int(s[i])*(10**(n-i-1)))%mod
c = Counter(dp)
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)

Fixed submission:
from collections import Counter
s = input()
n = len(s)
dp = [0]*(n+1)
mod = 2019
for i in range(n-1,-1,-1):
    dp[i] = (dp[i+1]+int(s[i])*pow(10,n-i-1,mod))%mod
c = Counter(dp)
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
s = input()
n = len(s)
dp = [0]*(n+1)
mod = 2019
for i in range(n-1,-1,-1):
    dp[i] = (dp[i+1]+int(s[i])*(10**(n-i-1)))%mod
c = Counter(dp)
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)

Fixed submission:
from collections import Counter
s = input()
n = len(s)
dp = [0]*(n+1)
mod = 2019
for i in range(n-1,-1,-1):
    dp[i] = (dp[i+1]+int(s[i])*pow(10,n-i-1,mod))%mod
c = Counter(dp)
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = sorted(a, reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
def f(s,e):
  return abs(e-s)*a[s]
for i in range(n):
  d = a.index(b[i])
  for l in range(0,i+1):
    r = i-l
    dp[l+1][r] = max(dp[l+1][r], dp[l][r]+f(d,l))
    dp[l][r+1] = max(dp[l][r+1], dp[l][r]+f(d,n-r-1))
  a[d] = 0
for i in range(n+1):
  ans = max(ans, dp[i][n-i])
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = sorted(a, reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
def f(s,e):
  return abs(e-s)*a[s]
for i in range(n):
  d = a.index(b[i])
  for l in range(0,i+1):
    r = i-l
    dp[l+1][r] = max(dp[l+1][r], dp[l][r]+f(d,l))
    dp[l][r+1] = max(dp[l][r+1], dp[l][r]+f(d,n-r-1))
  a[d] = 0
for i in range(n+1):
  ans = max(ans, dp[i][n-i])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
s = list(input())
c = Counter(s)
ans = c["R"]*c["G"]*c["B"]
for i in range(n-2):
  for j in range(1,n):
    if i+2*j >= n:
      break
    if sorted([s[i],s[i+j],s[i+2*j]]) == ["B","G","R"]:
      ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
if n <= 2:
  print(0)
  quit()
r,g,b = 0,0,0
for i in range(n):
  r += 1*(s[i]=="R")
  g += 1*(s[i]=="G")
  b += 1*(s[i]=="B")
ans = r*g*b

for i in range(n-2):
  for j in range(i+1,n):
    l = [i,j,2*j-i]
    if l[2] >= n:
      break
    r,g,b = 0,0,0
    for k in l:
      r += 1*(s[k]=="R")
      g += 1*(s[k]=="G")
      b += 1*(s[k]=="B")
    if r*g*b == 1:
      ans -= 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k,c = map(int,input().split())
s = [i == "o" for i in list(input())]
i = 0
cnt = 0
l = [0]*n
r = [0]*n
while i < n:
    if s[i]:
        cnt += 1
        for j in range(i,c+i+1):
            if j < n:
                l[j] = cnt
        i += c+1
    else:
        l[i] = cnt
        i += 1
i = n-1
cnt = 0
while i >= 0:
    if s[i]:
        cnt += 1
        for j in range(i,i-1-c,-1):
            if j >= 0:
                r[j] = cnt
        i -= c+1
    else:
        r[i] = cnt
        i -= 1
#print(l,r)
if r[1] < k:
    print(1)
for i in range(1,n-1):
    if not s[i]:
        continue
    if l[i-1] + r[i+1] < k:
        print(i+1)
if l[n-2] < k:
    print(n)

Fixed submission:
n,k,c = map(int,input().split())
s = [i == "o" for i in list(input())]
i = 0
cnt = 0
l = [0]*n
r = [0]*n
while i < n:
    if s[i]:
        cnt += 1
        for j in range(i,c+i+1):
            if j < n:
                l[j] = cnt
        i += c+1
    else:
        l[i] = cnt
        i += 1
i = n-1
cnt = 0
while i >= 0:
    if s[i]:
        cnt += 1
        for j in range(i,i-1-c,-1):
            if j >= 0:
                r[j] = cnt
        i -= c+1
    else:
        r[i] = cnt
        i -= 1
#print(l,r)
r.append(0)
if r[1] < k:
    print(1)
for i in range(1,n-1):
    if not s[i]:
        continue
    if l[i-1] + r[i+1] < k:
        print(i+1)
if l[n-2] < k:
    print(n)
Buggy python submission (verdict: Runtime Error):
x,y,a,b,c = map(int,input().split())
print(sum(sorted(sorted(list(map(int,input().split())),reverse=True)[:x]+sorted(list(map(int,input().split())),reverse=True)[:y]+list(map(int,input().split())),reverse=True)[:(x+y)]))

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
  print("Yes")
else:
  print("No")