TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
N = int(input())
A = [int(a) for a in input().split()]

print(*([A[i] for i in range(N-1,-1,-2)]+[A[i] for i in range(2,N,2)]))  


N = int(input())
A = [int(a) for a in input().split()]

print(*([A[i] for i in range(N-1,-1,-2)]+[A[i] for i in range(N%2,N,2)]))     

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
from collections import deque

N = int(input())
A = list(map(int, input().split()))

q = deque()
q.append(A[0])
q.append(A[1])
for i in range(2, N):
  a = A[i]
  if i % 2 == 1:
    q.appendleft(a)
  else:
    q.append(a)

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


from collections import deque

N = int(input())
A = list(map(int, input().split()))

q = deque()
for i in range(N):
  a = A[i]
  if i > 1 and i % 2 == 0:
    q.appendleft(a)
  else:
    q.append(a)

if N % 2 == 0:
  q.reverse()
print(" ".join(map(str, q)))


Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
import collections
n = int(input())
a = list(map(int, input().split()))
b = collections.deque(list)
if n % 2 == 0:
    for i, ele in enumerate(a):
        if i % 2 == 0:
            b.append(ele)
        else:
            b.appendleft(ele)
else:
    for i, ele in enumerate(a):
        if i % 2 == 0:
            b.appendleft(ele)
        else:
            b.append(ele)

print(" ".join(b))

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    n = II()
    a = list(map(str, input().split()))
    return n, a


def solve(n, a):
    b = collections.deque([])
    if n % 2 == 0:
        for i, ele in enumerate(a):
            if i % 2 == 0:
                b.append(ele)
            else:
                b.appendleft(ele)
    else:
        for i, ele in enumerate(a):
            if i % 2 == 0:
                b.appendleft(ele)
            else:
                b.append(ele)

    ans = " ".join(list(b))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

b = []

for i in range(n):
    if i % 2 != n % 2:
        b.insert(0, a[i])
    else:
        b.append(a[i])

for i in range(n):
    print(b[i], end=" ")


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

b = []

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

for i in range(n):
    print(b[i], end = " ")


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

b = []

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

print(b)


from collections import deque

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

b = deque()

for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])

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


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

ans = []

l1 = A[0::2]
l2 = A[1::2]
if N % 2 == 0:
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(ans))


N = int(input())
A = list(input().split())

ans = []

l1 = A[0::2]
l2 = A[1::2]
if N % 2 == 0:
    l2 = l2[::-1]
    ans = l2+l1
else:
    l1 = l1[::-1]
    ans = l1+l2

print(" ".join(ans))


Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
from operator import mul
from functools import reduce

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

def com(n, k):
    if n == 0 or k == 0:
        return 1
    return int(reduce(mul, range(n + 1 - k, n + 1)) / reduce(mul, range(1, k + 1)))

idx_list = [-1] * (n + 2)
l = 0
r = 0
for i, a_i in enumerate(a):
    if idx_list[a_i] < 0:
        idx_list[a_i] = i
    else:
        l = idx_list[a_i]
        r = n - i
        break

for k in range(1, n + 2):
    m = k - 1
    dup = 0
    for l_n in range(0, m + 1):
        r_n = m - l_n
        if l_n > l or r_n > r:
            continue
        l_c = com(l, l_n)
        r_c = com(r, r_n)
        dup += l_c * r_c
    ans = (com(n + 1, k) - dup) % (10 ** 9 + 7)
    print(ans)

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

b = []
if n % 2 == 0:
    for i in reversed(range(1, n, 2)):
        b.append(str(a[i]))
    for i in range(0, n, 2):
        b.append(str(a[i]))
else:
    for i in reversed(range(0, n + 1, 2)):
        b.append(str(a[i]))
    for i in range(1, n, 2):
        b.append(str(a[i]))

ans = ' '.join(b)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = input()
an = list(map(int, input().split()))
b = []

for i in an:
    b.append(i)
    b.reverse()

print(b)


n = int(input())
a = list(input().split())
if n == 1:
    print(a[0])
