ZhenlongDai/ACPR huggingface dataset:
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    
print(ans)

Failing test case input:
54
0 0 1 0 1 2 1 2 6 2 3 3 2 2 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 1 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
1152


Fixed submission (verdict: Accepted):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1
MOD = 1000000007

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    
  else:
    ans = 0
    break
    
print(ans%MOD)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

l = [0,0,0]

r = 1000000007

ans = 1

for i in range(n):
    if a[i] == l[0]:
        if a[i] == l[1]:
            if a[i] == l[2]:
                ans *= 3
            else:
                ans *= 2
        l[0] += 1
    elif a[i] == l[1]:
        if a[i] == l[2]:
            ans *= 2
        l[1] += 1
    elif a[i] == l[2]:
        l[2] += 1
    ans %= r

print(ans)

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

Expected output:
0


Actual output:
6


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

l = [0,0,0]

r = 1000000007

ans = 1

for i in range(n):
    if a[i] == l[0]:
        if a[i] == l[1]:
            if a[i] == l[2]:
                ans *= 3
            else:
                ans *= 2
        l[0] += 1
    elif a[i] == l[1]:
        if a[i] == l[2]:
            ans *= 2
        l[1] += 1
    elif a[i] == l[2]:
        l[2] += 1
    else:
        ans = 0
    ans %= r

print(ans)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
C = [0, 0, 0]  
B = 10 ** 9 + 7
ans = 1
for i in range(N):
    if A[i] in C:
        ans *= C.count(A[i])
        C[C.index(A[i])] += 1
if ans == 1:
    ans -= 1
print(ans % B)


Failing test case input:
6
0 3 1 1 3 6

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
C = [0, 0, 0]  
B = 10 ** 9 + 7
ans = 1
for i in range(N):
    if A[i] in C:
        ans *= C.count(A[i])
        C[C.index(A[i])] += 1
    else:
        ans = 0
        break
print(ans % B)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input()) 
a = list(map(int, input().split()))
a[0:0] = [-1, -1, -1]
x=1
for i in range(3,N+2):
  b=a[0:i]
  x = x*(b.count(a[i]-1)-b.count(a[i]))
  x = x % 1000000007
print(x)

Failing test case input:
6
0 1 0 1 2 5

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input()) 
a = list(map(int, input().split()))
b = [-1, -1, -1]
x=1
for i in range(N):
  x = x*b.count(a[i]-1) % 1000000007
  if b[0]==(a[i]-1):
    b[0]+=1
  elif b[1]==(a[i]-1):
    b[1]+=1
  else:
    b[2]+=1
print(x)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
C = [0, 0, 0]  
B = 10 ** 9 + 7
ans = 1
for i in range(N):
    if A[i] in C:
        ans *= C.count(A[i])
        C[C.index(A[i])] += 1
print(ans % B)


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

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
C = [0, 0, 0]  
B = 10 ** 9 + 7
ans = 1
for i in range(N):
    if A[i] in C:
        ans *= C.count(A[i])
        C[C.index(A[i])] += 1
    else:
        ans = 0
        break
print(ans % B)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(a) for a in input().split()]

mod = 10**9+7
r = 0
g = 0
b = 0

cnt = 1

for i in range(N):
    if A[i] == r:
        if r == g and r == b:
            cnt *= 3
        elif r == g or r == b:
            cnt *= 2
        r += 1
    elif A[i] == g:
        if g == b:
            cnt *= 2
        g += 1
    else:
        b += 1
    cnt %= mod
    
print(cnt)

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 13 10 13 14 11 11 12 12 20 13 14 14 15 15 15 16 16 16 17 17 13

Expected output:
0


Actual output:
7077888


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

mod = 10**9+7
r = 0
g = 0
b = 0

cnt = 1

for i in range(N):
    if A[i] == r:
        if r == g and r == b:
            cnt *= 3
        elif r == g or r == b:
            cnt *= 2
        r += 1
    elif A[i] == g:
        if g == b:
            cnt *= 2
        g += 1
    elif A[i] == b:
        b += 1
    else:
        cnt = 0
        break
        
    cnt %= mod
    
print(cnt)

Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a_=max(a)
con=[0]*(a_+1)
tou=[0]*(a_+1)
ans=[]
for i in range(len(a)):
    u=a[i]
    if u==0:
        con[0]+=1
        tou[0]+=1
        ans.append(4-con[0])

    else:
        con[u]+=1 
        tou[u]+=1  
        ans.append(min(tou[u-1],4-con[u]))
c=1
for i in range(len(ans)):
    c*=ans[i]
print(c%(10**9+7))   


Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
115295190

