Power Sums

3.5

2 votes
Problem

You are given N positive integers, where N is even. You can arrange them in any order, to maximise the value of the following expression

pow(A1,A2)+pow(A3,A4)++pow(AN1,AN)

where pow(a,b) means ab % b.

Find the maximum value possible.

INPUT:

  • First line contains a single integer N, which is even
  • Second line contains N positive integers

OUTPUT

  • Print a single integer, the maximum value possible

CONSTRAINTS

  • 2N18
  • 1Ai109
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The maximum value is achived as  pow(1,2)+pow(2,5)=1+2=3

Editor Image

?