Marichka's Gift
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Today everyone is celebrating Lucky Numbers Day!
On the occasion of the holiday, Zenyk wants to give Marichka a gift. Zenyk has a string \(s\), which he wants to give as a gift. Of course, the gift string for such a holiday consists only of the numbers 4 and 7.
On the eve of the holiday, Marichka complained to Zenyk that she is very tired of palindromes. She simply hates them. Because of this, Zenyk is very worried, so he wants to trim his string so that it is not a palindrome. You can remove an arbitrary number of characters from the beginning or the end of the string.
State the maximum length of the string that Zenyk can get after trimming it. Or state that this is impossible.
A palindrome is a string that reads the same in both directions.
Input
The single line contains \(s\) – the string that Zenyk is preparing for the gift.
Output
In the single line, print the maximum length of the string that can
be obtained after trimming. If it is impossible to trim the string so
that it is not a palindrome, print -1.
Constraints
\(1 \le |s| \le 10^5\),
\(s_i \in \{4, 7\}\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 47474 | 4 |
| Input (stdin) | Output (stdout) |
|---|---|
| 44 | -1 |
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|