LCC '18 Contest 1 S3 - Abelian

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

An abelian square is a string of even length where the first half of the string is an anagram of the second half of the string. Here are some examples:

  • hannah is an abelian square.
  • reappear is an abelian square.
  • racecar is NOT an abelian square as it has odd length.
  • soot is NOT an abelian square, but the substring oo is an abelian square.

Given a string, determine the length of the longest substring that is an abelian square.

Input Specification

The first line of input contains an integer N (1 \le N \le 10 000). The next line contains a lower-case string of N characters.

Output Specification

The length of the longest substring that is an abelian square.

Sample Input 1

8
reappear

Sample Output 1

8

Sample Input 2

11
programming

Sample Output 2

2

Comments

There are no comments at the moment.