elif n % 2:
    print(*(a[-1::-2] + a[1::2]))
else:
    print(*(a[-1::-2] + a[0::2]))


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

b = []
for aa in a:
    b.append(aa)
    b.reverse()

ans = ''
for bb in b:
    ans += bb + ' '

print(ans[:-1])


from collections import deque

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

b = deque()
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n % 2 == 1:
    b.reverse()

print(' '.join(b))


Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
f = lambda: list(map(int,input().split()))
n = int(input())
a = f()
if n&1:
    b = a[::-2]+a[1::2]
else:
    b = a[::-1]+a[::2]
print(*b)


ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


n = int(input())
a = ai()
MOD = 10**9+7

from collections import Counter
dup = list(Counter(sorted(a)).values()).index(2)+1
ant = a.index(dup)
post = a[::-1].index(dup)


def nCb(n, r):
    fac = [1, 1] + [0] * n
    finv = [1, 1] + [0] * n
    inv = [0, 1] + [0] * n
    for i in range(2, n + 2):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = -inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
        
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCb(n+1,k)
        if ant+post+1 >= k:
            ans -= nCb(ant+post,k-1)
        print(ans)


f = lambda: list(map(int,input().split()))
n = int(input())
a = f()
if n&1:
    b = a[::-2]+a[1::2]
else:
    b = a[::-2]+a[::2]
print(*b)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
import math
N=int(input())
a=list(map(int,input().split()))
c=[]
for i in range(N+1):
  if a[i] in c:
    b=a[i]
    j=c.index(a[i])
    k=i
    L=j+N-k
    break
  c+=[a[i]]
Base=N+1
Minu=1
for i in range(0,min(L+1,N+1)):
  print((Base-Minu)%(10**9+7))
  Base=int(Base*(N-i)/(i+2))
  Minu=int(Minu*(L-i)/(i+1))
  
for i in range(L+1,N+1):
  print(Base%(10**9+7))
  Base=int(Base*(N-i)/(i+2))

N=int(input())
a=list(map(int,input().split()))
b=[]
if N%2==0:
  for i in range(int(N/2)):
    b+=[a[N-1-2*i]]
  for i in range(int(N/2)):
    b+=[a[2*i]]
else:
  for i in range(int((N+1)/2)):
    b+=[a[N-1-2*i]]
  for i in range(int((N-1)/2)):
    b+=[a[2*i+1]]
print(' '.join(map(str, b)))

Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = int(input())
l = list(map(int, input().split()))
k = []

for i in range(n):
  k.append(l[i])
  k = list(reversed(k))

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

from collections import deque

n = int(input())
l = list(map(int, input().split()))
d = deque()

for i in range(n):
  if (i % 2 == 0):
    d.appendleft(l[i])
  else:
    d.append(l[i])

if (n % 2 == 0):
  d = reversed(d)

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


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n = int(input())
x = list(input().split()) 
a = ''.join(x)

if n == 1:
    print(a)
    exit()

s1 = a[::2]     
s2 = a[1::2]    

s2 = s2[::-1]

s = s2 + s1

if n%2 == 1:
    s = s[::-1]

for i in s:
    print(int(i), end=' ')


n = int(input())
a = list(map(int,input().split()))
b = []
c = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    if i % 2 == 1:
        c.append(a[i])
c.reverse()
c += b
if n % 2 == 1:
    c.reverse()
print(*c)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
import sys
n, *alst = map(int, sys.stdin.read().split())
lst1 = alst[::2]
lst2 = alst[1::2]
if n % 2:
  lst1.reverse()
  print(''.join(lst1 + lst2))
else:
  lst2.reverse()
  print(''.join(lst2 + lst1))

n = int(input())
alst = input().split()
lst1 = alst[::2]
lst2 = alst[1::2]
if n % 2:
  lst1.reverse()
  print(' '.join(lst1 + lst2))
else:
  lst2.reverse()
  print(' '.join(lst2 + lst1))


Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
a1=[]
for i in range(n-1,-1,-2):
    a1.append(a[i])
