Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# 2019/07/24

from collections import Counter

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

even=[]
odd=[]

for i in range(n):
    if i%2==0:even.append(v[i])
    else:odd.append(v[i])

e=Counter(even).most_common(2)
e=list([e[0][0]]+[e[1][0]])
o=Counter(odd).most_common(2)
o=list([o[0][0]]+[o[1][0]])
ans=float('inf')
for i in e:
    for j in o:
        cnt=0
        if i==j:continue
        for k in range(n):
            if k%2==0 and v[k]!=i:
                cnt+=1
            elif k%2==1 and v[k]!=j:
                cnt+=1
        ans=min(cnt,ans)

print(ans)

Fixed submission:
# 2019/07/24

from collections import Counter

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

even=[]
odd=[]

for i in range(n):
    if i%2==0:even.append(v[i])
    else:odd.append(v[i])

e=Counter(even).most_common(2)
if len(e)<2:e=[e[0][0]]
else:e=list([e[0][0]]+[e[1][0]])
o=Counter(odd).most_common(2)
if len(o)<2:o=[o[0][0]]
else:o=list([o[0][0]]+[o[1][0]])

ans=float('inf')
for i in e:
    for j in o:
        cnt=0
        if i==j:continue
        for k in range(n):
            if k%2==0 and v[k]!=i:
                cnt+=1
            elif k%2==1 and v[k]!=j:
                cnt+=1
        ans=min(cnt,ans)

if ans==float('inf'):ans=n//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print('No War' if max(max(x),X)<min(min(y),Y) else 'War')

Fixed submission:
s=sorted(map(int,input().split()))
print(int(str(s[2])+str(s[1]))+s[0])
Buggy python submission (verdict: Runtime Error):
x1,y1,x2,y2=map(int,input().split())
x=x2-x1
y=y2-y1
x3=x2-y
y3=y2+x
x4=x1-y
y4=y1+x
print(f'{x3} {y3} {x4} {y4}')

Fixed submission:
# 2019/08/06

x1,y1,x2,y2=map(int,input().split())

xx=x2-x1
yy=y2-y1

x3=x2-yy
y3=y2+xx
x4=x1-yy
y4=y1+xx
print(x3,y3,x4,y4)
Buggy python submission (verdict: Runtime Error):
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(n+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

Fixed submission:
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
a=n//k
b=(n+(k//2))//k if k%2==0 else 0
print(a**3+b**3)
Buggy python submission (verdict: Runtime Error):
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(n+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)

Fixed submission:
# 2019/09/10
# かんにんぐ

n,k=map(int,input().split())
cnt=0
num=[0]*(k+1)
for i in range(1,n+1):
    num[i%k]+=1

for a in range(k):
    b=(k-a)%k
    c=(k-a)%k
    if (b+c)%k:continue
    cnt+=num[a]*num[b]*num[c]
    
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
flag=False
for i in range(n//4+1):
    for j in range(n//7+1):
        sum=4*i+7*j
        if sum==n:
            flag=True
print('Yes' if flag else'No')
    

Fixed submission:
n,k=map(int,input().split())
print(0 if n%k==0 else 1)
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
i=2
a=1
while a+i<A:
    a+=i
    i+=1
    ans=a+i
print(ans-A)

Fixed submission:
a,b=map(int,input().split())
n=(b-a)
S=(n*(n+1))//2
ans=S-b
print(ans)
Buggy python submission (verdict: Runtime Error):
def wa(t):
    sum=0
    while t>0:
       sum+=t%10
       t=t//10
    return sum

n=int(input())
ans=[]
for i in range(2,n+1-2):
    ans.append(wa(i)+wa(n-i)) 
print(min(ans))

Fixed submission:
def wa(t):
    sum=0
    while t>0:
       sum+=t%10
       t//=10
    return sum

n=int(input())
ans=[]
for i in range(1,n):
    ans.append(wa(i)+wa(n-i)) 
    if wa(i)+wa(n-i)==1:
        print(i)
print(min(ans))
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from collections import Counter

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

A=[0]+list(accumulate(a))
res=0
for e in Counter(A).values():
	res+=e*(e-1)//2
print(res)

Fixed submission:
n=int(input())
s=input()

cnt=s[1:].count('E')
ans=[cnt]

for i in range(1,n):
    if s[i-1]=='W':cnt+=1
    if s[i]=='E':cnt-=1
    ans+=[cnt]

print(min(ans))
Buggy python submission (verdict: Runtime Error):
x=int(input())
ans=[]

for p in range(2,x+1):
    b=2
    while p**b<=x:
        ans.append(p**b)
        b+=1
print(max(ans))

Fixed submission:
x=int(input())
ans=[1] #1を入れないとエラー

for p in range(2,x+1):
    b=2
    while p**b<=x:
        ans.append(p**b)
        b+=1
print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
# 2019/09/05

n=int(input())
*a,mx=sorted(map(int,input().split()))

def cmb(n):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i)
    return fac


fac=cmb(mx)
res=0
ans=[]

for r in a:
    tmp=fac[mx]//(fac[r]*fac[mx-r])
    if tmp>res:
        res=tmp
        ans=[mx,r]
print(*ans)

Fixed submission:
# 2019/09/06

from bisect import bisect_left

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

mid=mxv//2

r=bisect_left(a,mid) 
if r>=n-1:
    r=0
l=r-1 if r else 0

ans=[mxv]

if abs(mxv/2-a[r])>abs(mxv/2-a[l]):
    ans.append(a[l])
else:
    ans.append(a[r])
print(*ans)
Buggy python submission (verdict: Runtime Error):
# 2019/08/12

s=input()
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

st=set(s)
"""
if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()
"""
s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))

Fixed submission:
# 2019/08/12

s=input()
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

st=set(s)

if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()

s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))

