#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=10e3+5;
const int MAX_P=10e1+5;
int n,m,p,mn,mn_idx,pom,a[MAX_P],ans[MAX_P],dx[4]={1,-1,0,0},dy[4]={0,0,-1,1};
char mat[MAX_N][MAX_N];
bool visted[MAX_N][MAX_N];
map<pii,int> ds[MAX_P];
queue<pii> qs[MAX_P];
pii tmp;

bool good(int i,int j,int k){
 if(i>=n || j>=m || i<0 || j<0 || ds[k].count({i,j}) || mat[i][j]=='#'){return false;}
 return true;
}

int main(){
  cin >> n >> m >> p;
  for(int i=0;i<p;++i){
    cin >> a[i];
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
        cin >> mat[i][j];
        if(mat[i][j]!='.' && mat[i][j]!='#'){
            qs[mat[i][j]-'0'-1].push({i,j});
            ds[mat[i][j]-'0'-1][{i,j}]=0;
        }
        if(mat[i][j]=='#')
            for(int k=0;k<p;++k){
                ds[k][{i,j}]=MAX_N*MAX_N+5;
            }
     }
  }
  for(int i=0;i<p;++i){
    while(!qs[i].empty()){
        tmp=qs[i].front();
        qs[i].pop();
        for(int j=0;j<4;++j){
            if(good(tmp.f+dx[j],tmp.s+dy[j],i)){
                qs[i].push({tmp.f+dx[j],tmp.s+dy[j]});
                ds[i][{tmp.f+dx[j],tmp.s+dy[j]}]=ds[i][tmp]+1;
            }
        }
    }
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
         if(mat[i][j]!='#'){
            mn=INT_MAX;mn_idx=-1;
            for(int k=0;k<p;++k){
                if((ds[k][{i,j}]/a[k])+1<mn){
                    mn=(ds[k][{i,j}]/a[k])+1;
                    mn_idx=k;
                }
            }
            ++ans[mn_idx];
         }
    }
  }
  for(int i=0;i<p;++i){cout << ans[i] << " ";}
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=10e3+5;
const int MAX_P=10e1+5;
int n,m,p,flag,s_d,dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},ans[MAX_P];
ll s[MAX_P];
short visited[MAX_N][MAX_N];
char mat[MAX_N][MAX_N];
queue<pii> qs[MAX_P];
map<pii,int> ds[MAX_P];
pii tmp;

bool good(int i,int j){
  return !(i>=n || j>=m || i<0 || j<0 || visited[i][j] || mat[i][j]=='#');
}

int main(){
  cin >> n >> m >> p;
  for(int i=0;i<p;++i){
    cin >> s[i];
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
        cin >> mat[i][j];
        if(isdigit(mat[i][j])){
            qs[mat[i][j]-'0'-1].push({i,j});
            ds[mat[i][j]-'0'-1][{i,j}]=0;
            visited[i][j]=mat[i][j]-'0';
        }
        if(mat[i][j]=='#'){
            visited[i][j]=-1;
        }
    }
  }
  while(1){
    flag=false;
    for(int i=0;i<p;++i){
        s_d=ds[i][qs[i].front()];
        while(!qs[i].empty() && ds[i][qs[i].front()]-s_d<s[i]){
          flag=true;
          tmp=qs[i].front();
          qs[i].pop();
          for(int d=0;d<4;++d){
            if(good(tmp.f+dx[d],tmp.s+dy[d])){
                qs[i].push({tmp.f+dx[d],tmp.s+dy[d]});
                ds[i][{tmp.f+dx[d],tmp.s+dy[d]}]=ds[i][tmp]+1;
                visited[tmp.f+dx[d]][tmp.s+dy[d]]=i+1;
            }
          }
        }
    }
    if(!flag){break;}
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
       ++ans[visited[i][j]-1];
    }
  }
  for(int i=0;i<p;++i){cout << ans[i] << " ";}
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

const int MAX_N=10e3+5;
const int MAX_P=10e1+5;
int n,m,p,mn,mn_idx,pom,a[MAX_P],ans[MAX_P],dx[4]={1,-1,0,0},dy[4]={0,0,-1,1};
char mat[MAX_N][MAX_N];
bool visted[MAX_N][MAX_N];
map<pii,int> ds[MAX_P];
queue<pii> qs[MAX_P];
//vector<pii> vs[MAX_P];
pii tmp;

bool good(int i,int j,int k){
 if(i>=n || j>=m || i<0 || j<0 || ds[k].count({i,j}) || mat[i][j]=='#'){return false;}
 return true;
}

int main(){
  cin >> n >> m >> p;
  for(int i=0;i<p;++i){
    cin >> a[i];
  }
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
        cin >> mat[i][j];
        if(mat[i][j]!='.' && mat[i][j]!='#'){
            qs[mat[i][j]-'0'-1].push({i,j});
           // vs[mat[i][j]-'0'-1].push_back({i,j});
            ds[mat[i][j]-'0'-1][{i,j}]=0;
        }
        if(mat[i][j]=='#')
            for(int k=0;k<p;++k){
                ds[k][{i,j}]=MAX_N*MAX_N+5;
            }
     }
  }
  for(int i=0;i<p;++i){
    while(!qs[i].empty()){
        tmp=qs[i].front();
        qs[i].pop();
        //vs[i].erase(vs[i].begin());
        for(int j=0;j<4;++j){
            if(good(tmp.f+dx[j],tmp.s+dy[j],i)){
                qs[i].push({tmp.f+dx[j],tmp.s+dy[j]});
                //vs[i].push_back({tmp.f+dx[j],tmp.s+dy[j]});
                ds[i][{tmp.f+dx[j],tmp.s+dy[j]}]=ds[i][tmp]+1;
            }
        }
    }
  }
  for(int k=0;k<p;++k){
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            //cout << ds[k][{i,j}] << " ";
            if(ds[k][{i,j}]==0){continue;}
            if(ds[k][{i,j}]==MAX_N*MAX_N+5){continue;}
            if(a[k]==1){continue;}
            ds[k][{i,j}]=(ds[k][{i,j}]/a[k])+((ds[k][{i,j}]%a[k])!=0);
        }
        //cout << endl;
    }
    //cout << endl;
  }
  /*for(int k=0;k<p;++k){
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            cout << ds[k][{i,j}] << " ";
        }
        cout << endl;
    }
    cout << endl;
  }*/
  for(int i=0;i<n;++i){
    for(int j=0;j<m;++j){
         if(mat[i][j]!='#'){
            mn=INT_MAX;mn_idx=-1;
            for(int k=0;k<p;++k){
                if(ds[k][{i,j}]==0){mn=0;mn_idx=k;continue;}
                if(a[k]>1){
                    //cout << (ds[k][{i,j}]/a[k])+1 << " ";
                    if((ds[k][{i,j}]/a[k])+1<mn){
                        mn=(ds[k][{i,j}]/a[k])+1;
                        mn_idx=k;
                    }
                }
                else{
                   // cout << (ds[k][{i,j}]/a[k]) << " ";
                    if((ds[k][{i,j}]/a[k])<mn){
                        mn=(ds[k][{i,j}]/a[k]);
                        mn_idx=k;
                    }
                }
            }
            ++ans[mn_idx];
           // cout << mn_idx+1 << endl;
         }
        // else{cout << 'x' << endl;}
    }
    //cout << endl;
  }
  //cout << endl;
  for(int i=0;i<p;++i){cout << ans[i] << " ";}
  return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