a2=[]
for i in range(n-2,-1,-2):
    a2.append(a[i])
a2.reverse
a1+=a2
print(*a1)

n=int(input())
a=list(map(int,input().split()))
a1=[]
for i in range(n-1,-1,-2):
    a1.append(a[i])
a2=[]
for i in range(n-2,-1,-2):
    a2.append(a[i])
a2.reverse()
a1+=a2
print(*a1)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b.  The i-th operation is as follows:    1. Append a_i to the end of b.   2. Reverse the order of the elements in b.  Find the sequence b obtained after these n operations.

Submission attempts (in order):
import sys





def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    b = [0] * n
    p = 0
    q = n - 1
    for i in range(n):
        if i % 2 == (n - 1) % 2:
            b[p] = a[i]
            p += 1
        else:
            b[q] = a[i]
            q += -1
    return ' '.join(map(str, b))


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


import sys





def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    a = read_int_list()
    b = [0] * n
    p = 0
    q = n - 1
    for i in range(n-1, -1, -1):
        if i % 2 == (n-1) % 2:
            b[p] = a[i]
            p += 1
        else:
            b[q] = a[i]
            q += -1
    return ' '.join(map(str, b))


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
MOD = (10 ** 9) + 7

f_list = [1] * 100001
f_r_list = [1] * 100001

for i in range(100000):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, 100002)
	f_r_list[-i] = int((f_r_list[-i + 1] * (100003 - i)) % MOD)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

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


doubled = sum(a) - n * (n + 1) / 2
x = a.index(doubled)
y = a_r.index(doubled)
num = x + y

print(n)

for i in range(2, n + 2):
	if num >= i - 1:
		print(int((comb(n + 1, i) - comb(num, i - 1)) % MOD))
	else:
		print(comb(n + 1, i))

MOD = (10 ** 9) + 7

f_list = [1] * 100001
f_r_list = [1] * 100001

for i in range(100000):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, 100002):
	f_r_list[-i] = int((f_r_list[-i + 1] * (100003 - i)) % MOD)

def comb(n, r):
	if n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

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


doubled = sum(a) - n * (n + 1) / 2
x = a.index(doubled)
y = a_r.index(doubled)
num = x + y

print(n)

for i in range(2, n + 2):
	if num >= i - 1:
		print(int((comb(n + 1, i) - comb(num, i - 1)) % MOD))
	else:
		print(comb(n + 1, i))

Verdicts: Runtime Error

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
from scipy.misc import comb

n=int(input())
s=[int(i) for i in input().split()]
for i in range(1,n+1):
    k=s.count(i)
    if k==2:
        a=s.index(i)
        b=s.index(i,a+1)

for i in range(1,n+2):
    print(comb(n+1,i,1)-comb(a+n-b,i-1,1))


import scipy.misc as scm
from collections import Counter

n=int(input())
s=[int(i) for i in input().split()]
c = Counter(s)
j=-1
for i in range(1, n + 1):
    if c[i] == 2:
        j = i
        break
a,b = [i for i in range(n + 1) if s[i] == j]

for i in range(1,n+2):
    print(scm.comb(n+1,i,1)-scm.comb(a+n-b,i-1,1))


import scipy.misc as scm
import sys

n=int(input())
s=[int(i) for i in input().split()]
for i in range(1,n+1):
    k=s.count(i)
    if k==2:
        a=s.index(i)
        b=s.index(i,a+1)
        print(a,b)

for i in range(1,n+2):
    print(scm.comb(n+1,i,1)-scm.comb(a+n-b,i-1,1))


import scipy.misc as scm
import sys

n=int(input())
s=[int(i) for i in input().split()]
for i in range(1,n+1):
    k=s.count(i)
    if k==2:
        a=s.index(i)
        b=s.index(i,a+1)
        print(a,b)
z=a+n-b
print(z)
if n==1:
    print(1)
    print(1)
    sys.exit()
if n==2:
    print(2)
    print(scm.comb(n+1,i,1)-z)
    print(1)
    sys.exit()

