B. Big Mod
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice is playing a game with cards. In the game, there are two types of cards: number cards and operator cards. Each number card has a number between $$$1$$$ and $$$10^9$$$ on it, while each operator card has one of $$$+$$$, $$$-$$$, $$$*$$$, or $$$/$$$ on it.

Unfortunately, evil Bob steals all of Alice's operator cards and gives her a card with the symbol $$$\%$$$ on it. She now has $$$N+1$$$ cards, $$$1$$$ operator card (with $$$\%$$$ on it), and $$$N$$$ number cards, the $$$i$$$-th number card has number $$$A_i$$$ on it. Here, $$$\%$$$ is defined as the modulo operator. However, poor Alice doesn't know it and is puzzled by it.

You are reminded that for two positive integers $$$X$$$ and $$$Y$$$, $$$X$$$ $$$\%$$$ $$$Y$$$ is defined as the remainder when $$$X$$$ is divided by $$$Y$$$. For example, $$$14$$$ $$$\%$$$ $$$3$$$ is $$$2$$$, and $$$15$$$ $$$\%$$$ $$$15$$$ is $$$0$$$.

Help Alice by constructing an expression using two number cards owned by her and the new $$$\%$$$ card. To impress Bob, you should also make the result of the expression as large as possible. Output the largest possible result of the expression with $$$\%$$$.

Input

The first line contains a single integer $$$N$$$ ($$$2 \leq N \leq 10^5$$$) representing the number of number cards.

The second line describes the number cards. The $$$i$$$-th integer is $$$A_i$$$ ($$$1 \leq A_i \leq 10^9$$$), representing the number on the $$$i$$$-th number card.

Output

Output a single integer: the maximum value of the expression constructed by using two number cards owned by her and the $$$\%$$$ operator card, i.e. $$$A_i$$$ $$$\%$$$ $$$A_j$$$. ($$$1 \leq i, j \leq N$$$, $$$i \neq j$$$)

Example
Input
6
3 1 4 1 5 9
Output
5