ABCBAC

AtCoder
IDabc284_f
Time2000ms
Memory256MB
Difficulty
For a string $S$ of length $N$ and an integer $i\ (0\leq i\leq N)$, let us define the string $f_i(S)$ as the concatenation of: * the first $i$ characters of $S$, * the reversal of $S$, and * the last $(N-i)$ characters of $S$, in this order. For instance, if $S=$ `abc` and $i=2$, we have $f_i(S)=$ `abcbac`. You are given a string $T$ of length $2N$. Find a pair of a string $S$ of length $N$ and an integer $i\ (0\leq i\leq N)$ such that $f_i(S)=T$. If no such pair of $S$ and $i$ exists, report that fact. ## Constraints * $1\leq N \leq 10^6$ * $N$ is an integer. * $T$ is a string of length $2N$ consisting of lowercase English letters. ## Input The input is given from Standard Input in the following format: $N$ $T$ [samples]
Samples
Input #1
3
abcbac
Output #1
abc
2

As mentioned in the problem statement, if $S=$ `abc` and $i=2$, we have $f_i(S)=$ `abcbac`, which equals $T$, so you should print `abc` and $2$.
Input #2
4
abababab
Output #2
abab
1

$S=$ `abab` and $i=3$ also satisfy the condition.
Input #3
3
agccga
Output #3
cga
0

$S=$ `agc` and $i=3$ also satisfy the condition.
Input #4
4
atcodeer
Output #4
\-1

If no pair of $S$ and $i$ satisfies the condition, print `-1`.
API Response (JSON)
{
  "problem": {
    "name": "ABCBAC",
    "description": {
      "content": "For a string $S$ of length $N$ and an integer $i\\ (0\\leq i\\leq N)$, let us define the string $f_i(S)$ as the concatenation of: *   the first $i$ characters of $S$, *   the reversal of $S$, and *   th",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc284_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For a string $S$ of length $N$ and an integer $i\\ (0\\leq i\\leq N)$, let us define the string $f_i(S)$ as the concatenation of:\n\n*   the first $i$ characters of $S$,\n*   the reversal of $S$, and\n*   th...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments