PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000032. Tổng phần dư lớn nhất (Modulo Summation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng phần dư lớn nhất (Modulo Summation)

Modulo Summation

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given positive integers a1,…,aNa_1,\ldots,a_N, define f(m)=∑i=1N(m mod ai)f(m)=\sum_{i=1}^N(m\bmod a_i) for any nonnegative integer mm. Find the maximum possible value of f(m)f(m); you need not output mm.

Input

First line: NN. Second line: NN values aia_i.

Output

Print the maximum possible value of f(m)f(m).

Subtasks

  • Subtask 1 (20 points): 2≤N≤102 \le N \le 10; 2≤ai≤1002 \le a_i \le 100
  • Subtask 2 (30 points): 2≤N≤3002 \le N \le 300; 2≤ai≤1042 \le a_i \le 10^{4}
  • Subtask 3 (50 points): 2≤N≤30002 \le N \le 3000; 2≤ai≤1052 \le a_i \le 10^{5}

Examples

Input

3
3 4 6

Output

10

Explanation

For m=11m=11, the remainders modulo 3,4,63,4,6 are 2,3,52,3,5, summing to 1010, the sum of their individual maxima.