Actual output:
230590380


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a_=max(a)
con=[0]*(a_+1)
tou=[0]*(a_+1)
ans=[]
for i in range(len(a)):
    u=a[i]
    if u==0:
        con[0]+=1
        tou[0]+=1
        ans.append(4-con[0])

    else:
        con[u]+=1 
        tou[u]+=1  
        ans.append(min(tou[u-1]-con[u]+1,4-con[u]))
c=1
for i in range(len(ans)):
    c*=ans[i]
    c=c%(10**9+7)
print(c%(10**9+7))
Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

L = 1000000007

state = [0,0,0]

M = [0,0,0]
for a in A:
    t = None
    n = 0
    for i,s in enumerate(state):
        if s == a:
            t = i
            n += 1
    if n == 0:
        break
    M[n-1] += 1
    state[t] += 1

x = 2**30 % L
y = 3**19 % L


k = M[1] % x
l = M[2] % y
r = 2**k * 3**l % L
print(r)


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

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):

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

L = 1000000007

state = [0,0,0]

M = [0,0,0]
for a in A:
    t = None
    n = 0
    for i,s in enumerate(state):
        if s == a:
            t = i
            n += 1
    if n == 0:
        break
    M[n-1] += 1
    state[t] += 1

if n > 0:
    x = 2**30 % L
    y = 3**19 % L


    k = M[1] % x
    l = M[2] % y
    r = 2**k * 3**l % L
    print(r)
else:
    print(0)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
MOD = 10**9+7

N = int(input())
count = [0] * 3
ans = 1

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

for i in range(N):
    sames = 0
    for j in range(3):
        if A[i] == count[j]:
            sames += 1

    if sames == 0:
        break

    ans *= sames
    ans %= MOD

    for j in range(3):
        if A[i] == count[j]:
            count[j] += 1
            break
print(ans)



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

Expected output:
0


Actual output:
1


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

N = int(input())
count = [0] * 3
ans = 1

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

for i in range(N):
    sames = 0
    for j in range(3):
        if A[i] == count[j]:
            sames += 1

    if sames == 0:
        ans = 0
        break

    ans *= sames
    ans %= MOD

    for j in range(3):
        if A[i] == count[j]:
            count[j] += 1
            break
print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    
    
print(ans%p)




Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 7 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
73728


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    
    
if flag==1:
    print(ans%p)
else:
    print(flag)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    print(b)
    
print(ans)

Failing test case input:
54
0 0 1 0 1 4 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 23 17 17 17

Expected output:
0


Actual output:
3
2
2
1
2
1
3
2
2
1
1
2
1
1
1
1
1
1
1
1
1
2
1
2
1
2
1
1
1
1
1
1
1
2
1
2
1
2
1
36864


Fixed submission (verdict: Accepted):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1
MOD = 1000000007

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    
  else:
    ans = 0
    break
    
print(ans%MOD)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
MOD=1000000007
hats=[0,0,0]
ans=1
for i in range(n):
    ai=a[i]
    ans=((ans%MOD)*hats.count(ai))%MOD
    if(ans==0):
        break
    hats[hats.index(ai)]+=1
    print(ai,ans,hats)
print(ans%MOD)


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

Expected output:
0


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


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
MOD=1000000007
hats=[0,0,0]
ans=1
for i in range(n):
    ai=a[i]
    ans=((ans%MOD)*hats.count(ai))%MOD
    if(ans==0):
        break
    hats[hats.index(ai)]+=1

print(ans%MOD)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from copy import deepcopy

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

    t = [[0,0,0]]

    total = 1
    for i in range(n):
        count = 0
        for j in range(3):
            if t[i][j] == a[i]:
                count +=1
        for j in range(3):
            if t[i][j] == a[i]:
                tmp = deepcopy(t[i])
                tmp[j] += 1
                t.append(tmp)
                break
        
        if count == 0:
            return 0
        total *= count
    return total

if __name__ == "__main__":
    print(main())

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
115295190

Actual output:
6115295232


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = list(map(int, input().split()))

    t = [0,0,0]

    total = 1
    for i in range(n):
        count = 0
        for j in range(3):
            if t[j] == a[i]:
                count +=1
        for j in range(3):
            if t[j] == a[i]:
                t[j] += 1
                break
        if count == 0:
            return 0
        total *= count
    return total%1000000007

if __name__ == "__main__":
    print(main())
Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask == 0:
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)


Failing test case input:
6
1 0 2 2 11 6

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask==0:
        Ans=0
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)

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

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    ans %= mod
    for i in range(3):
      if caps[i] == a:
        caps[i] += 1
print(ans)


Failing test case input:
3
0 0 0

Expected output:
6

Actual output:
0


Fixed submission (verdict: Accepted):
import sys

readline = sys.stdin.buffer.readline
n = int(readline())
A = map(int, readline().split())
mod = 1000000007

