ZhenlongDai/ACPR huggingface dataset:
Problem: p03752
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
bills = list(map(int,input().split()))
ans = 0
k = 0
while k < K:
	k = 0
	cost =[]
	cosd = {}
	tatekae = {}
	maxh = 0
	for bi,b in enumerate(bills):
		if b > maxh:
			cost.append(0)
			maxh = b
			k = k + 1
		else:
			c = maxh - b + 1
			cost.append(c)
			maxh2 = maxh + 1
			tatekae[bi] = []
			for b2i,b2 in enumerate(bills[bi:]):
				if maxh2 < b2:
					break
				elif maxh2 == b2:
					c = c + 1
					maxh2 = maxh2 + 1
					tatekae[bi].append(b2i + bi)
			cosd[bi] = c
	if k > K:
		break
	a = min(cosd.items(),key =lambda x: x[1])[0]
	ans = ans + cosd[a]
	bills[a] = bills[a] + cost[a]
	for t in tatekae[a]:
		bills[t] = bills[t] + 1
	k = k + 1
print(ans)

Failing test case input:
5 1
5960 3170 3598 610 3424

Expected output:
0


Actual output:
2363


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
bills = list(map(int,input().split()))
ans = 0
k = 0
while k < K:
	k = 0
	cost =[]
	cosd = {}
	tatekae = {}
	maxh = 0
	for bi,b in enumerate(bills):
		if b > maxh:
			cost.append(0)
			maxh = b
			k = k + 1
		else:
			c = maxh - b + 1
			cost.append(c)
			maxh2 = maxh + 1
			tatekae[bi] = []
			for b2i,b2 in enumerate(bills[bi:]):
				if maxh2 < b2:
					break
				elif maxh2 == b2:
					c = c + 1
					maxh2 = maxh2 + 1
					tatekae[bi].append(b2i + bi)
			cosd[bi] = c
	if k >= K:
		break
	a = min(cosd.items(),key =lambda x: x[1])[0]
	ans = ans + cosd[a]
	bills[a] = bills[a] + cost[a]
	for t in tatekae[a]:
		bills[t] = bills[t] + 1
	k = k + 1
print(ans)

Problem: p03752
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def dfs(index):
    global ans
    if index == N :
        if blst.count(1) >= K - 1:
            tmp = a1
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
a1 = a[0]
ans = 10 ** 18
dfs(1)

print(ans)

Failing test case input:
5 5
2312 3208 19389 3469 3424

Expected output:
31888


Actual output:
0


Fixed submission (verdict: Accepted):
def dfs(index):
    global ans
    if index == N:
        if blst.count(1) >= K - 1:
            tmp = a[0]
            anstmp = 0
            for i in range(1, N):
                if blst[i - 1] == 0:
                    if tmp < a[i]:
                        tmp = a[i]
                    continue
                if tmp >= a[i]:
                    anstmp += tmp - a[i] + 1
                    tmp += 1
                else:
                    tmp = a[i]
            ans = min(ans, anstmp)
        return
    for i in range(2):
        blst[index - 1] = i
        dfs(index + 1)
    return

N, K = map(int, input().split())
a = list(map(int, input().split()))
blst = [0] * (N - 1)
ans = float('inf')
dfs(1)

print(ans)
Problem: p03752
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import combinations
INF = int(1e18)
def main():
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    p = [i for i in range(1,n)]
    
    
    ans = INF
    for i in combinations(p, k-1):
        s = set(i)
        cost = 0
        mx = a[0]
        for j in range(1, n):
            if j in s:
                if a[j] > mx:
                    continue
                mx += 1
                cost += mx-a[j]
            mx = max(mx, a[j])
        ans = min(cost, ans)                
    print(ans)
main()

Failing test case input:
5 5
1993 607 9355 3469 4674

Expected output:
11957


Actual output:
1387


Fixed submission (verdict: Accepted):
from itertools import combinations
INF = int(1e18)
def main():
    n, k = map(int, input().split())
    a = [int(i) for i in input().split()]
    p = [i for i in range(1,n)]
    
    
    ans = INF
    for i in combinations(p, k-1):
        s = set(i)
        cost = 0
        mx = a[0]
        for j in range(1, n):
            if j in s:
                if a[j] > mx:
                    mx = a[j]
                    continue
                mx += 1
                cost += mx-a[j]
            mx = max(mx, a[j])
        ans = min(cost, ans)                
    print(ans)
main()

Problem: p03752
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N,K = map(int,input().split())
A = list(map(int,input().split()))

res = float('inf')

for i in range(1<<N):
  a = A[::]
  paint = 0
  cur = None
  add = 0
  for j in range(N):
    if (i>>j)&1:
      paint += 1
      h = a[j]
      if cur is None:
        if j>0 and a[j-1]>=h:
          break
        else:
          cur = h
      else:
        min_h = max(cur, a[j-1])
        if h < min_h:
          add += (min_h+1) - h
          cur = min_h + 1
          a[j] = cur

  if paint == K:
    res = min(res, add)

print(res)


Failing test case input:
5 2
5960 3170 3598 610 3424

Expected output:
2363


Actual output:
175


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
A = list(map(int,input().split()))

res = float('inf')

for i in range(1<<N):
  a = A[::]
  paint = 0
  cur = 0
  add = 0
  for j in range(N):
    if (i>>j)&1:
      paint += 1
      if a[j] <= cur:
        add += (cur+1) - a[j]
        a[j] = cur+1
      cur = max(cur, a[j])
    else:
      cur = max(cur, a[j])

  if paint == K:
    res = min(res, add)

print(res)
Problem: p03675
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(input().split())

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

print(' '.join(b))


Failing test case input:
3
2 1 8

Expected output:
8 2 1


Actual output:
1 2 8


Fixed submission (verdict: Accepted):
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))

Problem: p03675
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
s = input().split()








ans = []
if N % 2 == 1:
    for ss in s[::-1][0::2]:
        ans.append(ss[::-1])
    for ss in s[1::2]:
        ans.append(ss)
else:
    for ss in s[::-1][0::2]:
        ans.append(ss[::-1])
    for ss in s[0::2]:
        ans.append(ss)
print(" ".join(ans))


Failing test case input:
6
0 39 1 75 15 0

Expected output:
0 75 39 0 1 15


Actual output:
0 57 93 0 1 15


Fixed submission (verdict: Accepted):
N = int(input())
s = input().split()








ans = []
if N % 2 == 1:
    for ss in s[::-1][0::2]:
        ans.append(ss)
    for ss in s[1::2]:
        ans.append(ss)
else:
    for ss in s[::-1][0::2]:
        ans.append(ss)
    for ss in s[0::2]:
        ans.append(ss)
print(" ".join(ans))

Problem: p03675
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(str,input().split()))
s=list(reversed(a[1::2]))+a[::2]
c=""
for i in range(n):
    c+=s[i]+" "
