ZhenlongDai/ACPR huggingface dataset:
Problem: p03972
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
h,w=map(int, input().split())
p=[int(input()) for i in range(w)]
q=[int(input()) for i in range(h)]
p.append(0)
q.append(0)
p.sort()
p.reverse()
q.sort()
q.reverse()

count=h*w
row=0
line=0
i=0
j=0
ans=0

while count>0:
    if p[i]>=q[j]:
        ans+=p[i]*(w-line)

        count-=w-line
        i+=1
        row+=1

    else:
        ans+=q[j]*(h-row)

        count-=h-row
        j+=1
        line+=1
x=sum(p)*(h+1)+sum(q)*(w+1)
print(x-ans)


Failing test case input:
2 4
1
6
-2
4
4
4
1

Expected output:
28


Actual output:
27


Fixed submission (verdict: Accepted):
w,h=map(int, input().split())
p=[int(input()) for i in range(w)]
q=[int(input()) for i in range(h)]
p.append(0)
q.append(0)
p.sort()
p.reverse()
q.sort()
q.reverse()

count=w*h
row=0
line=0
i=0
j=0
ans=0

while count>0:
    if p[i]>=q[j]:
        ans+=p[i]*(h-line)

        count-=h-line
        i+=1
        row+=1

    else:
        ans+=q[j]*(w-row)

        count-=w-row
        j+=1
        line+=1
x=sum(p)*(h+1)+sum(q)*(w+1)
print(x-ans)

Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
W,H=map(int,input().split())
p=sorted(int(input())for _ in'_'*W)
p+=10**18,
q=sorted(int(input())for _ in'_'*H)
q+=10**18,
z=i=j=0
h,w=H+1,W+1
while i<W or j<H:
	if h*p[i]<w*q[j]:
		z+=h*p[i]
		i+=1
		w-=1
	else:
		z+=w*q[j]
		j+=1
		h-=1
print(z)


Failing test case input:
2 3
1
2
-1
6
3
1
1

Expected output:
15


Actual output:
16


Fixed submission (verdict: Accepted):
W,H=map(int,input().split())
p=sorted(int(input())for _ in'_'*W)
p+=10**18,
q=sorted(int(input())for _ in'_'*H)
q+=10**18,
z=i=j=0
h,w=H+1,W+1
while i<W or j<H:
	if p[i]<q[j]:
		z+=h*p[i]
		i+=1
		w-=1
	else:
		z+=w*q[j]
		j+=1
		h-=1
print(z)

Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
H, W = (int(i) for i in input().split())
L = []
for i in range(W):
  L.append((int(input()), 0))
for i in range(H):
  L.append((int(input()), 1))
a = W
b = H
ans = 0
L.sort()
for i in range(H + W):
  if L[i][1] == 0:
    ans += (b+1) * L[i][0]
    a -= 1
  else:
    ans += (a+1) * L[i][0]
    b -= 1
print(ans)

Failing test case input:
4 3
0
0
0
3
62
2
0

Expected output:
72


Actual output:
67


Fixed submission (verdict: Accepted):
W, H = (int(i) for i in input().split())
L = []
for i in range(W):
  L.append((int(input()), 0))
for i in range(H):
  L.append((int(input()), 1))
a = W
b = H
ans = 0
L.sort()
for i in range(H + W):
  if L[i][1] == 0:
    ans += (b+1) * L[i][0]
    a -= 1
  else:
    ans += (a+1) * L[i][0]
    b -= 1
print(ans)
Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W = list(map(int, sys.stdin.readline().split()))
P = [int(sys.stdin.readline()) for _ in range(W)]
Q = [int(sys.stdin.readline()) for _ in range(H)]

P.sort(reverse=True)
Q.sort(reverse=True)

ans = 0
v_nodes = W + 1
h_nodes = H + 1
while P or Q:
    if P and Q:
        if P[-1] < Q[-1]:
            ans += P.pop() * h_nodes
            v_nodes -= 1
        else:
            ans += Q.pop() * v_nodes
            h_nodes -= 1
    elif P:
        ans += P.pop() * h_nodes
        v_nodes -= 1
    elif Q:
        ans += Q.pop() * v_nodes
        h_nodes -= 1

print(ans)


Failing test case input:
4 2
0
0
0
3
31
2
0

Expected output:
41


Actual output:
36


Fixed submission (verdict: Accepted):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


W,H = list(map(int, sys.stdin.readline().split()))
P = [int(sys.stdin.readline()) for _ in range(W)]
Q = [int(sys.stdin.readline()) for _ in range(H)]

edges = []
for p in P:
    edges.append((p, 'P'))
for q in Q:
    edges.append((q, 'Q'))
edges.sort()

ans = 0
a = W + 1
b = H + 1
for e, pq in edges:
    if pq == 'P':
        ans += e * b
        a -= 1
    else:
        ans += e * a
        b -= 1
print(ans)

Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h, w = map(int, input().split())

w_cost = [int(input()) for i in range(w)]
h_cost = [int(input()) for i in range(h)]

w_cost = sorted(w_cost, reverse = True)
h_cost = sorted(h_cost, reverse = True)
w_cnt = 0
h_cnt = 0
ans = 0