caps = [0] * 3
ans = 1
for a in A:
    ans *= caps.count(a)
    
    for i in range(3):
        if caps[i] == a:
            caps[i] += 1
            break
    ans %= mod
print(ans)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
MOD = 1000000007

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

res = 1
values = [0, 0, 0]

for e in a:
    yo = 0
    for v in values:
        if v == e:
            yo += 1
    if yo > 1:
        res = (res * yo) % MOD

    for i in range(3):
        if values[i] == e:
            values[i] += 1
            break

print(res)


Failing test case input:
6
0 1 0 1 2 5

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
MOD = 1000000007

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

res = 1
values = [0, 0, 0]
last = 0

for e in a:
    yo = 0
    for (i, v) in enumerate(values):
        if v == e:
            yo += 1
            last = i

    if yo == 0:
        res = 0
        break


    res = (res * yo) % MOD

    values[last] += 1

print(res)
Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
alist=[int(i) for i in input().split()]

zeros=0
answer=1
triple=[0,0,0]

for i in range(n):
    now=alist[i]
    if now==triple[0]:
        if now==triple[1]:
            if now==triple[2]:
                answer*=3
            else:
                answer*=2
        triple[0]+=1
    else:
        if now==triple[1]:
            if now==triple[2]:
                answer*=2
            triple[1]+=1
        else:
            triple[2]+=1
    answer%=(1000000007)

print(answer)

Failing test case input:
6
0 3 1 1 3 6

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
alist=[int(i) for i in input().split()]

zeros=0
answer=1
triple=[0,0,0]

for i in range(n):
    now=alist[i]
    if now==triple[0]:
        if now==triple[1]:
            if now==triple[2]:
                answer*=3
            else:
                answer*=2
        triple[0]+=1
    else:
        if now==triple[1]:
            if now==triple[2]:
                answer*=2
            triple[1]+=1
        else:
            if now==triple[2]:
                triple[2]+=1
            else:
                answer=0
    answer%=(1000000007)

print(answer)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a = [int(i) for i in input().split()]
mod = 10**9+7
ans = 3

red=1
gre=0
blu=0
for i in range(1,n):
    temp=0
    if a[i] == red:
        temp+=1
    if a[i] == gre:
        temp+=1        
    if a[i] == blu:
        temp+=1
    if temp!=0:
        ans*=temp
    
        ans=ans%mod
    if a[i]==red:
        red+=1
        continue
    if a[i]==gre:
        gre+=1
        continue
    if a[i]==blu:
        blu+=1
        continue
    
    
print(ans)

Failing test case input:
54
0 0 1 0 1 4 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 23 17 17 17

Expected output:
0


Actual output:
36864


Fixed submission (verdict: Accepted):
n=int(input())
a = [int(i) for i in input().split()]
mod = 10**9+7
ans = 3

red=1
gre=0
blu=0
for i in range(1,n):
    temp=0
    if a[i] == red:
        temp+=1
    if a[i] == gre:
        temp+=1        
    if a[i] == blu:
        temp+=1
    if temp!=0:
        ans*=temp
    
        ans=ans%mod
    if a[i]==red:
        red+=1
        continue
    if a[i]==gre:
        gre+=1
        continue
    if a[i]==blu:
        blu+=1
        continue
    else:
      ans=0
    
if a[0]!=0:
  ans=0
    
print(ans)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
A = list(map(int,input().split()))
lis = [0]*200000
ans=1
num_zero=0
mod = 1000000007
for i in A:
  lis[i]+=1
  if i!=0:
    ans*lis[i-1]
    lis[i-1]-=1
    ans%=mod
    if lis[i-1]<0:
      ans=0
      break
    
  else:
    num_zero+=1

if num_zero>=2:
  mul = 6
  
else:
  mul = 3
  
print((ans*mul)%mod)

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
115295190

Actual output:
6


Fixed submission (verdict: Accepted):
N=int(input())
A = list(map(int,input().split()))
lis = [0]*200000
ans=1
num_zero=0
mod = 1000000007
for i in A:
  lis[i]+=1
  if i!=0:
    ans*=lis[i-1]
    lis[i-1]-=1
    ans%=mod
    if lis[i-1]<0:
      ans=0
      break
    
  else:
    num_zero+=1

if (num_zero==2)or(num_zero==3):
  mul = 6
  
elif num_zero==1:
  mul = 3

else:
  mul = 0
  
print((ans*mul)%mod)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans *= cnt
    ans %= mod
print(ans%mod)

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

Expected output:
0


Actual output:
0
1


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans = ans*cnt%mod
else:
    print(ans%mod)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mod = 1000000007
memo = [[] for i in range(m+1)]
d = {}
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if ai - 1 in d:
        memo[ai].append(d[ai-1])
    else:
        memo[ai].append(3)