print(c)

Failing test case input:
3
6 2 3

Expected output:
3 6 2


Actual output:
2 6 3 


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(str,input().split()))
if n%2!=1:
    s=list(reversed(a[1::2]))+a[::2]
else:
    s=list(reversed(a[::2]))+a[1::2]
c=""
for i in range(n):
    c+=s[i]+" "
print(c)

Problem: p03675
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin

N = int(stdin.readline().rstrip())
A = stdin.readline().rstrip().split()

B = A[::-1]

ans = ""

if N % 2 == 0:
  for i in range(0,N,2):
    ans += B[i]
  for i in range(0,N,2):
    ans += A[i]
  
else:
  for i in range(0,N,2):
    ans += B[i]
  for i in range(1,N,2):
    ans += B[i]

print(*list(ans))

Failing test case input:
6
0 39 1 80 15 0

Expected output:
0 80 39 0 1 15


Actual output:
0 8 0 3 9 0 1 1 5


Fixed submission (verdict: Accepted):
from sys import stdin

N = int(stdin.readline().rstrip())
A = stdin.readline().rstrip().split()

B = A[::-1]

ans = []

if N % 2 == 0:
  for i in range(0,N,2):
    ans += [B[i]]
  for i in range(0,N,2):
    ans += [A[i]]
  
else:
  for i in range(0,N,2):
    ans += [B[i]]
  for i in range(1,N,2):
    ans += [A[i]]

print(*list(ans))
Problem: p03675
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
input()
n=[x for x in input().split()]
nb=n[::-1]
bs=n[::2]
if len(nb)%2==0:
    be=nb[::2]
else:
    be=nb[::2]
if len(n)==1:
    print(n[0])
else:
    print(" ".join(be+bs))

Failing test case input:
3
2 4 5

Expected output:
5 2 4


Actual output:
5 2 2 5


Fixed submission (verdict: Accepted):
input()
n=[x for x in input().split()]
nb=n[::-1]
bs=n[::2]
if len(nb)%2==0:
    be=nb[::2]
else:
    be=nb[1::2]
if len(n)==1:
    print(n[0])
else:
    ans=be+bs
    if len(n)%2!=0:
        ans=ans[::-1]
    print(" ".join(ans))
Problem: p03318
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


k = int(input())

count = 0
ans = []
minN = 10**15

for i in reversed(range(15)):
    for j in reversed(range(1,100)):
        num = str(j)+"9"*i
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n):
            minN = n
            ans.append(num)
            
for i in list(reversed(ans))[:k]:
    print(i)

Failing test case input:
131

Expected output:
1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
79
89
99
199
299
399
499
599
699
799
899
999
1099
1199
1299
1399
1499
1599
1699
1799
1899
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
39999
49999
59999
69999
79999
89999
99999
109999
119999
129999
139999
149999
159999
169999
179999
189999
199999
209999
219999
229999
239999
249999
259999
269999
279999
289999
299999
309999
319999
329999
339999
349999
359999
369999
379999
389999
399999
499999
599999
699999
799999
899999
999999
1099999
1199999
1299999
1399999
1499999
1599999
1699999
1799999
1899999
1999999
2099999
2199999
2299999
2399999
2499999
2599999
2699999
2799999
2899999
2999999
3099999
3199999
3299999


Actual output:
9
19
29
39
49
59
69
79
89
99
199
299
399
499
599
699
799
899
999
1099
1199
1299
1399
1499
1599
1699
1799
1899
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
29999
39999
49999
59999
69999
79999
89999
99999
109999
119999
129999
139999
149999
159999
169999
179999
189999
199999
299999
399999
499999
599999
699999
799999
899999
999999
1099999
1199999
1299999
1399999
1499999
1599999
1699999
1799999
1899999
1999999
2999999
3999999
4999999
5999999
6999999
7999999
8999999
9999999
10999999
11999999
12999999
13999999
14999999
15999999
16999999
17999999
18999999
19999999
29999999
39999999
49999999
59999999
69999999
79999999
89999999
99999999
109999999
119999999
129999999
139999999
149999999
159999999
169999999
179999999
189999999
199999999
299999999
399999999
499999999
599999999
699999999
799999999
899999999
999999999
1099999999
1199999999
1299999999
1399999999


Fixed submission (verdict: Accepted):


k = int(input())
count = 0
ans = []
minN = 10**15

for i in reversed(range(13)):
    minN = 10**15
    for j in reversed(range(1,10**3)):
        num = str(j)+"9"*i
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n or n==1):
            minN = n
            ans.append(int(num))

for i in list(sorted(list(set(ans))))[:k]:
    print(i)
Problem: p03318
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


k = int(input())
k = 100
count = 0
ans = []
minN = 10**15

for i in reversed(range(5)):
    for j in reversed(range(1,10**4)):
        num = str(j)+"9"*i*3
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n or n==1):
            minN = n
            ans.append(num)

for i in list(reversed(ans))[:k]:
    print(i)

Failing test case input:
122

Expected output:
1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
79
89
99
199
299
399
499
599
699
799
899
999
1099
1199
1299
1399
1499
1599
1699
1799
1899
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
39999
49999
59999
69999
79999
89999
99999
109999
119999
129999
139999
149999
159999
169999
179999
189999
199999
209999
219999
229999
239999
249999
259999
269999
279999
289999
299999
309999
319999
329999
339999
349999
359999
369999
379999
389999
399999
499999
599999
699999
799999
899999
999999
1099999
1199999
1299999
1399999
1499999
1599999
1699999
1799999
1899999
1999999
2099999
2199999
2299999
2399999


Actual output:
1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
79
89
99
199
299
399
499
599
699
799
899
999
1099
1199
1299
1399
1499
1599
1699
1799
1899
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
39999
49999
59999
69999
79999
89999
99999
109999
119999
129999
139999
149999
159999
169999
179999
189999
199999
209999
219999
229999
239999
249999
259999
269999
279999
289999
299999
309999
319999
329999
339999
349999
359999
369999
379999


Fixed submission (verdict: Accepted):


k = int(input())
count = 0
ans = []
minN = 10**15

for i in reversed(range(13)):
    minN = 10**15
    for j in reversed(range(1,10**3)):
        num = str(j)+"9"*i
        n = sum([int(k) for k in num])
        n = int(num)/n
        if(minN > n or n==1):
            minN = n
            ans.append(int(num))

for i in list(sorted(list(set(ans))))[:k]:
    print(i)
Problem: p03318
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
m=float("INF")
sunukes=[]
for i in range(15,-1,-1):
    for j in range(100,10,-1):
        
        sunuke=j*(10**i)-1
        s=str(sunuke)
        sn=0
        for k in range(len(s)):
            sn+=int(s[k])
        x=sunuke/sn
        
        if x<=m :
            m=x
            sunukes.append(sunuke)
for i in range(9,0,-1):
    sunukes.append(i)
