Given finishes over N years, find the lexicographically largest password substring allowed by rules and count its occurrences.
Medium7ArrayString matchingGreedyNo attempts yetTime limit4sMemory limit256 MBIn sports, and in professional baseball above all, a "password" is the list of season finishes a team recorded during its dark age, read out in order. The Lotte Giants of Korean professional baseball finished 8th, 8th, 8th, 8th, 5th, 7th and 7th from 2001 to 2007, which left the password 8-8-8-8-5-7-7. In the same league the LG Twins wrote 6-6-6-8-5-8-7-6-6-7 from 2003 to 2012, and the Hanwha Eagles have been writing 5-8-8-6-8-9-9-6 since 2008.
To use the word for every professional league and not for baseball alone, define a password as follows.
- between neighboring finishes. A team that finished 8th, 11th, 7th and 6th in four consecutive years gives 8-11-7-6.When several candidates satisfy the rules, pick the one whose sequence of finishes is largest in dictionary order, so that reading it hits hardest. Compare two candidates finish by finish as numbers; at the first position where the finishes differ, the candidate with the larger finish is larger. If one candidate matches the whole beginning of the other, the longer one is larger. In a league with 8 teams, a team that finished 8th, 7th, 2nd, 8th, 7th and 7th with L1=2 and L2=3 has the password 8-7-7. Under the same conditions, the finishes 8th, 7th, 2nd, 7th, 7th and 7th give the password 8-7.
You are given the finishes of one team over N years in a league of K teams. Find the password of this team and the number of times it appears in the record of N finishes. Occurrences that overlap each other are counted separately.
The first line has the number of test cases T.
The first line of each test case has four integers K, N, L1, L2 separated by spaces. (1≤K≤100000, 1≤N≤200000, 1≤L1≤L2≤N)
The second line of each test case has N integers, the finishes of the team over N years. The i-th integer Ri is the finish in year i. (1≤Ri≤K)
Print two lines for each test case.
Print the password on the first line, and print the number of times it appears in the record on the second line. If no password satisfies the rules, print -1 on the first line and 0 on the second line.