while True:
    if (not w_cost) and (not h_cost):
        break
    elif not w_cost:
        ans += h_cost[-1] * (w+1-w_cnt)
        h_cnt += 1    
        del h_cost[-1]
    elif not h_cost:
        ans += w_cost[-1] * (h+1-h_cnt)
        w_cnt += 1
        del w_cost[-1]
    elif w_cost[-1] < h_cost[-1]:
        ans += w_cost[-1] * (h+1-h_cnt)
        w_cnt += 1
        del w_cost[-1]
    else:
        ans += h_cost[-1] * (w+1-w_cnt)
        h_cnt += 1    
        del h_cost[-1]
        
print(ans)

Failing test case input:
4 2
0
0
0
3
31
2
0

Expected output:
41


Actual output:
36


Fixed submission (verdict: Accepted):
w, h = map(int, input().split())

w_cost = [int(input()) for i in range(w)]
h_cost = [int(input()) for i in range(h)]

w_cost = sorted(w_cost, reverse = True)
h_cost = sorted(h_cost, reverse = True)
w_cnt = 0
h_cnt = 0
ans = 0

while True:
    if not w_cost:
        ans += sum(h_cost)   
        break
    elif not h_cost:
        ans += sum(w_cost)
        break
    elif w_cost[-1] < h_cost[-1]:
        ans += w_cost[-1] * (h+1-h_cnt)
        w_cnt += 1
        del w_cost[-1]
    else:
        ans += h_cost[-1] * (w+1-w_cnt)
        h_cnt += 1
        del h_cost[-1]
        
print(ans)
Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
h, w = map(int, input().split())

w_cost = [int(input()) for i in range(w)]
h_cost = [int(input()) for i in range(h)]

w_cost = sorted(w_cost, reverse = True)
h_cost = sorted(h_cost, reverse = True)
w_cnt = 0
h_cnt = 0
ans = 0

while True:
    if not w_cost:
        ans += sum(h_cost)   
        break
    elif not h_cost:
        ans += sum(w_cost)
        break
    elif w_cost[-1] < h_cost[-1]:
        ans += w_cost[-1] * (h+1-h_cnt)
        w_cnt += 1
        del w_cost[-1]
    else:
        ans += h_cost[-1] * (w+1-w_cnt)
        h_cnt += 1
        del h_cost[-1]
        
print(ans)

Failing test case input:
2 1
0
0
-6
6
42
1
1

Expected output:
-18


Actual output:
-12


Fixed submission (verdict: Accepted):
w, h = map(int, input().split())

w_cost = [int(input()) for i in range(w)]
h_cost = [int(input()) for i in range(h)]

w_cost = sorted(w_cost, reverse = True)
h_cost = sorted(h_cost, reverse = True)
w_cnt = 0
h_cnt = 0
ans = 0

while True:
    if not w_cost:
        ans += sum(h_cost)   
        break
    elif not h_cost:
        ans += sum(w_cost)
        break
    elif w_cost[-1] < h_cost[-1]:
        ans += w_cost[-1] * (h+1-h_cnt)
        w_cnt += 1
        del w_cost[-1]
    else:
        ans += h_cost[-1] * (w+1-w_cnt)
        h_cnt += 1
        del h_cost[-1]
        
print(ans)
Problem: p03972
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    w, h = LI()
    a = IR(w + h)
    a.sort()
    acc = list(itertools.accumulate(a))[::-1]
    ans = acc[0]
    for i in range(1, w + h, 2):
        ans += acc[i]
    print(ans)
    return



if __name__ == '__main__':
    solve()


Failing test case input:
0 3
0
6
8
1
2
9
0

Expected output:
14


Actual output:
20


Fixed submission (verdict: Accepted):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10











































































def solve():
    w, h = LI()
    a = []
    x, y = 0, 1
    for _ in range(w):
        a.append((II(), x))
    for _ in range(h):
        a.append((II(), y))
    a.sort()
    plus_x = h + 1
    plus_y = w + 1
    ans = 0
    for ai, xy in a:
        if xy:
            ans += ai * plus_y
            plus_x -= 1
        else:
            ans += ai * plus_x
            plus_y -= 1
    print(ans)
    return



if __name__ == '__main__':
    solve()
Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
w,h = map(int,input().split())
arr=[]
for i in range(w):
    arr.append( (int(input()),'p') )
for i in range(h):
    arr.append( (int(input()),'q') )
arr.sort()
print(arr)
ans=0
for a in arr:
    if a[1]=='p':
        ans+=a[0]*(h+1)
        w-=1
    else:
        ans+=a[0]*(w+1)
        h-=1
print(ans)


Failing test case input:
1 4
1
1
-1
1
4
0
0

Expected output:
8


Actual output:
[(-1, 'q'), (1, 'p'), (1, 'q'), (1, 'q'), (4, 'q')]
8


Fixed submission (verdict: Accepted):
w,h = map(int,input().split())
arr=[]
for i in range(w):
    arr.append( (int(input()),'p') )
for i in range(h):
    arr.append( (int(input()),'q') )
arr.sort()

ans=0
for a in arr:
    if a[1]=='p':
        ans+=a[0]*(h+1)
        w-=1
    else:
        ans+=a[0]*(w+1)
        h-=1
print(ans)

Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
w,h = list(map(int,input().split()))
pq = []
for i in range(w):
    pq.append((int(input()),0))
for i in range(h):
    pq.append((int(input()),1))
pq.sort()
res = 0
w+=1
h+=1
dic = {0:w,1:h}

for x in pq:
    print(dic[x[1]],x[0])
    res += dic[1-x[1]]*x[0]
    dic[x[1]] -= 1

print(res)


Failing test case input:
2 2
3
9
0
7

Expected output:
29


