#abc284f. F - ABCBAC

    ID: 3881 传统题 1000ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>来源atcoder基础算法离散化(哈希)字符串KMP

F - ABCBAC

Score : 500500 points

问题描述

对于一个长度为 NN 的字符串 SS 和一个整数 i (0iN)i\ (0\leq i\leq N),我们定义字符串 fi(S)f_i(S) 如下:

  • 字符串 SS 的前 ii 个字符,
  • 字符串 SS 的反转,
  • 字符串 SS 的最后 (Ni)(N-i) 个字符,

按照这个顺序拼接而成。例如,如果 S=S= abc 并且 i=2i=2,那么有 fi(S)=f_i(S)= abcbac

现给定一个长度为 2N2N 的字符串 TT。找出一对字符串 SS(长度为 NN)和整数 i (0iN)i\ (0\leq i\leq N),使得 fi(S)=Tf_i(S)=T。若不存在这样的字符串 SS 和整数 ii 的组合,请报告这一事实。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

For a string SS of length NN and an integer i (0iN)i\ (0\leq i\leq N), let us define the string fi(S)f_i(S) as the concatenation of:

  • the first ii characters of SS,
  • the reversal of SS, and
  • the last (Ni)(N-i) characters of SS,

in this order. For instance, if S=S= abc and i=2i=2, we have fi(S)=f_i(S)= abcbac.

You are given a string TT of length 2N2N. Find a pair of a string SS of length NN and an integer i (0iN)i\ (0\leq i\leq N) such that fi(S)=Tf_i(S)=T. If no such pair of SS and ii exists, report that fact.

Constraints

  • 1N1061\leq N \leq 10^6
  • NN is an integer.
  • TT is a string of length 2N2N consisting of lowercase English letters.

Input

The input is given from Standard Input in the following format:

NN

TT

Output

If no pair of SS and ii satisfies the condition, print -1. Otherwise, print SS and ii, separated by a newline. If multiple pairs of SS and ii satisfy the condition, you may print any of them.

Sample Input 1

3
abcbac

Sample Output 1

abc
2

As mentioned in the problem statement, if S=S= abc and i=2i=2, we have fi(S)=f_i(S)= abcbac, which equals TT, so you should print abc and 22.

Sample Input 2

4
abababab

Sample Output 2

abab
1

S=S= abab and i=3i=3 also satisfy the condition.

Sample Input 3

3
agccga

Sample Output 3

cga
0

S=S= agc and i=3i=3 also satisfy the condition.

Sample Input 4

4
atcodeer

Sample Output 4

-1

If no pair of SS and ii satisfies the condition, print -1.

update @ 2024/3/10 11:54:13