The segment is not even.
InterviewTime limit1sMemory limit1024 MB
Find the longest contiguous subarray whose first half and second half contain the same multiset of values, where the halves are split at the midpoint.
- Level
Medium4 of 10
- Topics
- Sliding window, Hash map, Array
- Solved
- No attempts yet
Problem
Two sequences and of equal length are even if they can be made equal to each other by repeating the following operation as many times as you want.
- Choose two positive integers and with , and swap the values of and .
Given a sequence of length , let be the contiguous subsequence containing only the elements from the -th to the -th element of . Find the maximum length of that satisfies the following condition.
Let . Then and are even to each other.
Input
The first line contains an integer , the length of sequence . ()
The second line contains integers , separated by spaces. ()
Output
Print the maximum length of when splitting the contiguous subsequence in half gives two sequences that are even to each other.
If no such contiguous subsequence exists, print .