k=int(input())

print(sunukes[-k])


Failing test case input:
99

Expected output:
1
2
3
4
5
6
7
8
9
19
29
39
49
59
69
79
89
99
199
299
399
499
599
699
799
899
999
1099
1199
1299
1399
1499
1599
1699
1799
1899
1999
2999
3999
4999
5999
6999
7999
8999
9999
10999
11999
12999
13999
14999
15999
16999
17999
18999
19999
20999
21999
22999
23999
24999
25999
26999
27999
28999
29999
39999
49999
59999
69999
79999
89999
99999
109999
119999
129999
139999
149999
159999
169999
179999
189999
199999
209999
219999
229999
239999
249999
259999
269999
279999
289999
299999
309999
319999
329999
339999
349999
359999
369999


Actual output:
369999


Fixed submission (verdict: Accepted):
m=float("INF")
sunukes=[]
for i in range(7,-1,-1):
    for j in range(1000,10,-1):
        
        sunuke=j*(100**i)-1
        s=str(sunuke)
        sn=0
        for k in range(len(s)):
            sn+=int(s[k])
        x=sunuke/sn
        
        if x<=m :
            m=x
            sunukes.append(sunuke)
for i in range(9,0,-1):
    sunukes.append(i)
sunukes=sunukes[::-1]
k=int(input())

for i in range(k):
    print(sunukes[i])
Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from functools import reduce

n, m = map(int, input().split())

mod = 10 ** 9 + 7
ans = 0
c = 1
p1 = 1
p2 = reduce(lambda ac, v: ac * v % mod, range(m, m - n, -1), 1)
for i in range(n + 1):
    if i > 0:
        c = (c * (n - i + 1) * pow(i, mod - 2, mod)) % mod
        p1 = (p1 * (n - i + 1)) % mod
        p2 = (p2 * pow(n - i + 1, mod - 2, mod)) % mod
    x = c * p1 * (p2 ** 2)
    if i % 2 == 0:
        ans += x
    else:
        ans -= x
    ans %= mod
print(ans)


Failing test case input:
3299 39455

Expected output:
291535525


Actual output:
60513566


Fixed submission (verdict: Accepted):
from functools import reduce

n, m = map(int, input().split())

mod = 10 ** 9 + 7
ans = 0
c = 1
p1 = 1
p2 = reduce(lambda ac, v: ac * v % mod, range(m, m - n, -1), 1)
for i in range(n + 1):
    if i > 0:
        c = (c * (n - i + 1) * pow(i, mod - 2, mod)) % mod
        p1 = (p1 * (m - i + 1)) % mod
        p2 = (p2 * pow(m - i + 1, mod - 2, mod)) % mod
    x = c * p1 * (p2 ** 2)
    if i % 2 == 0:
        ans += x
    else:
        ans -= x
    ans %= mod
print(ans)

Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

def pre_c(n, mod):
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for i in range(n + 1):
        if i == 0:
            f[i] = 1
            g[i] = 1
        else:
            f[i] = (f[i - 1] * i) % mod
            g[i] = pow(f[i], mod - 2, mod)

    return f, g

n, m = map(int,input().split())
mod = 10 ** 9 + 7
f, g = pre_c(m, mod)
mCn = (f[m] * g[m - n] * g[n])

temp1 = (f[n] * f[n - 1])
temp2 = (f[n] * f[n])

if m < 2*n:
    res = (mCn ** 2 * temp1) %mod
else:
    m_nCn = (f[m - n] * g[n] * g[m - 2*n])
    execept = (mCn * m_nCn * temp2)
    res = (execept + ((mCn ** 2 - mCn * m_nCn) * temp1)) %mod
print(res)

Failing test case input:
85920 225813

Expected output:
894389469


Actual output:
286934694


Fixed submission (verdict: Accepted):

def pre_c(n, mod):
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for i in range(n + 1):
        if i == 0:
            f[i] = 1
            g[i] = 1
        else:
            f[i] = (f[i - 1] * i) % mod
            g[i] = pow(f[i], mod - 2, mod)

    return f, g

n, m = map(int,input().split())
mod = 10 ** 9 + 7
f, g = pre_c(m, mod)
res = 0
for i in range(n + 1):
    C = f[n] * g[i] * g[n - i]
    P1 = f[m] * g[m - i]
    P2 = f[m - i] * g[m - n]
    temp = C * P1 * (P2 ** 2) * pow(-1, i)
    res = (res + temp%mod) %mod
print(res%mod)
Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

def pre_c(n, mod):
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for i in range(n + 1):
        if i == 0:
            f[i] = 1
            g[i] = 1
        else:
            f[i] = (f[i - 1] * i) % mod
            g[i] = pow(f[i], mod - 2, mod)

    return f, g

n, m = map(int,input().split())
mod = 10 ** 9 + 7

f, g = pre_c(m, mod)
temp1 = f[m] * g[m - n] * g[n] % mod
temp2 = f[n - 1]
ans = temp1 * (temp2%mod)
print(ans%mod)

Failing test case input:
141421 356237

Expected output:
881613484

Actual output:
466189106


Fixed submission (verdict: Accepted):

def pre_c(n, mod):
    f = [0] * (n + 1)
    g = [0] * (n + 1)
    for i in range(n + 1):
        if i == 0:
            f[i] = 1
            g[i] = 1
        else:
            f[i] = (f[i - 1] * i) % mod
            g[i] = pow(f[i], mod - 2, mod)

    return f, g

n, m = map(int,input().split())
mod = 10 ** 9 + 7
f, g = pre_c(m, mod)
res = 0
for i in range(n + 1):
    C = f[n] * g[i] * g[n - i]
    P1 = f[m] * g[m - i]
    P2 = f[m - i] * g[m - n]
    temp = C * P1 * (P2 ** 2) * pow(-1, i)
    res = (res + temp%mod) %mod
print(res%mod)

Problem: p02625
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
MOD = 10**9 + 7
MAX = 5*10**5 + 1

fact = [0 for _ in range(MAX)]
factinv = [0 for _ in range(MAX)]

fact[0] = 1
for k in range(1, MAX):
    fact[k] = fact[k - 1]*k
    fact[k] %= MOD

factinv[MAX - 1] = pow(fact[MAX - 1], MOD - 2, MOD)
for k in range(MAX - 1, 0, -1):
    factinv[k - 1] = fact[k]*k
    factinv[k - 1] %= MOD

def nCk(n, k):
    return fact[n]*factinv[k]*factinv[n - k] % MOD

def nPk(n, k):
    return fact[n]*factinv[n - k] % MOD

n, m = map(int, input().split(' '))

ans = 0
for k in range(n + 1):
    tmp = nCk(n, k)*nPk(m, k)*nPk(m - k, n - k)*nPk(m - k, n - k) % MOD
    if k % 2: ans += tmp
    else: ans -= tmp
    ans %= MOD

print(ans)