#define LL __int64
const int INF=0x3f3f3f3f;
int _hash[2100000], dp[2100000], a[2100000];
int main()
{
    int n, i, j, x, min1, ans, max1;
    while(scanf("%d",&n)!=EOF)
    {
        memset(_hash,0,sizeof(_hash));
        min1=INF;
        max1=-1;
        for(i=0; i<n; i++)
        {
            scanf("%d",&x);
            _hash[x]=1;
            min1=min(min1,x);
            max1=max(max1,x);
        }
        for(i=min1; i<=2000000; i++)
        {
            if(_hash[i-1]) dp[i]=i-1;
            else dp[i]=dp[i-1];
        }
        ans=0;
        for(i=1; i<=1000000; i++)
        {
            if(_hash[i])
            {
                for(j=2*i; ; j+=i)
                {
                    if(dp[j]<i) continue ;
                    ans=max(ans,dp[j]%i);
                    if(dp[j]==max1) break;
                    //printf("%d %d\n",j,ans);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2000005;
int flag[maxn],dp[maxn],a[maxn];
int n;

int main(void){
	int i,j;
	while(~scanf("%d",&n)){
		int maxx=-1,minn=20000000;
		memset(flag,0,sizeof(flag));
		for(i=1;i<=n;i++){
			scanf("%d",&a[i]);
			flag[a[i]]=1;
			maxx=max(maxx,a[i]);
			minn=min(minn,a[i]);
		}
		memset(dp,0,sizeof(dp));
		for(i=minn;i<=2*maxx;i++){
			if(flag[i-1]) dp[i]=i-1;
			else dp[i]=dp[i-1];
		}
		int ans=0;
		for(i=minn;i<=maxx;i++){
			if(flag[i]){
				for(j=2*i;;j+=i){
					if(dp[j]>i) ans=max(ans,dp[j]%i);
					if(dp[j]==maxx) break;
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 100;

int main()
{
    int n, a;
    int res = 0;
    vector<int> V;
    cin >> n;
    for(int i = 0; i < n; i++) { cin >> a; V.push_back(a); }
    sort(V.begin(), V.end());
    while(!V.empty())
    {
        int cur = V.back();
        V.pop_back();
        for(int i = V.size()-1; i >= 0; i--)
        {
            if(V[i]%((V[i]/2)+1) < res) break;
            res = max(res, cur%V[i]);
        }
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];

int main()
{
    int n, a, M = 0;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        maxj[a] = a;
        if(a > M) M = a;
        V.push_back(a);
    }
    sort(V.begin(), V.end());
    M *= 2;
    int prev = 0;
    for(int i = 0; i <= M; i++)
        if(maxj[i] == 0) maxj[i] = prev;
        else swap(maxj[i], prev);
    for(int i = V.size()-1; i >= 0; i--)
    {
        if(V[i] <= res+1) continue;
        for(int j = 2*V[i]; j <= M; j+=V[i])
            res = max(res, maxj[j] % V[i]);
    }

    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];

int main()
{
    int n, a, M = 0;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        maxj[a] = a;
        if(a > M) M = a;
        V.push_back(a);
    }
    sort(V.begin(), V.end());
    M *= 2;
    int prev = 0;
    for(int i = 0; i <= M; i++)
        if(maxj[i] == 0) maxj[i] = prev;
        else swap(maxj[i], prev);
    for(int i = V.size()-2; i >= 0; i--)
    {
        if(V[i] <= res+1) break;
        for(int j = 2*V[i]; j <= (M/2)+V[i]; j+=V[i])
            res = max(res, maxj[j] % V[i]);
    }

    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];

int main()
{
    int n, a, M = 0;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        maxj[a] = a;
        if(a > M) M = a;
        V.push_back(a);
    }
    sort(V.begin(), V.end());
    M *= 2;
    int prev = 0;
    for(int i = 0; i <= M; i++)
        if(maxj[i] == 0) maxj[i] = prev;
        else swap(maxj[i], prev);
    for(int i = V.size()-2; i >= 0; i--)
    {
        if(V[i] <= res+1) continue;
        for(int j = 2*V[i]; j <= (M/2)+V[i]; j+=V[i])
            res = max(res, maxj[j] % V[i]);
    }

    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];

int main()
{
    int n, a, M = 0;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        maxj[a] = a;
        if(a > M) M = a;
        V.push_back(a);
    }
    M *= 2;
    int prev = 0;
    for(int i = 0; i <= M; i++)
        if(maxj[i] == 0) maxj[i] = prev;
        else swap(maxj[i], prev);
    for(int i = 0; i < V.size(); i++)
    {
        if(V[i] <= res+1) continue;
        for(int j = 2*V[i]; j <= M; j+=V[i])
            res = max(res, maxj[j] % V[i]);
    }

    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 100;

int main()
{
    int n, a;
    int res = 0;
    set <int> V;
    cin >> n;
    for(int i = 0; i < n; i++) { cin >> a; V.insert(a); }

    //cout << *V.lower_bound(4) << " " << *V.upper_bound(4) << endl;

    while(!V.empty())
    {
        set<int>::iterator cur = V.end(); --cur;
        //cout << *cur << endl;
        if(*cur % (( *cur /2)+1) < res) break;
        set<int>::iterator i = --V.lower_bound(*cur - res);
        for(; i != V.begin(); i--)
        {
            //cout << *i << " ";
            if(*i % ((*i/2)+1) < res) break;
            res = max(res, *cur % *i);
        }
        res = max(res, *cur % *V.begin());
        //cout << endl;
        V.erase(cur);
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];

int main()
{
    int n, a, M;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        V.push_back(a);
    }
    sort(V.begin(), V.end());
    M = 2*V.back();
    for(int i = 1; i < V.size(); i++)
        for(int j = V[i-1]+1; j <= V[i]; j++)
            maxj[j] = V[i-1];
    for(int i = V.back()+1; i <= M; i++)
        maxj[i] = V.back();
    for(int i = 0; i < V.size(); i++)
        for(int j = 2*V[i]; j <= M; j+=V[i])
            res = max(res, maxj[j] % V[i]);

    cout << res;
    return 0;
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using std::map;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
#define mp make_pair

const int CMAX = 2000005;

int maxj[CMAX];
bool used[CMAX];

int main()
{
    int n, a, M = 0;
    int res = 0;
    vector <int> V;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        if(!used[a])
        {
            used[a] = true;
            maxj[a] = a;
            if(a > M) M = a;
            V.push_back(a);
        }
    }
    sort(V.begin(), V.end());
    M *= 2;
    int prev = 0;
    for(int i = 0; i <= M; i++)
        if(maxj[i] == 0) maxj[i] = prev;
        else swap(maxj[i], prev);
    for(int i = V.size()-2; i >= 0; i--)
    {
        if(V[i] <= res+1) break;
        for(int j = 2*V[i]; j <= (M/2)+V[i]; j+=V[i])
            res = max(res, maxj[j] % V[i]);
    }

    cout << res;
    return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[1000006];
int n;
int judge(int x)
{
	int xx=x;
	int pos=upper_bound(a+1,a+1+n,x)-a;
	if(pos>=n)return 0;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[2000006];
int n;
int judge(int x)
{
	int xx=x;
	if(a[n]<=x)return 0;
	int pos=lower_bound(a+1,a+1+n,x)-a;
	if(pos>=n || pos<1)return 0;
	while(a[pos]<=x && pos<n)pos++;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{

		int mid=(l+r)/2;
		if(n==200000 && a[2]!=1)printf("%d\n",mid);
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[1000006];
int n;
int judge(int x)
{
	int pos=upper_bound(a+1,a+1+n,x)-a;
	if(pos>=n)return 0;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x])return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=a[n];
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=30;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		int cnt=2000000/x;
		for(int j=1;j<=cnt;j++)
		{
			x=j*a[i];
			if(vis[x-1]==-1 || vis[x-1]<a[i])continue;
			sum=max(sum,(long long)vis[x-1]%a[i]);
			/*if(sum==4)
			{
			printf("x:%d\n",x);
			getchar();
			}*/
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[1000006];
int n;
int judge(int x)
{
	int pos=upper_bound(a+1,a+1+n,x)-a;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x])return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=a[n];
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[1000006];
int n;
int judge(int x)
{
	int xx=x;
	if(a[n]<=x)return 0;
	int pos=upper_bound(a+1,a+1+n,x)-a;
	if(pos>=n || pos<1)return 0;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[2000006];
int n;
int judge(int x)
{
	int xx=x;
	if(a[n]<=x)return 0;
	int pos=lower_bound(a+1,a+1+n,x)-a;
	if(pos>=n || pos<1)return 0;
	while(a[pos]<=x && pos<n)pos++;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{
		int mid=(l+r)/2;
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		while(x<=2000000)
		{
			if(vis[x]==-1)
			{
				x+=a[i];
				continue;
			}
			long long aa=(vis[x])%a[i];
			sum=max((long long)sum,aa);
			x+=a[i];
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[2000006];
int n;
int judge(int x)
{
	int xx=x;
	if(a[n]<=x)return 0;
	int pos=lower_bound(a+1,a+1+n,x)-a;
	if(pos>=n || pos<1)return 0;
	while(a[pos]<=x && pos<n)pos++;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{

		int mid=(l+r)/2;
		if(n==200000)printf("%d\n",mid);
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		while(x<2000000)
		{
			if(vis[x]+a[i]<=x)
			{
			x+=a[i];
			continue;

			}
			long long aa=(vis[x]+a[i])%a[i];
			sum=max((long long)sum,aa);
			x+=a[i];
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		int cnt=2000000/x;
		for(int j=1;j<=cnt;j++)
		{
			x=j*a[i];
			if(vis[x]==-1)continue;
			sum=max(sum,(long long)vis[x]%a[i]);
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=1000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
		while(x<1000000)
		{
			if(vis[x]+a[i]<=x)
			{
			x+=a[i];
			continue;

			}
			long long aa=(vis[x]+a[i])%a[i];
			sum=max((long long)sum,aa);
			x+=a[i];
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int a[1000000];
int vis[20000006];
int n;
int judge(int x)
{
	int xx=x;
	if(a[n]<=x)return 0;
	int pos=lower_bound(a+1,a+1+n,x)-a;
	if(pos>=n || pos<1)return 0;
	while(a[pos]<=x && pos<n)pos++;
	for(int i=pos;i<=n;i++)
		{
		    x=a[i]+x;
			while(x<=a[n])
			{
				if(vis[x] && x%a[i]==xx)return 1;
				x+=a[i];
			}
		}
	return 0;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)vis[a[i]]=1;
	int l=0,r=1000000;
	while(l+1<r)
	{

		int mid=(l+r)/2;
		if(n==200000 && a[2]!=1)printf("%d\n",mid);
		if(judge(mid))
		{
			l=mid;
		}
		else r=mid-1;
	}
	if(judge(r))l=r;
	printf("%d\n",l);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=30;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		int cnt=2000000/x;
		for(int j=1;j<=cnt;j++)
		{
			x=j*a[i];
			if(vis[x-1]==-1 || vis[x-1]<a[i])continue;
			sum=max(sum,(long long)vis[x-1]%a[i]);
			if(sum==4)
			{
			printf("x:%d\n",x);
			getchar();
			}
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2500006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2500000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		int cnt=2500000/x;
		for(int j=1;j<=cnt;j++)
		{
			x=j*a[i];
			if(vis[x]==-1)continue;
			sum=max(sum,(long long)vis[x]%a[i]);
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		int cnt=1000000/x;
		for(int i=1;i<=cnt;i++)
		{
			x=a[i]*cnt;
			if(vis[x]==-1)continue;
			sum=max(sum,(long long)vis[x]%a[i]);
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		while(x<=2000000)
		{
			long long aa=(vis[x])%a[i];
			sum=max((long long)sum,aa);
			x+=a[i];
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;

int vis[2000006];
int a[1000000];
int main()
{
	int n;
	scanf("%d",&n);
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;i++)
	{
	scanf("%d",&a[i]);
	vis[a[i]]=a[i];
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=2000000;i++)
	 if(vis[i]==-1)vis[i]=vis[i-1];
	//for(int i=1;i<=20;i++)printf("%d\n",vis[i]);
	long long sum=0;
	for(int i=1;i<=n;i++)
	if(a[i]!=a[i-1])
	{
		int x=a[i];
	//	printf("%d\n",x);
		while(x<=2000000)
		{
			if(vis[x]+a[i]<=x)
			{
			x+=a[i];
			continue;

			}
			long long aa=(vis[x])%a[i];
			sum=max((long long)sum,aa);
			x+=a[i];
		}
	 }

	printf("%I64d\n",sum);
	return 0;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (mid+1 >= n || v[mid+1] >= y))
			return v[mid];

		if (v[mid] <= y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	for (int i = 1; i <= 1000000; i++)
	{
		if (*lower_bound(v,v+n,i) == i)
		{
			for (int h = i; h <= 1000000; h+=i)
			{
				int k = tap(h,h+i);

				if (k != 0)
					ans = max(ans,k%i);
			}
		}
	}
	cout << ans;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (v[mid+1] >= y || mid+1 == n))
			return v[mid];

		if (v[mid] > x && v[mid] < y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	for (int i = 1; i <= 1000000; i++)
	{
		if (*lower_bound(v,v+n,i) == i)
		{
			for (int h = i; h <= 1000000; h+=i)
			{
				int k = tap(h,h+i);

				if (k != 0)
					ans = max(ans,k%i);
			}
		}
	}
	cout << ans;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (v[mid+1] >= y || mid+1 == n))
			return v[mid];

		if (v[mid] > x && v[mid] < y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	for (int i = 1; i <= 1000000; i++)
	{
		if (lower_bound(v,v+n,i)!=v+n)
		{
			for (int h = i; h <= 1000000; h+=i)
			{
				int k = tap(h,h+i);

				if (k != 0)
					ans = max(ans,k%i);
			}
		}
	}
	cout << ans;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (mid+1 >= n || v[mid+1] >= y))
			return v[mid];

		if (v[mid] < y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	for (int i = 0; i < n; i++)
	{
		for (int h = v[i]; h <= 1000000; h+=v[i])
		{
			int k = tap(h,h+v[i]);

			if (k != 0)
				ans = max(ans,k%v[i]);
		}
	}
	cout << ans;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (mid+1 >= n || v[mid+1] >= y))
			return v[mid];

		if (v[mid] < y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	for (int i = 1; i <= 1000000; i++)
	{
		if (*lower_bound(v,v+n,i) == i)
		{
		for (int h = i; h <= 1000000; h+=i)
		{
			int k = tap(h,h+i);

			if (k != 0)
				ans = max(ans,k%i);
		}}
	}
	cout << ans;
}


//BTTHS
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

int n, v[200009], ans;

int tap(int x, int y)
{
	int head = 0, tail = n, mid;
	while (head <= tail)
	{
		mid = (head+tail)/2;

		if (v[mid] > x && v[mid] < y && (v[mid+1] >= y || mid+1 == n))
			return v[mid];

		if (v[mid] > x && v[mid] < y)
			head = mid+1;
		else
			tail = mid-1;
	}
	return 0;
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i];

	sort(v,v+n);

	if (n == 1) {cout << 0; return 0;}

	for (int i = 1; i <= 1000000; i++)
	{
		if (lower_bound(v,v+n,i)!=v+n)
		{
			for (int h = i; h <= 1000000; h+=i)
			{
				int k = tap(h,h+i);

				if (k != 0)
					ans = max(ans,k%i);
			}
		}
	}
	cout << ans;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    long long n, max, k, ma;
    short a[1000001];
    cin >> n;
    max = -1;
    for (long i = 1; i <= n; i++){
        cin >> k;
        a[k] = k;
        if (k >= max) max = k;
    }
    ma = 0;
    for (long long i = 1; i <= 1000000; i++) if (a[i] != i) a[i] = a[i - 1];
    for (long long i = 2; i <= 1000000; i++){
        if (a[i] == i) if (ma < i - 1){
           for (long long j = i * 2 - 1; j <= max; j += i){
               long long l;
               l = a[j] % i;
               if (l > ma) ma = l;
           }
        }
    }
    cout << ma;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    long long n, max, k, ma;
    short a[1000001];
    for (long long i = 1; i <= 1000000; i++) a[i] = 0;
    cin >> n;
    max = -1;
    for (long i = 1; i <= n; i++){
        cin >> k;
        a[k] = 1;
        if (k >= max) max = k;
    }
    ma = 0;
    for (long long i = 1; i <= 1000000; i++){
        if (a[i] == 1){
           for (long long j = i + 1; j <= max; j++){
               if (a[j] == 1){
                  long long l;
                  l = j % i;
                  if (l > ma) ma = l;
               }
           }
        }
    }
    cout << ma;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    long long n;
    long a[200001];
    cin >> n;
    for (long i = 1; i <= n; i++){
        cin >> a[i];
    }
    long long max = -100;
    for (long i = 1; i <= n; i++){
        for (long j = i + 1; j <= n; j++){
            if (a[i] >= a[j]){

               long l = a[i] % a[j];
                     if (l >= max) max = l;
            }

            if (a[i] < a[j]){
               long l = a[j] % a[i];
                     if (l >= max) max = l;
            }
        }
    }
    cout << max;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    short a[1000005];
    long long i, j, n;
    cin >> n;
    long long ma = -1;
    for (i = 1; i <= n; i++){
        int k;
        cin >> k;
        a[k] = k;
        if (k > ma) ma = k;
    }
    long long max = 0;
    for (i = 2; i <= ma; i++) if (a[i] != i) a[i] = a[i - 1];
    for (i = 2; i <= ma; i++)
    {
        if (a[i] == i){
           for (j = i * 2 - 1; j <= ma; j += i)
               if (a[j] % i > max) max = a[j] % i;
        }
    }
    cout << max;
    cin >> max;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN = 2111111;
int a[MAXN];
int maxi = -1;

main()
{
	int n, tmp;
	cin >> n;
	fill(a, a + MAXN, 0);

	for (int i = 0; i < n; i++)
		cin >> tmp, a[tmp] = tmp, (tmp > maxi ? maxi = tmp : 0);

	a[0] = 1;
	for (int i = 1; i < MAXN; i++)
		if (!a[i])
			a[i] = a[i - 1];

	int ans = 0;

	for (int i = maxi; i > ans; i--)
		if (a[i] == i)
			for (int j = 2 * i - 1; j < MAXN; j += i)
			{
				int tmp = a[j] % i;
				if (tmp > ans)
					ans = tmp;
			}
	cout << ans << endl;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long long a[2000006];
    long long i, j, n;
    cin >> n;
    long long ma = -1;
    for (i = 1; i <= n; i++){
        long k;
        cin >> k;
        a[k] = k;
        if (k > ma) ma = k;
    }
    long long max = 0;
    for (i = 2; i <= 2000006; i++) if (a[i] != i) a[i] = a[i - 1];

    for (i = 2; i <= ma; i++)
    {
        if (a[i] == i){
           for (j = i * 2 - 1; j <= ma; j += i)
               if (a[j] % i > max) max = a[j] % i;
        }
    }

    cout << max;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

long long a[2000006];

int main()
{
    long long i, j, n;
    cin >> n;
    long long ma = -1;
    for (i = 1; i <= n; i++){
        long k;
        cin >> k;
        a[k] = k;
        if (k > ma) ma = k;
    }
    long long max = 0;
    for (i = 2; i <= 2000006; i++) if (a[i] != i) a[i] = a[i - 1];

    for (i = 2; i <= ma; i++)
    {
        if (a[i] == i){
           for (j = i * 2 - 1; j <= ma; j += i)
               if (a[j] % i > max) max = a[j] % i;
        }
    }

    cout << max;
    return 0;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long a[1000005];
    long long i, j, n;
    cin >> n;
    long long ma = -1;
    for (i = 1; i <= n; i++){
        int k;
        cin >> k;
        a[k] = k;
        if (k > ma) ma = k;
    }
    long long max = 0;
    for (i = 2; i <= ma; i++) if (a[i] != i) a[i] = a[i - 1];
    for (i = 2; i <= ma; i++)
    {
        if (a[i] == i){
           for (j = i * 2 - 1; j <= ma; j += i)
               if (a[j] % i > max) max = a[j] % i;
        }
    }
    cout << max;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long a[1000005];
    long long i, j, n;
    cin >> n;
    long long ma = -1;
    for (i = 1; i <= n; i++){
        long k;
        cin >> k;
        a[k] = k;
        if (k > ma) ma = k;
    }
    long long max = 0;
    for (i = 2; i <= ma; i++) if (a[i] != i) a[i] = a[i - 1];
    for (i = 2; i <= ma; i++)
    {
        if (a[i] == i){
           for (j = i * 2 - 1; j <= ma; j += i)
               if (a[j] % i > max) max = a[j] % i;
        }
    }
    cout << max;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    long long n, max, k, ma;
    short a[1000001];
    cin >> n;
    max = -1;
    for (long i = 1; i <= n; i++){
        cin >> k;
        a[k] = 1;
        if (k >= max) max = k;
    }
    ma = 0;
    for (long long i = 1; i <= 1000000; i++){
        if (a[i] == 1)
           for (long long j = i + 1; j <= max; j++){
               if (a[j] == 1){
                  long long l;
                  l = j % i;
                  if (l > ma) ma = l;
               }
           }
    }
    cout << ma;
}


#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char *argv[])
{
    long long n;
    long a[200001];
    cin >> n;
    for (long i = 1; i <= n; i++){
        cin >> a[i];
    }
    long long max = 0;
    for (long i = 1; i <= n; i++){
        for (long j = i + 1; j <= n; j++){
            if (a[i] >= a[j]){

               long l = a[i] % a[j];
                     if (l >= max) max = l;
            }

            if (a[i] < a[j]){
               long l = a[j] % a[i];
                     if (l >= max) max = l;
            }
        }
    }
    cout << max;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
int a[200009],ans=0;
for (int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for (int i=0;i<n-1;i++)
 if (a[i]!=a[i+1])
    for (int k=2*a[i];k<=a[n-1]+a[i];k+=a[i])
    {int l=i+1,r=n-1;
     while (l!=r)
     {int m=(l+r+1)/2;
      if (a[m]>=k) r=m-1; else l=m;
     }
   //  cout<<i<<"    "<<a[i]<<"   "<<k<<"  "<<tmp<<"   "<<a[tmp]<<endl;
     ans=max(ans,a[l]%a[i]);
    }
cout<<ans;
return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
int a[200009],ans=0;
for (int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for (int i=0;i<n-1;i++)
 if (a[i]!=a[i+1])
    for (int k=2*a[i];k<=a[n-1]+a[i];k+=a[i])
    {int l=i+1,r=n-1;
     while (l!=r)
     {int m=(l+r+1)/2;
      if (a[m]>=k) r=m-1; else l=r;
     }
   //  cout<<i<<"    "<<a[i]<<"   "<<k<<"  "<<tmp<<"   "<<a[tmp]<<endl;
     ans=max(ans,a[l]%a[i]);
    }
cout<<ans;
return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
cout<<n<<endl;
int a[200009],ans=0;
for (int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for (int i=0;i<n-1;i++)
 if (i==0||a[i]!=a[i+1])
    for (int k=2*a[i];k<=a[n-1]+a[i];k+=a[i])
    {int tmp=i+1;
     for (int j=(1<<18);j>0;j>>=1)
         if (tmp+j<n&&a[tmp+j]<k) tmp+=j;
   //  cout<<i<<"    "<<a[i]<<"   "<<k<<"  "<<tmp<<"   "<<a[tmp]<<endl;
     ans=max(ans,a[tmp]%a[i]);
    }
cout<<ans;
return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
int a[200009],ans=0;
for (int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for (int i=0;i<n-1;i++)
 if (i==0||a[i]!=a[i+1])
    for (int k=2*a[i];k<=a[n-1]+a[i];k+=a[i])
    {int tmp=i+1;
     for (int j=(1<<18);j>0;j>>=1)
         if (tmp+j<n&&a[tmp+j]<k) tmp+=j;
   //  cout<<i<<"    "<<a[i]<<"   "<<k<<"  "<<tmp<<"   "<<a[tmp]<<endl;
     ans=max(ans,a[tmp]%a[i]);
    }
cout<<ans;
return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
int a[200009],ans=0;
for (int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for (int i=0;i<n-1;i++)
 if (a[i]!=a[i+1])
    for (int k=2*a[i];k<=a[n-1]+a[i];k+=a[i])
    {int tmp=i+1;
     for (int j=(1<<18);j>0;j>>=1)
         if (tmp+j<n&&a[tmp+j]<k) tmp+=j;
   //  cout<<i<<"    "<<a[i]<<"   "<<k<<"  "<<tmp<<"   "<<a[tmp]<<endl;
     ans=max(ans,a[tmp]%a[i]);
    }
cout<<ans;
return 0;
}


#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{//freopen("i.txt","r",stdin);
int n; cin>>n;
int a[200005];
for (int i=1;i<=n;i++) cin>>a[i];
int ans=0;
for (int i=1;i<=n;i++)
 for (int j=1;j<=n;j++)
  if (a[i]>a[j]) ans=max(ans,a[i]%a[j]);

cout<<ans;
return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    printf("a-");
    for(int i=N-1;Data[i]>=100000;i--)
        {
            for(int j=i-1;Data[j]>=100000;j--)
            {
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d-",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{

    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    int NN=1;
    for(int i=1;i<N;i++)
    {
        if(Data[i]!=Data[i-1])
            Data[NN++]=Data[i];
    }
    N=NN;
    for(int i=N-1;i>=1&&Data[i]>mod;i--)
    {
        int A=Data[i]/Data[i-1]+1;
        while(Data[i]/A>mod)
        {
            int Get=Solve(Data[i]/A+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A++;
        }
    }

    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);

    int mod=0;

    int Num,MM;
    int NID,MID;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        Num=Data[i];
        NID=i;
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                    MM=Data[Get];
                    MID=Get;
                }
            }
            A>>=1;
        }
    }
    if(mod==124993) printf("%d(%d)-%d(%d)-",Num,NID,MM,MID);
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    printf("a-");
    for(int i=N-1;Data[i]>=100000;i--)
        {
            for(int j=i-1;Data[j]>=100000;j--)
            {
                printf("%d:%d\n",i,j);
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d-",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);

    int mod=0;

    int Num,MM;
    int NID,MID;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;

                    Num=Data[i];
                    NID=i;
                    MM=Data[Get];
                    MID=Get;
                }
            }
            A>>=1;
        }
    }
    if(mod==124993) printf("%d(%d)-%d(%d)-",Num,NID,MM,MID);
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    for(int i=N-1;Data[i]>166665;i--)
        {
            for(int j=i-1;Data[j]>166665;j--)
            {
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{

    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=1&&Data[i]>mod;i--)
    {
        int A=Data[i]/Data[i-1]+1;
        while(Data[i]/A>mod)
        {
            int Get=Solve(Data[i]/A+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A++;
        }
    }

    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);
    qsort(Data,N,sizeof(int),cmp);

    int mod=0;
    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod) mod=M;
            }
            A>>=1;
        }
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    printf("a-");
    for(int i=N-1;Data[i]>166665;i--)
        {
            for(int j=i-1;Data[j]>166665;j--)
            {
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d-",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);

    int mod=0;
    int Num,MM;
    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        Num=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                    MM=Data[Get];
                }
            }
            A>>=1;
        }
    }
    if(mod==124993) printf("%d-%d-",Num,MM);
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    printf("a-");
    for(int i=N-1;Data[i]>=166665;i--)
        {
            for(int j=i-1;Data[j]>=166665;j--)
            {
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d-",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);

    int mod=0;
    int Num;
    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        Num=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod) mod=M;
            }
            A>>=1;
        }
    }
    if(mod==124993) printf("%d-",Num);
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);

    int mod=0;
    int Num,MM;
    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        Num=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(Data[Get]>Data[i]) while(1);
                if(M>mod)
                {
                    mod=M;
                    MM=Data[Get];
                }
            }
            A>>=1;
        }
    }
    if(mod==124993) printf("%d-%d-",Num,MM);
    printf("%d\n",mod);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define XMAX 200006

int Data[XMAX];
int N;

int cmp(const void* a,const void* b)
{
    int A=*(int*)a;
    int B=*(int*)b;
    if(A>B) return 1;
    else if(A==B) return 0;
    else return -1;
}

int Solve(int A)
{
    int l=0;
    int r=N-1;
    int mid=(l+r)/2;

    while(Data[mid]!=A&&l!=r)
    {
        if(Data[mid]<A)
            l=mid+1;
        else
            r=mid;
        mid=(l+r)/2;
    }
    if(Data[mid]==A)
        return mid;
    else return l;
}

void ABC(void)
{
    printf("a-");
    for(int i=N-1;Data[i]>=100000;i--)
        {
            for(int j=i-1;Data[j]>=100000;j--)
            {
                printf("%d(%d):%d(%d)\n",i,Data[i],j,Data[j]);
                if(Data[i]%Data[j]==166665)
                    printf("%d-%d-",Data[i],Data[j]);
                return;
            }
        }
}

int main(void)
{
    scanf("%d",&N);
    for(int i=0;i<N;i++)
        scanf("%d",&Data[i]);

    qsort(Data,N,sizeof(int),cmp);
    int mod=0;

    for(int i=N-1;i>=0&&Data[i]>mod;i--)
    {
        int A=Data[i];
        while(A>mod)
        {
            int Get=Solve(A/2+1);
            if(Get<i)
            {
                int M=Data[i]%Data[Get];
                if(M>mod)
                {
                    mod=M;
                }
            }
            A>>=1;
        }
    }

    if(mod==124993)
    {
        ABC();
    }
    printf("%d\n",mod);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 2e5 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], b[N];

int main(void){
    int n, ans = 0, top = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    sort(a + 1, a + n + 1);
    b[++top] = a[n];
    for (int i = n - 1; a[i] > ans; --i){
        if (a[i] == a[i + 1])
            continue;
        for (int j = 1; j <= top; ++j)
            ans = max(ans, b[j] % a[i]);
        b[++top] = a[i];
    }
    printf("%d\n", ans);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 2e5 + 7;
const int M = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], next[M + M];

int main(void){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a + i);
        next[a[i]] = a[i];
    }
    for (int i = 1; i < M + M; ++i)
        if (next[i] == 0)
            next[i] = next[i - 1];
    for (int i = 2; i < M; ++i)
        if (next[i] == i)
            for (int j = i + i; j < M + M; j += i)
                if (next[j - 1] >= i)
                    ans = max(ans, next[j - 1] % i);
    printf("%d\n", ans);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 2e5 + 7;
const int M = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], next[M];

int main(void){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a + i);
        next[a[i]] = a[i];
    }
    for (int i = 1; i < M; ++i)
        if (next[i] == 0)
            next[i] = next[i - 1];
    for (int i = 2; i < M; ++i)
        for (int j = i; j < M; j += i)
            if (next[j] >= i)
                ans = max(ans, next[j] % i);
    printf("%d\n", ans);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 1e5 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], b[N];

int main(void){
    int n, ans = 0, top = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d", a + i);
    sort(a + 1, a + n + 1);
    b[++top] = a[n];
    for (int i = n - 1; a[i] > ans; --i){
        if (a[i] == a[i + 1])
            continue;
        for (int j = 1; j <= top; ++j)
            ans = max(ans, b[j] % a[i]);
        b[++top] = a[i];
    }
    printf("%d\n", ans);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 2e5 + 7;
const int M = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], next[M];

int main(void){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a + i);
        next[a[i]] = a[i];
    }
    for (int i = 1; i < M; ++i)
        if (next[i] == 0)
            next[i] = next[i - 1];
    for (int i = 2; i < M; ++i)
        if (next[i] == i)
            for (int j = i + i; j < M; j += i)
                if (next[j - 1] >= i)
                    ans = max(ans, next[j - 1] % i);
    printf("%d\n", ans);
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

#define dprint(expr) fprintf(stderr, #expr " = %d\n", expr)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;

const int N = 2e5 + 7;
const int M = 1e6 + 7;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const double PI = acos(-1.0);

int a[N], next[M];

int main(void){
    int n, ans = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a + i);
        next[a[i]] = a[i];
    }
    for (int i = 1; i < M; ++i)
        if (next[i] == 0)
            next[i] = next[i - 1];
    for (int i = 2; i < M; ++i)
        if (next[i] == i)
            for (int j = i; j < M; j += i)
                if (next[j] >= i)
                    ans = max(ans, next[j] % i);
    printf("%d\n", ans);
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, t, mx, ans, cnt, a[2000005], b[200005];
bool v[1000005];
int main()
{
    int i, j;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &t);
        if (t > mx) mx = t;
        a[t] = t;
        if (!v[t]) {
            b[cnt++] = t;
            v[t] = true;
        }
    }

    t = 0;
    for (i = 1; i <= 2000000; i++) {
        if (t < a[i]) t = a[i];
        a[i] = t;
    }

    for (i = 0; i < cnt; i++) {
        for (j = b[i] * 2 - 1; j <= 2000000; j += b[i]) {
            if (a[j] % b[i] > ans) ans = a[j] % b[i];
            if (a[j] == mx) break;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, mx, ans, a[2000005];
int main()
{
    int i, j, t;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &t);
        if (t > mx) mx = t;
        a[t] = t;
    }

    for (i = 1; i <= 2 * mx; i++) {
        if (a[i] == 0) {
            a[i] = a[i - 1];
        }
    }

    for (i = 1; i <= mx; i++) {
        if (a[i] == i) {
            for (j = i * 2 - 1; j <= 2 * mx; j += i) {
                t = a[j] % i;
                if (t > ans) ans = t;
                if (t == i - 1) break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, mx, ans, a[2000005];
int main()
{
    int i, j, t;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &t);
        if (t > mx) mx = t;
        a[t] = t;
    }

    for (i = 1; i <= 2 * mx; i++) {
        if (a[i] == 0) {
            a[i] = a[i - 1];
        }
    }

    for (i = 1; i <= mx; i++) {
        if (a[i] == i) {
            for (j = i * 2 - 1; j <= 2 * mx; j += i) {
                if (a[j] % i > ans) ans = a[j] % i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, t, mx, ans, a[2000005], b[200005];
int main()
{
    int i, j;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &b[i]);
        if (b[i] > mx) mx = b[i];
        a[b[i]] = b[i];
    }

    t = 0;
    for (i = 1; i <= 2000000; i++) {
        if (t < a[i]) t = a[i];
        a[i] = t;
    }

    for (i = 0; i < n; i++) {
        for (j = b[i] * 2 - 1; j <= 2000000; j += b[i]) {
            if (a[j] % b[i] > ans) ans = a[j] % b[i];
            if (a[j] == mx) break;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, t, mx, ans, a[1000005], b[200005];
int main()
{
    int i, j;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &b[i]);
        if (b[i] > mx) mx = b[i];
        a[b[i]] = b[i];
    }

    t = 0;
    for (i = 1; i <= 1000000; i++) {
        if (t < a[i]) t = a[i];
        a[i] = t;
    }

    for (i = 0; i < n; i++) {
        for (j = b[i] * 2 - 1; j <= 1000000; j += b[i]) {
            if (a[j] % b[i] > ans) ans = a[j] % b[i];
            if (a[j] == mx) break;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;

int n, t, mx, ans, cnt, a[2000005], b[200005];
bool v[1000005];
int main()
{
    int i, j;
//    freopen ("input.txt", "r", stdin);
    cin >> n;
    for (i = 0; i < n; i++) {
        scanf ("%d", &t);
        if (b[i] > mx) mx = t;
        a[t] = t;
        if (!v[t]) {
            b[cnt++] = t;
            v[t] = true;
        }
    }

    t = 0;
    for (i = 1; i <= 2000000; i++) {
        if (t < a[i]) t = a[i];
        a[i] = t;
    }

    for (i = 0; i < cnt; i++) {
        for (j = b[i] * 2 - 1; j <= 2000000; j += b[i]) {
            if (a[j] % b[i] > ans) ans = a[j] % b[i];
            if (a[j] == mx) break;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=2000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
//    cout<<dpt;
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=maxa-5-i;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
	foru(i,1,mmax) dau[i]=(dau[i]?dau[i]:dau[i-1]);
	sort(a,a+n);
    n=unique(a,a+n)-a;
    rep(i,n){
		for(int j=2*a[i];j<=mmax+a[i];j+=a[i]){
			kq=max(kq,dau[j-1]%a[i]);
		}
//		cout<<i<<" "<<kq;
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
    rep(i,n) scanf("%d",&a[i]);
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
    ford(i,mmax,1){
		dau[i]=(dau[i]?dau[i]:dau[i+1]);
    }
    n=unique(a,a+n)-a;
    rep(i,n){
		int t=sqrt(a[i]);
		foru(j,2,min(a[i],t+2)){
			int t2=a[i]/j;
			kq=max(kq,a[i]%dau[t2]);
		}
		foru(j,2,min(a[i],t+2)){
			kq=max(kq,a[i]%dau[j]);
		}
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
//    cout<<dpt;
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=maxa-5-i;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
	foru(i,1,mmax) dau[i]=(dau[i]?dau[i]:dau[i-1]);
	sort(a,a+n);
    n=unique(a,a+n)-a;
    rep(i,n){
		for(int j=2*a[i];j<=mmax+a[i];j+=a[i]){
			kq=max(kq,dau[j-1]%a[i]);
		}
//		cout<<i<<" "<<kq;
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
    int dpt=0;
    rep(i,n) dpt+=sqrt(i);
//    cout<<dpt;
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=i+1;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
    ford(i,mmax,1){
		dau[i]=(dau[i]?dau[i]:dau[i+1]);
    }
    n=unique(a,a+n)-a;
    rep(i,n){
		int t=sqrt(a[i]);
		foru(j,2,min(a[i],t+2)){
			int t2=a[i]/j;
			kq=max(kq,a[i]%dau[t2+1]);
			kq=max(kq,a[i]%dau[j]);
		}
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
//    rep(i,n) scanf("%d",&a[i]);
	rep(i,n) a[i]=i+1;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
    ford(i,mmax,1){
		dau[i]=(dau[i]?dau[i]:dau[i+1]);
    }
    n=unique(a,a+n)-a;
    rep(i,n){
		int t=sqrt(a[i]);
		foru(j,2,min(a[i],t+2)){
			int t2=a[i]/j;
			kq=max(kq,a[i]%dau[t2+1]);
		}
		foru(j,2,min(a[i],t+2)){
			kq=max(kq,a[i]%dau[j]);
		}
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=2000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
//    cout<<dpt;
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=maxa-5-i;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
	foru(i,1,mmax*2) dau[i]=(dau[i]?dau[i]:dau[i-1]);
	sort(a,a+n);
    n=unique(a,a+n)-a;
    rep(i,n){
		for(int j=2*a[i];j<=mmax+a[i];j+=a[i]){
			kq=max(kq,dau[j-1]%a[i]);
		}
//		cout<<i<<" "<<kq;
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
    int dpt=0;
    rep(i,n) dpt+=sqrt(i);
    cout<<dpt;
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=i+1;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
    ford(i,mmax,1){
		dau[i]=(dau[i]?dau[i]:dau[i+1]);
    }
    n=unique(a,a+n)-a;
    rep(i,n){
		int t=sqrt(a[i]);
		foru(j,2,min(a[i],t+2)){
			int t2=a[i]/j;
			kq=max(kq,a[i]%dau[t2+1]);
			kq=max(kq,a[i]%dau[j]);
		}
    }
    cout<<kq;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define foru(i,l,r) for(int i=l;i<=r;i++)
#define ford(i,r,l) for(int i=r;i>=l;i--)
typedef long long ll;
using namespace std;

const int maxn=2*100005,maxa=1000005;
int n,a[maxn],dau[maxa],kq;

int main(){
//    freopen("test.inp","r",stdin);
    scanf("%d",&n);
    rep(i,n) scanf("%d",&a[i]);
//	rep(i,n) a[i]=i+1;
    rep(i,n) dau[a[i]]=a[i];
    int mmax=*max_element(a,a+n);
    ford(i,mmax,1){
		dau[i]=(dau[i]?dau[i]:dau[i+1]);
    }
    n=unique(a,a+n)-a;
    rep(i,n){
		int t=sqrt(a[i]);
		foru(j,2,min(a[i],t+2)){
			int t2=a[i]/j;
			kq=max(kq,a[i]%dau[t2+1]);
		}
		foru(j,2,min(a[i],t+2)){
			kq=max(kq,a[i]%dau[j]);
		}
    }
    cout<<kq;
}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:12:01
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 2e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        n=unique(a+1,a+1+n)-(a+1);
        for(int i = 1;i < n;i++)
                for(int j = a[i];j < a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n];j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                        if(dp[j] <= j-a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:12:01
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 2e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        n=unique(a+1,a+1+n)-(a+1);
        for(int i = 1;i < n;i++)
                for(int j = a[i]+1;j <= a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n]+1 ;j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                    //     if(a[i]==32) printf("j=%d,dp[j]=%d\n",j,dp[j]);
                        if(dp[j] <= j-a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:12:01
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 2e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) cin>>a[i];
        sort(a+1,a+1+n);
        for(int i = 1;i < n;i++)
                for(int j = a[i];j < a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n];j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                        if(dp[j] <= j-a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:12:01
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 2e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        for(int i = 1;i < n;i++)
                for(int j = a[i];j < a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n];j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                        if(dp[j] <= j-a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:12:01
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 1e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) cin>>a[i];
        sort(a+1,a+1+n);
        for(int i = 1;i < n;i++)
                for(int j = a[i];j < a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n];j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                        if(dp[j] <= j-a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


/* **********************************************
Auther: kalili
Created Time: 2015/6/18 12:10:15
File Name   : ģ����\Codeforces_Round_#276_Div.2\D.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <ctime>
#include <bitset>
#include <algorithm>
#define SZ(x) ((int)(x).size())
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define REP(i,n) for ( int i=1; i<=int(n); i++ )
using namespace std;

const int N = 2e5+100;
const int MAX_VAL = 1e6+100;
int a[N];
int dp[MAX_VAL];

int main()
{
        int n;
        cin>>n;
        int ans=0;
        REP(i,n) cin>>a[i];
        sort(a+1,a+1+n);
        for(int i = 1;i < n;i++)
                for(int j = a[i];j < a[i+1]; j++) dp[j] = a[i];
        for(int j = a[n];j < MAX_VAL; j++) dp[j] = a[n];
        REP(i,n)
                for(int j = 2*a[i] ; j<MAX_VAL ; j += a[i])
                {
                        if(dp[j] <= a[i]) continue;
                        ans = max(ans,dp[j]%a[i]);
                }
        cout<<ans<<endl;

}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int a[maxn],n;
bool ok(int mid){
    for(int i=0;i<n;i++){
        if(a[i]<=mid) continue;
        for(int j=1;j*a[i]<=a[n-1];j++)
            if(vis[j*a[i]+mid]) return true;
    }
    return false;
}
int main(){
    scanf("%d",&n);
    mem(vis,false);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        vis[a[i]]= true;
    }
    sort(a,a+n);
    int l = 0, r = a[n-1], mid,ans;
    while(l<r){
        mid = l+(r-l)/2;
        if(ok(mid)){
            ans = mid;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 2*100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int sum[maxm];
int a[maxn],n;
bool ok(int l,int r){
    for(int i=0;i<n;i++){
        if(a[i]<=l) continue;
        int rr = min(r,a[i]-1);
       // printf("%d %d\n",l,rr);
        for(int j=a[i];j<=a[n-1];j+=a[i]){
           // printf("%d %d %d\n",j,sum[j*a[i]+rr],sum[j*a[i]+l]);
            if(j+l<=a[n-1]){
                int tmp = min(a[n-1],j+rr);
                if(sum[tmp]>sum[j+l-1]) return true;
            }
        }
    }
    return false;
}
int main(){
   // freopen("in.txt","r",stdin);
    scanf("%d",&n);
    mem(sum,0);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum[a[i]]= 1;
    }
    sort(a,a+n);
    for(int i=1;i<=a[n-1];i++) sum[i] += sum[i-1];
    int l = 0, r = a[n-1], mid,ans=0;
    //.//printf("fdafdfdsafsa %d\n",ok(7,9));
    while(l<r){
        mid = l+(r-l)/2;
       // printf("%d %d %d\n",mid+1,r,ok(mid+1,r));
        if(ok(mid+1,r)){
            ans = mid+1;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 2*100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int sum[maxm];
int a[maxn],n;
bool ok(int l,int r){
    for(int i=0;i<n;i++){
        if(a[i]<=l) continue;
        int rr = min(r,a[i]-1);
       // printf("%d %d\n",l,rr);
        for(int j=1;j*a[i]<=a[n-1];j++){
           // printf("%d %d %d\n",j,sum[j*a[i]+rr],sum[j*a[i]+l]);
            if(j*a[i]+l<=a[n-1]){
                int tmp = min(a[n-1],j*a[i]+rr);
                if(sum[tmp]>sum[j*a[i]+l-1]) return true;
            }
        }
    }
    return false;
}
int main(){
   // freopen("in.txt","r",stdin);
    scanf("%d",&n);
    mem(sum,0);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum[a[i]]= 1;
    }
    sort(a,a+n);
    for(int i=1;i<=a[n-1];i++) sum[i] += sum[i-1];
    int l = 0, r = a[n-1], mid,ans=0;
    //.//printf("fdafdfdsafsa %d\n",ok(7,9));
    while(l<r){
        mid = l+(r-l)/2;
       // printf("%d %d %d\n",mid+1,r,ok(mid+1,r));
        if(ok(mid+1,r)){
            ans = mid+1;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 2*100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int sum[maxm];
int a[maxn],n;
bool ok(int l,int r){
    for(int i=0;i<n;i++){
        if(a[i]<=l) continue;
        int rr = min(r,a[i]-1);
       // printf("%d %d\n",l,rr);
        for(int j=1;j*a[i]<=a[n-1];j++){
           // printf("%d %d %d\n",j,sum[j*a[i]+rr],sum[j*a[i]+l]);
            if(j*a[i]+rr<=a[n-1] && sum[j*a[i]+rr]>sum[j*a[i]+l-1]) return true;
        }
    }
    return false;
}
int main(){
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    mem(vis,false);
    mem(sum,0);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        vis[a[i]]= true;
    }
    sort(a,a+n);
    if(vis[0]) sum[0]=1;
    for(int i=1;i<=a[n-1];i++){
        if(vis[i]) sum[i]=1;
        sum[i] += sum[i-1];
    }
    int l = 0, r = a[n-1], mid,ans=0;
    //.//printf("fdafdfdsafsa %d\n",ok(7,9));
    while(l<r){
        mid = l+(r-l)/2;
       // printf("%d %d %d\n",mid+1,r,ok(mid+1,r));
        if(ok(mid+1,r)){
            ans = mid+1;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 2*100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int sum[maxm];
int a[maxn],n;
bool ok(int l,int r){
    for(int i=0;i<n;i++){
        if(a[i]<=l) continue;
        int rr = min(r,a[i]-1);
       // printf("%d %d\n",l,rr);
        for(int j=1;j*a[i]<=a[n-1];j++){
           // printf("%d %d %d\n",j,sum[j*a[i]+rr],sum[j*a[i]+l]);
            if(j*a[i]+l<=a[n-1]){
                int tmp = min(a[n-1],j*a[i]+rr);
                if(sum[tmp]>sum[j*a[i]+l-1]) return true;
            }
        }
    }
    return false;
}
int main(){
   // freopen("in.txt","r",stdin);
    scanf("%d",&n);
    mem(vis,false);
    mem(sum,0);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        vis[a[i]]= true;
    }
    sort(a,a+n);
    if(vis[0]) sum[0]=1;
    for(int i=1;i<=maxm;i++){
        if(vis[i]) sum[i]=1;
        sum[i] += sum[i-1];
    }
    int l = 0, r = a[n-1], mid,ans=0;
    //.//printf("fdafdfdsafsa %d\n",ok(7,9));
    while(l<r){
        mid = l+(r-l)/2;
       // printf("%d %d %d\n",mid+1,r,ok(mid+1,r));
        if(ok(mid+1,r)){
            ans = mid+1;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define mem(name,value) memset(name,value,sizeof(name))
#define FOR(i,n) for(int i=1;i<=n;i++)
using namespace std;
const int maxn = 2*100000+5;
const int maxm = 1000000+5;
bool vis[maxm];
int a[maxn],n;
bool ok(int mid){
    for(int i=0;i<n;i++){
        if(a[i]<=mid) continue;
        for(int j=1;j*a[i]<=a[n-1];j++)
            if(vis[j*a[i]+mid]) return true;
    }
    return false;
}
int main(){
    scanf("%d",&n);
    mem(vis,false);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        vis[a[i]]= true;
    }
    sort(a,a+n);
    int l = 0, r = a[n-1], mid,ans;
    while(l<r){
        mid = l+(r-l)/2;
        if(ok(mid)){
            ans = mid;
            l = mid+1;
        }else r = mid;
    }
    printf("%d\n",ans);
    return 0;
}


//求前缀和可提高本题的运行效率
//Version 2018年8月6日17:02:18 //For GCC
#include<stdio.h>
int main()
{
	int n,k,i,t;
	double a[5000],sum[5000],p,ans=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{scanf("%lf",a+i); sum[i]=sum[i-1]+a[i];}
	for(i=0;i<n;i++)
		for(t=k;t<=n;t++)
		{
			if(i+t-1>=n) break;
			if(i==0) p=(sum[i+t-1]-0)/t;
			else p=(sum[i+t-1]-sum[i-1])/t;
			if(p>ans) ans=p;
		}
	printf("%lf",ans);
	return 0;
}


//求前缀和可提高本题的运行效率
//Version 2018年8月6日17:16:35 //For GCC
#include<stdio.h>
int main()
{
	int n,k,i,t;
	double a[5000],sum[5000],p,ans=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{scanf("%lf",a+i); sum[i]=sum[i-1]+a[i];}
	for(i=0;i<n;i++)
		for(t=k;t<=n;t++)
		{
			if(i+t-1>=n) break;
			if(i==0) p=(sum[i+t-1]-0)/t;
			else p=(sum[i+t-1]-sum[i-1])/t;
			if(p>ans) ans=p;
		}
	printf("%lf",ans);
	return 0;
}

/*#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	double a[5000],sum[5000],p,ans=0;
	int i,t,m;
	scanf("%d%d",&n,&k);
	getchar();sum[0]=0;
	for(i=0;i<n;i++)
	{
		scanf("%lf",a+i);
		if(i==0) sum[1]=a[i];
		else sum[i+1]=sum[i]+a[i];
		//printf("%lf\n",sum[i]);
	}
	getchar();
	//system("pause");
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	//for(auto &v:sum)
	//{
	//	cout<<v<<endl;
	//	if(&v==sum+n-1)
	//		break;
	//}
	//system("pause");
	double L,R;
	for(i=1;i<=n;i++)
	{
		for(t=k;t<=n;t++)
		{
			if(i+t-1>n) break;
			if(i-1==0)
			{
				R=((double)(0));
				L=sum[i+t-1];
				//if(i+t-1>n) break;
			}
			else
			{
				R=sum[i-1];
				L=sum[i+t-1];
			}
			p=L-R;
			p/=((double)t);
			if(p>ans) ans=p;
		}
	}

	printf("%lf",ans);
	return 0;
}*/

/*int main()
{
	int n,k,i,m,t,d;
	double a[5000],ans=-1,p;
	scanf("%d%d",&n,&k);
	getchar();
	for(i=0;i<n;i++)
		scanf("%lf",a+i);
	getchar();
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	for(i=0;i<=m;i++)
	{
		for(d=k;d<k+n-1;d++)
		{
			for(p=0,t=0;t<d;t++)
				p+=a[i+t];
			p/=((double)d);
			//printf("p=%lf\n",p);
			if(p>ans)
			{
				//printf("%lf,%lf\n",p,ans);
				ans=p;
			}
			//if(d>k+10)
			//{
			//	d=k+n-10;
			//	continue;
			//}
		}
	}
	for(p=0,i=0;i<n;i++)
		p+=a[i];
	p/=((double)n);
	if(p>ans)
		ans=p;
	printf("%lf",ans);
}*/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
double a[100000];
int main()
{
	int n,k,i,m,t,d;
	double ans=-1,p;
	scanf("%d%d",&n,&k);
	getchar();
	for(i=0;i<n;i++)
		scanf("%lf",a+i);
	getchar();
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	for(i=0;i<=m;i++)
	{
		for(d=k;d<k+n-1;d++)
		{
			for(p=0,t=0;t<d;t++)
				p+=a[i+t];
			p/=((double)d);
			//printf("p=%lf\n",p);
			if(p>ans)
			{
				//printf("%lf,%lf\n",p,ans);
				ans=p;
			}

		}
	}
	for(p=0,i=0;i<n;i++)
		p+=a[i];
	p/=((double)n);
	if(p>ans)
		ans=p;
	printf("%lf",a[-1]);
}*/


//求前缀和可提高本题的运行效率
//Version 2018年8月6日17:02:18
#include<stdio.h>
int main()
{
	int n,k,i,t;
	double a[5000],sum[5000],p,ans=0;
	scanf("%d%d",&n,&k);
	getchar();
	for(i=0;i<n;i++)
	{
		scanf("%lf",a+i);
		sum[i]=sum[i-1]+a[i];
	}
	getchar();
	for(i=0;i<n;i++)
		for(t=k;t<=n;t++)
		{
			if(i+t-1>=n) break;
			if(i==0) p=(sum[i+t-1]-0)/t;
			else p=(sum[i+t-1]-sum[i-1])/t;
			if(p>ans) ans=p;
		}
	printf("%lf",ans);
	return 0;
}

/*#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	int n,k;
	double a[5000],sum[5000],p,ans=0;
	int i,t,m;
	scanf("%d%d",&n,&k);
	getchar();sum[0]=0;
	for(i=0;i<n;i++)
	{
		scanf("%lf",a+i);
		if(i==0) sum[1]=a[i];
		else sum[i+1]=sum[i]+a[i];
		//printf("%lf\n",sum[i]);
	}
	getchar();
	//system("pause");
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	//for(auto &v:sum)
	//{
	//	cout<<v<<endl;
	//	if(&v==sum+n-1)
	//		break;
	//}
	//system("pause");
	double L,R;
	for(i=1;i<=n;i++)
	{
		for(t=k;t<=n;t++)
		{
			if(i+t-1>n) break;
			if(i-1==0)
			{
				R=((double)(0));
				L=sum[i+t-1];
				//if(i+t-1>n) break;
			}
			else
			{
				R=sum[i-1];
				L=sum[i+t-1];
			}
			p=L-R;
			p/=((double)t);
			if(p>ans) ans=p;
		}
	}

	printf("%lf",ans);
	return 0;
}*/

/*int main()
{
	int n,k,i,m,t,d;
	double a[5000],ans=-1,p;
	scanf("%d%d",&n,&k);
	getchar();
	for(i=0;i<n;i++)
		scanf("%lf",a+i);
	getchar();
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	for(i=0;i<=m;i++)
	{
		for(d=k;d<k+n-1;d++)
		{
			for(p=0,t=0;t<d;t++)
				p+=a[i+t];
			p/=((double)d);
			//printf("p=%lf\n",p);
			if(p>ans)
			{
				//printf("%lf,%lf\n",p,ans);
				ans=p;
			}
			//if(d>k+10)
			//{
			//	d=k+n-10;
			//	continue;
			//}
		}
	}
	for(p=0,i=0;i<n;i++)
		p+=a[i];
	p/=((double)n);
	if(p>ans)
		ans=p;
	printf("%lf",ans);
}*/
/*#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
double a[100000];
int main()
{
	int n,k,i,m,t,d;
	double ans=-1,p;
	scanf("%d%d",&n,&k);
	getchar();
	for(i=0;i<n;i++)
		scanf("%lf",a+i);
	getchar();
	if(k==1)
	{
		sort(a,a+n);
		printf("%lf\n",a[n-1]);
		return 0;
	}
	m=n-k;
	for(i=0;i<=m;i++)
	{
		for(d=k;d<k+n-1;d++)
		{
			for(p=0,t=0;t<d;t++)
				p+=a[i+t];
			p/=((double)d);
			//printf("p=%lf\n",p);
			if(p>ans)
			{
				//printf("%lf,%lf\n",p,ans);
				ans=p;
			}

		}
	}
	for(p=0,i=0;i<n;i++)
		p+=a[i];
	p/=((double)n);
	if(p>ans)
		ans=p;
	printf("%lf",a[-1]);
}*/


#include<stdio.h>
#include<stdlib.h>
int n, k, a[5001];
int total[5001];
double ans = 0.0;
double cal(int start, int step){
    return (total[start+step-1]-total[start-1])/(step*1.0);
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }

    total[0]=0;
    total[1]=a[1];
    for(int i=2;i<=n;i++){
        total[i]=total[i-1]+a[i];
    }

    for(int i=k;i<=n;i++){
        for(int j=1;j+i<=n;j++){
            double temp=cal(j,i);
            // printf("%d",temp)
            ans=temp>ans?temp:ans;
        }
    }
    printf("%lf",ans);
    // system("pause");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int n, k, a[5001];
int total[5001];
double ans = 0.0;
double cal(int start, int step){
    return (total[start+step-1]-total[start-1])/(step*1.0);
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }

    total[0]=0;
    total[1]=a[1];
    for(int i=2;i<=n;i++){
        total[i]=total[i-1]+a[i];
    }

    for(int i=k;i<=n;i++){
        for(int j=1;j+i-1<=n;j++){
            double temp=cal(j,i);
            // printf("%d",temp)
            ans=temp>ans?temp:ans;
        }
    }
    printf("%lf",ans);
    // system("pause");
    return 0;
}


#include <stdio.h>

int main() {
	int n,a[10000],k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	float maxi=0.0;
	int psum[n+1];
    for(int i=0;i<=n;i++)
    psum[i]=0;
	for(int i=1;i<=n;i++)
	{
	psum[i]=psum[i-1]+a[i-1];
//	cout<<psum[i]<<" ";
	}
	//cout<<endl;
	for(int i=k;i<=n;i++)
	{
	    for(int z=i-k;z>=0;z--)
	    {  //cout<<psum[i]-psum[z];
	        double curr=(double)((psum[i]-psum[z]))/(i-z);
	        if(curr>maxi)
	        maxi=curr;
	    }
	}
//	int precision = std::numeric_limits<double>::max_digits10;
//std::cout << std::setprecision(precision) << maxi << std::endl;

    printf("%0.16f",maxi);
	return 0;
}


#include <stdio.h>

int main() {
	int n,a[10000],k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	double maxi=0.0;
	int psum[n+1];
    for(int i=0;i<=n;i++)
    psum[i]=0;
	for(int i=1;i<=n;i++)
	{
	psum[i]=psum[i-1]+a[i-1];
//	cout<<psum[i]<<" ";
	}
	//cout<<endl;
	for(int i=k;i<=n;i++)
	{
	    for(int z=i-k;z>=0;z--)
	    {  //cout<<psum[i]-psum[z];
	        double curr=(double)(((psum[i]-psum[z])))/(double)(i-z);
	        if(curr>maxi)
	        maxi=curr;
	    }
	}
//	int precision = std::numeric_limits<double>::max_digits10;
//std::cout << std::setprecision(precision) << maxi << std::endl;

    printf("%0.16f",maxi);
	return 0;
}