This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
input = sys.stdin.readline
n=int(input())
k=[[[[False for i in range(26)]for j in range(26)]for m in range(26)]for _ in range(26)]
c=[]
t=0
v0=[[0 for _ in range(26)]for _ in range(26)]
v1=[[0 for _ in range(26)]for _ in range(26)]
h0=[[0 for _ in range(26)]for _ in range(26)]
h1=[[0 for _ in range(26)]for _ in range(26)]
p0=[[0 for _ in range(26)]for _ in range(26)]
p1=[[0 for _ in range(26)]for _ in range(26)]
q0=[[0 for _ in range(26)]for _ in range(26)]
q1=[[0 for _ in range(26)]for _ in range(26)]
for i in range(n):
a0,a1,ax=list(map(ord,input()))
b0,b1,bx=list(map(ord,input()))
a0-=65
a1-=65
b0-=65
b1-=65
if k[b0][b1][a0][a1]:
t-=1
if k[a1][a0][b1][b0]:
t-=1
if a1==b0:
if a0==b1:
if k[a1][a0][b1][b0]:
t+=3
t-=p0[a0][b0]
t-=p1[b1][b0]
p0[b0][b1]+=1
p1[b0][a0]+=1
if a0==b1:
t-=q0[a1][a0]
t-=q1[b0][a0]
q0[a0][b0]+=1
q1[a0][a1]+=1
if a0==a1 and b0==b1:
t-=1
if a0==b0 and a1==b1:
t-=1
k[a0][a1][b0][b1]=True
v0[a0][b0]+=1
v1[a1][b1]+=1
h0[a0][a1]+=1
h1[b0][b1]+=1
for i in range(26):
for j in range(26):
t+=h0[i][j]*h1[i][j]
t+=v0[i][j]*v1[i][j]
print(t)
# | 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... |