← 返回 roblox 的题目列表Count Distinct Cyclic Number Pairs
类型:online_judge
Given an integer array A, two numbers x and y form a cyclic pair if:
their decimal representations have the same length;
y can be obtained by cyclically rotating the decimal string of x any number of times, moving a suffix to the front;
decimal representations are not padded with leading zeros. A rotation that starts with 0 is not considered a valid representation with the same number of digits;
a pair is unordered and deduplicated by value: the same value pair is counted only once.
Return the number of distinct cyclic pairs present in the array.
For example, rotating 1234 once gives 4123, so they form a cyclic pair.
Example 1
A = [1001, 1100, 110, 11]
Output: 1
1001 and 1100 are rotations of each other. 110 and 11 have different digit lengths.
Example 2
A = [1234, 4123, 3412, 2341]
Output: 6
All four values are cyclic rotations of one another, so every unordered pair is valid.
Constraints
1 ≤ A.length ≤ 2 × 10^5
0 ≤ A[i] ≤ 10^9
Example
Input
4
1001 1100 110 11
Output
1