You are given a sequence of integers a1, a2, ..., an. Let <image>, and <image> for 1 ≤ i < n. Here, <image> denotes the modulus operation. Find the maximum value of f(x, 1) over all nonnegative integers x. 

Input

The first line contains a single integer n (1 ≤ n ≤ 200000) — the length of the sequence.

The second lines contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1013) — the elements of the sequence.

Output

Output a single integer — the maximum value of f(x, 1) over all nonnegative integers x.

Examples

Input

2
10 5


Output

13


Input

5
5 4 3 2 1


Output

6


Input

4
5 10 5 10


Output

16

Note

In the first example you can choose, for example, x = 19.

In the second example you can choose, for example, x = 3 or x = 2.
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class ModModMod {
	
	Scanner scr;
	PrintWriter prt;
	StringTokenizer str;

	String nextToken() {
		while (str == null || !str.hasMoreTokens()) {
			str = new StringTokenizer(scr.nextLine());
		}
		return str.nextToken();
	}
	
	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
	
	void Nhap() {
		int n = nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextLong();
		}

		TreeMap<Long, Long> tree = new TreeMap<>();
		tree.put(a[0], 0L);
		
		for (int i = 1; i < n; i++) {
			long x = a[i];
			while (true) {
				Map.Entry<Long, Long> top = tree.lastEntry();
				long r = top.getKey();
				long v = top.getValue();
				if (r <= x) {
					break;
				}
				tree.pollLastEntry();
				long div = r / x;
				long mod = r % x;
				
				tree.merge(x, v + i*x*(div - 1), Long::max);
				if (mod > 0) {
					tree.merge(mod, v + i*x*div, Long::max);
				}
			}
		}
		
		long f1 = 0;
		for (Map.Entry<Long, Long> e : tree.entrySet()) {
			f1 = Math.max(f1, (e.getKey() - 1)*n + e.getValue());
		}	
		prt.println(f1);
	}

	ModModMod() throws IOException {
		scr = new Scanner(new InputStreamReader(System.in));
		prt = new PrintWriter(System.out);
		Nhap();
		prt.close();
	}
	
	public static void main(String[] args) throws IOException {
		new ModModMod();
	}
	
}