Buggy python submission (verdict: Runtime Error):
# 2019/08/12

s=input()
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

st=set(s)
if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()
s=list(s)
tmp=[]

def solve(s):
    for _ in range(26):
        for j in range(25,-1,-1):
            if s[j-1]>s[j]:
                tmp.append(s[j])
                s[j]=''
            else:
                if s[j]=='z':
                    s[j]=''
                    for e in tmp:
                        if e<s[j-1]:continue
                        s[j-1]=e
                        return s
                else:
                    s[j]=chr(ord(s[j-1])+1)
                    return s


print(''.join(solve(s)))

Fixed submission:
# 2019/08/12

s=input()
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    exit()

st=set(s)

if len(s)<26:
    for i in range(97,97+26+1):
        if chr(i) in st:continue
        print(s+chr(i))
        exit()

s=list(s)
res=[s.pop()]

def solve(s):
    for _ in range(len(s)):
        tmp=s.pop()
        if tmp>res[-1]:
            res.append(tmp)
            res.sort()
        else:            
            for e in res:
                if e<tmp:continue
                s.append(e)
                return s

print(''.join(solve(s)))
Buggy python submission (verdict: Runtime Error):
n=int(input())
d={int(input()) for i in range(n)}
print(len(d))

Fixed submission:
print('2018'+input()[4:])
Buggy python submission (verdict: Runtime Error):
a,op,b = [i for i in input().split()]
a=int(a)
b=int(b)

error = ['?','=','!']
if op == '+' :
  print(a+b)
elif op == '-':
  print(a-b)
elif op == '*':
  print(a*b)
elif op == '/':
  if b == 0 :
    print('error')
  else:
    print(int(a/b))
elif op in error:
  print('error')
 

Fixed submission:
import math
a,b = [int(i) for i in input().split()]
avg=math.ceil((a+b)/2)
print(avg)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n,k=map(int,input().split())
a=Counter(list(map(int,input().split())))
cnt=0
ls=[]
if len(a)>k:
	for i in range(len(a)):
		ls.append(a.most_common()[i][1])
print(sum(ls[k:]))

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
ls=[0]*(n+1)
for i in a:
    ls[i]+=1
