Buggy python submission (verdict: Runtime Error):
from numpy import*
n,M=map(int,input().split())
l=n*3+1
d=zeros(l,n*5)
d[0][0]=1
for i in range(1,l):j,k=i-1,i-2;d[i]=(d[i-3]*k*j+roll(d[k],-1)*j+roll(d[j],1))%M
print(sum(d[-1][:l])%M)


Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

Buggy python submission (verdict: Runtime Error):
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):j,k=i-1,j-1;d[i]=(d[i-3]*(k)*(j)+p.roll(d[k],-1)*(i-1)+p.roll(d[j],1))%M
print(d[-1][:l].sum()%M)

Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

Buggy python submission (verdict: Runtime Error):
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):
  d[i]=(d[i-3]*(i-2)*(i-1)+p.roll(p[i-2],-1)*(i-1)+p.roll(d[i-1],1))%M
print(d[-1][:l].sum()%M)

Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

Buggy python submission (verdict: Runtime Error):
import numpy as p
n,M=map(int,input().split())
l=n*3+1
d=p.zeros((l,n*5),p.int64)
d[0][0]=d[1][1]=d[2][2]=d[2][-1]=1
for i in range(3,l):
  d[i]=(d[i-3]*(i-2)*(i-1)+p.roll(p[i-2],-1)*(i-1)+p.roll(d[i-1],1))%M
print(d[-1][:l].sum()%M)


Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
N=3*n
d=[[0]*(N+1) for i in range(N+4)]
d[0][0]=1
for i in range(N):
  a,b,c,d=d[i:i+4]
  for j in range(N):
    b[j]=(b[j]+a[j])%m
    c[j+1]=(c[j+1]+a[j]*(i+1))%m
    d[j+1]=(d[j+1]+a[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)


Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,open(0))
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(1,n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j]+d0[j]*(i-1))%m
    d3[j+1]=(d3[j]+d0[j]*(i-1)*(i-2))%m
print(sum(d[n3][:n+1])%m)

Fixed submission:
n,m=map(int,input().split())
n3=3*n
x=lambda a,b:(a+b)%mod
d=[[0]*(n+2) for i in range(n3+4)]
d[0][0]=1
for i in range(n3):
  d0,d1,d2,d3=d[i:i+4]
  for j in range(n+1):
    d1[j]=(d1[j]+d0[j])%m
    d2[j+1]=(d2[j+1]+d0[j]*(i+1))%m
    d3[j+1]=(d3[j+1]+d0[j]*(i+1)*(i+2))%m
print(sum(d[n3][:n+1])%m)