Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Fixed submission:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
if m > 0:
    s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 0 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

ans = 0
if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Fixed submission:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
if m > 0:
    s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

ans = 0

for i in range(n):
    ans += arr[i]*(10**(n-i-1))

if arr[0] == 0:
    ans += 10**(n-1)

print(ans)

Fixed submission:
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
if m > 0:
    s,c = zip(*sc)

arr = [0 for i in range(n)]

for i in range(m):
    if arr[s[i]-1] != 0 and arr[s[i]-1] != c[i]:
        print(-1)
        exit()
    if n != 1 and s[i]-1 == 0 and c[i] == 0:
        print(-1)
        exit()
    else:
        arr[s[i]-1] = c[i]

if n == 1 and arr[0] == 0:
    print(0)
    exit()

if arr[0] == 0:
    arr[0] = 1

print("".join(map(str,arr)))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = [sum(p[i:i+K]) for i in range (N-(K-1))]

print((max(s)+K)/2)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = sum(p[:K]) 
m = s

for i in range(N-K):
    s = s - p[i] + p[K+i]
    if m < s:
        m = s

print((m+K)/2)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

tuples = [p[i:i+K] for i in range (N-(K-1))]
m = max(map(sum,tuples))

print((m+K)/2)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

s = sum(p[:K]) 
m = s

for i in range(N-K):
    s = s - p[i] + p[K+i]
    if m < s:
        m = s

print((m+K)/2)
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
    if dp[i] == -1:
        continue
    for j in range(N):
        k = min(i+A[j], H)
        if dp[k] == -1:
            dp[k] = dp[i]+B[j]
        else:
            dp[k] = min(dp[k], dp[i]+B[j])

print(dp[H])

Fixed submission:
H, N = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
    if dp[i] == -1:
        continue
    for j in range(N):
        k = min(i+A[j], H)
        if dp[k] == -1:
            dp[k] = dp[i]+B[j]
        else:
            dp[k] = min(dp[k], dp[i]+B[j])

print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
	if dp[i] == -1:
		continue
	for j in range(len(A)):
		if dp[i+A[j]] == -1:
			dp[i+A[j]] = dp[i]+B[j]
		else:
			dp[i+A[j]] = min(dp[i+A[j]], dp[i]+B[j])
			
print(min([n for n in dp[H:] if n > 0]))

Fixed submission:
H, N = map(int, input().split())

AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)

dp = [-1 for _ in range(H+max(A))]
dp[0] = 0

for i in range(H):
    if dp[i] == -1:
        continue
    for j in range(N):
        k = min(i+A[j], H)
        if dp[k] == -1:
            dp[k] = dp[i]+B[j]
        else:
            dp[k] = min(dp[k], dp[i]+B[j])

print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
n , k = map(int, input().split())

li = [0]*(n+2)
lis = []
lis2 =[0]*(3*n)
lis2[1]=1

for i in range(k):
    l,r = map(int, input().split())
    for j in range(l,r+1):
        lis.append(j)

for i in range(1,n+1):
    for j in lis:
        lis2[i]%=998244353
        lis2[i+j]+=lis2[i]

print(lis2[n])


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

li = [0]*(n+2)
lis = []
lr=[]
lis2 =[0]*(3*n)
lis2[1]=1
lis2[2]=-1

for i in range(k):
    l,r = map(int, input().split())
    lr.append((l,r))

for i in range(1,n+1):
    lis2[i]+=lis2[i-1]
    lis2[i]%=998244353

    for j,k in lr:
        lis2[i+j]+=lis2[i]
        lis2[i+k+1]-=lis2[i]

print(lis2[n]%998244353)

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

li = [0]*(n+2)
lis = []
lis2 =[0]*(3*n)
lis2[1]=1

for i in range(k):
    l,r = map(int, input().split())
    li[l]+=1
    li[r+1]-=1

for i in range(1,n+1):
    li[i]+=li[i-1]
    if li[i]==1:
        lis.append(i)

