#P5832. [USACO19DEC] Where Am I? B

[USACO19DEC] Where Am I? B

Problem Description

Farmer John goes out for a walk along the road, but now he realizes he might be lost.

Along the road there is a line of NN farms. Unfortunately, the farms are not numbered, which makes it hard for Farmer John to tell where he is on this road. However, each farm has a colored mailbox by the roadside, so Farmer John hopes to uniquely determine his position by looking at the colors of the most recent few mailboxes.

Each mailbox color is specified by a letter from A..Z, so the sequence of NN mailboxes along the road can be represented as a string of length NN consisting of letters A..Z. Some mailboxes may have the same color. Farmer John wants to know the smallest value of KK such that, by looking at any consecutive sequence of KK mailboxes, he can uniquely determine where this sequence occurs on the road.

For example, suppose the mailbox sequence along the road is ABCDABC. Farmer John cannot set K=3K=3, because if he sees ABC, there are two possible positions on the road where this consecutive color sequence could be. The smallest feasible value is K=4K=4, because if he looks at any consecutive 4 mailboxes, that color sequence can uniquely determine his position on the road.

Input Format

The first line of input contains NN. The second line contains a string of NN characters, each of which is in A..Z.

Output Format

Output one line containing an integer: the minimum value of KK that can solve Farmer John's problem.

7
ABCDABC
4

Hint

Constraints: 1N1001 \leq N \leq 100

Translated by ChatGPT 5