Failing test case input:
564 36214

Expected output:
459974839


Actual output:
750099756


Fixed submission (verdict: Accepted):
MOD = 10**9 + 7
MAX = 5*10**5 + 1

fact = [0 for _ in range(MAX)]
factinv = [0 for _ in range(MAX)]

fact[0] = 1
for k in range(1, MAX):
    fact[k] = fact[k - 1]*k
    fact[k] %= MOD

factinv[MAX - 1] = pow(fact[MAX - 1], MOD - 2, MOD)
for k in range(MAX - 1, 0, -1):
    factinv[k - 1] = factinv[k]*k
    factinv[k - 1] %= MOD

def nCk(n, k):
    return fact[n]*factinv[k]*factinv[n - k] % MOD

def nPk(n, k):
    return fact[n]*factinv[n - k] % MOD

n, m = map(int, input().split(' '))

ans = 0
for k in range(n + 1):
    tmp = nCk(n, k)*nPk(m, k)*nPk(m - k, n - k)*nPk(m - k, n - k) % MOD
    if not k % 2: ans += tmp
    else: ans -= tmp
    ans %= MOD

print(ans)
Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):
    return faclist[n] * pow(faclist[r], MOD - 2, MOD) * pow(faclist[n-r], -1) % MOD
def mperm(n, r):
    return faclist[n] * pow(faclist[n-r], MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)



Failing test case input:
4151 39455

Expected output:
208630339


Actual output:
356116208.0


Fixed submission (verdict: Accepted):
def makefac(n):
    global faclist
    faclist = [1, 1]
    for i in range(2, n + 1):
        faclist.append(faclist[-1] * i % MOD)
    return None
def mcomb(n, r):
    return faclist[n] * pow(faclist[r],MOD - 2, MOD) * pow(faclist[n-r], MOD - 2, MOD)
def mperm(n, r):
    return faclist[n] * pow(faclist[n-r],MOD - 2, MOD)

N, M = map(int, input().split())
MOD = 10 ** 9 + 7
makefac(M)
ans = mperm(M, N)
for k in range(1, N + 1):
    ans += ((-1)**k * mcomb(N, k) * mperm(M - k, N - k)) % MOD
ans = ans * mperm(M, N) % MOD
print(ans)

Problem: p02625
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n,m=map(int,input().split())
a = 1
Mod=1e9+7
d = [1]*(n+1)
for i in range(n):
  d[i+1]=((m-n+i)*d[i]+i*d[i-1])%Mod
  a=a*(m-i)%Mod
print(int(a*d[n]%Mod))

Failing test case input:
32 71

Expected output:
605744265


Actual output:
605744295


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a = 1
Mod=10**9+7
d = [1]*(n+1)
for i in range(n):
  d[i+1]=((m-n+i)*d[i]+i*d[i-1])%Mod
  a=a*(m-i)%Mod
print(a*d[n]%Mod)
Problem: p02625
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
MOD = 10**9 + 7
MAX = 5*10**5 + 1

fact = [0 for _ in range(MAX)]
factinv = [0 for _ in range(MAX)]

fact[0] = 1
for k in range(1, MAX):
    fact[k] = fact[k - 1]*k
    fact[k] %= MOD

factinv[MAX - 1] = pow(fact[MAX - 1], MOD - 2, MOD)
for k in range(MAX - 1, 0, -1):
    factinv[k - 1] = factinv[k]*k
    factinv[k - 1] %= MOD

def nCk(n, k):
    return fact[n]*factinv[k]*factinv[n - k] % MOD

def nPk(n, k):
    return fact[n]*factinv[n - k] % MOD

n, m = map(int, input().split(' '))

ans = 0
for k in range(n + 1):
    tmp = nCk(n, k)*nPk(m, k)*nPk(m - k, n - k)*nPk(m - k, n - k) % MOD
    if k % 2: ans += tmp
    else: ans -= tmp
    ans %= MOD

print(ans)

Failing test case input:
19 71

Expected output:
520068118


Actual output:
479931889


Fixed submission (verdict: Accepted):
MOD = 10**9 + 7
MAX = 5*10**5 + 1

fact = [0 for _ in range(MAX)]
factinv = [0 for _ in range(MAX)]

fact[0] = 1
for k in range(1, MAX):
    fact[k] = fact[k - 1]*k
    fact[k] %= MOD

factinv[MAX - 1] = pow(fact[MAX - 1], MOD - 2, MOD)
for k in range(MAX - 1, 0, -1):
    factinv[k - 1] = factinv[k]*k
    factinv[k - 1] %= MOD

def nCk(n, k):
    return fact[n]*factinv[k]*factinv[n - k] % MOD

def nPk(n, k):
    return fact[n]*factinv[n - k] % MOD

n, m = map(int, input().split(' '))

ans = 0
for k in range(n + 1):
    tmp = nCk(n, k)*nPk(m, k)*nPk(m - k, n - k)*nPk(m - k, n - k) % MOD
    if not k % 2: ans += tmp
    else: ans -= tmp
    ans %= MOD

print(ans)

Problem: p02625
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, m = map(int, input().split())
a,M,d=1,10**9+7,[1]*(n+1)
for i in range(n):
  d[i+1]=((m-n+1)*d[i]+i*d[i-1])%M
  a=a*(m-1)%M
print(a*d[-1]%M)

Failing test case input:
3477 100487

Expected output:
567655026


Actual output:
384833225


Fixed submission (verdict: Accepted):
n,m=map(int,input().split())
a,M,d=1,10**9+7,[1]*(n+1)
for i in range(n):
  d[i+1]=((m-n+i)*d[i]+i*d[i-1])%M
  a=a*(m-i)%M
print(a*d[-1]%M)

Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
MOD = 10 ** 9 + 7
N,M = map(int,input().split())
ans1 = 1
for i in range(N):
    ans1 *= M - i
    ans1 %= MOD
ans2 = [1,M-1]
for i in range(2,N+1):
    ans2.append((ans2[-2] * (N-1) + ans2[-1] * (M-1))% MOD)
print(ans1 * ans2[N] % MOD)

Failing test case input:
335 167585

Expected output:
595052928


Actual output:
22366826


Fixed submission (verdict: Accepted):
MOD = 10 ** 9 + 7
N,M = map(int,input().split())
ans1 = 1
for i in range(N):
    ans1 *= M - i
    ans1 %= MOD
ans2 = [1,M-N]
for i in range(2,N+1):
    ans2.append((ans2[-2] * (i -1) + ans2[-1] * (M - N + i - 1))% MOD)
print(ans1 * ans2[N] % MOD)
Problem: p02625
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
MOD = 10 ** 9 + 7
N,M = map(int,input().split())
ans1 = 1
for i in range(N):
    ans1 *= M - i
    ans1 %= MOD
ans2 = [1,M-N]
for i in range(2,N+1):
    ans2.append((ans2[-2] * (N-1) + ans2[-1] * (M-1))% MOD)
