SP5511 HSEQ - Heavy Sequences
Description
Given a sequence S of N integers, indexed from 0 to N-1, we define the weight of its continuous subsequence as the product of its length and its number of occurrences in the main sequence, and in case of uniqueness, we say its weight is 0.
Let's see an example:
N = 5
S = { 1, 7, 3, 1, 7 }
The continuous subsequence S\[ 0, 1 \], which is equal to { 1, 7 }, has a weight of 4, by definition. The continuous subsequence S\[ 2, 2 \] thus has a weight of 0.
Your task is to find the continuous subsequence of maximum weight. To break ties, choose the lexicographically smallest of the candidates ( a sequence A is lexicographically smaller than another sequence B if the first element at which they differ is smaller in A, or if A is a prefix of B ).
If the maximum weight of all the continuous subsequences is 0, we say the sequence is invalid.
Input Format
The first line of input contains a single integer, N ( 1
Output Format
In case of an invalid subsequence, output -1.
A continuous subsequence of the input sequence with the property defined above.