Actual output:
3 0
3 3
2 7
2 9
29


Fixed submission (verdict: Accepted):
w,h = list(map(int,input().split()))
pq = []
for i in range(w):
    pq.append((int(input()),0))
for i in range(h):
    pq.append((int(input()),1))
pq.sort()
res = 0
w+=1
h+=1
dic = {0:w,1:h}

for x in pq:
    res += dic[1-x[1]]*x[0]
    dic[x[1]] -= 1

print(res)

Problem: p03972
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W = list(map(int, sys.stdin.readline().split()))
P = [int(sys.stdin.readline()) for _ in range(W)]
Q = [int(sys.stdin.readline()) for _ in range(H)]

edges = []
for p in P:
    edges.append((p, 'P'))
for q in Q:
    edges.append((q, 'Q'))
edges.sort()

ans = 0
v_nodes = W + 1
h_nodes = H + 1
for e, pq in edges:
    if pq == 'P':
        ans += e * h_nodes
        v_nodes -= 1
    else:
        ans += e * v_nodes
        h_nodes -= 1

print(ans)


Failing test case input:
4 2
0
0
0
3
31
2
0

Expected output:
41


Actual output:
36


Fixed submission (verdict: Accepted):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


W,H = list(map(int, sys.stdin.readline().split()))
P = [int(sys.stdin.readline()) for _ in range(W)]
Q = [int(sys.stdin.readline()) for _ in range(H)]

edges = []
for p in P:
    edges.append((p, 'P'))
for q in Q:
    edges.append((q, 'Q'))
edges.sort()

ans = 0
a = W + 1
b = H + 1
for e, pq in edges:
    if pq == 'P':
        ans += e * b
        a -= 1
    else:
        ans += e * a
        b -= 1
print(ans)
Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input=sys.stdin.readline

N=int(input())
L=[]
for i in range(N):
    n=int(input())
    L.append(n)
    
dp=[0 for i in range(N)]
dp[0]=1
D=dict()
D[L[0]]=1
for i in range(1,N):
    if L[i] not in D:
        D[L[i]]=1
        dp[i]=dp[i-1]
    else:
        if L[i]==L[i-1]:
            dp[i]=dp[i-1]
        else:
            dp[i]=dp[i-1]+D[L[i]]
            D[L[i]]+=1
print(dp[-1])

Failing test case input:
6
2
1
2
8
2
8

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
N=int(input())
L=[]
for i in range(N):
    n=int(input())
    L.append(n)

dp=[0 for i in range(N)]
dp[0]=1
mod=10**9+7
D=dict()
D[L[0]]=1
for i in range(1,N):
    if L[i]==L[i-1]:
        dp[i]=dp[i-1]
    elif L[i] not in D:
        D[L[i]]=dp[i-1]
        dp[i]=dp[i-1]
    else:
        dp[i]=dp[i-1]+D[L[i]]
        dp[i]%=mod
        D[L[i]]=dp[i]
    
print(dp[-1]%mod)

Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(input())
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = 1
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print(dp[N-1] % mod)

Failing test case input:
7
1
3
1
2
4
3
2

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(input())
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = dp[i-1]
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print(dp[N-1] % mod)
Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

INF = 10 ** 9
MOD = 10 **9 + 7

N = int(input())

C = [int(input()) for _ in range(N)]
lst = [INF] * (2 * 10 ** 5 + 10) 
ans = [1] * N
 
lst[C[-1]] = N - 1

for i in range(N - 2, -1, -1):
    c = C[i]
    if lst[c] == INF or lst[c] == i + 1:
        ans[i] = ans[i + 1]
    else:
        ans[i] = ans[i + 1] + ans[lst[c]]
    lst[c] = i

print (ans)
print (ans[0] % MOD)

Failing test case input:
6
2
2
2
8
2
8

Expected output:
3


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


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

INF = 10 ** 9
MOD = 10 **9 + 7

N = int(input())

C = [int(input()) for _ in range(N)]
lst = [INF] * (2 * 10 ** 5 + 10) 
ans = [1] * N
 
lst[C[-1]] = N - 1

for i in range(N - 2, -1, -1):
    c = C[i]
    if lst[c] == INF or lst[c] == i + 1:
        ans[i] = ans[i + 1]
    else:
        ans[i] = ans[i + 1] + ans[lst[c]]
    lst[c] = i


print (ans[0] % MOD)
Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys

MOD = 1000000007  

def solve(N, C):
    last = [-1] * (N + 1)
    pairs = []
    for i, c in enumerate(C):
        try:
            prev = last[c - 1]
        except:
            if c > N:
                return
            else:
                raise Exception()
        if prev >= 0 and prev < i - 1:
            pairs.append((prev, i))
        last[c - 1] = i
    print(0)
    return
    pairs.sort()
    count = [0] * N
    count[0] = 1
    idx = 0
    for i in range(N):
        if i > 0:
            count[i] += count[i - 1]
            count[i] %= MOD
        while idx < len(pairs) and pairs[idx][0] == i:
            count[pairs[idx][1]] += count[i]
            count[pairs[idx][1]] %= MOD
            idx += 1
    print(count[N - 1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, C)

if __name__ == '__main__':
    main()


Failing test case input:
7
4
6
2
2
8
3
2

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):

import sys

MOD = 1000000007  
MAX_N = 200000