print(ans1 * ans2[N] % MOD)

Failing test case input:
1101 374785

Expected output:
1365523


Actual output:
918878734


Fixed submission (verdict: Accepted):
MOD = 10 ** 9 + 7
N,M = map(int,input().split())
ans1 = 1
for i in range(N):
    ans1 *= M - i
    ans1 %= MOD
ans2 = [1,M-N]
for i in range(2,N+1):
    ans2.append((ans2[-2] * (i -1) + ans2[-1] * (M - N + i - 1))% MOD)
print(ans1 * ans2[N] % MOD)
Problem: p02934
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(s) for s in input().split(' ')]

ret = 1
for a in A:
    ret *= a

print(ret / sum(A))



Failing test case input:
1
1001

Expected output:
1001.0000000000


Actual output:
1.0


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(s) for s in input().split(' ')]

ret = 1
for a in A:
    ret *= a
ret2 = sum([ret 
print(ret / ret2)
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
n = len(S)
maze = [1] * n

for i in range(0,n-1):
    if S[i] == S[i+1] == 'R':
        print('before',maze)
        maze[i+2] += maze[i]
        maze[i] = 0
        print('after',maze)

for i in range(n-1,0,-1):
    if S[i] == S[i-1] == 'L':
        maze[i-2] += maze[i]
        maze[i] = 0

print(*maze)


Failing test case input:
RLLLLRLRLRRLLRRL

Expected output:
3 2 0 0 0 1 1 1 1 0 2 2 0 0 1 2


Actual output:
before [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
after [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1]
before [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1]
after [1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 2, 1, 0, 1, 2]
3 2 0 0 0 1 1 1 1 0 2 2 0 0 1 2


Fixed submission (verdict: Accepted):
S = input()
n = len(S)
maze = [1] * n

for i in range(0,n-1):
    if S[i] == S[i+1] == 'R':
        
        maze[i+2] += maze[i]
        maze[i] = 0
        

for i in range(n-1,0,-1):
    if S[i] == S[i-1] == 'L':
        maze[i-2] += maze[i]
        maze[i] = 0

print(*maze)
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10 ** 7)

S = list(input())

is_hole = [None for _ in S]
is_s = [None for _ in S]

s_1 = None
for i, s in enumerate(S):
    if s_1 == 'R' and s == 'L':
        is_hole[i - 1] = 'R'
        is_hole[i] = 'L'
    if s_1 == 'L' and s == 'R':
        is_s[i] = 'S'  
    s_1 = s

result = [0 for _ in S]
mem_R = 0  
mem_Rx = 0  
mem_L = 0

def find_next_mem_R(i):
    while i < len(S):
        if is_hole[i] == 'R':
            return i
        i += 1

mem_Rx = find_next_mem_R(0)

for i, s in enumerate(S):
    if is_s[i] == 'S':
        result[mem_Rx] = mem_R
        result[mem_Rx + 1] = mem_L
        mem_R = 0
        mem_L = 0
        mem_Rx = find_next_mem_R(i)

    if s == 'R':
        x_diff_for_R = mem_Rx - i
        if x_diff_for_R % 2 == 0:
            mem_R += 1
        else:
            mem_L += 1
    else:
        x_diff_for_R = i - mem_Rx
        if x_diff_for_R % 2 == 0:
            mem_R += 1
        else:
            mem_L += 1

result[mem_Rx] = mem_R
result[mem_Rx + 1] = mem_L
print(result)


Failing test case input:
RRRLLRLRRLLLLLRL

Expected output:
0 0 3 2 0 1 1 0 3 4 0 0 0 0 1 1


Actual output:
[0, 0, 3, 2, 0, 1, 1, 0, 3, 4, 0, 0, 0, 0, 1, 1]


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10 ** 7)

S = list(input())

is_hole = [None for _ in S]
is_s = [None for _ in S]

s_1 = None
for i, s in enumerate(S):
    if s_1 == 'R' and s == 'L':
        is_hole[i - 1] = 'R'
        is_hole[i] = 'L'
    if s_1 == 'L' and s == 'R':
        is_s[i] = 'S'  
    s_1 = s

result = [0 for _ in S]
mem_R = 0  
mem_Rx = 0  
mem_L = 0

def find_next_mem_R(i):
    while i < len(S):
        if is_hole[i] == 'R':
            return i
        i += 1

mem_Rx = find_next_mem_R(0)

for i, s in enumerate(S):
    if is_s[i] == 'S':
        result[mem_Rx] = mem_R
        result[mem_Rx + 1] = mem_L
        mem_R = 0
        mem_L = 0
        mem_Rx = find_next_mem_R(i)

    if s == 'R':
        x_diff_for_R = mem_Rx - i
        if x_diff_for_R % 2 == 0:
            mem_R += 1
        else:
            mem_L += 1
    else:
        x_diff_for_R = i - mem_Rx
        if x_diff_for_R % 2 == 0:
            mem_R += 1
        else:
            mem_L += 1

result[mem_Rx] = mem_R
result[mem_Rx + 1] = mem_L

result_str = [str(i) for i in result]
print(' '.join(result_str))
Problem: p02954
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from collections import Counter

S=input()
n=len(S)
dp=[[0]*n for _ in range(20)]

for i,s in enumerate(S):
    dp[0][i]=i-1 if s =='L' else i+1

for k in range(19):
    for i in range(n):
        dp[k+1][i]=dp[k][dp[k][i]]

C=Counter(dp[-1])
print(dp[-1])
print(C)
print(*[C[i] for i in range(n)])

Failing test case input:
RRLLLLRLLRRL

Expected output:
0 3 3 0 0 0 2 1 0 0 1 2


Actual output:
[2, 1, 2, 1, 2, 1, 6, 7, 6, 11, 10, 11]
Counter({2: 3, 1: 3, 6: 2, 11: 2, 7: 1, 10: 1})
0 3 3 0 0 0 2 1 0 0 1 2


Fixed submission (verdict: Accepted):
from collections import Counter

S=input()
n=len(S)
dp=[[0]*n for _ in range(20)]

for i,s in enumerate(S):
    dp[0][i]=i-1 if s =='L' else i+1

for k in range(19):
    for i in range(n):
        dp[k+1][i]=dp[k][dp[k][i]]

C=Counter(dp[-1])

print(*[C[i] for i in range(n)])

Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
ans = [0]*len(S)
tmp = []
cnt = 1;

for i in range(len(S)-1):
  if(S[i] == S[i+1]):
    cnt += 1
  else:
    tmp.append(cnt)
    cnt = 1
tmp.append(cnt)

cnt = 0
for i in range(len(tmp)-1):
  cnt += tmp[i]
  if(i % 2 == 0):
    if((tmp[i] - tmp[i+1])%2 == 0):
      ans[cnt-1] = int((tmp[i]+tmp[i+1])/2)
      ans[cnt] = int((tmp[i]+tmp[i+1])/2)
    else:
      if(abs(tmp[i] - tmp[i+1]) > 2):
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
      else:
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        
print(*ans)

Failing test case input:
RLRRLRLLLLLRRRLL

Expected output:
1 1 0 1 2 3 3 0 0 0 0 0 0 3 2 0


Actual output:
1 1 0 2 1 3 3 0 0 0 0 0 0 3 2 0


Fixed submission (verdict: Accepted):
S = input()
ans = [0]*len(S)
tmp = []
cnt = 1;

for i in range(len(S)-1):
  if(S[i] == S[i+1]):
    cnt += 1
  else:
    tmp.append(cnt)
    cnt = 1
tmp.append(cnt)

cnt = 0
for i in range(len(tmp)-1):
  cnt += tmp[i]
  if(i % 2 == 0):
    if((tmp[i] - tmp[i+1])%2 == 0):
      ans[cnt-1] = int((tmp[i]+tmp[i+1])/2)
      ans[cnt] = int((tmp[i]+tmp[i+1])/2)
    else:
      if(min(tmp[i], tmp[i+1]) % 2):
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
      else:
        if(tmp[i] > tmp[i+1]):
          ans[cnt-1] = int((tmp[i] + tmp[i+1]+1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]-1)/2)
        else:
          ans[cnt-1] = int((tmp[i] + tmp[i+1]-1)/2)
          ans[cnt] = int((tmp[i]+tmp[i+1]+1)/2)
        