for i in range(1,n+1):
    for j in lis:
        lis2[i]%=998244353
        lis2[i+j]+=lis2[i]

print(lis2[n])


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

li = [0]*(n+2)
lis = []
lr=[]
lis2 =[0]*(3*n)
lis2[1]=1
lis2[2]=-1

for i in range(k):
    l,r = map(int, input().split())
    lr.append((l,r))

for i in range(1,n+1):
    lis2[i]+=lis2[i-1]
    lis2[i]%=998244353

    for j,k in lr:
        lis2[i+j]+=lis2[i]
        lis2[i+k+1]-=lis2[i]

print(lis2[n]%998244353)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
print(i)


Fixed submission:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

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

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
print(i)


Fixed submission:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

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

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

if k%7==0:
    k//=7

mod = 1
i=1
while mod%k!=0:
    mod+=pow(10,i,k)
    mod%=k
    i+=1
print(i)


Fixed submission:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

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

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

if k%7==0:
    k//=7

mod = 1
i=1
while mod%k!=0:
    mod+=pow(10,i,k)
    i+=1
print(i)


Fixed submission:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)

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

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

if k%7==0:
    k//=7

mod = 1
i=1
while mod%k!=0:
    mod+=pow(10,i,k)
    i+=1
print(i)


Fixed submission:
k = int(input())

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

if k%7==0:
    k//=7

mod = 1
i=1
mod2 =1
while mod%k!=0 and i<=100000000:
    mod1 = mod2*10%k
    mod+=mod1
    mod%=k
    mod2=mod1
    i+=1
if i>=100000000:
    i=-1
print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import math

n , k = map(int, input().split())
a = list(map(int,input().split()))
b = [1]*n

for i in range(k):
    t = a.index(max(a))
    a[t]=a[t]*b[t]/(b[t]+1)
    b[t]+=1

print(math.ceil(max(a)))


Fixed submission:
import math

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

left=0
right=max(a)
mid = (left+right)/2
while right - left > 0.5:
    times = 0
    for i in range(n):
        times+=math.ceil(a[i]/mid)-1
    if times<=k:
        right=mid
        mid=(left+right)/2
    else:
        left = mid
        mid =(left+right)/2

print(math.ceil(mid))
Buggy python submission (verdict: Runtime Error):
n , m , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
su = 0
at=0
bt=0
ans=0
while su <= k:
    if a[at]<=b[bt]:
        su+=a[at]
        ans+=1
        at+=1
    else:
        su+=b[bt]
        ans+=1
        bt+=1
print(ans-1)


