Problem:
Score : 300 points

Problem Statement

You are given N positive integers a_1, a_2, ..., a_N.

For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N).

Here, X\ mod\ Y denotes the remainder of the division of X by Y.

Find the maximum value of f.

Constraints

All values in input are integers.

2 \leq N \leq 3000

2 \leq a_i \leq 10^5

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the maximum value of f.

Sample Input 1

3
3 4 6

Sample Output 1

10

f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f.

Sample Input 2

5
7 46 11 20 11

Sample Output 2

90

Sample Input 3

7
994 518 941 851 647 2 581

Sample Output 3

4527

Solution in Java (OpenJDK 11.0.6) (judge verdict: Accepted)

import java.util.Arrays;
import java.util.Scanner;


public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = ni();
        long[] a = new long[n];
        a[0] = ni();

        long lcm = a[0];

        for (int i = 1; i < n; i++) {
            a[i] = nl();
            lcm = lcm(lcm, a[i]);
        }

        lcm--;
        //debug(lcm);

        long ans = 0;

        for (int i = 0; i < n; i++) {
            ans += lcm % a[i];
        }

        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }
        //debug(sum);
        //out(ans);
        out(sum - n);

    }

    static boolean canSolve(long len, long[] a, long k) {

        /*
         * k回以下の伐採ですべてをx以下にできるか
         */
        boolean flg = false;
        long count = 0; // 切る回数
        for (int i = 0; i < a.length; i++) {
            count += a[i] / len;
            // debug(len + " " + count + " " + Math.ceil((double) a[i] / (double) len));
        }

        if (count <= k) {
            flg = true;
        } else {
            flg = false;
        }

        return flg;
    }

    /*
     * 以下メソッド集
     */
    static char[][] same(char[][] c, int h, int w) {

        char[][] a = new char[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                a[i][j] = c[i][j];
            }
        }
        return a;

    }

    static int countkuro(char[][] c) {

        int count = 0;
        for (char[] cc : c) {
            for (char ccc : cc) {
                if ('#' == ccc) {
                    count++;
                }
            }
        }
        return count;
    }

    static double[] sort(double[] r) {

        Arrays.sort(r);
        return r;
    }

    static void debug() {

        out("---");
    }

    static void debug(long a) {

        out("-------");
        out(a);
        out("-------");
    }

    static void debug(double a) {

        out("-------");
        out(a);
        out("-------");
    }

    static void debug(String a) {

        out("-------");
        out(a);
        out("-------");
    }

    static long[] sort(long[] n) {

        Arrays.sort(n);
        return n;
    }

    static int ketasuu(int n) {

        String str = "" + n;
        return str.length();
    }

    static int account(String str) {

        String target = "AC";
        int count = 0;
        int len = str.length();
        for (int i = 0; i < len - 1; i++) {
            if (target.equals(str.substring(i, i + target.length()))) {
                count++;
            }
        }
        return count;
    }

    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static double nd() {

        return sc.nextDouble();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void out(Object obj) {

        System.out.println(obj.toString());
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static double max(double d, double e) {

        return Math.max(d, e);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static long min(long d, long e) {

        return Math.min(d, e);
    }

    static int min(int a, int b) {

        return Math.min(a, b);
    }
}


class XY {

    int h;
    int c;

    XY(int h, int c) {
        this.h = h;
        this.c = c;
    }
}