#K82857. Digit Sum Reduction

    ID: 36068 Type: Default 1000ms 256MiB

Digit Sum Reduction

Digit Sum Reduction

You are given an array of n non-negative integers. In one operation, you can replace every number x in the array with the sum of its digits, defined by the formula \(digit\_sum(x) = \sum_{i} d_i\), where \(d_i\) represents each digit in x.

Your task is to determine the minimum number of operations required to transform every element of the array into a single-digit number (i.e., a number less than 10).

Example: For the array [123, 405, 678, 10, 89]:

  • Operation 1: Transform to [6, 9, 21, 1, 17] (since \(digit\_sum(123)=6, digit\_sum(405)=9, digit\_sum(678)=21, digit\_sum(10)=1, digit\_sum(89)=17\)).
  • Operation 2: Transform to [6, 9, 3, 1, 8] (\(digit\_sum(21)=3, digit\_sum(17)=8\)).

After 2 operations, all numbers become single-digit numbers. Hence, the answer is 2.

inputFormat

The first line contains a single integer n representing the number of elements in the array. The second line contains n space-separated non-negative integers.

For example:

5
123 405 678 10 89

outputFormat

Output a single integer - the minimum number of operations required to make all elements in the array single-digit numbers.

For example:

2
## sample
5
123 405 678 10 89
2