This page is still under construction.

Parts of this page are still being built. What you see may change.

Equal Digit Sums

Time limit2sMemory limit256 MB

Summary
Pick n distinct positive integers with the same digit sum so their total is as small as possible.
Level

Medium7 of 10

Topics
Math, Greedy, Brute force
Solved
No attempts yet

Problem

The digit sum of a positive integer xx is the sum of its decimal digits. For example, 22, 1111, and 2020 all have digit sum 22.

Pick nn distinct positive integers whose digit sums are all equal. Write a program that finds the smallest total the picked numbers can have.

Input

The first line contains an integer nn (1≤n≤50001 \le n \le 5000).

Output

Print the minimum possible sum of nn distinct positive integers that all have the same digit sum.

Examples5

  1. Example 1

    Input
    2
    
    Expected output
    11
    
  2. Example 2

    Input
    3
    
    Expected output
    33
    
  3. Example 3

    Input
    1
    
    Expected output
    1
    
  4. Example 4

    Input
    4
    
    Expected output
    66
    
  5. Example 5

    Input
    10
    
    Expected output
    495