ans = 1
for l in memo:
    i = 0
    for li in l:
        ans = ans * (li - i) %  mod
        i += 1
print(ans)


Failing test case input:
6
1 15 3 2 5 6

Expected output:
0


Actual output:
81


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mod = 1000000007
memo = [[] for i in range(m+1)]
d = {-1: 3}
ans = 1
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if ai - 1 in d:
        memo[ai].append(d[ai-1])
    else:
        ans  = 0
for l in memo:
    i = 0
    for li in l:
        ans = ans * (li - i) %  mod
        i += 1
print(ans)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1
MOD = 1000000007

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    
print(ans%MOD)

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

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
List=list(map(int,input().split()))

arr = [0,0,0]
ans = 1
MOD = 1000000007

for i in range(len(List)):
  a = List[i]
  
  b = arr.count(a)
  
  if b > 0:
    j = arr.index(a)
    arr[j] = a + 1
    
    ans = ans * b
    
  else:
    ans = 0
    break
    
print(ans%MOD)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    if (A - 1) is not rbg:
        ans = 0
        break
    rbg[rbg.index(A - 1)] = A

print(ans)


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

Expected output:
6


Actual output:
0


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

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    for i in range(3):
        if rbg[i] == A - 1:
            rbg[i] = A
            break

print(ans)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
MOD = 1000000007

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

res = 1
values = [0, 0, 0]
last = 0

for e in a:
    yo = 0
    for (i, v) in enumerate(values):
        if v == e:
            yo += 1
            last = i

    if yo > 1:
        res = (res * yo) % MOD

    values[last] += 1

print(res)


Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 3 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 11

Expected output:
0


Actual output:
589824


Fixed submission (verdict: Accepted):
MOD = 1000000007

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

res = 1
values = [0, 0, 0]
last = 0

for e in a:
    yo = 0
    for (i, v) in enumerate(values):
        if v == e:
            yo += 1
            last = i

    if yo == 0:
        res = 0
        break


    res = (res * yo) % MOD

    values[last] += 1

print(res)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
l = [0] * 3
ans = 1

for a in A:
    count = 1
    flag = False
    for i in range(3):
        if l[i] == a:
            if flag:
                count += 1
            else:
                flag = True
                l[i] += 1
    ans *= count

print(ans% mod)




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

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
mod = 1000000007
l = [0] * 3
ans = 1

for a in A:
    
    ans *= l.count(a)
    for i in range(3):
        if l[i] == a:
            l[i] += 1
            break

print(ans% mod)

Problem: p02845
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
mod = 1000000007

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

d = {-1:3}
ans = 1
for a in A:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1
    if a-1 in d:
        ans = ans*d[a-1]%mod
        d[a-1] -= 1


print(ans)

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

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
mod = 1000000007

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

d = {-1:3}
ans = 1
for a in A:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1
    if a-1 not in d:
        print(0)
        exit()
    ans = ans*d[a-1]%mod
    d[a-1] -= 1


print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans = ans*cnt%mod
print(ans%mod)

Failing test case input:
54
0 0 1 0 1 4 1 2 6 2 3 3 2 4 5 4 6 10 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 14 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 23 17 17 17

Expected output:
0


Actual output:
0
24


Fixed submission (verdict: Accepted):
N = int(input())
As = list(map(int, input().split()))
mod = 10**9+7

dp = [[0]*3 for _ in range(N+1)]
ans = 1
for i in range(N):
    a = As[i]
    dplis = dp[i]
    cnt = 0
    dp[i+1] = dplis[:]
    for j, d in enumerate(dplis):
        if a==d:
            cnt += 1
            if cnt==1:
                dp[i+1][j] = a+1
    if cnt==0:
        print(0)
        break
    ans = ans*cnt%mod
else:
    print(ans%mod)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input()) 
a = list(map(int, input().split()))
a[0:0] = [-1, -1, -1]
x=1
for i in range(3,N+2):
  b=a[0:i]
  x = x*(b.count(a[i]-1)-b.count(a[i]))
x = x % 1000000007
print(x)

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

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input()) 
a = list(map(int, input().split()))
b = [-1, -1, -1]
x=1
for i in range(N):
  x = x*b.count(a[i]-1) % 1000000007
  if b[0]==(a[i]-1):
    b[0]+=1
  elif b[1]==(a[i]-1):
    b[1]+=1
  else:
    b[2]+=1
print(x)

Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask==0:
        Ans=0
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
    print(C)
print(Ans)


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

Expected output:
0


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


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask==0:
        Ans=0
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
mod = 10 ** 9 + 7

N = int(input())

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

lis = [0,0,0]
ans = 1