ls=sorted(ls,reverse=True)
for i in range(k,n+1):
    if ls[i]==0:
        break
    else:
        cnt+=ls[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
i=1
while i**2<n:
    ans=i**2
    i+=1
print(ans)

Fixed submission:
n=int(input())
i=1
while i**2<=n:
    ans=i**2
    i+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=0
for i in range(n):
    ans+=(eval(input().replace(' ','-')[::-1]))+1
print(ans)

Fixed submission:
n=int(input())
sum=0
for i in range(n):
  l,r = [int(j) for j in input().split()]
  sum+=r-l+1
print(sum)
Buggy python submission (verdict: Runtime Error):
# 2019/07/11

import sys
from heapq import heappop,heappush

input=sys.stdin.readline

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1
    v-=1
    edge[u].append((c,v))
    edge[v].append((c,u))


def dijkstra(s):
    d=[float('inf')]*n
    visited=[False]*n
    d[s]=0
    visited[s]=True
    que=[]
    for e in edge[s]:
        heappush(que,e)
    while que:
        c,v=heappop(que)
        if visited[v]:continue
        d[v]=c
        visited[v]=True
        for cost,vtx in edge[v]:
            if visited[vtx]:continue
            hq=(cost+d[v],vtx)
            heappush(que,hq)

    return d

q,k=map(int,input().split())
k-=1

res=dijkstra(k)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(res[x]+res[y])



Fixed submission:
n=input()
print('Yes' if n==n[::-1] else 'No')
Buggy python submission (verdict: Runtime Error):
# 2019/07/12
# DFS ver

import sys

input=sys.stdin.readline

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1 ; v-=1
    edge[u].append((c,v))
    edge[v].append((c,u))

q,k=map(int,input().split())
k-=1

d=[0]*n
visited=[False]*n

def dfs(s,p):
    visited[s]=True
    for c,v in edge[s]:
        if visited[v] or p==v:continue
        d[v]=c+d[s]
        visited[v]=True
        dfs(v,s)
    return 


dfs(k,-1)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1 ; y-=1
    print(d[x]+d[y])



Fixed submission:
# 2019/07/11

from heapq import heappop,heappush

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,c=map(int,input().split())
    u-=1
    v-=1
    edge[u].append((c,v))
    edge[v].append((c,u))


def dijkstra(s):
    d=[float('inf')]*n
    visited=[False]*n
    d[s]=0
    visited[s]=True
    que=[]
    for e in edge[s]:
        heappush(que,e)
    while que:
        c,v=heappop(que)
        if visited[v]:continue
        d[v]=c
        visited[v]=True
        for cost,vtx in edge[v]:
            if visited[vtx]:continue
            hq=(cost+d[v],vtx)
            heappush(que,hq)

    return d

q,k=map(int,input().split())
k-=1

res=dijkstra(k)
for _ in range(q):
    x,y=map(int,input().split())
    x-=1
    y-=1
    print(res[x]+res[y])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
s={}
for i in range(m):
    a,b=map(int,input().split())
    s[a]=s.get(a,0)+1
    s[b]=s.get(b,0)+1
for i in range(1,n+1):
    print(s[i])

Fixed submission:
n,m=map(int,input().split())
ls=[0]*(n+1)
for i in range(m):
    a,b= map(int,input().split())
    ls[a]+=1
    ls[b]+=1
for j in range(1,n+1):
    print(ls[j])
Buggy python submission (verdict: Runtime Error):
from heapq import heappop,heappush

input=open(0).readline
n,k=map(int,input().split())
res={}
for i in range(n):
    a,b=map(int,input().split())
    res[a]=res.get(a,0)+b

que=[]
for key,val in res.items():
    heappush(que,(key,val))

while k:
    key,val=heappop(que)
    if val<=k:
        print(key)
        exit()
    k-=val

Fixed submission:
from heapq import heappop,heappush

input=open(0).readline
n,k=map(int,input().split())
res={}
for i in range(n):
    a,b=map(int,input().split())
    res[a]=res.get(a,0)+b

que=[]
for key,val in res.items():
    heappush(que,(key,val))

while k:
    key,val=heappop(que)
    if val>=k:
        print(key)
        exit()
    k-=val

Buggy python submission (verdict: Time Limit Exceeded):
# 2019/07/23

input=open(0).readline
n,k=map(int,input().split())
res=[]
for i in range(n):
    a,b=map(int,input().split())
    res+=[a]*b
res.sort()
print(res[k-1])

Fixed submission:
from heapq import heappop,heappush

input=open(0).readline
n,k=map(int,input().split())
res={}
for i in range(n):
    a,b=map(int,input().split())
    res[a]=res.get(a,0)+b

que=[]
for key,val in res.items():
    heappush(que,(key,val))

while k:
    key,val=heappop(que)
    if val>=k:
        print(key)
        exit()
    k-=val
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
ans='No'
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j]==b[0][0] and a[i][j+1]==b[0][1] and a[i+1][j]==b[1][0] and a[i+1][j+1]==b[1][1]:
            ans='Yes'
            break
