#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 200010;
vector<int> v[N],pos[N];
int a[N];
int main(void)
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        int num=v[a[i]].size();
        vector<int>::iterator iter;
        iter=lower_bound(v[a[i]].begin(),v[a[i]].end(),i-num-k);
        if(v[a[i]].size()!=0)
        {
            int u=iter-v[a[i]].begin();
            ans=max(ans,num-u+1);
        }
        v[a[i]].push_back(i-num);
        pos[a[i]].push_back(i);
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 100010;
vector<int> v[N],pos[N];
int a[N];
int main(void)
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int num=v[a[i]].size();
		vector<int>::iterator iter;
		iter=lower_bound(v[a[i]].begin(),v[a[i]].end(),i-num-k);
		if(v[a[i]].size()!=0)
		{
			int u=iter-v[a[i]].begin();
			ans=max(ans,num-u+1);
		}
		v[a[i]].push_back(i-num);
		pos[a[i]].push_back(i);
	}
	printf("%d\n",ans);
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 100010;
vector<int> v[N],pos[N];
int a[N];
int main(void)
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int ans=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        int num=v[a[i]].size();
        vector<int>::iterator iter;
        iter=lower_bound(v[a[i]].begin(),v[a[i]].end(),i-num-k);
        if(v[a[i]].size()!=0)
        {
            int u=iter-v[a[i]].begin();
            ans=max(ans,num-u+1);
        }
        v[a[i]].push_back(i-num);
        pos[a[i]].push_back(i);
    }
    printf("%d\n",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=110000;
struct T1
{
    int l,r;
};
vector<T1> b[maxn];
int a[maxn],n,m,k,ans;
T1 c[maxn];
int run(int n)
{
    //cout<<b[n].size()<<endl;
    int m=0,i,cost=0,ans=0;
    if (b[n].size()==0) return 0;
    for (int i=0; i<b[n].size();i++)
    c[i+1]=b[n][i];
    int head=1,tail=0;
    while (true)
    {
        //cout<<head<<' '<<tail<<endl;
        if (head<=tail)
        {
            m-=c[head].r-c[head].l+1;
            head++;
            if (cost>0) cost=cost-(c[head].l-c[head-1].r-1);
        }
        if (head>tail)
        {
            tail++; m=c[tail].r-c[tail].l+1;
            cost = 0;
        }
        while (tail+1<=b[n].size()&&cost+c[tail+1].l-c[tail].r-1<=k)
        {
            tail++; m+=c[tail].r-c[tail].l+1;
            cost+=c[tail].l-c[tail-1].r-1;
        }
        ans=max(ans,m);
        if (tail==b[n].size()) break;
    }
    return ans;
}
int main()
{
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin>>n>>m>>k;
    for (int i=1; i<=n; i++) scanf("%d",&a[i]);
    int i=1,j;
    while (true)
    {
        if (i>n) break;
        j=i;
        while (a[j+1]==a[i]) j++;
        T1 p; int t=a[i];
        p.l=i; p.r=j;
        b[t].push_back(p);
        i=j+1;
    }
    for (int i=1; i<=m; i++)
    ans=max(ans,run(i));
    cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int maxn=1100000;
struct T1
{
    int l,r;
};
vector<T1> b[maxn];
int a[maxn],n,m,k,ans;
T1 c[maxn];
int run(int n)
{
    //cout<<b[n].size()<<endl;
    int m=0,i,cost=0,ans=0;
    if (b[n].size()==0) return 0;
    for (int i=0; i<b[n].size();i++)
    c[i+1]=b[n][i];
    int head=1,tail=0;
    while (true)
    {
        //cout<<head<<' '<<tail<<endl;
        if (head<=tail)
        {
            m-=c[head].r-c[head].l+1;
            head++;
            if (cost>0) cost=cost-(c[head].l-c[head-1].r-1);
        }
        if (head>tail)
        {
            tail++; m=c[tail].r-c[tail].l+1;
            cost = 0;
        }
        while (tail+1<=b[n].size()&&cost+c[tail+1].l-c[tail].r-1<=k)
        {
            tail++; m+=c[tail].r-c[tail].l+1;
            cost+=c[tail].l-c[tail-1].r-1;
        }
        ans=max(ans,m);
        if (tail==b[n].size()) break;
    }
    return ans;
}
int main()
{
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    cin>>n>>m>>k;
    for (int i=1; i<=n; i++) scanf("%d",&a[i]);
    int i=1,j;
    while (true)
    {
        if (i>n) break;
        j=i;
        while (a[j+1]==a[i]) j++;
        T1 p; int t=a[i];
        p.l=i; p.r=j;
        b[t].push_back(p);
        i=j+1;
    }
    for (int i=1; i<=m; i++)
    ans=max(ans,run(i));
    cout<<ans<<endl;
}


#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <bitset>
#include <vector>
#include <string>
#include <cstdio>
#include <cassert>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define fill(a,key) memset(a, key, sizeof(a))
#define all(x) x.begin(), x.end()
#define sqr(x) (x)*(x)
#define fi first
#define se second
#define forn(i,n) for (i = 0; i < n; i++)
#define curtime double(clock())/double(CLOCKS_PER_SEC)
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int dx[] = {-1,0,1,0,-1,-1,1,1,0};
const int dy[] = {0,1,0,-1,-1,1,1,-1,0};
const int inf = 1<<30;

int n,m,k,x,best,i,s[100500];
vi c[100500];

void calc(const vi &a)
{
	int i, n = sz(a),l,r,mid,ans;
	for (i = 0; i+1 < n; i++)
		s[i] = a[i+1] - a[i] - 1;
	for (i = 0; i < n; i++)
		s[i] += (i>0?s[i-1]:0);
	for (i = 0; i < n; i++)
	{
		l=0;
		r=i;
		ans=i;
		while (l<=r)
		{
			mid = (l+r)/2;
			if (s[i]-(((i+1<n)?(a[i+1] - a[i] - 1):0))-(mid>0?s[mid-1]:0)<=k)
				ans=mid,
				r=mid-1;
			else
				l=mid+1;
		}
		best = max(best, i-ans+1);
	}
}

int main()
{
	//ios_base::sync_with_stdio(0);
	srand(time(0));
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d%d",&n,&m,&k);

	for (i = 1; i <= n; i++)
	{
		scanf("%d", &x);
		c[x].pb(i);
	}

	for (i = 1; i <= m; i++)
		calc(c[i]);

	printf("%d", best);

	return 0;
}


#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <bitset>
#include <vector>
#include <string>
#include <cstdio>
#include <cassert>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define fill(a,key) memset(a, key, sizeof(a))
#define all(x) x.begin(), x.end()
#define sqr(x) (x)*(x)
#define fi first
#define se second
#define forn(i,n) for (i = 0; i < n; i++)
#define curtime double(clock())/double(CLOCKS_PER_SEC)
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int dx[] = {-1,0,1,0,-1,-1,1,1,0};
const int dy[] = {0,1,0,-1,-1,1,1,-1,0};
const int inf = 1<<30;

int n,m,k,x,ans,i,s[100500];
vi c[100500];

int calc(const vi &a)
{
	int i, n = sz(a),l,r,mid,best=0,ans;
	for (i = 0; i+1 < n; i++)
		s[i] = a[i+1] - a[i] - 1;
	for (i = 0; i < n; i++)
		s[i] += (i>0?s[i-1]:0);
	for (i = 0; i < n; i++)
	{
		l=0;
		r=i;
		ans=-1;
		while (l<=r)
		{
			mid = (l+r)/2;
			if (s[i]-(mid>0?s[mid-1]:0)<=k)
				ans=mid,
				r=mid-1;
			else
				l=mid+1;
		}
		if (ans!=-1)
            best = max(best, i-ans+1);
	}
	return best;
}

int main()
{
	//ios_base::sync_with_stdio(0);
	srand(time(0));
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d%d",&n,&m,&k);

	for (i = 1; i <= n; i++)
	{
		scanf("%d", &x);
		c[x].pb(i);
	}

	for (i = 1; i <= m; i++)
		ans = max(ans, calc(c[i]));

	printf("%d", ans);

	return 0;
}


#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <bitset>
#include <vector>
#include <string>
#include <cstdio>
#include <cassert>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;

#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define fill(a,key) memset(a, key, sizeof(a))
#define all(x) x.begin(), x.end()
#define sqr(x) (x)*(x)
#define fi first
#define se second
#define forn(i,n) for (i = 0; i < n; i++)
#define curtime double(clock())/double(CLOCKS_PER_SEC)
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int dx[] = {-1,0,1,0,-1,-1,1,1,0};
const int dy[] = {0,1,0,-1,-1,1,1,-1,0};
const int inf = 1<<30;

int n,m,k,x,best,i,s[100500];
vi c[100500];

void calc(const vi &a)
{
	int i, n = sz(a),l,r,mid,ans;
	for (i = 0; i+1 < n; i++)
		s[i] = a[i+1] - a[i] - 1;
	s[n-1] = 0;
	for (i = 1; i < n; i++)
		s[i] += s[i-1];
	for (i = 0; i < n; i++)
	{
		l=0;
		r=i;
		while (l<=r)
		{
			mid = (l+r)/2;
			if ((i>0?s[i-1]:0)-(mid>0?s[mid-1]:0)<=k)
				ans=mid,
				r=mid-1;
			else
				l=mid+1;
		}
		best = max(best, i-ans+1);
	}
}

int main()
{
	//ios_base::sync_with_stdio(0);
	srand(time(0));
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	scanf("%d%d%d",&n,&m,&k);

	for (i = 1; i <= n; i++)
	{
		scanf("%d", &x);
		c[x].pb(i);
	}

	for (i = 1; i <= m; i++)
		calc(c[i]);

	printf("%d", best);

	return 0;
}


#include<bits/stdc++.h>
#define allset(x) __builtin_popcount(x)a
#define trail0(x) __builtin_ctz(x)
#define sn(x) scanf("%d",&x) ;
#define ff first
#define ss second
#define p_b push_back
#define ll long long
#define m_p make_pair
#define p_q priority_queue
#define pii pair<int,int>
#define pli pair<ll,ll>1
#define vi  vector<int>
#define vl vector<ll>
#define mod 1000000007
#define f(i,a,b) for(int i = a;i<b;i++)
#define INF 100000000
int dr4[] = {1,0,-1,0} , dc4[]= {0,-1,0,1} ;
int dr8[] = {1,1,0,-1,-1,-1,0,1} , dc8[] = {0,-1,-1,-1,0,1,1,1} ;

using namespace std ;

int n,m,k,x,ans ;
vector<int> v[100009] ;

int main()
{
    cin>>n>>m>>k ;
    for(int i = 0;i<n;i++)
     {
         cin>>x ; v[x].push_back(i) ;
     }
     ans=0;
    f(i,1,100001)
    {
         int len = v[i].size() ,temp = 0 ,res = 1;
         if(len)
         {
             int lo = 0  , hi = 0;
             while(hi<len-1&&lo<len-1)
             {
                 temp+= (v[i][hi+1] - v[i][hi] -1) ;
                        //cout<<temp<<" "<<lo<<" "<<hi<<" "<<ans<<" "<<res<<endl ;
                 if(temp<=k){hi++ ; res++ ;}
                 else{temp-= ((v[i][lo+1]-v[i][lo])+1) ; lo++ ;res--;}
                 ans = max(res,ans) ;

             }
         }
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define allset(x) __builtin_popcount(x)a
#define trail0(x) __builtin_ctz(x)
#define sn(x) scanf("%d",&x) ;
#define ff first
#define ss second
#define p_b push_back
#define ll long long
#define m_p make_pair
#define p_q priority_queue
#define pii pair<int,int>
#define pli pair<ll,ll>1
#define vi  vector<int>
#define vl vector<ll>
#define mod 1000000007
#define f(i,a,b) for(int i = a;i<b;i++)
#define INF 100000000
int dr4[] = {1,0,-1,0} , dc4[]= {0,-1,0,1} ;
int dr8[] = {1,1,0,-1,-1,-1,0,1} , dc8[] = {0,-1,-1,-1,0,1,1,1} ;

using namespace std ;

int n,m,k,x,ans ;
vector<int> v[100009] ;

int main()
{
    cin>>n>>m>>k ;
    for(int i = 0;i<n;i++)
     {
         cin>>x ; v[x].push_back(i) ;
     }
     ans=1;
    f(i,1,100001)
    {
         int len = v[i].size() ;
         if(len)
         {
             int temp = 0 ,res = 1,lo = 0,hi = 0 ;
             while(hi<len-1&&lo<=hi)
             {
                 temp+= (v[i][hi+1] - (v[i][hi]+1)) ;

                 if(temp<=k){hi++ ; res++ ;}
                 else{if(lo==hi){lo++; hi++ ; temp = 0; } else {temp-= (v[i][lo+1]-(v[i][lo]+1)) ;temp-=(v[i][hi+1] - (v[i][hi]+1)) ; lo++ ;res--;}}
                 ans = max(res,ans) ;
                // if(i==1){
               //  cout<<temp<<" "<<lo<<" "<<hi<<" ";
               // cout<<ans<<" "<<res<<endl ;}
             }
         }
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define allset(x) __builtin_popcount(x)a
#define trail0(x) __builtin_ctz(x)
#define sn(x) scanf("%d",&x) ;
#define ff first
#define ss second
#define p_b push_back
#define ll long long
#define m_p make_pair
#define p_q priority_queue
#define pii pair<int,int>
#define pli pair<ll,ll>1
#define vi  vector<int>
#define vl vector<ll>
#define mod 1000000007
#define f(i,a,b) for(int i = a;i<b;i++)
#define INF 100000000
int dr4[] = {1,0,-1,0} , dc4[]= {0,-1,0,1} ;
int dr8[] = {1,1,0,-1,-1,-1,0,1} , dc8[] = {0,-1,-1,-1,0,1,1,1} ;

using namespace std ;

int n,m,k,x,ans ;
vector<int> v[100009] ;

int main()
{
    cin>>n>>m>>k ;
    for(int i = 0;i<n;i++)
     {
         cin>>x ; v[x].push_back(i) ;
     }
     ans=1;
    f(i,1,100001)
    {
         int len = v[i].size() ;
         if(len)
         {
             int temp = 0 ,res = 1,lo = 0,hi = 0 ;
             while(hi<len-1&&lo<=hi)
             {
                 temp+= (v[i][hi+1] - (v[i][hi]+1)) ;

                 if(temp<=k){hi++ ; res++ ;}
                 else{temp-= (v[i][lo+1]-(v[i][lo]+1)) ;temp-=(v[i][hi+1] - (v[i][hi]+1)) ; lo++ ;res--;}
                 ans = max(res,ans) ;
                 //cout<<temp<<" "<<lo<<" "<<hi<<" ";
                // cout<<ans<<" "<<res<<endl ;
             }
         }
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define allset(x) __builtin_popcount(x)a
#define trail0(x) __builtin_ctz(x)
#define sn(x) scanf("%d",&x) ;
#define ff first
#define ss second
#define p_b push_back
#define ll long long
#define m_p make_pair
#define p_q priority_queue
#define pii pair<int,int>
#define pli pair<ll,ll>1
#define vi  vector<int>
#define vl vector<ll>
#define mod 1000000007
#define f(i,a,b) for(int i = a;i<b;i++)
#define INF 100000000
int dr4[] = {1,0,-1,0} , dc4[]= {0,-1,0,1} ;
int dr8[] = {1,1,0,-1,-1,-1,0,1} , dc8[] = {0,-1,-1,-1,0,1,1,1} ;

using namespace std ;

int n,m,k,x,ans ;
vector<int> v[100009] ;

int main()
{
    cin>>n>>m>>k ;
    for(int i = 0;i<n;i++)
     {
         cin>>x ; v[x].push_back(i) ;
     }
     ans=0;
    f(i,1,100001)
    {
         int len = v[i].size() ;
         if(len)
         {
             int temp = 0 ,res = 1,lo = 0,hi = 0 ;
             while(hi<len-1&&lo<=hi)
             {
                 temp+= (v[i][hi+1] - (v[i][hi]+1)) ;

                 if(temp<=k){hi++ ; res++ ;}
                 else{temp-= (v[i][lo+1]-(v[i][lo]+1)) ;temp-=(v[i][hi+1] - (v[i][hi]+1)) ; lo++ ;res--;}
                 ans = max(res,ans) ;
                 //cout<<temp<<" "<<lo<<" "<<hi<<" ";
                // cout<<ans<<" "<<res<<endl ;
             }
         }
    }
    cout<<ans<<endl ;
}


#include<bits/stdc++.h>
#define allset(x) __builtin_popcount(x)a
#define trail0(x) __builtin_ctz(x)
#define sn(x) scanf("%d",&x) ;
#define ff first
#define ss second
#define p_b push_back
#define ll long long
#define m_p make_pair
#define p_q priority_queue
#define pii pair<int,int>
#define pli pair<ll,ll>1
#define vi  vector<int>
#define vl vector<ll>
#define mod 1000000007
#define f(i,a,b) for(int i = a;i<b;i++)
#define INF 100000000
int dr4[] = {1,0,-1,0} , dc4[]= {0,-1,0,1} ;
int dr8[] = {1,1,0,-1,-1,-1,0,1} , dc8[] = {0,-1,-1,-1,0,1,1,1} ;

using namespace std ;

int n,m,k,x,ans ;
vector<int> v[100009] ;

int main()
{
    cin>>n>>m>>k ;
    for(int i = 0;i<n;i++)
     {
         cin>>x ; v[x].push_back(i) ;
     }
     ans=0;
    f(i,1,100001)
    {
         int len = v[i].size() ;
         if(len)
         {
             int temp = 0 ,res = 1,lo = 0,hi = 0 ;
             while(hi<len-1&&lo<=hi)
             {
                 temp+= (v[i][hi+1] - (v[i][hi]+1)) ;

                 if(temp<=k){hi++ ; res++ ;}
                 else{temp-= (v[i][lo+1]-(v[i][lo]+1)) ;temp-=(v[i][hi+1] - (v[i][hi]+1)) ; lo++ ;res--;}
                 ans = max(res,ans) ;
                 cout<<temp<<" "<<lo<<" "<<hi<<" ";
                 cout<<ans<<" "<<res<<endl ;
             }
         }
    }
    cout<<ans<<endl ;
}


#include <cstdio>
#include <vector>
using namespace std;
vector<int> a[222222];
int solve(vector<int> a,int k)
{
  int n=a.size();
  int res=1;
  int st,ed; st=0; ed=0;
  int p=0;
  while(ed<n){
    //printf("%d %d %d\n",a.size(),st,ed);
    while(st<n-1 && p+(a[ed+1]-a[ed]-1)>k){
      if(st<n)p-=a[st+1]-a[st]-1;
      st++;
    }
    if(ed<n)p+=(a[ed+1]-a[ed]-1);
    ed++;
    if(ed<n)res=max(res,ed-st+1);
  }
  return res;
}
int main(void)
{
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  for(int i=0;i<n;i++){
    int p; scanf("%d",&p); p--;
    a[p].push_back(i);
  }
  int res=0;
  for(int i=0;i<m;i++){
    res=max(res,solve(a[i],k));
  }
  printf("%d\n",res);
  return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
vector<int> a[222222];
int solve(vector<int> a,int k)
{
  int n=a.size();
  int res=1;
  int st,ed; st=0; ed=0;
  int p=0;
  while(ed<n){
    //printf("%d %d %d\n",a.size(),st,ed);
    while(st<n && p+(a[ed+1]-a[ed]-1)>k){
      p-=a[st+1]-a[st]-1;
      st++;
    }
    p+=(a[ed+1]-a[ed]-1);
    ed++;
    if(ed<n)res=max(res,ed-st+1);
  }
  return res;
}
int main(void)
{
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  for(int i=0;i<n;i++){
    int p; scanf("%d",&p); p--;
    a[p].push_back(i);
  }
  int res=0;
  for(int i=0;i<m;i++){
    res=max(res,solve(a[i],k));
  }
  printf("%d\n",res);
  return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
vector<int> a[222222];
int solve(vector<int> a,int k)
{
  int n=a.size();
  int res=1;
  int st,ed; st=0; ed=0;
  int p=0;
  while(ed<n-1){
    //printf("%d %d %d\n",a.size(),st,ed);
    while(st<n-1 && p+(a[ed+1]-a[ed]-1)>k){
      if(st<n)p-=a[st+1]-a[st]-1;
      st++;
    }
    if(ed<n)p+=(a[ed+1]-a[ed]-1);
    ed++;
    if(ed<n)res=max(res,ed-st+1);
  }
  return res;
}
int main(void)
{
  int n,m,k;
  scanf("%d%d%d",&n,&m,&k);
  for(int i=0;i<n;i++){
    int p; scanf("%d",&p); p--;
    a[p].push_back(i);
  }
  int res=0;
  for(int i=0;i<m;i++){
    res=max(res,solve(a[i],k));
  }
  printf("%d\n",res);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int mod=1000000007;
long long int c[100003];
long a[200004],v[200004];
int main()
{
    long n,m,k;
    cin>>n>>m>>k;
    set< pair< long ,long > >s;
    for(long i=1;i<=n;i++){cin>>a[i];
    }
    long j=1;
    long ans=1;
    for(long i=1;i<=n;i++)
    {
        while(j<=n)
        {
           if(v[j]==0){ s.erase(make_pair(-c[a[j]],a[j]));
            c[a[j]]++;//cout<<c[a[j]]<<endl;
            s.insert(make_pair(-c[a[j]],a[j]));v[j]=1;}
            long h=-s.begin()->first;
            if(j-i+1-h<=k){ans=max(ans,h);j++;}
            else {break;}
        }
        s.erase(make_pair(-c[a[i]],a[i]));
        c[a[i]]--;
        s.insert(make_pair(-c[a[i]],a[i]));

    }
    cout<<ans<<endl;

}


#include <bits/stdc++.h>
using namespace std;
long a[1000004],dp[1000004];
int main()
{
    ios::sync_with_stdio(false);
        	cin.tie(0);
        	cout.tie(0);
    long n,m,k;
 scanf("%d", &(n));scanf("%d", &(m));scanf("%d", &(k));
    for(long i=1;i<=n;i++)scanf("%d", &(a[i]));
    long l=1;long r=n+1;
    long ans=1;
    while(r-l>1)
    {
        set< pair<long ,long > >s;
        while(!s.empty())s.erase(s.begin());
        for(long i=1;i<=100000;i++)dp[i]=0;
        long mid=(l+r)/2;
        for(long i=1;i<=mid;i++)
        {
            s.erase(make_pair(-dp[a[i]],a[i]));
            dp[a[i]]++;
            s.insert(make_pair(-dp[a[i]],a[i]));
        }
        bool g=false;
        long h=-s.begin()->first;
      //  cout<<mid<<endl;
        //cout<<h<<" fff "<<s.begin()->second<<endl;

        if(h>=mid-k){g=true; ans=max(ans,h);}
        for(long i=mid+1;i<=n;i++)
        {
            long f=i-mid;
            s.erase(make_pair(-dp[a[f]],a[f]));
            dp[a[f]]--;
           //cout<<a[f]<< " bb "<<dp[a[f]]<<endl;
            s.insert(make_pair(-dp[a[f]],a[f]));

            s.erase(make_pair(-dp[a[i]],a[i]));
            dp[a[i]]++;
            //cout<<a[i]<<" bb "<<dp[a[i]]<<endl;
            s.insert(make_pair(-dp[a[i]],a[i]));
            long h=-s.begin()->first;
           // cout<<h<<" ff "<<s.begin()->second<<endl;
            if(h>=mid-k){g=true; ans=max(ans,h);}
        }
        if(g)l=mid;
        else r=mid;
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<set>
using namespace std;
long a[1000004],dp[1000004];
int main()
{
    ios::sync_with_stdio(false);
        	cin.tie(0);
        	cout.tie(0);
    long n,m,k;
    cin>>n>>m>>k;
    for(long i=1;i<=n;i++)cin>>a[i];
    long l=1;long r=n+1;
    long ans=1;
    while(r-l>1)
    {
        set< pair<long ,long > >s;
        while(!s.empty())s.erase(s.begin());
        for(long i=1;i<=100000;i++)dp[i]=0;
        long mid=(l+r)/2;
        for(long i=1;i<=mid;i++)
        {
            s.erase(make_pair(-dp[a[i]],a[i]));
            dp[a[i]]++;
            s.insert(make_pair(-dp[a[i]],a[i]));
        }
        bool g=false;
        long h=-s.begin()->first;
      //  cout<<mid<<endl;
        //cout<<h<<" fff "<<s.begin()->second<<endl;

        if(h>=mid-k){g=true; ans=max(ans,h);}
        for(long i=mid+1;i<=n;i++)
        {
            long f=i-mid;
            s.erase(make_pair(-dp[a[f]],a[f]));
            dp[a[f]]--;
           //cout<<a[f]<< " bb "<<dp[a[f]]<<endl;
            s.insert(make_pair(-dp[a[f]],a[f]));

            s.erase(make_pair(-dp[a[i]],a[i]));
            dp[a[i]]++;
            //cout<<a[i]<<" bb "<<dp[a[i]]<<endl;
            s.insert(make_pair(-dp[a[i]],a[i]));
            long h=-s.begin()->first;
           // cout<<h<<" ff "<<s.begin()->second<<endl;
            if(h>=mid-k){g=true; ans=max(ans,h);}
        }
        if(g)l=mid;
        else r=mid;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 10 * 1000 +50;

int n ,m , k,a[maxn], r[maxn] , s[maxn];
int l[maxn][maxn];
int t = -1;
int x;

int main(){
    cin >> n >> m >> k;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        l[a[i]][s[i]] = i + 1;
        r[a[i]] = i + 1;
        x = 0;
        while(r[a[i]] - l[a[i]][x] + 1 - k > s[a[i]] - x){
            x++;
        }
        t = max(t , s[a[i]] - x);
        s[a[i]] ++;
    }
    cout << t << endl;
    return 0;
}


#include <bits/stdc++.h>

#define SZ(x) (( (int)x.size() ))

using namespace std;

typedef long long ll;
const int N = 200 * 1000 +50;

int  n , m , k , t;
vector <int> place[N];

bool valid(int x){
    for(int i = 0; i < m; ++i)
        for(int j = 0; j < SZ(place[i]) - x + 1; ++j)
            if(place[i][j + x - 1] - place[i][j] + 1 - x <= k)
                return true;
    return false;
}

int main(){
    cin >> n >> m >> k;
    for(int i = 0; i < n; ++i){
        cin >> t;t--;
        place[t].push_back(i);
    }
    int f = 1, l = n + 1 , mid;
    while(l - f > 1){
        mid = (f + l)/2;
        if(valid(mid))
            f = mid;
        else
            l = mid;
    }
    cout << f << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 10 * 1000 +50;

int n ,m , k,a[maxn], r[maxn] , s[maxn];
vector <int > l[maxn];
int t = -1;
int x;

int main(){
    cin >> n >> m >> k;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        l[a[i]].push_back(0);
        l[a[i]][s[i]] = i + 1;
        r[a[i]] = i + 1;
        x = 0;
        while(r[a[i]] - l[a[i]][x] + 1 - k > s[a[i]] - x){
            x++;
        }
        t = max(t , s[a[i]] - x);
        s[a[i]] ++;
    }
    cout << t << endl;
    return 0;
}


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

typedef pair<int,int> pii;

#define MAXN 200010
#define MAXM 100010

int n, m, k, ans, v[MAXN];
vector< pii > color[MAXM];

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif

    scanf("%d%d%d", &n, &m, &k);
    rep(i, n) scanf("%d", v+i);

    int last = 0;
    fab(i, 1, n-1)
        if (v[last] != v[i]) {
            color[v[last]].pb(mp(i-last, last));
            //cerr << "Trovato un gruppo (" << last << ", " << i-1 << ") di colore " << v[last] << "\n";
            last = i;
        }
    color[v[last]].pb(mp(n-last, last));
    //cerr << "Trovato un gruppo (" << last << ", " << n-1 << ") di colore " << v[last] << "\n";

    fab(c, 1, m)
        rep(i, sz(color[c])) {
            int tot = color[c][i].fs;
            for (int j = i+1; j < sz(color[c]) && (color[c][j].sc - color[c][i].sc - tot) <= k; j ++)
                tot += color[c][j].fs;
            MAX(ans, tot);
        }

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


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

typedef pair<int,int> pii;

#define MAXN 20
#ifdef ONLINE_JUDGE
#define MAXN 100010
#endif

int n, m, k, ans, v[MAXN];
vector< pair<int,pii> > color[MAXN];

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif

    scanf("%d%d%d", &n, &m, &k);
    rep(i, n) scanf("%d", v+i);

    int last = 0;
    fab(i, 1, n-1)
        if (v[last] != v[i]) {
            color[v[last]].pb(mp(i-last, mp(last, i-1)));
            //cerr << "Trovato un gruppo (" << last << ", " << i-1 << ") di colore " << v[last] << "\n";
            last = i;
        }
    color[v[last]].pb(mp(n-last, mp(last, n-1)));
    //cerr << "Trovato un gruppo (" << last << ", " << n-1 << ") di colore " << v[last] << "\n";

    fab(c, 1, m)
        rep(i, sz(color[c])) {
            int j = i+1, tot = color[c][i].fs;
            while (j < sz(color[c]) && (color[c][j].sc.fs - color[c][i].sc.fs - tot) <= k) {
                tot += color[c][j].fs;
                j++;
            }
            MAX(ans, tot);
        }

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


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

typedef pair<int,int> pii;

#define MAXN 200010
#define MAXM 100010

int n, m, k, ans, v[MAXN];
vector< pii > color[MAXM];
vector< int > sums[MAXM];

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif

    scanf("%d%d%d", &n, &m, &k);
    rep(i, n) scanf("%d", v+i);

    int last = 0;
    fab(i, 1, n-1)
        if (v[last] != v[i]) {
            color[v[last]].pb(mp(i-last, last));
            last = i;
        }
    color[v[last]].pb(mp(n-last, last));

    fab(c, 1, m) {
        if (color[c].empty()) continue;
        sums[c].resize(sz(color[c]), 0);
        fab(i, 1, sz(color[c])-1) sums[c][i] = sums[c][i-1] + color[c][i].sc - color[c][i-1].sc - color[c][i-1].fs;
    }

    fab(c, 1, m)
        rep(i, sz(color[c])) {
            int lx = i, rx = sz(color[c])-1, j = -1;
            while (rx - lx > 5) {
                int mid = (lx+rx)/2;
                if (sums[c][mid] - sums[c][i] <= k) lx = mid;
                else rx = mid;
            }
            fba(mid, rx, lx) if (sums[c][mid] - sums[c][i] <= k) {
                j = mid;
                break;
            }
            assert( j >= 0 );
            MAX(ans, color[c][j].sc - color[c][i].sc + color[c][j].fs - sums[c][j] + sums[c][i]);
        }

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


#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <cassert>
#include <ctime>
#include <iostream>
#include <utility>
#include <algorithm>
#include <limits>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <complex>

#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fs first
#define sc second
#define sz(x) (int((x).size()))
#define all(x) ((x).begin()),((x).end())
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define fab(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define fba(i,b,a) for(int (i)=(b);(i)>=(a);(i)--)
#define MAX(a,x) a=max(a,x)
#define MIN(a,x) a=min(a,x)

using namespace std;

const double eps = 1e-10, inf = 1e10;
typedef long long ll;

typedef pair<int,int> pii;

int n, m, k, ans, v[100010];
vector< pair<int,pii> > color[100010];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    scanf("%d%d%d", &n, &m, &k);
    rep(i, n) scanf("%d", v+i);

    int last = 0;
    fab(i, 1, n-1)
        if (v[last] != v[i]) {
            color[v[last]].pb(mp(i-last, mp(last, i-1)));
            last = i;
        }
    color[v[last]].pb(mp(n-last, mp(last, n-1)));

    fab(c, 1, m)
        rep(i, sz(color[c])) {
            MAX(ans, color[c][i].fs);
            int j = i+1, corp = 0;
            while (j < sz(color[c]) && (color[c][j].sc.fs - color[c][i].sc.sc - 1 - corp) <= k) {
                MAX(ans, corp + color[c][i].fs + color[c][j].fs);
                corp += color[c][j].fs;
                j++;
            }
        }

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


#define problem "180E"
#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
const int maxN(1e5 + 10);
typedef int i_N[maxN];
int N, M, K;
i_N A;
vector<int> pos[maxN];

int main(){
    scanf("%d %d %d\n", &N, &M, &K);
    for(int i = 0; i < N; i++) scanf("%d ", A + i), pos[A[i]].push_back(i);
    int ans(0);
    for(int color = 1; color <= M; color++){
        for(int l = 0, r = 0; l < (int)pos[color].size(); l++){
            while(r < (int)pos[color].size() && (pos[color][r] - pos[color][l]) - (r - l) <= K) r++;
            ans = max(ans, r - l);
        }
    }
    cout << ans;
}


#define problem "180E"
#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
const int maxN(2e5 + 10);
typedef int i_N[maxN];
int N, M, K;
i_N A;
vector<int> pos[maxN];

int main(){
    scanf("%d %d %d\n", &N, &M, &K);
    for(int i = 0; i < N; i++) scanf("%d ", A + i), pos[A[i]].push_back(i);
    int ans(0);
    for(int color = 1; color <= M; color++){
        for(int l = 0, r = 0; l < (int)pos[color].size(); l++){
            while(r < (int)pos[color].size() && (pos[color][r] - pos[color][l]) - (r - l) <= K) r++;
            ans = max(ans, r - l);
        }
    }
    cout << ans;
}


#include <cstdio>
#include <cstring>
#include <vector>
#define fMAX(a,b) (a>b?a:b)
using namespace std;
int n,m,k,next[100005],c[200005],dp[200005];
vector <int> seq[100005];

int main(){
    int max=0;
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<n;++i){
        scanf("%d",&c[i]);
        seq[c[i]-1].push_back(i);
    }
    for (int i=0;i<m;++i){
        int st,end,sep=0;
        if (seq[i].size())
            st=end=0;
        while (end<seq[i].size()-1){
            ++end;
            sep+=seq[i][end]-seq[i][end-1]-1;
            while (sep>k){
                ++st;
                sep-=seq[i][st]-seq[i][st-1]-1;
            }
            max=fMAX(max,end-st+1);
        }
    }
    printf("%d",max);
}


#include <cstdio>
#include <cstring>
#include <vector>
#define fMAX(a,b) (a>b?a:b)
using namespace std;
int n,m,k,c[200005];
vector <int> seq[100005];

int main(){
    int max=1;
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<n;++i){
        scanf("%d",&c[i]);
        seq[c[i]-1].push_back(i);
    }
    for (int i=0;i<m;++i){
        int st,end,sep=0;
        if (seq[i].size())
            st=end=0;
        else continue;
        while (end<seq[i].size()-1){
            ++end;
            sep+=seq[i][end]-seq[i][end-1]-1;
            while (sep>k){
                ++st;
                sep-=seq[i][st]-seq[i][st-1]-1;
            }
            max=fMAX(max,end-st+1);
        }
    }
    printf("%d",max);
}


#include <cstdio>
#include <cstring>
#include <vector>
#define fMAX(a,b) (a>b?a:b)
using namespace std;
int n,m,k,next[100005],c[200005],dp[200005];
vector <int> seq[100005];

int main(){
    int max=1;
    scanf("%d%d%d",&n,&m,&k);
    for (int i=0;i<n;++i){
        scanf("%d",&c[i]);
        seq[c[i]-1].push_back(i);
    }
    for (int i=0;i<m;++i){
        int st,end,sep=0;
        if (seq[i].size())
            st=end=0;
        while (end<seq[i].size()-1){
            ++end;
            sep+=seq[i][end]-seq[i][end-1]-1;
            while (sep>k){
                ++st;
                sep-=seq[i][st]-seq[i][st-1]-1;
            }
            max=fMAX(max,end-st+1);
        }
    }
    printf("%d",max);
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

vector<int>pos[N];
int solve(int id,int k)
{
	int sz=pos[id].size();
	int j=0;
	int temp=0;
	for(int i=0;i<sz;i++)
	{
		j=max(i,j);
		while(j+1<sz)
		{
			if(((pos[id][j+1]-pos[id][i]+1)-((j+1)-i+1))<=k)
				j++;
			else
				break;
		}
		temp=max(temp,j-i+1);
	}
	return temp;
}
int main()
{
	IOS;
	int n,m,k;
	cin >> n >> m >> k;
	int a;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		pos[a].pb(i);
	}
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		ans=max(ans,solve(i,k));
	}
	cout << ans;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define M 1000006
# define N 100005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

vector<int>pos[N];
int solve(int id,int k)
{
	int sz=pos[id].size();
	int j=0;
	int temp=0;
	for(int i=0;i<sz;i++)
	{
		for(int j=i+1;j<sz;j++)
		{
			if(((pos[id][j]-pos[id][i]+1)-(j-i+1))<=k)
				temp=max(temp,j-i+1);
			else
				break;
		}
	}
	return temp;
}
int main()
{
	IOS;
	int n,m,k;
	cin >> n >> m >> k;
	int a;
	for(int i=0;i<n;i++)
	{
		cin >> a;
		pos[a].pb(i);
	}
	int ans=0;
	for(int i=1;i<=m;i++)
	{
		ans=max(ans,solve(i,k));
	}
	cout << ans;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

/*
 * */
#define MAXN 100010

int N, M, K;
int C[MAXN << 1], head[MAXN], next[MAXN], rec[MAXN], sum[MAXN];
bool en[MAXN];
int main()
{
    cin >> N >> M >> K;
    memset(head, 0, sizeof(head));
    memset(next, 0, sizeof(next));
    memset(rec, 0, sizeof(rec));
    memset(sum, 0, sizeof(sum));
    memset(en,0,sizeof(en));
    for(int i = 1; i <= N; i++)
    {
        cin >> C[i];
        if(!head[C[i]]) head[C[i]] = i;
    }

    for(int i = 1; i <= N; i++)
    {
        sum[C[i]]++;
        rec[i] = sum[C[i]];
        if(C[i] != C[i - 1])
        {
            next[head[C[i]]] = i;
            head[C[i]] = i;
            en[i-1] = true;
        }
    }
    en[N] = true;
    memset(head, 0, sizeof(head));
    for(int i = 1; i <= N; i++)
        if(!head[C[i]]) head[C[i]] = i;

    int ans = 0;
    for(int i = 1; i <= N; i++)
    {
        if(!en[i]) continue;
        int same_color, tot_color;
        for(;;)
        {
            same_color = rec[i] - rec[head[C[i]]] + 1;
            tot_color = i - head[C[i]] + 1;
            if(tot_color - same_color <= K) break;
            head[C[i]] = next[head[C[i]]];
        }
        ans = max(ans, same_color);
    }
    cout<<ans<<endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

/*
 * */
#define MAXN 100010

int N, M, K;
int C[MAXN << 1], head[MAXN], next[MAXN], rec[MAXN], sum[MAXN];
int main()
{
    cin >> N >> M >> K;
    memset(head, 0, sizeof(head));
    memset(next, 0, sizeof(next));
    memset(rec, 0, sizeof(rec));
    memset(sum, 0, sizeof(sum));
    for(int i = 1; i <= N; i++)
    {
        cin >> C[i];
        if(!head[C[i]]) head[C[i]] = i;
    }

    for(int i = 1; i <= N; i++)
    {
        sum[C[i]]++;
        rec[i] = sum[C[i]];
        if(C[i] != C[i - 1])
        {
            next[head[C[i]]] = i;
            head[C[i]] = i;
        }
    }
    memset(head, 0, sizeof(head));
    for(int i = 1; i <= N; i++)
        if(!head[C[i]]) head[C[i]] = i;

    int ans = 0;
    for(int i = 1; i <= N; i++)
    {
        int same_color, tot_color;
        for(;;)
        {
            same_color = rec[i] - rec[head[C[i]]] + 1;
            tot_color = i - head[C[i]] + 1;
            if(tot_color - same_color <= K) break;
            head[C[i]] = next[head[C[i]]];
        }
        ans = max(ans, same_color);
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }
ll power(ll xx, ll yy) { if (yy == 0)return 1; ll pp=power(xx, yy / 2);if (yy % 2 == 0) return pp * pp; return xx * pp * pp; }
ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt=cnt+labs(a[i]-power(c,i));
    return cnt;
}

double kthRoot(double n, int k)
{
    return pow(k, (1.0 / k) * (log(n)  / log(k)));
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    double num=kthRoot((double)a[n-1],n-1);
    ll p=ll(num);
    // deb(p);
    // cout<<power(2,n-1)<<endl;
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return (pp) * pp;
    return ((xx) * pp) * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    double pq = (log(double(a[n-1]))/(log(10)*(n-1)));
    double p = pow(10.00,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return (pp * pp);
    return ((xx * pp) * pp);
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    long double pq = log10(a[n-1]+0.0000)/(n-1.00000);
    ll p = ll(pow(10.000,pq));
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    float pq = log10(a[n-1])/(n-1);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }
ll power(ll xx, ll yy) { if (yy == 0)return 1; ll pp=power(xx, yy / 2);if (yy % 2 == 0) return pp * pp; return xx * pp * pp; }
ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt=cnt+labs(power(c,i)-a[i]);
    return cnt;
}

double kthRoot(double n, int k)
{
    return pow(k, (1.0 / k) * (log(n)  / log(k)));
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    double num=kthRoot((double)a[n-1],n-1);
    ll p=ll(num);
    // deb(p);
    // cout<<power(4,n-1)<<endl;
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    long double pq = log10(a[n-1]+0.0)/(n-1.0);
    ll p = floor(pow(10.0,pq));
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    long double pq = log10(a[n-1]+0.0)/(n-1.0);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    if(n>50 and c>1)    return LLONG_MAX;
    ll cnt=0;
    REP(i,0,n){
        cnt+=llabs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    long double pq = log10(a[n-1]+0.0)/(n-1.0);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }
ll power(ll xx, ll yy) { if (yy == 0)return 1; ll pp=power(xx, yy / 2);if (yy % 2 == 0) return pp * pp; return xx * pp * pp; }
ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt=cnt+labs(power(c,i)-a[i]);
    return cnt;
}

double kthRoot(double n, int k)
{
    return pow(k, (1.0 / (k+0.0)) * (log(n)  / log(k)));
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    double num=kthRoot((long double)a[n-1],n-1);
    ll p=ll(num);
    // deb(p);
    // cout<<power(4,n-1)<<endl;
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    double pq = log10(double(a[n-1]))/(n-1);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt+=labs(a[i]-power(c,i));
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    ll p = pow(a[n-1],1/(n+0.0));
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }
ll power(ll xx, ll yy) { if (yy == 0)return 1; ll pp=power(xx, yy / 2);if (yy % 2 == 0) return pp * pp; return xx * pp * pp; }
ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt=cnt+labs(power(c,i)-a[i]);
    return cnt;
}

double kthRoot(double n, int k)
{
    return pow(k, (1.0 / (k+0.001)) * (log(n)  / log(k)));
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    double num=kthRoot((long double)a[n-1],n-1);
    ll p=ll(num);
    // deb(p);
    // cout<<power(4,n-1)<<endl;
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return (pp) * pp;
    return ((xx) * pp) * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    double pq = (log(double(a[n-1]))/(log(10.00)*(n-1)));
    double p = pow(10.00,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt+=labs(a[i]-power(c,i));
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    ll p = pow(a[n-1],1/(n-1+0.0));
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  if (cnt < 1e15) cnt+=labs(a[i]-powl(c,i));

    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    long double pq = log10(a[n-1]+0.0)/(n-1.0);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=abs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    double pq = (log(double(a[n-1]))/(log(10)*(n-1)));
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)
        return 1;
    else if (yy % 2 == 0)
        return power(xx, yy / 2) * power(xx, yy / 2);
    else
        return xx * power(xx, yy / 2) * power(xx, yy / 2);
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    ll p = pow(10,log10(a[n-1])/(n-1));
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }
ll power(ll xx, ll yy) { if (yy == 0)return 1; ll pp=power(xx, yy / 2);if (yy % 2 == 0) return pp * pp; return xx * pp * pp; }
ll n,a[MAX6],sum,ans;

ll func(ll c){
    ll cnt=0;
    REP(i,0,n)  cnt=cnt+labs(a[i]-power(c,i));
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);

    ll p = pow(a[n-1],1/(n-1.0));
    // deb(p);
    // cout<<power(2,n-1)<<endl;
    ans=func(p);
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    ll p = pow(10,log10(a[n-1])/(n-1));
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    float pq = log10(float(a[n-1]))/(n-1);
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    double pq = (log(double(a[n-1]))/(log(10)*(n-1)));
    ll p = pow(10.0,pq);
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include<map>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define NREP(i,a,b) for(int i=a;i>=b;i--)
#define clr(a) memset(a,0,sizeof a)
#define CLR(a,t) memset(a,t,sizeof a)
#define help ios::sync_with_stdio(0)
#define SORTV(a,n) sort(a.begin(),a.begin()+n)
#define SORTA(a,n) sort(a,a+n)
#define f first
#define ii second
#define mp make_pair
#define pb push_back
typedef long long int ll;
typedef long double ld;
#define vip vector<pair<ll,ll>>
#define vv vector<vector<ll>>
#define vi vector<ll>
#define FORS(it,m) for(set<int>::iterator it=m.begin();it!=m.end();it++)
#define FORM(it,m) for(map<ll,ll>::iterator it=m.begin();it!=m.end();it++)
#define FORV(it,m) for(vector<ll>::iterator it=m.begin();it!=m.end();it++)
#define FORL(it,l) for(list<int> :: iterator it=l.begin();it!=l.end();it++)
#define MAX6 1000000
#define MAX5 100000
#define MAX4 10000
#define ipair pair<ll,ll>
#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define minHeap priority_queue<ipair,vector<ipair>,greater<ipair>>
#define maxHeap priority_queue<ipair>
#define iminHeap priority_queue<ll,vector<ll>,greater<ll>>
#define imaxHeap priority_queue<ll>
#define iMap map<ll,ll>
#define iuMap unordered_map<ll, ll>
#define piMap map<pair<ll,ll>,ll>

#define sz(a) a.size()
#define tc(t) ll t; cin>>t; while(t--)
#define debArr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" ";  cout<<endl;
#define si cout<<"YES"<<endl;
#define nada cout<<"NO"<<endl;
ll upperBound(ll a[],ll n,ll val) {return upper_bound(a,a+n,val)-a;}
ll lowerBound(ll a[],ll n,ll val) {return lower_bound(a,a+n,val)-a;}
bool persqr(int a) { return (int(sqrt(a))*int(sqrt(a))==a)?1:0; }
ll gcd(ll a,ll b) { return (a?gcd(b%a,a):b);}
bool powerOf2(int a)   {   return !(a&(a-1));}
ll abs(ll n1,ll n2){    return n1>n2?n1-n2:n2-n1;}
ll highestPowerof2(ll n) { return pow(2,(ll)log2(n)); }

ll n,a[MAX6],sum,ans;

ll power(ll xx, ll yy) //DO NOT REMOVE IT!!
{
    if (yy == 0)    return 1;
    ll pp=power(xx, yy / 2);
    if (yy % 2 == 0) return pp * pp;
    return xx * pp * pp;
}

ll func(ll c){
    ll cnt=0;
    REP(i,0,n){
        cnt+=labs(a[i]-power(c,i));
    }
    return cnt;
}

int main(){
    help;
    ans=LLONG_MAX;
    cin>>n;
    REP(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    SORTA(a,n);
    ll p = pow(10,float(log10(a[n-1])/(n-1)));
    ans=func(p);
    // cout<<p<<endl;
    if(p>1) ans=min(ans,func(p-1));
    ans=min(ans,func(p+1));
    cout<<ans<<endl;

    return 0;
}