Fixed submission:
import bisect
n , m , k = map(int, input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ax = [0]*(n+1)
bx = [0]*(m+1)
for i in range(1,n+1):
    ax[i]=ax[i-1]+a[i-1]
for i in range(1,m+1):
    bx[i]=bx[i-1]+b[i-1]

c = bisect.bisect_right(ax,k)
ma = 0
for i in range(c):
    d = bisect.bisect_right(bx,k-ax[i])
    ma = max(ma,i+d-1)
print(ma)
Buggy python submission (verdict: Runtime Error):
n = int(input())
N = 10**9
x = [0]*(N+1)
x1= [0]*N
x2= [0]*N
for i in range(n):
    a , b = map(int, input().split())
    x[a-1]+=1
    x[b]-=1

for i in range(1,N):
    x[i]=x[i]+x[i-1]

for i in range(1,N):
    x1[i]=x1[i]+x1[i-1]

x.reverse()
for i in range(1,N):
    x2[i]=x2[i]+x2[i-1]

ans =0
if n % 2 == 1:
    for i in range(N):
        if x1[i]+x2[i]>n//2:
            ans +=1
    print(ans)
else:
    for i in range(N):
        if x1[i]+x2[i]>n//2:
            ans +=1
    print(ans*2+1)


Fixed submission:
n = int(input())
al=[]
bl=[]
for i in range(n):
    a , b = map(int, input().split())
    al.append(a)
    bl.append(b)
al.sort()
bl.sort()
if n%2==1:
    mi = al[n//2]
    ma = bl[n//2]
    print(int(ma-mi)+1)
else:
    mi = (al[n//2-1]+al[n//2])/2
    ma = (bl[n//2-1]+bl[n//2])/2
    print(int((ma-mi)*2+1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
N = 10**9
x = [0]*(N+1)
x1= [0]*N
x2= [0]*N
for i in range(n):
    a , b = map(int, input().split())
    x[a-1]+=1
    x[b]-=1

for i in range(1,N):
    x[i]=x[i]+x[i-1]

for i in range(1,N):
    x1[i]=x1[i]+x1[i-1]

x.reverse()
for i in range(1,N):
    s2[i]=x2[i]+x2[i-1]

ans =0
if n % 2 == 1:
    for i in range(N):
        if x1[i]+x2[i]>n//2:
            ans +=1
    print(ans)
else:
    for i in range(N):
        if x1[i]+x2[i]>n//2:
            ans +=1
    print(ans*2+1)


Fixed submission:
n = int(input())
al=[]
bl=[]
for i in range(n):
    a , b = map(int, input().split())
    al.append(a)
    bl.append(b)
al.sort()
bl.sort()
if n%2==1:
    mi = al[n//2]
    ma = bl[n//2]
    print(int(ma-mi)+1)
else:
    mi = (al[n//2-1]+al[n//2])/2
    ma = (bl[n//2-1]+bl[n//2])/2
    print(int((ma-mi)*2+1))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n , m = map(int, input().split())
g = [[0]*n for i in range(n)]
v = [0]*n
v[0]=1
f = [0]*n
for i in range(m):
    a , b = map(int, input().split())
    a-=1
    b-=1
    g[a][b]=1
    g[b][a]=1

d=deque()
d.append(0)

while d:
    room = d.popleft()
    for i in range(n):
        if v[i]==1:
            continue
        if g[room][i]==1:
            d.append(i)
            v[i]=1
            f[i]=room

for i in range(n):
    if v[i]==0:
        print('No')
        exit()
print('Yes')
for i in range(1,n):
    print(f[i]+1)


Fixed submission:
from collections import deque
n , m = map(int, input().split())
g = [[] for i in range(n)]
v = [0]*n
v[0]=1
f = [0]*n
for i in range(m):
    a , b = map(int, input().split())
    a-=1
    b-=1
    g[a].append(b)
    g[b].append(a)

d=deque()
d.append(0)

while d:
    room = d.popleft()
    for i in g[room]:
        if v[i]==1:
            continue

        d.append(i)
        v[i]=1
        f[i]=room

for i in range(n):
    if v[i]==0:
        print('No')
        exit()
print('Yes')
for i in range(1,n):
    print(f[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
for i in range(n):
    b[i] = a[i]-i
for i in range(n):
    c[i] = a[i]+i
cb = Counter(b)
cc = Counter(c)
mb = cb.most_common()
mc = cc.most_common()
mb.sort(reverse = True)
mc.sort()
lb =len(mb)
lc =len(mc)
ans = 0
for i in range(lb):
    for j in range(lc):
        if mb[i][0]==mc[j][0]*(-1):
            ans += mb[i][1]*mc[j][1]
            break
print(ans)


Fixed submission:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
c = [0]*n
for i in range(n):
    b[i] = a[i]-i
for i in range(n):
    c[i] = a[i]+i
cb = Counter(b)
cc = Counter(c)
k=cb.keys()
ans = 0
for i in k:
    ans += cb[i]*cc[i*(-1)]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from collections import Counter
n,x,y = map(int, input().split())
x-=1
y-=1

dis=[['NONE']*n for i in range(n)]
d = deque()
for i in range(n):
    d.append((i,0))
    c=0
    while d:
        p,j=d.popleft()
        if p==x and c==0:
            d.append((y,j+1))
            c=1
        if p==y and c==0:
            d.append((x,j+1))
            c=1
        if dis[i][p]=='NONE':
            dis[i][p]=j
            if p+1<n:
                if dis[i][p+1]=='NONE':
                    d.append((p+1,j+1))
            if p-1>=0:
                if dis[i][p-1]=='NONE':
                    d.append((p-1,j+1))
s=[]
for i in dis:
    s+=i
c=Counter(s)
for i in range(1,n):
    print(c[i]//2)


Fixed submission:
from collections import Counter
n,x,y = map(int, input().split())
x-=1
y-=1

dis=[]

for i in range(n-1):
    for j in range(i,n):
        dis.append(min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1))
c=Counter(dis)
for i in range(1,n):
    print(c[i])
Buggy python submission (verdict: Runtime Error):
n , m , k = map(int, input().split())
r = [[] for i in range(n)]
bk = [[] for i in range(n)]
for i in range(m):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(k):
    c , d = map(int, input().split())
    bk[c-1].append(d-1)
    bk[d-1].append(c-1)


v=[0]*n
l=[0]*n
w=[0]*n

def dfs(now,c):
    global ln
    if v[now]==1:
        return
    v[now]=1
    ln+=1
    w[now]=c
    l[c]=ln
    for i in r[now]:
        dfs(i,c)
    return

for i in range(n):
    ln=0
    dfs(i,i)

ans =[]
for i in range(n):
    d=0
    for j in bk[i]:
        if w[j]==w[i]:
            d+=1
    ans.append(str(l[w[i]]-1-d-len(r[i])))
print(' '.join(ans))


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
n , m , k = map(int, input().split())
r = [[] for i in range(n)]
bk = [[] for i in range(n)]
for i in range(m):
    a , b = map(int, input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
for i in range(k):
    c , d = map(int, input().split())
    bk[c-1].append(d-1)
    bk[d-1].append(c-1)


v=[0]*n
l=[0]*n
w=[0]*n

def dfs(now,c):
    global ln
    if v[now]==1:
        return
    v[now]=1
    ln+=1
    w[now]=c
    l[c]=ln
    for i in r[now]:
        dfs(i,c)
    return

for i in range(n):
    ln=0
    dfs(i,i)

ans =[]
for i in range(n):
    d=0
    for j in bk[i]:
        if w[j]==w[i]:
            d+=1
    ans.append(str(l[w[i]]-1-d-len(r[i])))
print(' '.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
x = [t.most_common()[i][0] for i in range(len(t.most_common())) if t.most_common()[i][1]==t.most_common()[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])

Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
tm = t.most_common()
x = [tm[i][0] for i in range(len(tm)) if tm[i][1]==tm[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])

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

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
d = 0
i = 0
x = []
y = []
for i in range(len(t.most_common())):
    y.append(t.most_common()[i][1])
c = y.count(y[0])
for i in range(c):
    x.append(t.most_common()[i][0])
x.sort()
for i in range(len(x)):
    print(x[i])


Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
tm = t.most_common()
x = [tm[i][0] for i in range(len(tm)) if tm[i][1]==tm[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])

Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
d = 0
i = 0
x = []
while d==0:
    x.append(t.most_common()[i][0])
    if len(t.most_common())>1:
        d=t.most_common()[i][1]-t.most_common()[i+1][1]
        i+=1
    else:
        d=1
x.sort()
for i in range(len(x)):
    print(x[i])

Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
tm = t.most_common()
x = [tm[i][0] for i in range(len(tm)) if tm[i][1]==tm[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])

Buggy python submission (verdict: Runtime Error):
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
d = 0
i = 0
x = []
while d==0:
    x.append(t.most_common()[i][0])
    if len(t.most_common())>1:
        d=t.most_common()[i][1]-t.most_common()[i+1][1]
        i+=1
    else:
        d=1
x.sort()
for i in range(len(x)):
    print(x[i])

Fixed submission:
import collections

n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
tm = t.most_common()
x = [tm[i][0] for i in range(len(tm)) if tm[i][1]==tm[0][1]]
x.sort()
for i in range(len(x)):
    print(x[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s0=list(str(n))
ans=0

if len(s0)==1:
    print(n)
    exit()

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):#nより小さい桁数のものを足す
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)


Fixed submission:
n = int(input())
s0=list(str(n))
ans=0

if len(s0)==1:
    print(n)
    exit()

if len(s0)==2:
    for i in range(1,n+1):
        s1=list(str(i))
        if s1[-1]=='0':
            continue
        if s1[0]==s1[-1]:
            ans+=1
        if int(s1[-1])*10+int(s1[0])<=n:
            ans+=1
    print(ans)
    exit()

for i in range(1,n+1):
    s1=list(str(i))
    if s1[-1]=='0':
        continue
    if s1[0]==s1[-1]:
        ans+=1
    for j in range(2,len(s0)):#nより小さい桁数のものを足す
        ans+=10**(j-2)
    if int(s0[0])>int(s1[-1]):#nより入れ替えた数の最高位数が小さいとき、全て足す
        ans+=10**(len(s0)-2)
    elif s0[0]==s1[-1]:#nと入れ替えた数の最高位数が同じ時
        ans+=int(''.join(s0[1:len(s0)-1]))+1
        if int(s0[-1])<int(s1[0]):
            ans-=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n , m = map(int, input().split())
a = list(map(int,input().split()))

def gcd(num1,num2):
    r=1
    while r>0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    gcd1=gcd(num1,num2)
    return num1*num2//gcd1

lcm1=a[0]//2
lcm2=a[0]

for i in range(1,n):
    t=a[i]
    ta=max(t//2,lcm1)
    tb=min(t//2,lcm1)
    if ta!=tb and ta//tb%2==0:
        lcm1=0
        lcm2=0
    lcm1=lcm(lcm1,t//2)
    lcm2=lcm(lcm2,t)


if lcm1!=0:
    ans1=m//lcm1
    ans2=m//lcm2
    ans=ans1-ans2
else:
    ans=0

print(ans)


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

def gcd(num1,num2):
    r=1
    while r>0:
        r=num1%num2
        num1=num2
        num2=r
    return num1

def lcm(num1,num2):
    gcd1=gcd(num1,num2)
    return num1*num2//gcd1

lcm1=a[0]//2
lcm2=a[0]

for i in range(1,n):
    t=a[i]
    lcm1=lcm(lcm1,t//2)
    lcm2=lcm(lcm2,t)
    ta=max(t//2,lcm1)
    tb=min(t//2,lcm1)
    if ta!=tb and ta//tb%2==0:
        lcm1=0
        lcm2=0
        break

if lcm1!=0:
    ans1=m//lcm1
    ans2=m//lcm2
    ans=ans1-ans2
else:
    ans=0

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


Fixed submission:
n = int(input())
s = input()
se = set()
for i in range(1000):
    se.add(str(i).zfill(3))

ans = 0
for i in se:
    t1=s.find(i[0])
    if t1!=-1:
        t2=s.find(i[1],t1+1,)
        if t2!=-1:
            t3=s.find(i[2],t2+1,)
            if t3!=-1:
                ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD=10**9+7
x , y = map(int, input().split())
a=(2*x-y)//3
b=(2*y-x)//3
if 2*a+b!=x:
    print(0)
    exit()

factorial = [1]
inverse = [1]

n=a+b
r=a

for i in range(1, n+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))

def combi(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD

ans = combi(n,r)
print(ans)


Fixed submission:
MOD=10**9+7
x , y = map(int, input().split())
a=(2*x-y)//3
b=(2*y-x)//3
if 2*a+b!=x:
    print(0)
    exit()

factorial = [1]
inverse = [1]

n=a+b
r=a

for i in range(1, n+2):
    factorial.append(factorial[-1] * i % MOD)
    inverse.append(pow(factorial[-1], MOD - 2, MOD))

def combi(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % MOD

ans = combi(n,r)
print(ans)