for i in range(N):

    na = A[i]
    ind = 0
    nn = 0

    for j in range(3):
        if lis[j] == na:
            nn += 1
            ind = j

    lis[ind] += 1

    if nn == 2:
        ans *= 2
    elif nn == 3:
        ans *= 3

    ans %= mod
    

print (ans)


Failing test case input:
54
0 0 1 0 1 4 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
127401984


Fixed submission (verdict: Accepted):
mod = 10 ** 9 + 7

N = int(input())

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

lis = [0,0,0]
ans = 1

for i in range(N):

    na = A[i]
    ind = 0
    nn = 0

    for j in range(3):
        if lis[j] == na:
            nn += 1
            ind = j

    lis[ind] += 1

    if nn == 0:
        ans *= 0

    elif nn == 2:
        ans *= 2
    elif nn == 3:
        ans *= 3

    ans %= mod
    

print (ans % mod)
Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a_=max(a)
con=[0]*(a_+1)
tou=[0]*(a_+1)
ans=[]
for i in range(len(a)):
    u=a[i]
    if u==0:
        con[0]+=1
        tou[0]+=1
        ans.append(4-con[0])

    else:
        con[u]+=1 
        tou[u]+=1  
        ans.append(min(tou[u-1],4-con[u]))
c=1
for i in range(len(ans)):
    c*=ans[i]
print(c%(10**9+7))   
print(ans) 

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

Expected output:
0


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


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a_=max(a)
con=[0]*(a_+1)
tou=[0]*(a_+1)
ans=[]
for i in range(len(a)):
    u=a[i]
    if u==0:
        con[0]+=1
        tou[0]+=1
        ans.append(4-con[0])

    else:
        con[u]+=1 
        tou[u]+=1  
        ans.append(min(tou[u-1]-con[u]+1,4-con[u]))
c=1
for i in range(len(ans)):
    c*=ans[i]
    c=c%(10**9+7)
print(c%(10**9+7))

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
A=[int(i) for i in input().split()]
X=[-1,-1,-1]
ans=1
mod=10**9+7
for i in range(N):
    tmp=0
    for j in range(3):
        if X[j]==A[i]-1:
            tmp+=1
    for j in range(3):
        if X[j]==A[i]-1:
            ans=tmp*ans
            ans%=mod
            X[j]+=1
            break
print(ans)


Failing test case input:
6
0 1 0 1 2 5

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
N=int(input())
A=[int(i) for i in input().split()]
X=[-1,-1,-1]
ans=1
mod=10**9+7
for i in range(N):
    tmp=0
    if A[i]>i:
        ans=0
    for j in range(3):
        if X[j]==A[i]-1:
            tmp+=1
    for j in range(3):
        if X[j]==A[i]-1 or tmp==0:
            ans=tmp*ans
            ans%=mod
            X[j]+=1
            break
print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
MOD = 10**9+7

N = int(input())
count = [0] * 3
ans = 1

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

for i in range(N):
    sames = 0
    for j in range(3):
        if A[i] == count[j]:
            sames += 1

    if sames == 0:
        print(0)
        break

    ans *= sames
    ans %= MOD

    for j in range(3):
        if A[i] == count[j]:
            count[j] += 1
            break
print(ans)



Failing test case input:
6
0 2 2 1 5 6

Expected output:
0


Actual output:
0
3


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

N = int(input())
count = [0] * 3
ans = 1

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

for i in range(N):
    sames = 0
    for j in range(3):
        if A[i] == count[j]:
            sames += 1

    if sames == 0:
        ans = 0
        break

    ans *= sames
    ans %= MOD

    for j in range(3):
        if A[i] == count[j]:
            count[j] += 1
            break
print(ans)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(j) for j in input().split()]
mod=10**9+7
ans=1
from collections import Counter
c=Counter()
for i in a:
    if c[i-1]==0:
        ans*=(3-c[i])
    else:
        ans*=(c[i-1]-c[i])
    c[i]+=1
    ans%=mod
print(ans)

Failing test case input:
6
0 1 0 1 4 7

Expected output:
0


Actual output:
54


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(j) for j in input().split()]
mod=10**9+7
ans=1
from collections import Counter
c=Counter()
c[0]+=3
for i in a:
    ans*=c[i]
    if ans==0:
        break
    c[i]-=1
    c[i+1]+=1
    ans%=mod
print(ans)

Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

MOD = 1000000007


C=[0,0,0]
ans=1
for a in A:
    
    found=False
    count=C.count(a)
    if count==0:
        print(0)
        exit()
    
    C[C.index(a)]+=1
    
    ans=ans*count%MOD
    print(count)

print(ans)

Failing test case input:
6
0 5 1 2 3 6

Expected output:
0


Actual output:
3
0


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

MOD = 1000000007