def solve(N, C):
    last = [-1] * MAX_N
    pairs = []
    for i, c in enumerate(C):
        try:
            prev = last[c - 1]
        except:
            if c >= N:
                return
            else:
                raise Exception()
        if prev >= 0 and prev < i - 1:
            pairs.append((prev, i))
        last[c - 1] = i
    pairs.sort()
    count = [0] * N
    count[0] = 1
    idx = 0
    for i in range(N):
        if i > 0:
            count[i] += count[i - 1]
            count[i] %= MOD
        while idx < len(pairs) and pairs[idx][0] == i:
            count[pairs[idx][1]] += count[i]
            count[pairs[idx][1]] %= MOD
            idx += 1
    print(count[N - 1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, C)

if __name__ == '__main__':
    main()
Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = {}
for i in range(N):
    C[i] = int(input())
    if not C[i] in dic:
        dic[C[i]] = [ i ]
    else:
        dic[C[i]].append(i)

dp = [0] * N
dp[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i] == C[i-1]:
        continue

    for prev in dic[C[i]]:
        if prev < i:
            if prev > 0:
                dp[i] += dp[prev-1]
            else:
                dp[i] += 1

print(dp[N-1])

Failing test case input:
6
2
2
2
8
2
8

Expected output:
3


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(input())
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = dp[i-1]
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print(dp[N-1] % mod)

Problem: p03096
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n=int(input())
cc=[int(input()) for _ in range(n)]


c=[cc[0]]
for i in range(1,n):
    if cc[i]!=cc[i-1]:
        c.append(cc[i])

n=len(c)

right_index=[-1]*n
tmp_right_index=[-1]*(max(c)+1)

for i in range(n):
    if tmp_right_index[c[i]]==-1:
        tmp_right_index[c[i]]=i
    else:
        right_index[i]=tmp_right_index[c[i]]
        tmp_right_index[c[i]]=i

dp=[0]*n
mod=10**9+7
print(0,c)
for i in range(n):
    if i==0:
        dp[i]=1
    else:
        if right_index[i]==-1:
            dp[i]+=dp[i-1]%mod
        else:
            dp[i]+=dp[i-1]+dp[right_index[i]]%mod

print(dp[-1]%mod)







    



Failing test case input:
7
1
2
2
2
2
6
2

Expected output:
2


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


Fixed submission (verdict: Accepted):
n=int(input())
cc=[int(input()) for _ in range(n)]


c=[cc[0]]
for i in range(1,n):
    if cc[i]!=cc[i-1]:
        c.append(cc[i])

n=len(c)

right_index=[-1]*n
tmp_right_index=[-1]*(max(c)+1)

for i in range(n):
    if tmp_right_index[c[i]]==-1:
        tmp_right_index[c[i]]=i
    else:
        right_index[i]=tmp_right_index[c[i]]
        tmp_right_index[c[i]]=i

dp=[0]*n
mod=10**9+7

for i in range(n):
    if i==0:
        dp[i]=1
    else:
        if right_index[i]==-1:
            dp[i]+=dp[i-1]%mod
        else:
            dp[i]+=dp[i-1]+dp[right_index[i]]%mod

print(dp[-1]%mod)
Problem: p03096
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
import math
import collections
import bisect
import copy



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


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    n = ni()
    idxlist = [[] for _ in range(2 * 10 ** 5 + 1)]
    d = []
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    for i in range(n):
        di = ni()
        di -= 1
        if i > 0:
            if d[-1] == di:
                d.append(-1)
                continue
        d.append(di)
        idxlist[di].append(i)

    for i, di in enumerate(d):
        
        dp[i + 1] = dp[i]
        if di == -1:
            continue
        bidx = bisect.bisect_left(idxlist[di], i)
        if bidx - 1 >= 0:
            dp[i + 1] += dp[idxlist[di][bidx - 1] + 1]
            dp[i + 1] %= MOD

    print(dp[n])


if __name__ == '__main__':
    main()


Failing test case input:
7
1
2
2
2
2
3
2

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
import math
import collections
import bisect
import copy



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


ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))





def main():
    n = ni()
    last = [-1 for _ in range(2 * 10 ** 5 + 1)]
    dp = [INF for _ in range(n + 1)]
    dp[0] = 1

    d = [ni()-1 for _ in range(n)]

    for i, di in enumerate(d):
        dp[i + 1] = dp[i]
        if last[di] != -1:
            if i - last[di] != 1:
                dp[i + 1] += dp[last[di] + 1]
                dp[i + 1] %= MOD
        last[di] = i

    print(dp[n])


if __name__ == '__main__':
    main()

Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i-1]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1])

Failing test case input:
7
1
3
1
2
1
3
2

Expected output:
7


Actual output:
6


Fixed submission (verdict: Accepted):
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1]%mod)
Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
table = [[] for _ in range(2 * pow(10, 5) + 1)]
a = []
t = 0
mod = 10 ** 9 + 7
for i in range(N):
  x = int(input())
  if t != x:
    table[x].append(i)
    t = x
  a.append(x)

dp = [0] * N
dp[0] = 1
for i in range(N):
  j = br(table[a[i]], i)
  if j < len(table[a[i]]):
    dp[table[a[i]][j]] += dp[i]
    dp[table[a[i]][j]] %= mod
  if i + 1 < N: 
    dp[i + 1] += dp[i]
    dp[i + 1] %= mod
  
print(dp[-1])