print(ans)

Fixed submission:
n,m=map(int,input().split())

a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
ans='No'
for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:flag=False
        if flag:
            ans='Yes'
            break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for i in range(k+1):
    for j in range(s+1-i):
        if j>k:break
        z=s-(i+j)
        if 0<=z<=k and s==i+j+z:cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
            if x+y+z == s:
                cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    if s/k==3 :
        cnt=1
        break
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
            sum=x+y+z   
            if sum == s:
                cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for i in range(k+1):
    if s/k==3 :
        cnt=1
        break
    for j in range(k+1):
        for k in range(k+1):
            sum=i+j+k
            if sum==s:
                cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            sum=i+j+k
            if sum==s:
                cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        z=s-x-y
        if 0<=z and z<=k:
          cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
# 2019/09/17

s=list(input())
n=len(s)
k=int(input())

for i in range(n):
    cnt=123-ord(s[i])
    if cnt>k:continue
    s[i]='a'
    k-=cnt
    if k==0:break
else:
    if k:
        s[-1]=chr(ord(s[i])+k)

print(''.join(s))    

Fixed submission:
# 2019/09/17

s=list(input())
n=len(s)
k=int(input())

cnta=0
min_l=10000

for i in range(n):
    cnt=123-ord(s[i])
    if cnt>k:continue
    if s[i]=='a':
        cnta+=1
        continue
    s[i]='a'
    k-=cnt
    if k==0:break
else:
    last=s[-1]
    while cnta>=0:
        tmp=ord(last)-97
        kk=(k-cnta*26)%26
        
        min_l=min(min_l,(tmp+kk)%26)
        cnta-=1
    else:
        s[-1]=chr(min_l+97)
        
print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
H, N = [int(s) for s in input().split()]
dec = []
cost = []
for i in range(N):
    a, b = [int(s) for s in input().split()]
    dec.append(a)
    cost.append(b)
memo = [None]*(H+1)
memo[0] = 0
for h in range(1,H+1):
    memo[h] = memo[max(0,h-dec[0])]+cost[0]
    for i in range(1,N):
        memo[h] = min(memo[h], memo[max(0,h-dec[i])]+cost[i])
print(memo[H])

Fixed submission:
H, N = [int(s) for s in input().split()]
dec = []
cost = []
for i in range(N):
    a, b = [int(s) for s in input().split()]
    dec.append(a)
    cost.append(b)