C=[0,0,0]
ans=1
for a in A:
    
    found=False
    count=C.count(a)
    if count==0:
        print(0)
        exit()
    
    C[C.index(a)]+=1
    
    ans=ans*count%MOD

print(ans)

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


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    
    N = read_int()
    A = read_ints()
    T = [0, 0, 0]
    answer = 1
    modulo = 1000000007
    for a in A:
        if a not in T:
            return -1
        answer = (answer*T.count(a))%modulo
        T[T.index(a)] += 1
    return answer


if __name__ == '__main__':
    print(solve())


Failing test case input:
54
0 0 1 1 1 4 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
-1


Fixed submission (verdict: Accepted):


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    
    N = read_int()
    A = read_ints()
    T = [0, 0, 0]
    answer = 1
    modulo = 1000000007
    for a in A:
        if a not in T:
            return 0
        answer = (answer*T.count(a))%modulo
        T[T.index(a)] += 1
    return answer


if __name__ == '__main__':
    print(solve())
Problem: p02845
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

m = 10**9+7
r, b, g = 0, 0, 0
ans = 1

for aa in a:
    if aa == r == b == g:
        ans *= 3
    elif aa == r == b or aa == b == g or aa == g == r:
        ans *= 2
    ans %= m

    aa += 1
    if aa > r:
        r = aa
    elif aa > b:
        b = aa
    elif aa > g:
        g = aa

print(ans%m)

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

Expected output:
0


Actual output:
3


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

m = 10**9+7
r, b, g = 0, 0, 0
ans = 1

for aa in a:
    if aa == r == b == g:
        ans *= 3
    elif aa == r == b or aa == b == g or aa == g == r:
        ans *= 2
    elif aa != r and aa != b and aa != g:
        print(0)
        exit()
    ans %= m

    aa += 1
    if aa > r:
        r = aa
    elif aa > b:
        b = aa
    elif aa > g:
        g = aa

print(ans%m)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
A=[int(i) for i in input().split()]
X=[-1,-1,-1]
ans=1
mod=10**9+7
for i in range(N):
    tmp=0
    if A[i]>i:
        ans=0
    for j in range(3):
        if X[j]==A[i]-1:
            tmp+=1
    for j in range(3):
        if X[j]==A[i]-1:
            ans=tmp*ans
            ans%=mod
            X[j]+=1
            break
print(ans)


Failing test case input:
54
0 0 1 0 1 4 1 2 6 2 3 3 2 4 5 4 6 5 7 8 5 6 6 7 7 7 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 9 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
36864


Fixed submission (verdict: Accepted):
N=int(input())
A=[int(i) for i in input().split()]
X=[-1,-1,-1]
ans=1
mod=10**9+7
for i in range(N):
    tmp=0
    if A[i]>i:
        ans=0
    for j in range(3):
        if X[j]==A[i]-1:
            tmp+=1
    for j in range(3):
        if X[j]==A[i]-1 or tmp==0:
            ans=tmp*ans
            ans%=mod
            X[j]+=1
            break
print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
mod=1000000007

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

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1

print(ans%mod)

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 20 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
113246208


Fixed submission (verdict: Accepted):
mod=1000000007

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

ans=1
c1=c2=c3=0
for Ai in A:
    if c1==c2==c3==Ai:
        c1+=1
        ans=ans*3%mod
    elif c1==c2==Ai:
        c1+=1
        ans=ans*2%mod
    elif c2==c3==Ai:
        c2+=1
        ans=ans*2%mod
    elif c1==Ai:
        c1+=1
    elif c2==Ai:
        c2+=1
    elif c3==Ai:
        c3+=1
    else:
        ans=0
        break

print(ans)
Problem: p02845
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
rbg = [0, 0, 0]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A)
    ans %= mod
    if A is not rbg:
        ans = 0
        break
    rbg[rbg.index(A)] += 1

print(ans)


Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 13 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
115295190

Actual output:
0


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

n = int(input())
a = list(map(int, input().split()))
rbg = [-1, -1, -1]
ans = 1
mod = 10 ** 9 + 7

for A in a:
    ans *= rbg.count(A - 1)
    ans %= mod
    for i in range(3):
        if rbg[i] == A - 1:
            rbg[i] = A
            break

print(ans)

Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask == 0:
        continue
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)


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

Expected output:
0


Actual output:
6


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
C = [0,0,0]
Ans = 1
MOD = 1000000007
for a in A:
    ask = C.count(a)
    if ask==0:
        Ans=0
        break
    ind = C.index(a)
    C[ind] += 1
    Ans = (Ans*ask)%MOD
