PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#QHD0000006. Xóa dần chữ số (Removing Digits)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xóa dần chữ số (Removing Digits)

Removing Digits

Source: CSES

Problem Statement

Given a positive integer nn, in one operation you may choose a nonzero digit appearing in the decimal representation of the current number and subtract that digit from the number.

Continue until the number becomes 00. Determine the minimum number of operations required.

Input

The input contains one positive integer nn.

Output

Print one integer: the minimum number of operations needed to reach 00.

Subtasks

  • Subtask 1 (20 points): 1≤n≤1001\le n\le 100.
  • Subtask 2 (30 points): 1≤n≤5⋅1041\le n\le 5\cdot10^4.
  • Subtask 3 (50 points): 1≤n≤1061\le n\le 10^6.

Examples

Input

27

Output

5

Explanation

One valid sequence is 27→20→18→10→9→027\to20\to18\to10\to9\to0, subtracting 7,2,8,1,97,2,8,1,9. It takes 55 steps, and no shorter valid sequence exists.