This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
n=int(input())
L=list(map(int,input().split()))
R=list(map(int,input().split()))
G=list(map(int,input().split()))
D=list(map(int,input().split()))
K=n*[n*[7]]
t=1
for i in range(n):
#print(K)
if L[i]==-1:
K[i]=n*[0]
else:
p=K[i][L[i]+1:]
K[i]=L[i]*[0]+[1]+p
for i in range(n):
#print(K)
if R[i]==-1:
if 1 in K[i]:
t=0
break
K[i]=n*[0]
else:
p=K[i][:n-R[i]-1]
if 1 in K[i][n-R[i]:]:
t=0
break
if K[i][n-R[i]-1]==0:
t=0
break
K[i]=p+[1]+R[i]*[0]
for i in range(n):
if t==0:
break
if G[i]==0:
if K[0][i]==0:
t=0
break
K[0][i]=1
else:
#print(K)
for j in range(G[i]==-1 and n or G[i]+1):
if G[i]==-1:
if K[j][i]==1:
t=0
break
K[j][i]=0
else:
if j==G[i]:
if K[j][i]==0:
t=0
break
K[j][i]=1
else:
if K[j][i]==1:
t=0
break
K[j][i]=0
for i in range(n):
if t==0:
break
if D[i]==0:
if K[-1][i]==0:
t=0
break
K[-1][i]=1
else:
#print(K)
for j in range(D[i]==-1 and n or D[i]+1):
if D[i]==-1:
if K[n-1-j][i]==1:
t=0
break
K[n-1-j][i]=0
else:
if j==D[i]:
if K[n-1-j][i]==0:
t=0
break
K[n-1-j][i]=1
else:
if K[n-1-j][i]==1:
t=0
break
K[n-1-j][i]=0
if t: print("DA")
else: print("NE")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |