Almost Bobo Number
Time limit3sMemory limit512 MB
Given an integer n with up to 5,000,000 digits, find the largest almost bobo number strictly less than n, or report -1 if none exists.
- Level
Hard8 of 10
- Topics
- String, Greedy, String matching
- Solved
- No attempts yet
Problem
A positive integer is called a bobo number if its decimal representation can be obtained by concatenating two copies of the same integer. For example, and are bobo numbers, while and are not.
A positive integer is called an almost bobo number if, after merging all the consecutive equal digits, the resulting number is a bobo number. For example, becomes after merging all the consecutive equal digits, and thus is an almost bobo number.
Bobo has a very large number , and he wants to know the largest almost bobo number less than .
Input
The input contains zero or more test cases, and is terminated by end-of-file. For each test case:
The first line contains an integer without leading zeros ().
It is guaranteed that the total length of the decimal representations of all in the input does not exceed .
Output
For each test case, output an integer without leading zeros denoting the largest almost bobo number strictly less than . If there is no such integer, output instead.