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 Main {
	

	static  HashMap<Integer,Integer> hm;
	static int[] last;
	static final int max = 2000005;
	
	public static void main( String args[] )
	{
		
		MyScanner sc = new MyScanner();
		
		int n = sc.nextInt();
		
		int array[] = new int[n];
		last = new int[max];
		
		for( int i = 0 ; i < n; ++i)
		{
			array[i] = sc.nextInt();
		}
		
		Arrays.sort(array);
		
		
		ArrayList<Integer> al = new ArrayList<Integer>();
		
		al.add( array[0]);
		
		for( int i = 1 ;i < n ; ++i)
			if( al.get(al.size()-1) != array[i]) al.add(array[i]);
		
		array = new int[al.size()];
		
		n = al.size();
		
		for( int i = 0 ; i < al.size() ; ++i)
			array[i] = al.get(i);
		
		
		int x= 0;
		int y = 0 ; 
		
		
		while( array[x] >= y)
		{
			last[y++] = -1 ;
		}
		
		
		while( x < n  )
		{
			if( array[x] >= y )
				{
				last[y++] = array[x-1];
				
				}
			
			else
			{
				while( x < n  && array[x] < y  ) ++x;
			}
		}
		
		for( ; y < max ; ++y)
			last[y] = array[x-1];
		
	
	//	for( int i = 0 ;i < 50 ; ++i )
	//		System.out.println( last[i] + " < " + i );
	
		int maxMod = 0 ;
		
		for( int i = n-1 ; i >= 0 && array[i] >= maxMod + 2 ; --i )
		{
			for( int j = 2*(array[i]) ; j <=  2*array[n-1] ; j += array[i] )
			{
				int temp = last[j];
				maxMod = Math.max( temp%array[i],maxMod);
			}
		}
		
		System.out.println(maxMod);

	}
	
static class MyScanner {
	      BufferedReader br;
	      StringTokenizer st;
	 
	      public MyScanner() {
	         br = new BufferedReader(new InputStreamReader(System.in),8*1024);
	      }
	 
	      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;
	      }

	   }

static class MyWriter {
	    BufferedWriter bw;

	    public  MyWriter() {
	       bw = new BufferedWriter(new OutputStreamWriter(System.out),8*1024);
	    }

	    void print(String s)
	    {
	    	
	    }
	    
	    void println(String s)
	    {
	    	try {
				bw.write( s , 0 , s.length() );
				bw.newLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }

	 void close()
	 {
		 try {
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	 }
	}

	
}

/*

Test: #1, time: 61 ms., memory: 0 KB, exit code: 0, checker exit code: 0, verdict: OK
Input
3
3 4 5
Output
2
Answer
2
Checker Log
ok answer is '2'
Test: #2, time: 62 ms., memory: 0 KB, exit code: 0, checker exit code: 1, verdict: WRONG_ANSWER
Input
3
1 2 4
Output
1
Answer
0
Checker Log
wrong answer expected '0', found '1'


*/