#ARC136D. [ARC136D] Without Carry

[ARC136D] Without Carry

Score : 600600 points

Problem Statement

You are given an integer sequence of length NN: A=(A1,A2,,AN)A=(A_1,A_2,\cdots,A_N).

Find the number of pairs of integers (i,j)(i,j) (1i<jN1 \leq i < j \leq N) such that calculation of Ai+AjA_i+A_j by column addition does not involve carrying.

Constraints

  • 2N1062 \leq N \leq 10^6
  • 0Ai10610 \leq A_i \leq 10^6-1
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \cdots ANA_N

Output

Print the answer.

4
4 8 12 90
3

The pairs (i,j)(i,j) that count are (1,3),(1,4),(2,4)(1,3),(1,4),(2,4).

For example, calculation of A1+A3=4+12A_1+A_3=4+12 does not involve carrying, so (i,j)=(1,3)(i,j)=(1,3) counts. On the other hand, calculation of A3+A4=12+90A_3+A_4=12+90 involves carrying, so (i,j)=(3,4)(i,j)=(3,4) does not count.

20
313923 246114 271842 371982 284858 10674 532090 593483 185123 364245 665161 241644 604914 645577 410849 387586 732231 952593 249651 36908
6
5
1 1 1 1 1
10