print(Ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
now = 0

c = [0 for k in range(max(A)+2)]
ans = 1
MOD = 1000000007

for k in range(N):
    c[A[k]] += 1
    ans *= c[A[k]]-c[A[k]+1]
    ans %= MOD
print(ans)


Failing test case input:
6
0 0 1 8 11 6

Expected output:
0


Actual output:
2


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

c = [0 for k in range(max(A)+2)]
ans = 1
MOD = 1000000007

c[0] = 3
for k in range(N):
    ans *= c[A[k]] - c[A[k]+1]
    c[A[k]+1] += 1
    ans %= MOD

print(ans)
Problem: p02845
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
    x = 0
    cnt = 0
    for j, g in enumerate(G):
        if g == A[i]:
            x = j if cnt == 0 else x
            cnt += 1
    
    G[x] += 1
    ans *= cnt
    ans = ans % mod
    print(i, G)

print(ans)

Failing test case input:
54
0 0 1 0 1 2 1 2 3 2 3 3 4 4 5 4 6 5 7 8 5 6 6 7 7 8 8 9 9 10 10 11 9 12 10 13 14 11 11 12 12 20 13 14 14 15 15 15 16 16 16 17 17 17

Expected output:
0


Actual output:
0 [1, 0, 0]
1 [1, 1, 0]
2 [2, 1, 0]
3 [2, 1, 1]
4 [2, 2, 1]
5 [3, 2, 1]
6 [3, 2, 2]
7 [3, 3, 2]
8 [4, 3, 2]
9 [4, 3, 3]
10 [4, 4, 3]
11 [4, 4, 4]
12 [5, 4, 4]
13 [5, 5, 4]
14 [6, 5, 4]
15 [6, 5, 5]
16 [7, 5, 5]
17 [7, 6, 5]
18 [8, 6, 5]
19 [9, 6, 5]
20 [9, 6, 6]
21 [9, 7, 6]
22 [9, 7, 7]
23 [9, 8, 7]
24 [9, 8, 8]
25 [9, 9, 8]
26 [9, 9, 9]
27 [10, 9, 9]
28 [10, 10, 9]
29 [11, 10, 9]
30 [11, 11, 9]
31 [12, 11, 9]
32 [12, 11, 10]
33 [13, 11, 10]
34 [13, 11, 11]
35 [14, 11, 11]
36 [15, 11, 11]
37 [15, 12, 11]
38 [15, 12, 12]
39 [15, 13, 12]
40 [15, 13, 13]
41 [16, 13, 13]
42 [16, 14, 13]
43 [16, 15, 13]
44 [17, 15, 13]
45 [17, 16, 13]
46 [18, 16, 13]
47 [19, 16, 13]
48 [19, 17, 13]
49 [20, 17, 13]
50 [21, 17, 13]
51 [21, 18, 13]
52 [22, 18, 13]
53 [23, 18, 13]
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
G = [0]*3
ans = 1
for i in range(N):
    x = 0
    cnt = 0
    for j, g in enumerate(G):
        if g == A[i]:
            x = j if cnt == 0 else x
            cnt += 1
    
    G[x] += 1
    ans *= cnt
    ans = ans % mod

print(ans)

Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

cnt = [0] * (max(A) + 2)
cnt[-1] = 1
ans = 1
for a in A:
    if a == 0:
        cnt[0] += 1
        continue
    ans = (ans * (cnt[a - 1] - cnt[a])) % mod
    cnt[a] += 1

if max(cnt) == 1:
    print((ans*3) % mod)
elif max(cnt) == 3:
    print((ans * 6) % mod)
elif max(cnt) == 2:
    print((ans * 3) % mod)
else:
    print(0)


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

Expected output:
6


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7

cnt = [0] * (max(A) + 2)
cnt[-1] = 1
ans = 1
for a in A:
    if a == 0:
        cnt[0] += 1
        continue
    ans = (ans * (cnt[a - 1] - cnt[a])) % mod
    cnt[a] += 1

if max(cnt) == 1:
    print((ans*3) % mod)
elif max(cnt) == 3:
    print((ans * 6) % mod)
elif max(cnt) == 2:
    print((ans * 6) % mod)
else:
    print(0)
Problem: p02845
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = 1
p = [0,0,0]  
mod = 10**9+7
for i in range(n-1):
    q = 0
    for j in range(3):
        if p[j] == a[i]:
            q +=1
    for k in range(3):
        if p[k] == a[i]:
            p[k] += 1
            break
    ans = ans*q%mod
print(ans%mod)

Failing test case input:
6
0 1 0 1 2 5

Expected output:
0


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
ans = 1
p = [0,0,0]  
mod = 10**9+7
for i in range(n):
    q = 0
    for j in range(3):
        if p[j] == a[i]:
            q +=1
    for k in range(3):
        if p[k] == a[i]:
            p[k] += 1
            break
    ans = ans*q%mod
print(ans%mod)
Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
n = int(input())
l = list(map(int,input().split()))

a = 0
for i in itertools.permutations(l,3):
    if i[0] < i[1] and i[1] < i[2] and i[2]*i[2] == i[0]*i[0] + i[1]*i[1]:
        a += 1

print(a)


Failing test case input:
10
16 4 3 1 2 12 13 1 13 0

Expected output:
11


Actual output:
0


Fixed submission (verdict: Accepted):
import itertools
n = int(input())
l = list(map(int,input().split()))

a = 0
for i in itertools.permutations(l,3):
    if i[0] < i[1] and i[1] < i[2] and i[0] + i[1] > i[2] and i[0] + i[2] > i[0] and i[1] + i[2] > i[0]:
        a += 1

print(a)

Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import itertools
n=int(input())
length=list(map(int,input().split()))
combination=list(itertools.combinations(length,3))
new_list=[]
for com in combination:
    a=com[0]
    b=com[1]
    c=com[2]
    if a!=b and b!=c:
        if com[0]+com[1]>com[2] and com[1]+com[2]>com[0] and com[0]+com[2]>com[1]:
            new_list.append(com)
        else:
            continue
print(len(new_list))

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

Expected output:
3


Actual output:
7


Fixed submission (verdict: Accepted):
import itertools
n=int(input())
length=list(map(int,input().split()))
combination=list(itertools.combinations(length,3))
new_list=[]
for com in combination:
    a=com[0]
    b=com[1]
    c=com[2]
    if a!=b and b!=c and a!=c:
        if com[0]+com[1]>com[2] and com[1]+com[2]>com[0] and com[0]+com[2]>com[1]:
            new_list.append(com)
        else:
            continue
print(len(new_list))

Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
L=list(map(int,input().split()))
a=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if L[i]!=L[j]:
            for k in range(j+1,n):
                
                
                if L[i]!=L[k] and L[j]!=L[k] and L[i]>L[j]+L[k] and L[j]>L[i]+L[k] and L[k]>L[j]+L[i]:
                    a+=1
                    
                    

print(a)


Failing test case input:
10
16 7 3 2 2 12 10 1 17 0

Expected output:
13


Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
l=list(map(int,input().split()))
 
ans=0
for i in range(0,n):
    for j in range(i+1,n):
        for k in range(j+1,n):
 
            if l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
                if  l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]:
                    ans+=1
 