for i in range(1,n+1):
    ans=scm.comb(n+1,i,1)
    if z>=i-1:
        ans=ans-scm.comb(z,i-1,1)
    fa=ans%(10**9+7)
    print(fa)

n = int(input())
a = list(map(int, input().split()))
occur = [0 for i in range(n + 1)]
MOD = 1000000007
for i in range(n + 1):
    if occur[a[i]] > 0: val = n - 1 - i + occur[a[i]]
    else: occur[a[i]] = i + 1
inv = [0 if i > 2 else 1 for i in range(n + 2)]
pinv = [0 if i > 2 else 1 for i in range(n + 2)]
perm = [0 if i > 2 else 1 for i in range(n + 2)]
for i in range(2, n + 2):
    inv[i] = -int(MOD / i) * inv[MOD % i] + MOD
    pinv[i] = pinv[i - 1] * inv[i] % MOD
    perm[i] = perm[i - 1] * i % MOD
def C(n, m):
    return (perm[m] * pinv[n] % MOD) * pinv[m - n] % MOD if n <= m else 0
for i in range(1, n + 2):
    temp = C(i, n + 1) - C(i - 1, val)
    if temp < 0: temp += MOD
    print(temp)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
import sys

stdin = sys.stdin

ns = lambda: stdin.readline()
ni = lambda: int(ns())
na = lambda: list(map(int,stdin.readline().split()))

MOD = 10**9+7

class Comb:
    def __init__(self, size):
        self.fact = [0 for i in range(size + 1)]
        self.inv_fact = [0 for i in range(size + 1)]
        self.factrical(size)

    def nCr(self, n,r):
        ret = self.fact[n]
        ret *= self.inv_fact[n-r]
        ret %= MOD
        ret *= self.inv_fact[r]
        ret %= MOD
        return ret

    def factrical(self, N):
        self.fact[0] = 1
        self.inv_fact[0] = 1
        for i in range(1,N+1):
            self.fact[i] = i * self.fact[i-1] % MOD
            self.inv_fact[i] = self.inv(self.fact[i]) % MOD

    def inv(self, a):
        return pow(a, MOD-2, MOD)

N = ni()
a = na()
c = [-1 for i in range (N)]
index = [-1,-1]

for i, x in enumerate(a):
    if (c[x-1]!=-1):
        index[0] = c[x-1]
        index[1] = i
        break

    c[x-1] = i

co = Comb(N+1)
print (co.fact[N])
for i in range(1, N+2):
    ans = co.nCr(N+1,i)
    if ((N-index[1]) + (index[0])>=i-1 ):
        ans -= co.nCr((N-index[1]) + (index[0]),i-1) 
    
    print (ans)     
            



import sys

stdin = sys.stdin

ns = lambda: stdin.readline()
ni = lambda: int(ns())
na = lambda: list(map(int,stdin.readline().split()))

MOD = 10**9+7

class Comb:
    def __init__(self, size):
        self.fact = [0 for i in range(size + 1)]
        self.inv_fact = [0 for i in range(size + 1)]
        self.factrical(size)

    def nCr(self, n,r):
        ret = self.fact[n]
        ret *= self.inv_fact[n-r]
        ret %= MOD
        ret *= self.inv_fact[r]
        ret %= MOD
        return ret

    def factrical(self, N):
        self.fact[0] = 1
        self.inv_fact[0] = 1
        for i in range(1,N+1):
            self.fact[i] = i * self.fact[i-1] % MOD
            self.inv_fact[i] = self.inv(self.fact[i]) % MOD

    def inv(self, a):
        return pow(a, MOD-2, MOD)

N = ni()
a = na()
c = [-1 for i in range (N)]
index = [-1,-1]

for i, x in enumerate(a):
    if (c[x-1]!=-1):
        index[0] = c[x-1]
        index[1] = i
        break

    c[x-1] = i

co = Comb(N+1)
for i in range(1, N+2):
    ans = co.nCr(N+1,i)
    if ((N-index[1]) + (index[0])>=i-1 ):
        ans -= co.nCr((N-index[1]) + (index[0]),i-1) 
        
    print (ans%MOD)     
            



Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()