bar = ((H-1)//dec[0]+1)*cost[0]
memo = [bar]*(H+1)
memo[0] = 0
for h in range(1,H+1):
    for i in range(N):
        memo[h] = min(memo[h], memo[max(0,h-dec[i])]+cost[i])
print(memo[H])
Buggy python submission (verdict: Time Limit Exceeded):
def f():
    n = int(input())
    s0 = input()
    poss = []
    for i in range(1000):
        char = str(i)
        poss.append('0'*(3-len(char)) + char)

    def exit(s):
        i = 0
        j = 0
        while i < n:
            if s0[i] == s[j]:
                i += 1
                j += 1
                if j == 3:
                    return True
            else:
                i += 1
        return False

    ans = 0
    for s in poss:
        if exit(s):
            ans += 1
    print(ans)



f()

Fixed submission:
def f():
    n = int(input())
    s = input()
    leftMemo = [None]*10
    rightMemo = [None]*10
    for i in range(10):
        char = str(i)
        for j in range(n):
            if s[j] == char:
                leftMemo[i] = j
                break
        for k in range(n-1,-1,-1):
            if s[k] == char:
                rightMemo[i] = k
                break
    ans = 0
    for leftNum in range(10):
        if leftMemo[leftNum] is None:
            continue
        start = leftMemo[leftNum]+1
        for rightNum in range(10):
            if rightMemo[rightNum] is None:
                continue
            end = rightMemo[rightNum]
            ans += len(set(s[start:end]))
    print(ans)


f()
Buggy python submission (verdict: Time Limit Exceeded):
mo = 1000000007
n = int(input())
A = [int(s) for s in input().split()]
maxLen = 0
for a in A:
    if a > maxLen:
        maxLen = a
maxLen += 1
memo = [[]for i in range(maxLen)]
for index,a in enumerate(A):
    memo[a].append(index)

def calc(cur,last):
    # ele in cur can choose ele in last which is smaller than it
    # person says i can choose person says i-1 who is in front of him
    # cur and last are naturally increase order
    if len(cur) > len(last):
        a = 0
        while True:
            a += 1 
    ans = 1
    minus = 0
    for i in cur:
        count = 0
        for j in last:
            if j < i:
                count += 1
        ans *= count-minus
        minus += 1
    return ans
    # j = 0
    # ans = 1
    # for i in range(len(cur)):
    #     while j < len(last):
    #         if last[j] < cur[i]:
    #             j += 1
    #         else:
    #             break
    #     ans *= (j-i)
    # return ans

memo.append([-1,-1,-1]) # for convenience
ans = 1
for i in range(maxLen):
    ans *= calc(memo[i],memo[i-1])
    ans %= mo
    # if len(memo[i]) == 1:  # mistake why???
    #     break

print(ans)

Fixed submission:
mo = 1000000007
n = int(input())
A = [int(s) for s in input().split()]
maxLen = 0
for a in A:
    if a > maxLen:
        maxLen = a
maxLen += 1
memo = [[]for i in range(maxLen)]
for index,a in enumerate(A):
    memo[a].append(index)

def calc(cur,last):
    # ele in cur can choose ele in last which is smaller than it
    # person says i can choose person says i-1 who is in front of him
    # cur and last are naturally increase order
    ans = 1
    minus = 0
    for i in cur:
        count = 0
        for j in last:
            if j < i:
                count += 1
        ans *= count-minus
        minus += 1
    return ans
    # j = 0
    # ans = 1
    # for i in range(len(cur)):
    #     while j < len(last):
    #         if last[j] < cur[i]:
    #             j += 1
    #         else:
    #             break
    #     ans *= (j-i)
    # return ans

memo.append([-1,-1,-1]) # for convenience
ans = 1
for i in range(maxLen):
    ans *= calc(memo[i],memo[i-1])
    ans %= mo
    # if len(memo[i]) == 1:
    #     break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def longestRepeatedSubstring(str):

    n = len(str)
    LCSRe = [[0 for x in range(n + 1)]
             for y in range(n + 1)]

    res = ""
    res_length = 0

    index = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if (str[i - 1] == str[j - 1] and
                    LCSRe[i - 1][j - 1] < (j - i)):
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1

                if (LCSRe[i][j] > res_length):
                    res_length = LCSRe[i][j]
                    index = max(i, index)

            else:
                LCSRe[i][j] = 0


    if (res_length > 0):
        for i in range(index - res_length + 1,
                       index + 1):
            res = res + str[i - 1]

    return res


if __name__ == "__main__":
    a = int(input())
    s = input()

    print(len(longestRepeatedSubstring(s)))


Fixed submission:
def lrs(str):
    n = len(str)
    LCSRe = [[0 for x in range(n + 1)]
             for y in range(n + 1)]
    res = ""
    res_length = 0
    index = 0
    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            if (str[i - 1] == str[j - 1] and
                    LCSRe[i - 1][j - 1] < (j - i)):
                LCSRe[i][j] = LCSRe[i - 1][j - 1] + 1

                if (LCSRe[i][j] > res_length):
                    res_length = LCSRe[i][j]
                    index = max(i, index)

            else:
                LCSRe[i][j] = 0


    if (res_length > 0):
        for i in range(index - res_length + 1,
                       index + 1):
            res = res + str[i - 1]

    return res


if __name__ == "__main__":
    a = int(input())
    s = input()

    print(len(lrs(s)))
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)
a = str(input())
a = a
length = len(a)
b = len(a)
ans = 0
for i in reversed(range(1,b+1)):
    if i%2 == 1 and i == b:
        temp = ""
        for k in range(i-1):
            temp += "9"
        ans += int(a[b-i:]) - int(temp)

    elif i%2 == 1:
        temp = 9*10**(i)//10

        ans += temp
print(ans)

Fixed submission:

import sys
sys.setrecursionlimit(4100000)
a = str(input())
a = a
length = len(a)
b = len(a)
ans = 0
if b == 1:
    print(a)
else:
    for i in reversed(range(1,b+1)):
        if i%2 == 1 and i == b:
            temp = ""
            for k in range(i-1):
                temp += "9"
            ans += int(a[b-i:]) - int(temp)

        elif i%2 == 1:
            temp = 9*10**(i)//10

            ans += temp
    print(ans)