print(*ans)
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=str(input())

l=[0]*len(s)

for i in range(len(s)):
        if s[i]=='R' and i%2==1:
                a=s.find('L',i)
                l[a-1]+=1
        elif s[i]=='R' and i%2==0:
                a=s.find('L',i)
                l[a]+=1
        elif s[i]=='L' and i%2==1:
                a=s.rfind('R',0,i)
                l[a]+=1
        elif s[i]=='L' and i%2==0:
                a=s.rfind('R',0,i)
                l[a+1]+=1
print(' '.join(map(str,l)))
        

Failing test case input:
RLRLRLRLLRRLRLLL

Expected output:
1 1 1 1 1 1 2 1 0 0 1 2 2 2 0 0


Actual output:
1 1 1 1 1 1 1 2 0 0 2 1 2 2 0 0


Fixed submission (verdict: Accepted):
s=str(input())

l=[0]*len(s)

for i in range(len(s)):
        a=s.find('L',i)
        b=s.rfind('R',0,i)
        if s[i]=='R' and (a-i)%2==0:
                l[a]+=1
        elif s[i]=='R' and (a-i)%2==1:
                l[a-1]+=1
        elif s[i]=='L' and (i-b)%2==0:
                l[b]+=1
        elif s[i]=='L' and (i-b)%2==1:
                l[b+1]+=1
print(' '.join(map(str,l)))

Problem: p02954
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S=input()
ans = [0] * len(S)
last_R=[0] * len(S)
tmp = 0
for i in range(len(S)):
    if S[i] == "R":
        tmp = i
    last_R[i] = tmp
first_L=[0] * len(S)
tmp = 0
for i in reversed(range(len(S))):
    if S[i] == "L":
        tmp = i
    first_L[i] = tmp
for i in range(len(S)):
    if S[i] == "L":
        R_index = last_R[i]
        if i - R_index % 2 == 1:
            ans[R_index+1] += 1
        else:
            ans[R_index] += 1
    if S[i] == "R":
        L_index = first_L[i]
        if L_index - i %2 == 1:
            ans[L_index-1] += 1
        else:
            ans[L_index] += 1
ans = map(str, ans)
print(" ".join(ans))

Failing test case input:
RRRLLRLLRLLRLRLL

Expected output:
0 0 3 2 0 2 1 0 2 1 0 1 1 2 1 0


Actual output:
0 0 2 3 0 2 1 0 2 1 0 1 1 2 1 0


Fixed submission (verdict: Accepted):
S=input()
ans = [0] * len(S)
last_R=[0] * len(S)
tmp = 0
for i in range(len(S)):
    if S[i] == "R":
        tmp = i
    last_R[i] = tmp
first_L=[0] * len(S)
tmp = 0
for i in reversed(range(len(S))):
    if S[i] == "L":
        tmp = i
    first_L[i] = tmp
for i in range(len(S)):
    if S[i] == "L":
        R_index = last_R[i]
        if (i - R_index) % 2 == 1:
            ans[R_index+1] += 1
        else:
            ans[R_index] += 1
    if S[i] == "R":
        L_index = first_L[i]
        if (L_index - i) %2 == 1:
            ans[L_index-1] += 1
        else:
            ans[L_index] += 1
ans = map(str, ans)
print(" ".join(ans))
Problem: p02954
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
if __name__ == '__main__':
  str = input()
  strList = [c for c in str]
  strList.append('e')
  strLength = len(strList)
  rLength = 0
  lLength = 0
  i = 0
  changePoint = 0

  child = [0 for i in range(strLength)]

  c = 'R'
  
  while(c != 'e'):
    c = strList[i]
    while(c == 'R'):
      i += 1
      c = strList[i]
      rLength += 1
    
    changePoint = i
    
    while(c == 'L'):
      i += 1
      c = strList[i]
      lLength += 1

    rRight = int(rLength/2)
    rLeft = rLength - rRight

    lLeft = int(lLength/2)
    lRight = lLength - lLeft

    child[changePoint-1] += rLeft + lLeft
    child[changePoint] += rRight + lRight

    rLength = 0
    lLength = 0
  
  for numOfChild in child:
    print(numOfChild, end="")
    print(' ', end="")

Failing test case input:
RRLLLLLLRRRL

Expected output:
0 4 4 0 0 0 0 0 0 0 2 2


Actual output:
0 4 4 0 0 0 0 0 0 0 2 2 0 

Fixed submission (verdict: Accepted):
if __name__ == '__main__':
  str = input()
  strList = [c for c in str]
  strList.append('e')
  strLength = len(strList)
  rLength = 0
  lLength = 0
  i = 0
  changePoint = 0

  child = [0 for i in range(strLength-1)]

  c = 'R'
  
  while(c != 'e'):
    c = strList[i]
    while(c == 'R'):
      i += 1
      c = strList[i]
      rLength += 1
    
    changePoint = i
    
    while(c == 'L'):
      i += 1
      c = strList[i]
      lLength += 1

    rRight = int(rLength/2)
    rLeft = rLength - rRight

    lLeft = int(lLength/2)
    lRight = lLength - lLeft

    child[changePoint-1] += rLeft + lLeft
    child[changePoint] += rRight + lRight

    rLength = 0
    lLength = 0
  
  for numOfChild in child:
    print(numOfChild, end="")
    print(' ', end="")
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()