dup = sum(a)-n*(n+1)//2
ant = a.index(dup)
post = a[::-1].index(dup)
print(ant,post)

mod = 10**9+7
factorial = [1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i %mod)

inverse = [0]*(n+2)
inverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)
for i in range(n+2-2, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod


def nCr(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % mod


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCr(n+1,k) - nCr(ant+post,k-1)
        if ans < 0:
            ans += mod
        print(ans)


ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


n = int(input())
a = ai()

from collections import Counter
dup = list(Counter(sorted(a)).values()).index(2)+1
ant = a.index(dup)
post = a[::-1].index(dup)


mod = 10**9+7
factorial = [1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i %mod)

inverse = [0]*(n+2)
inverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)
for i in range(n+2-2, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod


def nCr(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % mod


for k in range(1,n+2):
    ans = nCr(n+1,k) - nCr(ant+post,k-1)
    print(ans)


ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]

n = int(input())
a = ai()

dup = sum(a)-n*(n+1)//2
ant = a.index(dup)
post = a[::-1].index(dup)

mod = 10**9+7
factorial = [1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i %mod)

inverse = [0]*(n+2)
inverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)
for i in range(n+2-2, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod


def nCr(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n] * inverse[r] * inverse[n-r] % mod


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCr(n+1,k) - nCr(ant+post,k-1)
        if ans < 0:
            ans += mod
        print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
from operator import mul
from functools import reduce
mod=10**9+2
def cmb(n,r):
    if r>n: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n=int(input())
a=list(map(int,input().split()))
sums=0
for aa in a:
        sums+=aa

sames=[i for i,x in enumerate(a) if x==sums-(n*(n+1)//2)]
same_len = sames[0]+(32-sames[1])

print(n)

for i in range(1,n):
      print((cmb((n+1),(i+1))-cmb(same_len,i))%mod)
print(1)

from collections import Counter
mod=10**9+7
N=10**5+11
fac,finv,inv = [0]*N,[0]*N,[0]*N
 
def cmb_init():
        fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1
        for i in range(2,N):
                fac[i] = fac[i-1]*i%mod
                inv[i] = mod-inv[mod%i] * (mod//i) % mod
                finv[i] = finv[i-1] * inv[i] % mod
 
 
def cmb_mod(n,k):
        if n<k : return 0
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod
 
n=int(input())
a=list(map(int,input().split()))
ac = Counter(a).most_common()[0][0]
sames=[i for i,x in enumerate(a) if x==ac]
same_len = sames[0]+(n-sames[1])
cmb_init()
print(n)
 
for i in range(1,n):
        nums = cmb_mod(n+1,i+1) - cmb_mod(same_len,i)
        if nums < 0: nums+=mod
        print(nums)
print(1)

Verdicts: Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
factorial=[1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+2)
inverse[n+1]=pow(factorial[n+1],mod-2,mod)
for i in range(n,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
factorial=[1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+2)
inverse[n+1]=pow(factorial[n+1],mod-2,mod)
for i in range(n,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)% mod
def comb(n,r):
    if n<r or n==0 or r==0:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)%mod-comb(n+idx[0]-idx[1],k-1)%mod)%mod)

#077-D
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
from collections import Counter
mod=10**9+7
n=int(input())
A=list(map(int,input().split()))
factorial=[1]
for i in range(1,n+2):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+2)
inverse[n+1]=pow(factorial[n+1],mod-2,mod)
for i in range(n,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
C=Counter(A)
i=C.most_common()[0][0]
idx=[k for k, x in enumerate(A) if x==i]
for k in range(1,n+2):
    print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

Submission attempts (in order):
# -*- coding: utf-8 -*-
from math import factorial
from scipy.misc import comb
def inpl(): return tuple(map(int, input().split()))

def combination(n, r):
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))

n = int(input())
A = inpl()
C = ["" for i in range(n+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(n)

for k in range(2, n+2):
    total = comb(n+1, k, 1)
    b = comb(n+i-j, k-1, 1)
    res = (total-b)%(10**9 + 7)
    print(res)

# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

n = int(input())
A = inpl()
mod = 10**9 + 7

fct = [1]
inv = [1]

for i in range(1, n+2):
    fct.append((fct[-1]*i)%mod)
    inv.append((pow(fct[i], mod-2, mod)))

def comb(n, k):
    if k < 0 or k > n:
        return 0
    return (fct[n] * inv[n - k] * inv[k]) % mod    

C = ["" for i in range(n+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(n)

for k in range(2, n+2):
    total = comb(n+1, k)
    b = comb(n+i-j, k-1)
    res = (total-b)%(mod)
    print(res)

Verdicts: Time Limit Exceeded

Accepted
Problem: There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.  You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.  Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

Submission attempts (in order):
n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()
print(0)
exit()

class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf= UF()
ans = 0
for d, i0, i1 in es:
    c0 = uf.find(i0)
    c1 = uf.find(i1)
    if c0 == c1:
        continue
    ans += d
    uf.merge(i0, i1)
print(ans)


n = int(input())
xs = []
ys = []

for i in range(n):
    x, y = map(int, input().split())
    xs.append((x, i))
    ys.append((y, i))


xs.sort()
ys.sort()

es = []

for i in range(n-1):
    es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))
    es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))

es.sort()

class UF:
    def __init__(self):
        self.p = {}
    def find(self, x):
        if x not in self.p:
            self.p[x] = x
        if x == self.p[x]:
            return x
        self.p[x] = self.find(self.p[x])
        return self.p[x]
    def merge(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            self.p[x] = y


uf = UF()
ans = 0
try:
    for d, i0, i1 in es:
        c0 = uf.find(i0)
        c1 = uf.find(i1)
        if c0 == c1:
            continue
        ans += d
        uf.merge(i0, i1)
    print(ans)
except:
    print(0)


Verdicts: Wrong Answer

Accepted
Problem: There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.  You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.  Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

Submission attempts (in order):
from collections import defaultdict
from heapq import *

def prim(V, E):
    '''
    Input:
        V = list(range(N))
        E = {i: defaultdict(int) for i in range(N)}
    Output:
        the edges of the minimum weight tree and its weight
    '''
    N = len(V)
    weight = 0; edges = [];
    used = [False]*N; used[0] = True; n_used = 1;
    heap = [(c, 0, v) for v, c in E[0].items()]; heapify(heap)
    while heap and n_used < N:
        c, u, v = heappop(heap)
        if used[v]: continue
        used[v] = True; n_used += 1; edges.append((u, v))
        weight += c
        for w, d in E[v].items():
            if not used[w]: heappush(heap, (d, v, w))
    return edges, weight

N = int(input())
cities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]
sorted_x, sorted_y = sorted(cities, key=lambda x:x[0]), sorted(cities, key=lambda x:x[1])
E = {i: defaultdict(int) for i in range(N)}
for i in range(N-1):
    (a1, _, u), (a2, _, v) = sorted_x[i], sorted_x[i+1]
    E[u][v], E[v][u] = a2 - a1, a2 - a1
    (_, b1, u), (_, b2, v) = sorted_y[i], sorted_y[i+1]
    E[u][v], E[v][u] = min(b2 - b1, E[u][v]), min(b2 - b1, E[v][u])
V = list(range(N))
_, ans = prim(V, E)
print(ans)

from heapq import *

def prim(V, E):
    '''
    Input:
        V = list(range(N))
        E = {i: defaultdict(int) for i in range(N)}
    Output:
        the edges of the minimum weight tree and its weight
    '''
    N = len(V)
    weight = 0; edges = [];
    used = [False]*N; used[0] = True; n_used = 1;
    heap = [(c, 0, v) for v, c in E[0].items()]; heapify(heap)
    while heap and n_used < N:
        c, u, v = heappop(heap)
        if used[v]: continue
        used[v] = True; n_used += 1; edges.append((u, v))
        weight += c
        for w, d in E[v].items():
            if not used[w]: heappush(heap, (d, v, w))
    return edges, weight

N = int(input())
cities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]
sorted_x, sorted_y = sorted(cities, key=lambda x:x[0]), sorted(cities, key=lambda x:x[1])
E = {i: {} for i in range(N)}
for i in range(N-1):
    (a1, _, u), (a2, _, v) = sorted_x[i], sorted_x[i+1]
    E[u][v] = min(a2 - a1, E[u][v]) if E[u].get(v) is not None else a2 - a1
    E[v][u] = E[u][v]
    (_, b1, u), (_, b2, v) = sorted_y[i], sorted_y[i+1]
    E[u][v] = min(b2 - b1, E[u][v]) if E[u].get(v) is not None else b2 - b1
    E[v][u] = E[u][v]
