## Art Academy II: The Grand Escape

View as PDF

Points: 7 (partial)
Time limit: 3.0s
Memory limit: 64M
PyPy 2 128M
PyPy 3 128M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

After being trapped and tormented inside of hewmatt10's basement "Art Academy", astrocat879 decided that it was finally time for him to plan an escape. Fortunately, hewmatt10 had never actually considered the possibility of him wanting to escape, so the actual escape would be a piece of cake.

Along the Academy, there are a total of paintings spread across the area, each with a value of . Since astrocat879 is short on money, he plans to steal some of the paintings while making his escape. However, because hewmatt10 is insecure, all of his paintings' values have been hashed, meaning that the value that astrocat879 sees them at is NOT the actual value. Specifically, the paintings' values have been hashed using the following function:

( represents the hashed value, while represents the original value. It is guaranteed that all integer values of under will be given a unique hash value.)

astrocat879 doesn't have the time to figure out the original value of the paintings, and so has asked YOU to create a program for him, that will to maximize his profits. More specifically, he would like you to sum up the paintings with the greatest original value.

#### Input Specification

On the first line, there will be two space-separated integers, and . The next lines will contain a single integer , representing the hashed value of the painting. It is guaranteed that the original value of this hashed number will be greater than , but no greater than .

#### Output Specification

A single integer, representing the sum of the paintings with the greatest original value.

1 10 , .
2 10 .
3 80 No further constraints.

#### Sample Input

5 2
387276917
145972072
2654435761
147926525
2415085369

#### Sample Output

1013

#### Explanation

The original values for the paintings with values , , , , and , are , , , , and , respectively.

The sum of the two greatest values, and , is .