even = 0
odd = 0
l = S.index('L')
r = S.index('R')
ans = [0] * len(S)

for i in range(len(S) - 1):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        l = i
        r = i + 1
        if i % 2 == 0:
            ans[i] += even
            ans[i + 1] += odd
        else:
            ans[i] += odd
            ans[i + 1] += even
        even = 0
        odd = 0
    elif S[i] == 'L' and S[i + 1] == 'R':
        if l % 2 == 0:
            ans[l] += even
            ans[l + 1] += odd
        else:
            ans[l] += odd
            ans[l + 1] += even
        even = 0
        odd = 0


if (len(S) - 1 - l) % 2 == 0:
    ans[l] += 1
else:
    ans[r] += 1

if l % 2 == 0:
    ans[l] += even
    ans[l + 1] += odd
else:
    ans[l] += odd
    ans[l + 1] += even

print(''.join(map(str, ans)))

Failing test case input:
RRLLLLRRLRLL

Expected output:
0 3 3 0 0 0 0 1 2 2 1 0


Actual output:
033000012210


Fixed submission (verdict: Accepted):
S = input()

even = 0
odd = 0
l = S.index('L')
r = S.index('R')
ans = [0] * len(S)

for i in range(len(S) - 1):
    if i % 2 == 0:
        even += 1
    else:
        odd += 1
    if S[i] == 'R' and S[i + 1] == 'L':
        l = i
        r = i + 1
        if i % 2 == 0:
            ans[i] += even
            ans[i + 1] += odd
        else:
            ans[i] += odd
            ans[i + 1] += even
        even = 0
        odd = 0
    elif S[i] == 'L' and S[i + 1] == 'R':
        if l % 2 == 0:
            ans[l] += even
            ans[l + 1] += odd
        else:
            ans[l] += odd
            ans[l + 1] += even
        even = 0
        odd = 0


if (len(S) - 1 - l) % 2 == 0:
    ans[l] += 1
else:
    ans[r] += 1

if l % 2 == 0:
    ans[l] += even
    ans[l + 1] += odd
else:
    ans[l] += odd
    ans[l + 1] += even

print(' '.join(map(str, ans)))
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = list(input())

N = len(s)

RL = []
LR = [-1]
for i in range(N-1):
    if s[i] == 'R' and s[i+1] == 'L':
        RL.append(i)
    if s[i] == 'L' and s[i+1] == 'R':
        LR.append(i)

LR.append(N-1)

_num = []
for i in range(len(LR)-1):
    _num.append(LR[i+1] - LR[i])


ans = [0]*N

for i in range(len(_num)):
    if int(_num[i]/2) == _num[i]/2:
        ans[RL[i]] = int(_num[i]/2)
        ans[RL[i]+1] = int(_num[i]/2)
    else:
        if RL[i] - LR[i] > LR[i+1] - RL[i]:
            if int(RL[i] - LR[i]) == RL[i] - LR[i]:
                ans[RL[i]] = int(_num[i]/2) + 1
                ans[RL[i]+1] = int(_num[i]/2)
            else:
                ans[RL[i]] = int(_num[i]/2)
                ans[RL[i]+1] = int(_num[i]/2) + 1
        else:
            if int(LR[i+1] - RL[i]) == LR[i+1] - RL[i]:
                ans[RL[i]] = int(_num[i]/2) + 1
                ans[RL[i]+1] = int(_num[i]/2)
            else:
                ans[RL[i]] = int(_num[i]/2)
                ans[RL[i]+1] = int(_num[i]/2) + 1
                
print(ans)

Failing test case input:
RRLLLRRLLRRLLRLL

Expected output:
0 2 3 0 0 0 2 2 0 0 2 2 0 2 1 0


Actual output:
[0, 3, 2, 0, 0, 0, 2, 2, 0, 0, 2, 2, 0, 2, 1, 0]


Fixed submission (verdict: Accepted):
s = list(input())

N = len(s)

RL = []
LR = [-1]
for i in range(N-1):
    if s[i] == 'R' and s[i+1] == 'L':
        RL.append(i)
    if s[i] == 'L' and s[i+1] == 'R':
        LR.append(i)

LR.append(N-1)

_num = []
for i in range(len(LR)-1):
    _num.append(LR[i+1] - LR[i])


ans = [0]*N

for i in range(len(_num)):
    if int(_num[i]/2) == _num[i]/2:
        ans[RL[i]] = int(_num[i]/2)
        ans[RL[i]+1] = int(_num[i]/2)
    else:
        if int((RL[i] - LR[i])/2) == ((RL[i] - LR[i])/2):
            ans[RL[i]] = int(_num[i]/2)
            ans[RL[i]+1] = int(_num[i]/2) + 1
        else:
            ans[RL[i]] = int(_num[i]/2) + 1
            ans[RL[i]+1] = int(_num[i]/2)

print(' '.join(map(str, ans)))
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
n = len(s)

def solve(s, c1, c2):
    res = [0] * (n)
    odd = 0
    even = 0
    for i in range(n):
        if s[i] == c1:
            if i % 2 == 1:
                odd += 1
            else:
                even += 1
        if s[i] == c2:
            if i % 2 == 1:
                res[i] += odd
                res[i-1] += even
            else:
                res[i] += even
                res[i-1] += odd
            odd, even = 0, 0
    return res

A = solve(s, 'R', 'L')
B = solve(s[::-1], 'L', 'R')[::-1]
ans = [a+b for a, b in zip(A,B)]
print(ans)

Failing test case input:
RRLRL

Expected output:
0 1 2 1 1

Actual output:
[0, 1, 2, 1, 1]


Fixed submission (verdict: Accepted):
s = input()
n = len(s)

def solve(s, c1, c2):
    res = [0] * (n)
    odd = 0
    even = 0
    for i in range(n):
        if s[i] == c1:
            if i % 2 == 1:
                odd += 1
            else:
                even += 1
        if s[i] == c2:
            if i % 2 == 1:
                res[i] += odd
                res[i-1] += even
            else:
                res[i] += even
                res[i-1] += odd
            odd, even = 0, 0
    return res

A = solve(s, 'R', 'L')
B = solve(s[::-1], 'L', 'R')[::-1]
ans = [a+b for a, b in zip(A,B)]
print(' '.join(map(str, ans)))
Problem: p02954
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


import sys

class DGatheringChildren:
    def solve(self):
        s = input()
        n = len(s)
        i = 0
        last = 0
        ans = [0] * n
        while i < n - 1:
            if s[i] == 'R' and s[i + 1] == 'L':
                ans[i + 1] += 1
                for j in range(last, i + 1):
                    if (i - j) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                k = i + 2
                while k < n and s[k] == 'L':
                    if (k - i) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                    k += 1

                last = k
                i += 1

            i += 1

        print(*ans)

solver = DGatheringChildren()
input = sys.stdin.readline

solver.solve()


Failing test case input:
RRRLLRRLLLLLLRRL

