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 C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    internal static class Program
    {
        public static void Main(string[] args)
        {
            Solve(Console.OpenStandardInput(), Console.OpenStandardOutput());
        }

        internal static void Solve(Stream inputStream, Stream outputStream)
        {
            // ABC 103 B - String Rotation
            var scanner = new StreamScanner(inputStream);
            var writer = new StreamWriter(outputStream)
            {
                AutoFlush = false
            };
            
            Action<string> Write = (string str) => writer.Write(str);
            Action<string> WriteLine = (string str) => writer.WriteLine(str);
            Action Flush = () => writer.Flush();

            var n = scanner.Integer();
            var arr = new long[n];
            for (var i = 0; i < n; i++)
            {
                arr[i] = scanner.Long();
            }

            var f = arr[0];
            for (var i = 1; i < n; i++)
            {
                f = Lcm(f, arr[i]);
            }

            f -= 1;
            
            var score = 0L;
            for (var j = 0; j < n; j++)
            {
                score += f % arr[j];
            }

            /*
            var max = arr.Max();

            var maxScore = 0L;
            for (var i = 0; i < 100000000; i++)
            {
                var score = 0L;
                for (var j = 0; j < n; j++)
                {
                    score += i % arr[j];
                }

                if (maxScore < score)
                {
                    maxScore = score;
                }
            }

            WriteLine($"{maxScore}");
            Flush();
            */
            WriteLine($"{score}");
            Flush();
        }
        
        static long Lcm(long a, long b) {
            return a * b / Gcd(a, b);
        }
        static int Lcm(int a, int b) {
            return a * b / Gcd(a, b);
        }
        
        static long Gcd(long a, long b)
        {
            if (a < b) return Gcd(b, a);
            while(b != 0)
            {
                var r = a % b;
                a = b;
                b = r;
            }
            return a;
        }
        static int Gcd(int a, int b)
        {
            if (a < b) return Gcd(b, a);
            while(b != 0)
            {
                var r = a % b;
                a = b;
                b = r;
            }
            return a;
        }
    }
    
    // https://qiita.com/Camypaper/items/de6d576fe5513743a50e
    public class StreamScanner
    {   
        private readonly Stream stream;
        private readonly byte[] buf = new byte[1024];
        private int len, pos;
        private bool isEof = false;
        public bool IsEndOfStream => isEof;

        public StreamScanner(Stream stream) { this.stream = stream; }
        
        private byte Read()
        {
            if (isEof) throw new EndOfStreamException();
            if (pos >= len) {
                pos = 0;
                if ((len = stream.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[pos++];
        }
        
        public char Char() 
        {
            byte b = 0;
            do b = Read();
            while (b < 33 || 126 < b);
            return (char)b; 
        }
        
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)Read())
                sb.Append(b);
            return sb.ToString();
        }
        
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = Read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = Read(); }
            for (; true; b = Read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        
        public int Integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}