V = list(range(N))
_, ans = prim(V, E)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.  You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.  Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

Submission attempts (in order):
s UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.par = list(range(n))
        self.rank = [1] * n

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        elif self.rank[x]  < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            self.rank[x] += 1


N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, i))
    Y.append((y, i))

X = sorted(X)
Y = sorted(Y)
graph = []
for i in range(N - 1):
    graph.append((X[i + 1][0] - X[i][0], X[i][1], X[i + 1][1]))
    graph.append((Y[i + 1][0] - Y[i][0], Y[i][1], Y[i + 1][1]))

graph.sort()
uf = UnionFind(N)

total_cost = 0
for cost, a, b in graph:
    if not uf.is_same(a, b):
        uf.unite(a, b)
        total_cost += cost

print(total_cost)


class UnionFind(object):

    def __init__(self, n):
        self.n = n
        self.par = list(range(n))
        self.rank = [1] * n

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.par[y] = x
        elif self.rank[x]  < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            self.rank[x] += 1


N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, i))
    Y.append((y, i))

X = sorted(X)
Y = sorted(Y)
graph = []
for i in range(N - 1):
    graph.append((X[i + 1][0] - X[i][0], X[i][1], X[i + 1][1]))
    graph.append((Y[i + 1][0] - Y[i][0], Y[i][1], Y[i + 1][1]))