print(ans)
Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
count = 0
N = int(input())
L = list(map(int, input().split())) 
L.sort(reverse=True) 
for i in range(0, N-2):
    for j in range(1, N-1):
        for k in range(2, N-1):
            if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                count += 0
            elif L[i] < L[j] + L[k]:
                
                count += 1
print(count)

Failing test case input:
6
1 5 7 11 12 1

Expected output:
3


Actual output:
10


Fixed submission (verdict: Accepted):
count = 0
N = int(input())
L = list(map(int, input().split())) 
L.sort(reverse=True) 
for i in range(0, N-2): 
    for j in range(i, N-1):
        for k in range(j, N):
            if L[i] == L[j] or L[j] == L[k] or L[i] == L[k]:
                count += 0
            elif L[i] < L[j] + L[k]:
                
                count += 1
print(count)

Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
count=0

a=list(map(int,input().split()))
a.sort()
print(a)
if N>=3:
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                if a[i]!=a[j]!=a[k]!=a[i]:
                    if a[k]<a[i]+a[j]:
                            count+=1
                        
print(count)

Failing test case input:
5
1 -9 0 1 0

Expected output:
0


Actual output:
[-9, 0, 0, 1, 1]
0


Fixed submission (verdict: Accepted):
N=int(input())
count=0

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

if N>=3:
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                if a[i]!=a[j]!=a[k]!=a[i]:
                    if a[k]<a[i]+a[j]:
                            count+=1
                        
print(count)

Problem: p02583
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
L = list(map(int, input().split()))
 
ans = 0
if(N >= 3):
  t = []
  for i in range(N):
    for j in range(i+1, N):
      for k in range(j+1, N):
        if((abs(L[j]-L[k]) < L[i]) & (L[i] < L[j]+L[k])): t.append((L[i], L[j], L[k]))
  ans = len(set(t))

print(ans)

Failing test case input:
6
0 5 7 7 7 5

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
N = int(input())
L = list(map(int, input().split()))
 
ans = 0
if(N >= 3):
  t = []
  for i in range(N):
    for j in range(i+1, N):
      for k in range(j+1, N):
        if((L[i] != L[j]) & (L[i] != L[k]) & (L[j] != L[k]) & (abs(L[j]-L[k]) < L[i]) & (L[i] < L[j]+L[k])): t.append((L[i], L[j], L[k]))
  ans = len(t)

print(ans)