Under construction

Still being built. Things may change

Almost Bobo Number

Time limit3sMemory limit512 MB

Summary
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, 1234123412341234 and 32323232 are bobo numbers, while 12343211234321 and 13221322 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, 111⏟222⏟3⏟11⏟22⏟33⏟\underbrace{111}\underbrace{222}\underbrace{3}\underbrace{11}\underbrace{22}\underbrace{33} becomes 123123123123 after merging all the consecutive equal digits, and thus is an almost bobo number.

Bobo has a very large number nn, and he wants to know the largest almost bobo number less than nn.

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 nn without leading zeros (1≤n≤105 000 0001 \leq n \leq 10^{5\,000\,000}).

It is guaranteed that the total length of the decimal representations of all nn in the input does not exceed 5 000 0005\,000\,000.

Output

For each test case, output an integer without leading zeros denoting the largest almost bobo number strictly less than nn. If there is no such integer, output −1-1 instead.

Examples1

  1. Example 1

    Input
    12345
    67890
    11111
    1000
    26782641
    
    Expected output
    12212
    67767
    11010
    -1
    26777267