graph.sort()
uf = UnionFind(N)

total_cost = 0
for cost, a, b in graph:
    if not uf.is_same(a, b):
        uf.unite(a, b)
        total_cost += cost

print(total_cost)


Verdicts: Runtime Error

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
s = input()[:-1]
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

ans = len(s)
for i in range(26):
  k = s.count(alphabet[i])
  ans = min(ans, len(s)-k)
print(ans)

s = input()[:-1]
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

n = len(s)
ans = n
for v in alphabet:
    key = [s[i] for i in range(n)]
    for i in range(n):
        for j in range(n-i):
            if key[j] != v:
                break
            if j == n-i-1:
                ans = min(i, ans)
                break
            
        for j in range(n-1-i):
            if key[j] == v or key[j+1] == v:
                key[j] = v
            

print(ans)

s = input()
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

n = len(s)
ans = n

for v in alphabet:
    key = [s[i] for i in range(n)]
    
    count = 0
    end = False
    while True:
        for i in range(n-count):
            if key[i] != v:
                break
            if i == n-count-1:
                ans = min(ans, count)
                end = True
        if count == n-1:
            break
        
        if end:
            break
        
        count += 1
        for i in range(n-count):
            if key[i] == v or key[i+1] == v:
                key[i] = v

print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
s = input()
n = len(s)
min_t = float('inf')
for i in range(n):
    target = s[i]
    pre = 0
    max_t = 0
    for j in range(n):
        if s[j] == s[i]:
            max_t = max(max_t, j-pre-1)
            pre = j
    max_t = max(max_t, n - pre-1)
    if max_t < min_t:
        min_t = min(min_t, max_t)
print(min_t)

import string
s = input()
n = len(s)

min_cnt = float('inf')