Failing test case input:
7
4
6
2
2
8
5
2

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
from bisect import bisect_left as bl
from bisect import bisect_right as br
input = sys.stdin.readline
N = int(input())
table = [[] for _ in range(2 * pow(10, 5) + 1)]
a = []
t = 0
mod = 10 ** 9 + 7
for i in range(N):
  x = int(input())
  if t != x:
    table[x].append(i)
    t = x
  a.append(x)

dp = [0] * N
dp[0] = 1
for i in range(N):
  j = br(table[a[i]], i)
  k = bl(table[a[i]], i)
  if j < len(table[a[i]]) and (table[a[i]][k] == i):
    dp[table[a[i]][j]] += dp[i]
    dp[table[a[i]][j]] %= mod
  if i + 1 < N: 
    dp[i + 1] += dp[i]
    dp[i + 1] %= mod
  
print(dp[-1])

Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(200001)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    x[c[i]] = (x[c[i]]+num)%(10**9+7)
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)

Failing test case input:
6
1
1
2
12
3
8

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
c = [int(input()) for i in range(n)]
num,x = 1,[0]*(200001)
c.append(0)
x[c[0]]+=1
for i in range(1,n):
    if c[i]-c[i-1]: x[c[i]] = (x[c[i]]+num)%(10**9+7)
    if c[i]-c[i+1]: num = x[c[i]]
    else: num = 0
