cswork / OA打开练习工作台

ZipRecruiterOA #6

Cycle Shift

简单可在线判题

考点(AI 标注)字符串哈希计数

Given an array of positive integers, count index pairs i<j where the two numbers have the same number of decimal digits and one can become the other through any number of cyclic shifts (including shifting by 0). Repeated values are counted separately by index. The fixed source example's answer is corrected from 3 to 5; the basis for the erratum is in the notes.

输入格式

The first line contains n (site range 1≤n≤100), and the second line contains n positive integers a[i] (source range 1≤a[i]≤10000).

输出格式

Output the number of qualifying index pairs.

样例 1

输入:

9
13 5604 31 2 13 4560 546 654 456

输出:

5

样例 2

输入:

4
11 11 11 11

输出:

6

样例 3

输入:

4
123 231 312 132

输出:

3

样例说明

Group numbers by the minimum over all cyclic shifts of their decimal strings; each group contributes C(frequency,2). The public example's output is corrected to 5 based on the five matching pairs listed in the source explanation.