#K75957. Minimum Operations to Reduce to a Single-Digit

    ID: 34534 Type: Default 1000ms 256MiB

Minimum Operations to Reduce to a Single-Digit

Minimum Operations to Reduce to a Single-Digit

You are given a non-negative integer \( n \). Your task is to compute the minimum number of operations required to reduce \( n \) to a single-digit number. In each operation, replace \( n \) by the sum of its digits.

Formally, define the digit sum operation as:

[ S(n) = \sum_{i} d_i, ]

where \( d_i \) are the digits of \( n \). The process is repeated until \( n \) becomes a single-digit number (i.e., \( n < 10 \)).

Example:

  • If \( n = 38 \), then:
    • First operation: \( 3 + 8 = 11 \)
    • Second operation: \( 1 + 1 = 2 \)
  • Total operations = 2

If the input number is already a single digit, the answer is 0.

inputFormat

The input consists of a single line containing a non-negative integer \( n \). The integer is given in its string representation (which can be very large).

outputFormat

Output a single integer representing the minimum number of sum-of-digits operations required to reduce \( n \) to a single-digit number.

## sample
5
0