print(num)
Problem: p03096
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
C = [int(input()) for i in range(n)]
pairs = [-1]*(n+1)
data = [-1]*(2*10**5+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs[data[ci]] = i
  data[ci] = i
imos = [0] * (n+1)
for i in range(n-1,-1,-1):
  
  if pairs[i] == -1: continue
  j = pairs[i]
  ans += pow(2,imos[j])
  ans %= mod
  imos[i] += 1
  imos[i-1] += imos[i]

print((ans+1)%mod)


Failing test case input:
7
1
3
1
2
1
3
2

Expected output:
7


Actual output:
8


Fixed submission (verdict: Accepted):
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
C = [int(input()) for i in range(n)]
pairs = [-1]*(n+1)
data = [-1]*(2*10**5+1)
for i,ci in enumerate(C):
  if data[ci] != -1 and abs(i-data[ci]) != 1:
    pairs[data[ci]] = i
  data[ci] = i
imos = [0] * (n+1)
for i in range(n-1,-1,-1):
  
  if pairs[i] == -1:
    imos[i] = imos[i+1]
    
  else:
    j = pairs[i]
    imos[i] = imos[i+1] + imos[j] + 1
    imos[i] %= mod
  
  
  
print((imos[0]+1)%mod)
Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys

MOD = 1000000007  

def solve(N, C):
    last = [-1] * (N + 1)
    pairs = []
    for i, c in enumerate(C):
        try:
            prev = last[c - 1]
        except:
            return
        if prev >= 0 and prev < i - 1:
            pairs.append((prev, i))
        last[c - 1] = i
    print(0)
    return
    pairs.sort()
    count = [0] * N
    count[0] = 1
    idx = 0
    for i in range(N):
        if i > 0:
            count[i] += count[i - 1]
            count[i] %= MOD
        while idx < len(pairs) and pairs[idx][0] == i:
            count[pairs[idx][1]] += count[i]
            count[pairs[idx][1]] %= MOD
            idx += 1
    print(count[N - 1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, C)

if __name__ == '__main__':
    main()


Failing test case input:
6
2
2
2
8
2
8

Expected output:
3


Actual output:

Fixed submission (verdict: Accepted):

import sys

MOD = 1000000007  
MAX_N = 200000

def solve(N, C):
    last = [-1] * MAX_N
    pairs = []
    for i, c in enumerate(C):
        try:
            prev = last[c - 1]
        except:
            if c >= N:
                return
            else:
                raise Exception()
        if prev >= 0 and prev < i - 1:
            pairs.append((prev, i))
        last[c - 1] = i
    pairs.sort()
    count = [0] * N
    count[0] = 1
    idx = 0
    for i in range(N):
        if i > 0:
            count[i] += count[i - 1]
            count[i] %= MOD
        while idx < len(pairs) and pairs[idx][0] == i:
            count[pairs[idx][1]] += count[i]
            count[pairs[idx][1]] %= MOD
            idx += 1
    print(count[N - 1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, C)

if __name__ == '__main__':
    main()
Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def solve(N, Cs):
    counts = [-1 for _ in Cs] + [1]
    latest_c = {}
    ans = 1
    d = 10**9 + 7
    for i, c in enumerate(Cs):
        if c not in latest_c:
            latest_c[c] = i
            counts[i] = ans
        else:
            previous_i = latest_c[c]
            if previous_i != i - 1:
                ans += counts[previous_i - 1]
            ans %= d
            latest_c[c] = i
            counts[i] = ans
    return ans % d

if __name__ == "__main__":
    N = int(input())
    Cs = [int(input()) for _ in range(N)]
    print(solve(N, Cs))


Failing test case input:
5
1
2
1
2
1

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
def solve(N, Cs):
    counts = [-1 for _ in Cs] + [1]
    latest_c = {}
    ans = 1
    d = 10 ** 9 + 7
    for i, c in enumerate(Cs):
        if c not in latest_c:
            latest_c[c] = i
            counts[i] = ans
        else:
            previous_i = latest_c[c]
            if previous_i != i - 1:
                ans += counts[previous_i]
            latest_c[c] = i
            counts[i] = ans
    return ans % d

if __name__ == "__main__":
    N = int(input())
    Cs = [int(input()) for _ in range(N)]
    print(solve(N, Cs))

Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
m = 10 ** 9 + 7
d = {}
r = 1
p = 0
for _ in range(int(input())):
  c = int(input())
  if c == p:
    continue
  if c in d:
    r += d[c]
  r %= m
  d[c] = r
  p = c


Failing test case input:
6
4
1
5
8
3
1

Expected output:
2


Actual output:

Fixed submission (verdict: Accepted):
from collections import defaultdict as dd
d = dd(int)
r = 1
p = ""
for _ in range(int(input())):
  c = input()
  if c != p:
    r = (r + d[c]) % (10**9 + 7)
    d[c] = r
  p = c
print(r)
Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter, defaultdict

def compress(s):
    ret = []
    for i, si in enumerate(s):
        if i == 0:
            ret.append(si)
        else:
            if si == ret[-1]:
                continue
            else:
                ret.append(si)
                
    return ret

def removeonly1(s):
    cnt = Counter(s)
    ret = []
    
    for si in s:
        if cnt[si] == 1:
            continue
        else:
            ret.append(si)
            
    return ret

n = ni()
c = [ni() for _ in range(n)]
MOD = 10**9+7

colors = removeonly1(compress(c))


dp = [0 for _ in range(len(colors)+1)]

dp[0] = 1
idxs = defaultdict(list)

for i, ci in enumerate(colors):
    dp[i+1] = dp[i]
    
    if ci in idxs.keys():
        dp[i+1] += dp[idxs[ci][-1]]
        dp[i+1] %= MOD
        
    idxs[ci].append(i)
        
print(dp[len(colors)])

Failing test case input:
6
2
1
2
12
2
8

Expected output:
4


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter, defaultdict

def compress(s):
    ret = []
    for i, si in enumerate(s):
        if i == 0:
            ret.append(si)
        else:
            if si == ret[-1]:
                continue
            else:
                ret.append(si)
                
    return ret

def removeonly1(s):
    cnt = Counter(s)
    ret = []
    
    for si in s:
        if cnt[si] == 1:
            continue
        else:
            ret.append(si)
            
    return ret

n = ni()
c = [ni() for _ in range(n)]
MOD = 10**9+7

colors = removeonly1(compress(c))


dp = [0 for _ in range(len(colors)+1)]

dp[0] = 1
idxs = defaultdict(list)
keys = set()

for i, ci in enumerate(colors):
    dp[i+1] = dp[i]
    
    if ci in keys:
        dp[i+1] += dp[idxs[ci][-1]+1]
        dp[i+1] %= MOD
        
    idxs[ci].append(i)
    keys.add(ci)
        
print(dp[len(colors)])
Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i+1]
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Failing test case input:
6
4
2
5
2
3
2

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i]
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
N = int(input())
C = [0]
c = [int(sys.stdin.readline()) for i in range(N)]

C = C+c
ans = 1
dp = [0] * (N + 100)
color = [[]for i in range((2*(10**5)+100))]
dp[0] = 1

dp[1] = 1
color[C[1]].append(1)
for i in range(2, N+1):
    dp[i] = dp[i - 1]

    
    for col in reversed(color[C[i]]):
        
        if i - col == 1:
            break
        else:
            dp[i] += dp[col-1]
    
    color[C[i]].append(i)
    


print(dp[N] % (10 ** 9 + 7))





Failing test case input:
6
3
2
2
1
2
4

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import sys
N = int(input())
C = [0]
n = N
for i in range(1, n + 1):
    c = int(sys.stdin.readline())
    if c == C[-1]:
        N -= 1
    else:
        C.append(c)
dp = [0] * (N + 2)
dp[0] = 1
dp[1] = 1
cumsum = [0] * (2 * (10 ** 5) + 2)
cumsum[C[1]] = 1
for i in range(2, N+1):
    dp[i] = dp[i - 1] + cumsum[C[i]]
    cumsum[C[i]] += dp[i-1]
    dp[i] %= (10 ** 9 + 7)
print(dp[N])

Problem: p03096
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = {}
for i in range(N):
    C[i] = int(input())
    if not C[i] in dic:
        dic[C[i]] = [ i ]
    else:
        dic[C[i]].append(i)

dp = [0] * N
dp[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1]
    if C[i] == C[i-1]:
        continue
    for prev in dic[C[i]]:
        if prev < i:
            if prev > 0:
                dp[i] += dp[prev-1]
            else:
                dp[i] += 1
        dp[i] %= mod

print(dp[N-1] % mod)

Failing test case input:
7
1
2
2
2
2
6
2

Expected output:
2


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
C = [0] * N
mod = 10 ** 9 + 7
dic = [-1]*(2*(10**5)+1)
prevIdx = [0] * N
for i in range(N):
    C[i] = int(input())
    if i > 0 and C[i] == C[i-1]:
        continue
    prevIdx[i] = dic[C[i]]
    dic[C[i]] = i

dp = [0] * N
dp[0] = 1
acc = [0] * N
acc[0] = 1
for i in range(1,N):
    dp[i] = dp[i-1] % mod
    if C[i] == C[i-1] or prevIdx[i] == -1:
        acc[i] = dp[i-1]
        continue
    
    dp[i] += acc[prevIdx[i]]
    acc[i] = acc[prevIdx[i]] + dp[i-1]
    acc[i] %= mod
    dp[i] %= mod

print(dp[N-1] % mod)
Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
c = [int(input()) for _i in range(n)]

dic = {}
dp = [0 for _i in range(n)]
dp[0] = 1
for i in range(1, n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] += dic[c[i]]
            dic[c[i]] += dp[i-1]
        else:
            dic[c[i]] = dp[i-1] + 1
    dp[i] += dp[i-1]
print(dp[n-1])

Failing test case input:
6
3
2
2
2
3
4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1]%mod)

