with open('27.txt') as f:
n = int(f.readline())
cnt = 0
sp = [0] * 35
sp1 = [0] * 35
for i in range:
x = int(f.readline())
if x > 120:
cnt += sp[35 - x % 35] + sp1[35 - x % 35]
sp1[x % 35] += 1
else:
cnt += sp1[35 - x % 35]
sp[x % 35] += 1
print(cnt)
n = int(f.readline())
cnt = 0
sp = [0] * 35
sp1 = [0] * 35
for i in range:
x = int(f.readline())
if x > 120:
cnt += sp[35 - x % 35] + sp1[35 - x % 35]
sp1[x % 35] += 1
else:
cnt += sp1[35 - x % 35]
sp[x % 35] += 1
print(cnt)