#P14745. [ICPC 2021 Seoul R] Trio

[ICPC 2021 Seoul R] Trio

题目描述

Let AA be any set of nn natural numbers whose decimal representations consist of exactly four digits without 00 in any decimal place.

A trio is a set of three numbers {a,b,c}\{a, b, c\} chosen from AA such that the following conditions are fulfilled simultaneously:

  • The ones decimals of three numbers a,b,ca, b, c are either all equal or all distinct.
  • The tens decimals of three numbers a,b,ca, b, c are either all equal or all distinct.
  • The hundreds decimals of three numbers a,b,ca, b, c are either all equal or all distinct.
  • The thousands decimals of three numbers a,b,ca, b, c are either all equal or all distinct.

For examples, {1425,1113,1354}\{1425, 1113, 1354\} is a trio if the three numbers are members of AA because the ones decimals of the three numbers are all distinct, their tens decimals are all distinct, their hundreds decimals are all distinct, and their thousands decimals are all equal. The set {1425,1113,5436}\{1425, 1113, 5436\}, however, is not a trio, even if AA contains those three numbers.

Given a set AA as input, write a program that computes and prints out the number of different trios.

输入格式

Your program is to read from standard input. The input starts with a line consisting of a single integer nn (1n2,0001 \leq n \leq 2,000) that represents the number of members in AA. Each of the following nn lines consists of a positive integer in decimal form that consists of exactly four digits without 00 in any decimal place. These nn numbers are supposed to be all distinct and the members of the input set AA.

输出格式

Your program is to write to standard output. Print exactly one line. The line should consist of a single integer that represents the number of different trios for the input set AA.

6
1234
1235
1244
1233
7133
8133
1
9
1234
5678
9123
4567
8912
3456
7891
2345
6789
84