Problem: p03096
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
from bisect import *
def solve():
    d = defaultdict(lambda: [])
    N = int(input())
    for i in range(N):
        a = int(input())
        d[a].append(i)
    selist = []
    for l in d.values():
        for i in range(len(l)-1):
            if l[i+1]-1>l[i]:
                selist.append([l[i],l[i+1]])
    start_sort = sorted(selist)
    e_ind = {}
    for i,(s,e) in enumerate(start_sort):
        e_ind[e] = i
    ends = list(e_ind.keys())
    ends.sort()
    dp = [0]*(len(selist)+1)
    for i in range(1,len(selist)+1):
        dp[i] = dp[i-1]+1
        ind = bisect_right(ends,selist[i-1][0])
        if ind>0:
            j = e_ind[ends[ind-1]]
            dp[i] += dp[j+1]
    ans = dp[-1]+1
    return ans
print(solve())

Failing test case input:
6
4
2
3
2
4
2

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import defaultdict
from bisect import *
def solve():
    mod = 10**9+7
    d = defaultdict(lambda: [])
    N = int(input())
    for i in range(N):
        a = int(input())
        d[a].append(i)
    selist = []
    ends = [-1]
    for l in d.values():
        for i in range(len(l)-1):
            if l[i+1]-1>l[i]:
                selist.append([l[i],l[i+1]])
                ends.append(l[i+1])
    selist = [[-1,-1]]+sorted(selist,key=lambda x:x[1])
    
    
        
    
    ends.sort()
    dp = [0]*(len(selist))
    for i in range(1,len(selist)):
        dp[i] = dp[i-1]+1
        ind = bisect_right(ends,selist[i][0])
        dp[i] += dp[ind-1]
    ans = dp[-1]+1
    ans %= mod
    return ans
print(solve())
Problem: p02950
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
p = int(input())
a = list(map(int, input().split()))
MOD = p

P = p
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[n - k] * rfact[k] % MOD


b = [0] * p
for i in range(p):
    if a[i]:
        b[0] += 1
        b[0] %= MOD
        s = 1
        for j in range(p):
            b[j] -= comb(p - 1, j) * s
            b[j] %= MOD
            s *= -i
            s %= MOD

print(*b)

Failing test case input:
5
1 1 0 0 1

Expected output:
1 0 3 0 2


Actual output:
0 0 3 0 3


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
p = int(input())
a = list(map(int, input().split()))
MOD = p

P = p
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD


def comb(n, k):
    return fact[n] * rfact[n - k] * rfact[k] % MOD


b = [0] * p
for i in range(p):
    if a[i]:
        b[0] += 1
        b[0] %= MOD
        s = 1
        for j in range(p - 1, -1, -1):
            b[j] -= comb(p - 1, j) * s
            b[j] %= MOD
            s *= -i
            s %= MOD

print(*b)

Problem: p02950
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
p=int(input())
A=[int(i) for i in input().split()]
B=[0]*p

P=[[0]*p for _ in range(p)]
for i in range(1,p): 
  for j in range(p):
    if j==0:
      P[i][j]=i
    else:
      P[i][j]=(P[i][j-1]*i)%p
PP=[0]*p
for i in range(1,p):
  for j in range(1,p):
    PP[j]=(PP[j]+P[i][j])%p
for i in range(p):
  a=A[i]
  B[0]-=a
  for j in range(1,p):
    B[j]-=a*PP[j]
    if j==p-1:
      B[j]+=a
B=B[::-1]
for i in range(p):
  B[i]%=p
print(*B)

Failing test case input:
5
0 0 0 0 1

Expected output:
0 1 4 1 4


Actual output:
1 1 0 0 4


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
p=int(input())
A=[int(i) for i in input().split()]
B=[0]*p

P=[[0]*p for _ in range(p)]
for i in range(1,p): 
  for j in range(1,p):
    if j==1:
      P[i][j]=i
    else:
      P[i][j]=(P[i][j-1]*i)%p

for i in range(p):
  a=A[i]
  B[0]-=a
  for j in range(1,p):
    B[j]-=a*P[i][j]
    if j==p-1:
      B[j]+=a
B=B[::-1]
for i in range(p):
  B[i]%=p
print(*B)
Problem: p02950
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
p = int(input())
a_list = list(map(int, input().split()))
r_list = [0] * p

fact = [0] * p
fact[0] = 1
for i in range(1, p):
    fact[i] = fact[i - 1] * i % p

fact_inv = [0] * p
fact_inv[-1] = pow(fact[-1], p-2, p)
for i in range(p-2, -1 ,-1):
    fact_inv[i] = (fact_inv[i+1] * (i+1)) % p

ncr = [(fact[p-1] * fact_inv[p-1-i] * fact_inv[i]) % p for i in range(p)]

for j in range(p):
    if a_list[j] == 0:
        continue
    k = 1
    for i in range(p-1, -1, -1):
        r_list[i] -= ncr[i] * k
        r_list[i] %= p
        k *= -j
        k %= p
    r_list[0] += 1


print(*r_list)


Failing test case input:
5
0 1 0 0 1

Expected output:
0 0 3 0 3


