PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000464. Xâu con lặp dài nhất (Longest Duplicate Substring)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Xâu con lặp dài nhất (Longest Duplicate Substring)

Longest Duplicate Substring

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a string ss of lowercase English letters, a substring is a contiguous block of characters of ss. A substring is repeated if it occurs at two or more distinct starting positions. The occurrences may overlap.

Find a repeated substring of maximum length. If several substrings attain that length, any of them is accepted.

Input

The only line contains the string ss. Let n=∣s∣n=|s|.

Output

Print any longest repeated substring. If no nonempty repeated substring exists, print -1.

Subtasks

  • Subtask 1 (20 points): 2≤n≤602\le n\le 60; every character of ss is between a and z.
  • Subtask 2 (30 points): 2≤n≤20002\le n\le 2000; every character of ss is between a and z.
  • Subtask 3 (50 points): 2≤n≤300002\le n\le 30000; every character of ss is between a and z.

Examples

Input

banana

Output

ana

Explanation

ana begins at positions 22 and 44 (one-based); the occurrences overlap at position 44. The length-four substrings bana, anan, nana are distinct, so 33 is optimal.

Input

abcd

Output

-1

Explanation

All four letters are distinct, so no nonempty substring occurs twice. Print -1.

Input

aabb

Output

a

Explanation

Both a and b occur twice. The length-two blocks aa, ab, bb are distinct. Either a or b is accepted.