Expected output:
0 0 3 2 0 0 4 4 0 0 0 0 0 0 1 2


Actual output:
0 0 3 2 0 0 4 4 0 0 0 0 0 0 1 2 0


Fixed submission (verdict: Accepted):


import sys

class DGatheringChildren:
    def solve(self):
        s = input().strip()
        n = len(s)
        i = 0
        last = 0
        ans = [0] * n
        while i < n - 1:
            if s[i] == 'R' and s[i + 1] == 'L':
                ans[i + 1] += 1
                for j in range(last, i + 1):
                    if (i - j) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                k = i + 2
                while k < n and s[k] == 'L':
                    if (k - i) % 2 == 0:
                        ans[i] += 1
                    else:
                        ans[i + 1] += 1
                    k += 1

                last = k
                i += 1

            i += 1

        print(*ans)

solver = DGatheringChildren()
input = sys.stdin.readline

solver.solve()
Problem: p02954
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
n = len(s)
temp = s[0]
group = []
ans = [0]*n
sec = [temp]
rlind = []
for i in range(1,n):
  if temp=='L' and s[i]=='R':
    group.append(sec)
    sec = []
  elif temp=='R' and s[i]=='L':
    rlind.append(i)
  sec.append(s[i])
  temp = s[i]
group.append(sec)

for i in range(len(group)):
  ind = rlind[i]
  m = len(group[i])
  if m%2==0:
    p = m
    ans[ind]=p
    ans[ind-1]=p
  else:
    p = group[i].count('R')
    q = max(p,m-p)
    if (q-1)%2==0:
      ans[ind]=m-p
      ans[ind-1]=p
    else:
      ans[ind]=p
      ans[ind-1]=m-p
print(*ans)

Failing test case input:
RRLLLLRLLRRL

Expected output:
0 3 3 0 0 0 2 1 0 0 1 2


Actual output:
0 6 6 0 0 0 2 1 0 0 1 2


Fixed submission (verdict: Accepted):
s = input()
n = len(s)
temp = s[0]
grp = []
ans = [0]*n
sec = [temp]
rlind = []
for i in range(1,n):
  if temp=='L' and s[i]=='R':
    grp.append(sec)
    sec = []
  elif temp=='R' and s[i]=='L':
    rlind.append(i)
  sec.append(s[i])
  temp = s[i]
grp.append(sec)

for i in range(len(grp)):
  ind = rlind[i]
  m = len(grp[i])
  if m%2==0:
    p = m
    ans[ind]=p
    ans[ind-1]=p
  else:
    p = grp[i].count('R')
    q = max(p,m-p)
    if p==q:
      p = -(-m
    else:
      p = m
    if (q-1)%2==0:
      ans[ind]=m-p
      ans[ind-1]=p
    else:
      ans[ind]=p
      ans[ind-1]=m-p
print(*ans)
Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input() + 'O'
N = len(S)
n = [0] * (N - 1)
t = []
i = 0
j =  0
while S[i] != 'O':
    count = 0
    if S[i] == 'R':
        while S[i] == 'R':
            count += 1
            i += 1
    elif S[i] == 'L':
        while S[i] == 'L':
            count += 1
            i += 1
    t.append(count)
T = int(len(t)/2)  
for i in range(T):
    j += t[2*i]
    if t[2*i] % 2 == 0:
        if t[2*i + 1] % 2 == 0:
            n[j - 1] = int((t[2*i] + t[2*i + 1])/2)
            n[j] = n[j - 1]
        elif t[2*i + 1] % 2 == 1:
            n[j - 1] = t[2*i + 1]
            n[j] = t[2*i]
    elif t[2*i] % 2 == 1:
        if t[2*i + 1] % 2 == 0:
            n[j - 1] = int((t[2*i] + t[2*i + 1] + 1)/2)
            n[j] = n[j - 1] - 1
        elif t[2*i + 1] % 2 == 1:
            n[j - 1] = int((t[2*i] + t[2*i + 1])/2)
            n[j] = n[j - 1]
    j += t[2*i+1]
print(' '.join(map(str, n)))


Failing test case input:
RRLLLRRLRLLL

Expected output:
0 2 3 0 0 0 1 2 2 2 0 0


Actual output:
0 3 2 0 0 0 1 2 2 2 0 0


Fixed submission (verdict: Accepted):
S = input() + 'O'
N = len(S)
n = [0] * (N - 1)
t = []
i = 0
j =  0
while S[i] != 'O':
    count = 0
    if S[i] == 'R':
        while S[i] == 'R':
            count += 1
            i += 1
    elif S[i] == 'L':
        while S[i] == 'L':
            count += 1
            i += 1
    t.append(count)
T = int(len(t)/2)  
for i in range(T):
    j += t[2*i]
    if t[2*i] % 2 == 0:
        if t[2*i + 1] % 2 == 0:
            n[j - 1] = int((t[2*i] + t[2*i + 1])/2)
            n[j] = n[j - 1]
        elif t[2*i + 1] % 2 == 1:
            n[j - 1] = int((t[2*i] + t[2*i + 1] - 1)/2)
            n[j] = n[j - 1] + 1
    elif t[2*i] % 2 == 1:
        if t[2*i + 1] % 2 == 0:
            n[j - 1] = int((t[2*i] + t[2*i + 1] + 1)/2)
            n[j] = n[j - 1] - 1
        elif t[2*i + 1] % 2 == 1:
            n[j - 1] = int((t[2*i] + t[2*i + 1])/2)
            n[j] = n[j - 1]
    j += t[2*i+1]
print(' '.join(map(str, n)))

Problem: p02954
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
print(S)

N = len(S)

ans = [0]*N

for _ in range(2):
    cnt = 0
    for i in  range(len(S)):
        if S[i] =='R':cnt +=1
        else:
            ans[i] += int(cnt/2)
            ans[i-1] += int((cnt+1)/2)
            cnt = 0

    S.reverse()
    ans.reverse()
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] ='R'
        else:
            S[i] = 'L'

print(*ans)

Failing test case input:
RRRLLLRLLRRLLLRL

Expected output:
0 0 3 3 0 0 2 1 0 0 2 3 0 0 1 1


Actual output:
['R', 'R', 'R', 'L', 'L', 'L', 'R', 'L', 'L', 'R', 'R', 'L', 'L', 'L', 'R', 'L']
0 0 3 3 0 0 2 1 0 0 2 3 0 0 1 1


Fixed submission (verdict: Accepted):
S = list(input())

N = len(S)

ans = [0]*N

for _ in range(2):
    cnt = 0
    for i in  range(len(S)):
        if S[i] =='R':cnt +=1
        else:
            ans[i] += int(cnt/2)
            ans[i-1] += int((cnt+1)/2)
            cnt = 0

    S.reverse()
    ans.reverse()
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] ='R'
        else:
            S[i] = 'L'

print(*ans)