Actual output:
5 0 3 0 3


Fixed submission (verdict: Accepted):
p = int(input())
a_list = list(map(int, input().split()))
r_list = [0] * p

fact = [0] * p
fact[0] = 1
for i in range(1, p):
    fact[i] = fact[i - 1] * i % p

fact_inv = [0] * p
fact_inv[-1] = pow(fact[-1], p-2, p)
for i in range(p-2, -1 ,-1):
    fact_inv[i] = (fact_inv[i+1] * (i+1)) % p

ncr = [(fact[p-1] * fact_inv[p-1-i] * fact_inv[i]) % p for i in range(p)]

for j in range(p):
    if a_list[j] == 0:
        continue
    k = 1
    for i in range(p-1, -1, -1):
        r_list[i] -= ncr[i] * k
        r_list[i] %= p
        k *= -j
        k %= p
    r_list[0] += 1

r_list[0] %= p
print(*r_list)

Problem: p02950
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
p = int(input())
b_list = [0 for _ in range(p)]
a_list = list(map(int,input().split()))
if a_list[0] == 1:
    a_list[0] = 0
    b_list[0] = 1
    b_list[p-1] = -1
c = 0
for i in a_list:
    if i == 1:
        for j in range(p-1):
            b_list[j+1] -= (c**(p-j-1))%p
    c += 1
for j in b_list:
    print(j % p,end = ' ')


Failing test case input:
5
1 0 1 0 1

Expected output:
1 3 0 4 2


Actual output:
1 3 3 0 3 

Fixed submission (verdict: Accepted):
p = int(input())
b_list = [0 for _ in range(p-1)]
a_list = list(map(int,input().split()))
def frac(n):
    if a_list[n] == 1:
        t = 1
        for j in range(p-1):
            b_list[j] -= t
            t = (t*n)%p
if a_list[0] == 1:
    b_list[0] -= 1
for i in range(p-1):
    frac(i+1)
b_list.reverse()
print(a_list[0],end = ' ')
for j in b_list:
    print(j % p,end = ' ')
Problem: p02950
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
p = int(input())
mod = p


def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci

frac, fraci = frac(p)



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

C = [0]*p
for i in range(p):
    a = A[i]
    for j in range(i):
        a = (a-C[j]*frac[i]*fraci[i-j])
    C[i] = fraci[i]*a%p

B = [0]*p
t = [0]*p
t[0] = 1
for i in range(1, p):
    t2 = ([0] + t)[::-1]
    t2 = [a-b*i for a, b in zip(t2, t)]
    for j in range(p):
        B[j] += t2[j]*C[i]
    t = t2[:]

B = [b%p for b in B]
print(*B)


Failing test case input:
5
0 0 0 1 1

Expected output:
0 4 0 3 3


Actual output:
3 0 0 0 2


Fixed submission (verdict: Accepted):
p = int(input())
mod = p


def frac(limit):
    frac = [1]*limit
    for i in range(2,limit):
        frac[i] = i * frac[i-1]%mod
    fraci = [None]*limit
    fraci[-1] = pow(frac[-1], mod -2, mod)
    for i in range(-2, -limit-1, -1):
        fraci[i] = fraci[i+1] * (limit + i + 1) % mod
    return frac, fraci

frac, fraci = frac(p)



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

C = [0]*p
for i in range(p):
    a = A[i]
    for j in range(i):
        a = (a-C[j]*frac[i]*fraci[i-j])
    C[i] = fraci[i]*a%p
B = [0]*p
t = [0]*p
t[0] = 1
for i in range(p):
    for j in range(p):
        B[j] += t[j]*C[i]
    t2 = ([0] + t)[:-1]
    t2 = [(a-b*i)%p for a, b in zip(t2, t)]
    t = t2[:]

B = [b%p for b in B]
print(*B)
Problem: p02974
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1
dp[(0, 1, 2)] = 1

def perm(i, j, k):

  if i < 0 or j < 0 or k < 0:
    return 0
  
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  else:
    dp[(i, j, k)] = (j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j)
    return dp[(i, j, k)]

print(perm(n-1, 0, k))

Failing test case input:
47 22

Expected output:
733787098


Actual output:
526733790780


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  if i == 0:
      if k == 0 and j == 0:
          return 1
      else:
          return 0
  elif k < 0 or j < 0 or i < j:
      return 0
  else:
    dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j))%(10**9+7)
    return dp[(i, j, k)]

print(perm(n, 0, k))

Problem: p02974
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1
dp[(0, 1, 2)] = 1

def perm(i, j, k):
  if i < 0 or j < 0 or k < 0:
    return 0
  
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  else:
    dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j))%int(10e9+7)
    return dp[(i, j, k)]

print(perm(n-1, 0, k))

Failing test case input:
47 22

Expected output:
733787098


Actual output:
6733790416


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
dp = {}

dp[(0, 0, 0)] = 1

def perm(i, j, k):
  if (i, j, k) in dp:
    return dp[(i, j, k)]
  if i == 0:
      if k == 0 and j == 0:
          return 1
      else:
          return 0
  elif k < 0 or j < 0 or i < j:
      return 0
  else:
    dp[(i, j, k)] = ((j+j+1)*perm(i-1, j, k-2*j)\
                  + (j+1)*(j+1)*perm(i-1, j+1, k-2*j)\
                  +  1*perm(i-1, j-1, k-2*j))%(10**9+7)
    return dp[(i, j, k)]

print(perm(n, 0, k))