for c in string.ascii_lowercase:
    if c not in s:
        continue
    cnt = 0
    s_ = s[:]
    while s_:
        m = len(s_) - 1
        is_same = True
        for d in s_:
            if d != c:
                is_same = False
                break
        if is_same:
            min_cnt = min(min_cnt, n - m-1)
        s_next = [''] * m
        for i in range(m):
            if s_[i] == c or s_[i + 1] == c:
                s_next[i] = c
            else:
                s_next[i] = s_[i]
        s_ = s_next

print(min_cnt)


Verdicts: Wrong Answer

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
from collections import Counter
s = input()
cnt = Counter(s).most_common()
print(cnt)

mins = len(s) - 1
for k, v in cnt:
    if v != 1:
        ind = 0
        dist = []
        for i in range(len(s)):
            if k == s[i]:
                dist.append(i-ind+1) 
                ind = i
        mins = min(max(dist), mins)
print(mins)

s = input()

ans = 1000
for c in set(s):
    ans = min(ans, max([len(si) for si in s.split(c)]))
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
import sys

sys.setrecursionlimit(10**6)

def handling(string, letter):
    global cnt
    cnt += 1
    for i, r in enumerate(string):
        if r == letter and 0 < i < len(string):
            if string[i-1] != letter:
                string[i-1] = letter
            elif i < len(string)-1:
                string[i+1] = letter
            else:
                pass
    if string[-1] != letter:
        string.pop()
    else:
        string = string[1:]
    if len(set(string)) != 1:
        handling(string, letter)

def main():
    global cnt
    s = list(input())
    sletter = set(s)
    if len(sletter) == 1:
        print(0)
        return
    ans = 101
    for l in sletter:
        cnt = 0
        t = s.copy()
        handling(t, l)
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


import sys

sys.setrecursionlimit(10**6)

def handling(string, letter):
    global cnt
    cnt += 1; nxt = []
    for i in range(len(string)-1):
        s1, s2 = string[i], string[i+1]
        if s1 == letter:
            nxt.append(s1)
        elif s2 == letter:
            nxt.append(s2)
        else:
            nxt.append(s1)
    if len(set(nxt)) != 1:
        handling(nxt, letter)

def main():
    global cnt
    s = list(input())
    sletter = set(s)
    if len(sletter) == 1:
        print(0)
        return
    ans = 101
    for l in sletter:
        cnt = 0
        t = s.copy()
        handling(t, l)
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
s = input()
a = [[0] for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')].append(i)

for i in range(26):
    a[i].append(len(s)-1)

ans = float('inf')
for i in range(26):
    ma = 0
    for j in range(1,len(a[i])):
        dis = a[i][j]-a[i][j-1]-1
        ma = max(dis,ma)
    ans = min(ma,ans)

print(ans)


s = input()
a = [[-1] for i in range(26)]

for i in range(len(s)):
    a[ord(s[i])-ord('a')].append(i)

for i in range(26):
    a[i].append(len(s))

ans = float('inf')
for i in range(26):
    ma = 0
    for j in range(1,len(a[i])):
        dis = a[i][j]-a[i][j-1]-1
        ma = max(dis,ma)
    ans = min(ma,ans)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: Snuke can change a string t of length N into a string t' of length N - 1 under the following rule:    * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t.  There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.

Submission attempts (in order):
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
pos=[0]*26
for i in range(l):
  for j in range(26):
    if s[i]==check[j]:
      pos[j].append(i)
ans=10**9:
  for i in range(26):
    tmp=0
    for j in range(len(pos[i])-1):
      tmp=max(tmp,pos[i][j+1]-pos[i][j])
    tmp=max(tmp,(l-1)-pos[i][-1])
    ans=min(ans,tmp)
print(ans)

check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
pos=[[0] for _ in range(26)]
for i in range(l):
  for j in range(26):
    if s[i]==check[j]:
      pos[j].append(i+1)
ans=10**9
for i in range(26):
  tmp=0
  for j in range(len(pos[i])-1):
    tmp=max(tmp,pos[i][j+1]-pos[i][j]-1)
  tmp=max(tmp,l-pos[i][-1])
  ans=min(ans,tmp)
print(ans)


Verdicts: Runtime Error

Accepted