You are given a sequence a consisting of n integers. Find the maximum possible value of <image> (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.

Input

The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105). 

The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).

Output

Print the answer to the problem.

Examples

Input

3
3 4 5


Output

2
import java.io.*;
import java.util.*;
public class c
{ 
static PrintWriter out = new PrintWriter(System.out);


public static void main(String[] args) 
{ 
    int n = ni();
    int v[] = new int[1000008];
    int f[] = new int[1000008];
    int a[] = new int[n];
   
    for(int i=0;i<n;i++)
           v[ni()]=1;
  
   n=0;
   int max =0;
   for(int i=1;i<v.length;i++){
      if(v[i]==1)
        {  a[n++]=i; f[i]=max; max=i;}
      else
           f[i]=max;
   }
   int ans=0;
   for(int i=0;i<n;i++){
          int temp = 2*a[i];
           int large = (a[n-1]/a[i])*a[i];
               large = large+a[i];
          while(temp<=large){
                  int x = a[n-1];
                  if(temp<=a[n-1])
                     x = f[temp];
                  ans = Math.max(ans,x%a[i]);
                  temp=temp+a[i];
           }
    }    
         out.println(ans);
         out.flush();

}

static long mod = 1000000007;
static void fact(long a[]){
         a[0]=1;
         for(int i=1;i<a.length;i++)
                a[i] = (i*a[i-1])%mod;
}
static long gcd(long a,long b){

  if(b%a==0) return a;
  return gcd(b%a,a);
}
static long pow(long a,long b,long mod){

long ans=1;
while(b>0){
if(b%2==1)
    ans = (ans*a)%mod;
    b=b/2;
    a=(a*a)%mod;
}
   return ans;
}  
    static FastReader sc=new FastReader(); 
 
      static int ni(){
                 int x = sc.nextInt();
                 return(x);
        }
      static long nl(){
              long x = sc.nextLong();
              return(x);
         }
      static String n(){
                 String str = sc.next();
                     return(str);
       }
     static String ns(){
                 String str = sc.nextLine();
                   return(str);
      }
     static double nd(){
               double d = sc.nextDouble();
                 return(d);
       }
  static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}