Problem

16 /23


Based on the exam 2019

Problem

The input of the program is a sequence of N positive integers, all numbers in the sequence are different. All pairs of different elements of the sequence are considered, located at a distance of at least 4 (the difference in the indices of the elements of the pair must be 4 or more, the order of the elements in the pair is unimportant). It is necessary to determine the maximum sum of a pair of numbers divisible by 112, while the first element of the pair must be greater than the second (\(a[i] > a[j]\), \(i < j\)).

Input
The first line of the input specifies the number of numbers N (\(5 <= N <= 1000\)). Each of the following N lines contains one positive integer not exceeding 10,000.


Input
The program should print one number in the first line: the maximum sum of a pair of elements located in the sequence at a distance of at least 4, in which the sum of the elements is a multiple of 112, and in the second line – numbers that form a pair, separated by a space. If there are no suitable pairs, you need to print a single number –1.
 
Examples
# Input Output
1 7
119
62
343
50
48
105
274
224
119 105