Smooth numbers
InterviewTime limit2sMemory limit1024 MB
Given a digit count l (1 to 100), find the largest l-digit number whose interior digits are each less than the average of their neighbors, or report -1.
- Level
Medium5 of 10
- Topics
- Math, Greedy, Brute force
- Solved
- No attempts yet
Problem
A positive integer is called smooth if each of its digits except the first and the last is less than the average of its two neighboring digits. That is, if , then for every with .
Vasya has studied smooth numbers for a long time. He wants to know whether a smooth number with exactly digits exists and, if one does, what the greatest such number is. Help Vasya find the greatest -digit smooth number.
Input
The input file contains one integer (), the number of digits in the smooth number.
Output
Print the greatest -digit smooth number, or if no such number exists.