All problems

Problem 250

Minimum Number of Notes

Easy · 10 pts · Greedy, Math

Problem

You have an unlimited supply of notes worth 2000, 500, 200, 100, 50, 20, 10, 5, 2 and 1. Pay exactly the amount N using as few notes as possible, and print how many notes you need. For this set of note values, the greedy method is optimal: always use as many of the largest note as fit, then move to the next smaller note. With division, the count for each note is the remaining amount divided by the note's value.

Input

A single integer N.

Output

Print the minimum number of notes.

Constraints

1 <= N <= 1000000000

Example input

2847

Example output

8

Explanation

2847 = 2000 + 500 + 200 + 100 + 20 + 20 + 5 + 2. Taking the largest note that fits at each step uses 8 notes.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Partition Labels Next: Job Sequencing with Deadlines