#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
ld PI=asin(1)*2;
//using namespace atcoder;

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    ll H,W,M;
    cin >> H >> W >> M;
    vector<ll> X(M),Y(M);
    vector<ll> A(W+1,H), B(H+1,W);
    rep(i,M){
        cin >> X[i] >> Y[i];
        X[i]--;Y[i]--;
        cmin(A[Y[i]],X[i]);
        cmin(B[X[i]],Y[i]);
    }
    ll ans = 0;
    rep(y,B[0]){
        ans += A[y];
    }
    rep(x,A[0]){
        ans += B[x];
    }
    ll sum = 0;
    BIT<ll> tr(W);
    rep(y,B[0]) tr.add(y,1);
    vector<vector<ll> > ends(H+1);
    rep(y,B[0]) ends[A[y]].push_back(y);
    rep(x,A[0]){
        for(auto& y:ends[x]) tr.add(y,-1);
        ans -= tr.sum(0,B[x]);
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int m=0;
int vis[109],pm[109];
int sm[109];
ll f[2][1050009];
void init()
{
	for(int i=2;i<=72;i++)
	{
		if(!vis[i])
			pm[++m]=i;
		for(int j=1;j<=m&&i*pm[j]<=72;j++)
			vis[i*pm[j]]=1;
	}
}
int main()
{
	ll a,b;
	scanf("%lld%lld",&a,&b);
	init();
	int cur=0;
	f[0][0]=1;
	for(ll i=a;i<=b;i++)
	{
		cur^=1;
		memset(f[cur],0,sizeof(f[cur]));
		int ns=0;
		for(int j=1;j<=m;j++)
			if(i%pm[j]==0)
				ns|=1<<(j-1);
		for(int s=0;s<1<<m;s++)
		{
			f[cur][s]+=f[cur^1][s];
			if((ns&s)==0)
				f[cur][ns|s]+=f[cur^1][s];
		}
	}
	ll ans=0;
	for(int s=0;s<1<<m;s++)
		ans+=f[cur][s];
	printf("%lld",ans);
	return 0;
}


#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack>
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};

ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 ll modd = 1e9+ 7;
ll wa (ll n,ll mi, ll ma){
    ll ans  = n * (mi+ma) /2;
    return ans;
}
int r5 (int a){
    int x = a * a * a * a * a;
    return x;
}

struct  Edge {int to,id;};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v,int c = -1, int p = -1){
    int k = 1;
    REP(i,g[v].size()){
        int u = g[v][i].to, ei = g[v][i].id;
        if(u == p ) continue;
        if(c == k) k++;
        ans[ei] = k; k++;
        dfs(u,k-1,v);

    }
}

int main(){
    int n;
    cin >> n;

    vector<double> x(n),y(n);

    REP(i,n){
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            double a = x[j] - x[i], b = y[j] - y[i];
            if(a == 0) continue;
            double c = b/a;
            if(-1 <= c && c <=1) ans ++;
        }
    }
    cout << ans <<endl;
}

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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

template <typename>
struct is_mint : public std::false_type { };

template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	using mint = static_mint<998244353>;

	int n, m;
	cin >> n >> m;

	vector<mint> fact(n + 1), inv(n + 1);
	fact[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = i * fact[i - 1];
		inv[i] = fact[i].inv();
	}

	auto choose = [&](int n, int k) -> mint {
		if (0 <= n && 0 <= k && k <= n)
			return fact[n] * inv[k] * inv[n - k];
		return 0;
	};

	int lg = 32 - __builtin_clz(m) - 1;
	vector<vector<mint>> dp(lg + 1, vector<mint>(m + 1));

	for (int i = 0; i <= min(n, m); i += 2) {
		dp[0][i] = choose(n, i);
	}

	for (int b = 1; b <= lg; b++) {
		for (int sum = 0; sum <= m; sum++) {
			for (int c = 0; (1 << b) * c <= sum; c += 2) {
				dp[b][sum] += choose(n, c) * dp[b - 1][sum - (1 << b) * c];
			}
		}
	}
	cout << dp[lg][m] << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
#define TIME cerr<<"Time Taken:"<<(float)clock()/CLOCKS_PER_SEC*1000<<"ms"<<endl
//  When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef somujena
    freopen("/home/somujena/competitive/input.txt", "r", stdin);
    freopen("/home/somujena/competitive/output.txt", "w", stdout);
    #endif
    // code goes here
    LL t=1;//cin>>t;
    while(t--){
      LL n,i,j;cin>>n;
      LL a[n];
      fo(i,0,n) cin>>a[i];
      std::vector<LL> v;
      LL in=1,prev=0,f=1;
      fo(i,0,n){
        if(a[i]==in){
          if(i-1==prev){
            if(a[i]>a[i-1]) {f=0;break;}
            else{
              swap(a[i],a[i-1]);
              v.pb(i);
              if(a[i]-a[i-1]==1) {prev=i+1,in=a[i]+1;}
              else {prev=i;in=a[i-1]+1;}
            }
            continue;
          }
          if(i==prev){
            prev=i+1;
            in=a[i]+1;
            continue;
          }
          bool f1=1;
          if(a[prev]-in!=1) f1=0;
          fo(j,prev,i-2){
            if(a[j+1]-a[j]!=1) f1=0;//,cout<<j<<endl;
          }
          if(a[i-1]<a[i-2]) f1=0;
          if(!f1) f=0;//,cout<<i<<sp<<in<<endl;
          else{
            rfo(j,i,prev) swap(a[j],a[j-1]),v.pb(j);
            if(a[i]-a[i-1]!=1) {in=a[i-1]+1,prev=i;}
            else {in=a[i]+1,prev=i+1;}
          }
        }
      }
      if(v.size()!=n-1) f=0;
      if(!f) cout<<-1;
      else{
        for(auto x:v) cout<<x<<endl;
      }
    }
    TIME;
    return 0;
}

#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
lli digits(lli n)
{
	lli cnt = 0;
	while(n)
	{
		cnt++;
		n = n / 10;
	}
	return cnt;
}
int main()
{
	lli i,j,t,n,sum,m,x1,x2,y1,y2,ans,num,a,b,c,d,cnt = 0,l,odd=0,even=0,diff,x,mini,k,maxi,y;
	cin >> n;
	for(i=1;;i++)
	{
		if(stoll(to_string(i) + to_string(i)) > n)
		{
			cout << i - 1;
			break;
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        v.push_back(make_pair(x, y));
    }
    vector<pair<int, int> >::iterator it;
    ll result = 0;
    for (it = v.begin(); it != v.end(); it++)
    {

       ll n = it->second - it->first + 1;
       ll sum = n * (it->first + it->second) / 2;
       result += sum;
    }

    cout << result << endl;
}

// JG GAP GG

#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>
#include<bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];
#define forr(a,b) for(ll i=a;i<b;i++);
#define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];});
#define vsort(v) sort(v.begin(),v.end());
#define vdownsort(v) sort(v.begin(),v.end(),greater<ll>());
ll modpow(ll a, ll n, ll mod)
{
	ll res = 1;
	while (0 < n)
	{
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	ll n;
	cin >> n;
	ll ans = 0;
	ll a, b;
	for (ll i = 0; i < n; i++)
	{
		cin >> a >> b;
		ans += (a + b) * (b - a + 1) / 2;
	}

	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n , m;

bool palindrome(string s) {
    string t = s;
    reverse(s.begin() , s.end());
    return s == t;
}

void solve(int testCase){

    string s;
    cin >> s;

    for(int i = 0 ; i < 100 ; i ++) {
            if(palindrome(s)) {
                    printf("Yes\n");
                    return;
            }
            s = "0" + s;
    }

    printf("No\n");
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}

//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll num[524310];
bool kazu[524310];
const int ma = (1 << 19) - 1;
int k;
void add(ll n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) {
			kazu[n2] = !kazu[n2];
			k += (kazu[n2] * 2) - 1;
			return;
		}
		n2 = n2 * 2 % 524309;
	}
	num[n2] = n + 1;
	kazu[n2] = 1;
	k++;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int T;
	cin >> T;

	rep(t, T) {
		int N;
		cin >> N;

		if (N % 2) {
			rep(i, N) {
				int a;
				cin >> a;
			}
			co("Second");
		}
		else {
			int tmp = k;
			rep(i, N) {
				int a;
				cin >> a;
				add(a + 1000000000ll * t);
			}
			if (tmp == k) co("Second");
			else co("First");
		}
	}

	Would you please return 0;
}


#include <bits/stdc++.h>
#define int long long
#define INF 9223372036854775806
#define cignore cin.ignore(numeric_limits<streamsize>::max(), '\n');
using namespace std;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    string s[n];
    for(int i = 0; i < n; ++i)
        cin >> s[i];
    unordered_set<string> ust (s, s+n);
    for(string ss: s)
    {
        if(ust.count('!'+ss))
        {
            cout << ss << '\n';
            return 0;
        }
    }
    cout << "satisfiable\n";
    return 0;
}

#include<bits/stdc++.h>
#define y1 y3647
#define earse erase
#define INF 1000000000
#define LL long long
using namespace std;
inline void read(int &x)
{
	x=0;int f=1;
	char ch=getchar();
	while(ch!=45&&(ch>'9'||ch<'0'))ch=getchar();
	if(ch==45){f=-1,ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getchar();}
	x*=f;
}
/*

*/
const int N=2e5+10;
int i,j,k,n,s,t,m;
char ch[N];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//freopen(".ans","w",sdtout);
	read(n);
	scanf("%s",ch+1);
	if(ch[1]!=ch[n])
	{
		printf("1\n");
		return 0;
	}
	for(i=2;i<n;i++)
	if(ch[i]!=ch[1]&&ch[i+1]!=ch[n])
	{
		printf("2\n");
		return 0;
	}
	printf("-1\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N; cin >> N;

    unordered_set<ll> s;
    for(ll a=2; a*a <= N; a++){
        ll x = a*a;
        while(x <= N){
            s.insert(x);
            x *= a;
        }
    }

    ll ans = N - s.size();
    cout << ans << endl;
}

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

int main()
{
    long long n,i,m,ans;
    cin>>n;
    vector<long long> a;
    i=2;
    ans=0;
    while (i*i<=n)
    {
        m=pow(i,2);
        while (m<=n)
        {
            a.push_back(m);
            m*=i;
        }
        i++;
    }
    sort(a.begin(),a.end());
    /* for (i = 0; i < a.size(); i++) cout<<a[i]<<" ";
    cout<<endl; */
    if (a.size()>=1) ans=1;
    for (i = 1; i < a.size(); i++)
    {
        if (a[i]!=a[i-1]) ans++;
    }
    cout<<n-ans<<endl;
}


//Author: Xzirium
//Time and Date: 17:04:30  21 March 2021

//Optional FAST
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

template <typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template <typename T> using ordered_set1 = tree<T,null_type,greater<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll b, ll e)
{
    ll r = 1ll;
    for(; e > 0; e /= 2, (b *= b) %= MOD)
        if(e % 2) (r *= b) %= MOD;
    return r;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);

}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    ll lpf[N+1]={0};
    FORI(i,2,N+1)
    {
        if(lpf[i]==0)
        {
            lpf[i]=i;
            for (ll j = 2; i*j <= N; j++)
            {
                if(lpf[i*j]==0)
                {
                    lpf[i*j]=i;
                }
            }

        }
    }
    ll ans[N+1]={0};
    ans[1]=1;
    FORI(i,2,N+1)
    {
        ans[i]=ans[i/lpf[i]]+1;

    }
    FORI(i,1,N+1)
    {
        cout<<ans[i]<<" ";
    }
    cout<<endl;

//-----------------------------------------------------------------------------------------------------------//

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

//Making love with his ego Ziggy sucked up into his mind
#include<bits/stdc++.h>
using namespace std;
#define sz(x) int(x.size())
#define pb push_back
#define ff first
#define ss second
#define ter(x) cerr << #x << " = " << x << endl
typedef long long ll;
typedef pair<ll,ll> ii;

const int N=1e5+100;
int mm[N];
int here[N];

int main(){
	int n;cin>>n;
	int mx=1;
	mm[1]=1;
	for(int i=2;i<=n;i++){
		here[1]=i;
		for(int j=2;j*j<=i;j++)if(i%j==0){
			here[mm[j]]=i;
			here[mm[i/j]]=i;
		}
		int j=1;
		while(here[j]==i)j++;
		mm[i]=j;
		mx=max(mx,j);
	}
	for(int i=1;i<=n;i++)cout<<mm[i]<<" ";
	cout<<endl;

	return 0;
}


    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second

    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int h,w;
        cin>>h>>w;
        int arr[h*w+10];
        int mn=mod;ll sum=0;
        for(int i=0;i<h*w;i++)
        {
            cin>>arr[i];
            mn=min(mn,arr[i]);
        }
        // cout<<mn<<" ";
        for(int i=0;i<h*w;i++)
        {
            sum+=arr[i]-mn;
            // cout<<arr[i]<<" ";
        }
        cout<<sum;

        return 0;
    }

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define free(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define bs binary_search
#define le length()
#define np(s) next_permutation(s.begin(),s.end())
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define unq(v) v.erase(unique(v.begin(),v.end()),v.end())
//1 1 1 2 2 2 to 1 2
const ll max_i=1e18+7;
const int dx[]={1,0,-1,0,-1,1,1,-1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const char dir[]={'R','D','L','U'};
const ll mod=1e12+7;
const ll N=1e5+1;

void solve()
{
	int n,m;
	cin>>n>>m;
	char arr[n][m];
	forn(i,n)
	forn(j,m)
	cin>>arr[i][j];
	//up
	ll ans=0;
	forn(i,m){
	forn(j,n)
	{
		 if(arr[j][i]=='#')
		  {
			if(arr[j-1][i]=='.' && !(arr[j-1][i+1]=='.' && arr[j][i+1]== '#'))
			{
				ans++;
			}
		  }
	}
   }
   //cout<<ans<<"\n";
	//down
	forn(i,m)
	for(int j=n-1;j>=0;j--)
	{
		  if(arr[j][i]=='#')
		  {
			if(arr[j+1][i]=='.' && !(arr[j+1][i+1]=='.' && arr[j][i+1]== '#'))
			{
				ans++;
			}
		  }
	}
	//cout<<ans<<"\n";
	//left
	forn(i,n)
	forn(j,m)
	{
		 if(arr[i][j]=='#')
		  {
			if(arr[i][j-1]=='.' && !(arr[i-1][j-1]=='.' && arr[i-1][j]== '#'))
			{
				ans++;
			}
		  }
	}
	//cout<<ans<<"\n";
	//right
	forn(i,n){
	for(int j=m-1;j>=0;j--)
	{
		if(arr[i][j]=='#')
		  {
			if(arr[i][j+1]=='.' && !(arr[i-1][j+1]=='.' && arr[i-1][j]== '#'))
			{
				ans++;
			}
		  }
	}
}
  cout<<ans<<"\n";
}

int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input1.txt", "r",stdin);
  freopen("output1.txt","w",stdout);
  #endif
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

  int t=1;
  //cin>>t;
  while(t--) solve();
  return 0;
}
//unordered_map
//unordered_set
//find
//insert
//cout<<fixed<<setprecision(9)<<x;


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

int main(){
    string S; cin >> S;
    int ans = 0;
    for(int i=0; i<=9999; i++){
        vector<bool> flag(10);
        int X = i;
        for(int j=0; j<4; j++){
            flag[X%10] = true;
            X /= 10;
        }
        bool flag2 = true;
        for(int j=0; j<10; j++){
            if(S[j]=='o' && !flag[j]) flag2 = false;
            if(S[j]=='x' && flag[j]) flag2 = false;
        }
        ans += flag2;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 87;
ll n, f[MX];
vi v;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);

	f[0] = f[1] = 1;
	for (int i = 2; i < MX; i++)
		f[i] = f[i - 1] + f[i - 2];

	cin >> n;

	int cn = 0;
	for (int i = MX - 1; i >= 0; i--) {
		if (f[i] <= n) {
			v.pb(1);
			cn++;
			n -= f[i];
		} else if (cn) {
			v.pb(0);
		}
	}

	int f = v.size() & 1;
	v.pop_back();

	cout << v.size() + cn << endl;
	for (int x : v) {
		if (x) {
			if (f) cout << 1 << endl;
			else cout << 2 << endl;
		}
		if (f) cout << 4 << endl;
		else cout << 3 << endl;
		f = 1 - f;
	}

	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    vector<ll> vec(4);
    in(vec);
    ll sum=0,sum2=0;
    rep(i,4){
        sum+=vec[i];
    }
    bool ans=false;
    for(int i=0;i<(1<<4);i++){
        sum2=0;
        rep(j,4){
            if(i&(1<<j))sum2+=vec[j];
        }
        if(sum2==sum-sum2){
            ans=true;
            break;
        }
    }
    Yes(ans);
}

#include<bits/stdc++.h>
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	solve();

	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}
void solve()
{

	int arr[4];

	for (int i = 0; i < 4; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + 4);

	int sp[6] {};

	int k = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			sp[k] = arr[i] + arr[j];
			k++;
		}
	}

	sort(sp, sp + 6);

	for (int i = 0; i < 5; i++) {
		if (sp[i] == sp[i + 1]) {
			cout << "Yes";
			return;
		}
	}

	int st[4];

	st[0] = arr[0] + arr[1] + arr[2];
	st[1] = arr[1] + arr[2] + arr[3];
	st[2] = arr[2] + arr[3] + arr[0];
	st[3] = arr[3] + arr[0] + arr[1];

	if (st[0] == arr[3]) {
		cout << "Yes";
		return;
	}
	else if (st[1] == arr[0]) {
		cout << "Yes";
		return;
	}
	else if (st[2] == arr[1]) {
		cout << "Yes";
		return;
	}
	else if (st[3] == arr[2]) {
		cout << "Yes";
		return;
	}
	cout << "No";
	return;

}


# include<bits/stdc++.h>

using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const bool MULTIPLE_TEST_CASES = false;

const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;

l H,W,A,B;

void cnt(vector<vector<bool> > &visited, l A_rem, l B_rem, l &ans) {
	if(A_rem<0 || B_rem<0) {
		return;
	}
	if(A_rem==0 && B_rem==0) {
		ans++;
		return;

	}
	bool found = false;
	l i=-1,j=-1;
	for(l x=0;x<H;x++) {

		for(l y=0;y<W;y++) {
			if(visited[x][y]==false) {
				i=x;
				j=y;
				found = true;
				break;
			}
		}
		if(found) {
			break;
		}
	}
	if(i==-1 || j==-1) {
		return;
	}
	dbg(i,j);
	visited[i][j]=true;
	cnt(visited, A_rem, B_rem-1,ans);

	if(i+1<H && visited[i+1][j]==false) {
		visited[i+1][j]=true;
		cnt(visited, A_rem-1, B_rem,ans);
		visited[i+1][j]=false;
	}

	if(j+1<W && visited[i][j+1]==false) {
		visited[i][j+1]=true;
		cnt(visited, A_rem-1, B_rem,ans);
		visited[i][j+1]=false;
	}
	visited[i][j] = false;
}

void solve() {

	cin>>H>>W>>A>>B;

	vector<vector<bool> > visited(H, vector<bool>(W, false));

	l ans = 0;
	cnt(visited, A, B, ans);
	cout<<ans<<"\n";

	return;
}

int main(){
	io;
	int t=1;
	if (MULTIPLE_TEST_CASES) cin>>t;
	rep(i,0,t) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>
/* #include <atcoder/all> */

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

using ll = long long;
using P = pair<int, int>;

const ll INF = 1 << 30;

template<class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

struct Data {
  int to;
  ll cost;
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> dist(n, INF);
  vector<vector<ll>> G2(n, vector<ll>(n, INF));
  vector<vector<Data>> G(n, vector<Data>());
  rep(i, m) {
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    if (a == b) {
      chmin(dist.at(a), c);
    } else {
//      chmin(G2.at(a).at(b), c);
      Data d = {b, c};
      G.at(a).push_back(d);
    }
  }
//  vector<vector<Data>> G(n, vector<Data>());
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
    }
  }

  vector<vector<ll>> dist2(n, vector<ll>(n, INF));
  rep(i, n) {
    vector<ll> dist3(n, INF);
    dist3.at(i) = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>,
        greater<pair<ll, int>>> que;
    que.push(make_pair(dist3.at(i), i));
    while (!que.empty()) {
      int v = que.top().second;
      ll d = que.top().first;
      que.pop();
      if (d > dist3.at(v)) continue;
      for (auto e : G.at(v)) {
        if (e.to == i) {
          continue;
        }
        if (chmin(dist3.at(e.to), dist3.at(v) + e.cost)) {
          que.push(make_pair(dist3.at(e.to), e.to));
        }
      }
    }
    rep(j, n) {
//      cerr << dist3.at(j) << " ";
      dist2.at(i).at(j) = dist3.at(j);
    }
//    cerr << endl;
  }
  rep(i, n) {
    rep(j, n) {
      if (i == j) continue;
      dist.at(i) = min(dist.at(i), dist2.at(i).at(j) + dist2.at(j).at(i));
    }
  }
  rep(i, n) {
    cout << ((dist.at(i) == INF) ? -1 : dist.at(i)) << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b,ll mod=MOD){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % mod;
      x = x * x % mod;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    cin >> res;
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = in();
    int m = in();
    vector<int> A(m);
    vector<int> B(m);
    rep(i,m){
        A[i] = in()-1;
        B[i] = in()-1;
    }
    int k = in();
    vvector<int> C(k,vector<int>(2));
    rep(i,k){
        rep(j,2){
            C[i][j] = in()-1;
        }
    }

    method(func,int,int use){
        vector<int> has(n,false);
        rep(i,k){
            has[C[i][(bit(i)&use) != 0]] = true;
        }
        int res = 0;
        rep(i,m){
            if(has[A[i]] and has[B[i]])++res;
        }
        return res;
    };
    int ans = 0;
    rep(i,bit(k)){
        chmax(ans,func(i));
    }
    cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  unsigned long long N;
  cin >> N;

  unsigned long long at = -1, bt = -1, ct = -1;
  unsigned long long sum = 1ll << 63;

  for (unsigned long long b = 0; b < 63; b++) {
    unsigned long long a = N / (1ll << b);
    unsigned long long c = N % (1ll << b);
    if (a + b + c <= sum) {
      at = a;
      bt = b;
      ct = c;
      sum = a + b + c;
    }
  }

  cout << sum << endl;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <uint M>
struct modint {
    uint val;
public:
    static modint raw(int v) { modint x; x.val = v; return x; }
    modint() : val(0) {}
    template <class T>
    modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = uint(x); }
    modint(bool v) { val = ((unsigned int)(v) % M); }
    modint& operator++() { val++; if (val == M) val = 0; return *this; }
    modint& operator--() { if (val == 0) val = M; val--; return *this; }
    modint operator++(int) { modint result = *this; ++*this; return result; }
    modint operator--(int) { modint result = *this; --*this; return result; }
    modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
    modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
    modint& operator*=(const modint& b) { ull z = val; z *= b.val; val = (uint)(z % M); return *this; }
    modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint() - *this; }
    modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
    modint inv() const { return pow(M-2); }
    friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
    friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
    friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
    friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
    friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
    friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
mint cnt[3000];

int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    for (auto &&i : A) scanf("%lld", &i);
    vector<ll> S(n+1);
    for (int i = 0; i < n; ++i) {
        S[i+1] = S[i] + A[i];
    }
    auto dp = make_v(n+1, n+1, mint(0));
    dp[0][0] = 1;
    mint ans = 0;
    for (int i = 1; i <= n; ++i) {
        fill_n(cnt, 3000, mint(0));
        for (int j = 0; j <= n; ++j) {
            dp[i][j] += cnt[S[j]%i];
            cnt[S[j]%i] += dp[i-1][j];
        }
        ans += dp[i].back();
    }
    cout << ans.val << "\n";
    return 0;
}

// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define mem(x,y) memset(x,y,sizeof x)
#define sz(x) (int)(x).size()
#define ln std::puts("")
#define lsp std::putchar(32)
#define pb push_back
#define MP std::make_pair
#ifdef _LOCAL_
#define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n"
#define dprintf(x...) std::fprintf(stderr,x)
#else
#define dbg(x) 42
#define dprintf(x...) 42
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
template <class t> inline void read(t &s){s=0;
reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;}
template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);}
template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x;
int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0;
while(top)putchar(buf[top--]^'0');return;}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;}
inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;}
template <class t>inline bool ckmin(t&x,t y){if(x>y){x=y;return 1;}return 0;}
template <class t>inline bool ckmax(t&x,t y){if(x<y){x=y;return 1;}return 0;}
inline int lowbit(int x){return x&(-x);}
const int MaxN=3050;
const int p=1e9+7;
int a[MaxN],f[MaxN][MaxN],s[MaxN],n;
int w[MaxN][MaxN];
inline void add(int &x,int y){(x+=y)>=p&&(x-=p);}
signed main(void)
{
	read(n);
	for(int i=1;i<=n;++i)read(a[i]),s[i]=s[i-1]+a[i];
	f[0][0]=1,w[1][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=i;++j)
			add(f[i][j],w[j][s[i]%j]);
		if(i<n)
		for(int j=0;j<=i;++j)
			add(w[j+1][s[i]%(j+1)],f[i][j]);
	}
	reg int ans=0;
	for(int i=1;i<=n;++i)add(ans,f[n][i]);
	write(ans),ln;
	return 0;
}

/*
 * Check List:
 * 1. Input / Output File (OI)
 * 2. long long
 * 3. Special Test such as n=1
 * 4. Array Size
 * 5. Memory Limit (OI) int is 4 and longlong is 8
 * 6. Mod (a*b%p*c%p not a*b*c%p  ,  (a-b+p)%p not a-b )
 * 7. Name ( int k; for(int k...))
 * 8. more tests , (T=2 .. more)
 * 9. blank \n after a case
*/


#include <bits/stdc++.h>
#include <limits.h>
#include <math.h>
#define mod 1000000007
#define pi 3.14159265
//  sin((deg*pi)/180.0);

using namespace std;

long long int ans = 0;
// map<int,int> m;
vector<int> m(31,0);
vector<vector<int>> dx;
vector<bool> vis(31,true);

void rec(int i,vector<int> cnt,vector<int> x)
{
    if(i==31)
    {
        bool ok = true;
        for(int z=0;z<10;z++)
        {
            if(cnt[z]>1)
            {
                ok = false;
            }
        }

        if(ok)
        {
            long long int ll = 1;
            bool llzx = false;

            for(int z=0;z<x.size();z++)
            {
                if(m[x[z]]>0)
                {
                    // cout<<x[z]<<" "<<m[x[z]]<<" ";
                    llzx = true;
                }
                ll*=m[x[z]];

            }

            if(llzx)
            {
                ans+=ll;
            }
        }

        return ;
    }

    if(vis[i]==true && m[i]>0)
    {
        for(int k=0;k<10;k++)
        {
            cnt[k]+=dx[i][k];
        }
        x.push_back(i);
        rec(i+1,cnt,x);
        x.pop_back();
        for(int k=0;k<10;k++)
        {
            cnt[k]-=dx[i][k];
        }
        rec(i+1,cnt,x);
    }
    else
    {
        rec(i+1,cnt,x);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    double n;
    cin>>n;

    double price = 1.08*(double(n));

    price = floor(price);

    if(price>206)
    {
        cout<<":("<<endl;
    }
    else if(price==206)
    {
        cout<<"so-so"<<endl;
    }
    else
    {
        cout<<"Yay!"<<endl;
    }

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define maxn 200005
int a[maxn];
double n;
signed main()
{
	cin>>n;
	n*=1.08;
	n=floor(n);
	if(n<206) puts("Yay!");
	if(n==206) puts("so-so");
	if(n>206) puts(":(");
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int  a,b;
	cin>>b>>a;
	int c=a+b;
	if(c>=15&&a>=8)
	cout<<1;
	else if(c>=10&&a>=3)
	cout<<2;
	else if (c>=3)
	cout<<3;
	else
	cout<<4;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n, m;
  cin >> n >> m;

  if (n == 1) {
    cout << ((m == 0) ? "1 2\n" : "-1") << endl;
    return 0;
  }
  if (m < 0 || m > n - 2) {
    cout << -1 << endl;
    return 0;
  }

  ll p = 2;
  rep(i, m + 1) {
    printf("%ld %ld\n", p, p + 1);
    p += 2;
  }
  printf("1 %ld\n", p);
  p++;
  rep(i, n - m - 2) {
    printf("%ld %ld\n", p, p + 1);
    p += 2;
  }
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <stdio.h>
#include <stack>
#include <queue>
#include <list>
#include <sstream>
#include <utility>
#include <cctype>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <map>
#include <fstream>

using namespace std;
const long long MOD = 1e9 +7;
const long long MODZ = 998244353;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    uint64_t a,b,c;
    cin >> a >> b >> c;
    uint64_t sum = 0;

    // uint64_t firstterm = (double)(((a % MODZ) * ((a+1)% MODZ ))  % MODZ)     /2.0;
    // uint64_t secterm = (double)(((b % MODZ) *((b+1)% MODZ ))  % MODZ)     /2.0;
    // uint64_t thirdterm = (double)(((c % MODZ) *((c+1)% MODZ ))  % MODZ)     /2.0;

    uint64_t firstterm = ((a*(a+1))     /2) % MODZ;
    uint64_t secterm = ((b*(b+1))     /2) % MODZ;
    uint64_t thirdterm = ((c*(c+1))     /2) % MODZ;

    //sum = ((firstterm % MODZ) * (secterm % MODZ) * (thirdterm % MODZ)) % MODZ;
    //sum = firstterm * secterm * thirdterm;
    sum = firstterm * secterm % MODZ * thirdterm % MODZ;

    // sum = (a * (a+1) * b * (b+1) * c * (c+1))/8 % MODZ;
    // for(long long i = 1; i<= a; ++i)
    // {
    //     for(long long j = 1; j <= b; ++j)
    //     {
    //         for(long long k = 1; k <= c; ++k)
    //         {
    //             sum = (sum % MODZ) + (((i % MODZ) *(j % MODZ) *(k % MODZ)) % MODZ) % MODZ ;
    //         }
    //     }
    // }
    cout << sum;

}

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&...tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 60) - 1LL;
constexpr ll MOD = 998244353LL;
//from http://noshi91.hatenablog.com/entry/2019/03/31/174006
template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

  public:
    u64 a;
    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint operator^(const u64 rhs) const noexcept {
        return modint(*this) ^= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    constexpr modint &operator^=(u64 exp) {
        modint rhs = modint(*this);
        a = 1;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
    friend ostream &operator<<(ostream &os, const modint &x) {
        os << x.a;
        return os;
    }
    friend istream &operator>>(istream &is, modint &x) {
        is >> x.a;
        return is;
    }
};
using mint = modint<MOD>;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    mint a, b, c;
    cin >> a >> b >> c;
    mint res = a * (a + 1) * b * (b + 1) * c * (c + 1) / mint(8);
    cout << res << newl;
}


#include <bits/stdc++.h>
using namespace std;
int fastio() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin.tie(nullptr); return 0; }
int __fastio = fastio();

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long ll;
typedef pair<ll, ll> ii;
#define fi first
#define se second
#define sz(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int main(){
    string s;
    cin >> s;
    while(s.size() && s.back() == '0') s.pop_back();
    int lo = 0, hi = s.size()-1;
    while(lo<hi) {
        if(s[lo++] != s[hi--]) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
#define Rep(i,s,n) for(int i = n; i >= (int)(s); i--)

int n, x[3030][5];

int getmask(int i, int lim) {
	int res = 0;
	rep(j, 0, 5) if (lim <= x[i][j]) res += 1 << j;
	return res;
}

bool check(int lim) {
	vector<int>cnt(1 << 5, 0);
	rep(i, 0, n) cnt[getmask(i, lim)]++;
	rep(m1, 0, 1 << 5) rep(m2, 0, 1 << 5) rep(m3, 0, 1 << 5) {
		if ((m1 | m2 | m3) == (1 << 5) - 1 && cnt[m1] && cnt[m2] && cnt[m3]) return 1;
	}
	return 0;
}

int main() {
	cin >> n;
	rep(i, 0, n) rep(j, 0, 5) cin >> x[i][j];
	int ok = 0, ng = 1e9 + 1;
	while (ng - ok != 1) {
		int mid = (ok + ng) / 2;
		if (check(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans = 0;
void Main(){
    double sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    sy = -sy;
    cout << fixed << setprecision(8) << sx - sy * (gx - sx) / (gy - sy) << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

#include<bits/stdc++.h>
#define RT register
#define ll long long
#define ull unsigned long long
#define lowbit(x) (x&(-x))
using namespace std;

template<typename T>
inline void read(T &x){
    x=0; bool f=0;char ch=getchar();
    while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    x=f?-x:x;
}
template<typename T>
inline void print(T x){
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int x,y,z;

int main(){
    read(x),read(y),read(z);
    int m=y*z;
    if(m%x==0) print(m/x-1);
    else print(m/x);
    return 0;
}


// |--------------------------------------------|
// | User - Kunal Kumar                         |
// |--------------------------------------------|

#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define pf push_front
#define ppf pop_front
#define pii pair<int,int>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ulli unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vulli vector<ulli>
#define vb vector<bool>
#define vpii vector<pii>
#define vpll vector<pll>
#define mod 1000000007
#define F first
#define S second
#define NN 200001
#define modu 998244353
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define INF 1e18
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define ppc __builtin_popcount
#define ppcll __builtin_popcountll
#define endl "\n"
using namespace std;

int gcd(int a, int b)
{
    if(b==0)
        return a;

    return gcd(b,a%b);
}

//seive
bool prime_num[1000001];
void SOE(vector <int> &v)
{
    int n = 1000000;
    memset(prime_num, true, sizeof(prime_num));

    for (int p = 2; p * p <= n; p++)
    {
        if (prime_num[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime_num[i] = false;
        }
    }

    for (int p = 2; p <= n; p++)
        if (prime_num[p])
            v.pb(p);
}

bool binary_search(vector <int> v,int s, int e,int num)
{
    while(s<=e)
    {
        int mid=(s+(e-s)/2);

        if(v[mid]==num)
            return true;
        else
        if(v[mid]>num)
            e=mid-1;
        else
            s=mid+1;
    }

    return false;
}

ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}

ll modInverse(ll n,ll p)
{
    return power(n, p - 2, p);

    /*
    ll inv[maxn],finv[maxn];
    inv[1] =inv[0]= 1;
    finv[0]=finv[1]=1;
    for (int i=2; i<maxn; ++i)
        inv[i] = (m - (m/i) * inv[m%i] % m) % m;

    for (int i=2;i<maxn;++i){
        finv[i]=(inv[i]%m * finv[i-1]%m)%m;
    }

    */
}

ll factorial[200001];
ll nCr(ll n, ll r, ll p)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;

    return (factorial[n] * (modInverse(factorial[r], p) % p) * (modInverse(factorial[n - r], p) % p))% p;
}

void addEdge(vector <int> G[], int s, int e )
{
    G[s].pb(e);
    G[e].pb(s);
}

void solve()
{
    ll n;
    cin>>n;

    vl A(n),B(n);
    rep(i,0,n)
        cin>>A[i];

    rep(i,0,n)
        cin>>B[i];

    ll maxA = A[0], minB = B[0];

    rep(i,1,n)
    {
        if(maxA<A[i])
            maxA = A[i];
        if(minB>B[i])
            minB = B[i];
    }
    if(maxA>minB)
    {
        cout<<0;
        return;
    }

    cout<<(minB-maxA+1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

    int t;
    t=1;
    //cin>>t;

    while(t--)
    {
        solve();
    }

}

// Keep Hustling!!!!!!!!!!!

// #MerinoNoMeRepresenta
#include<bits/stdc++.h>
#define fp(x,a,b) for(ll x=a; x<b; x++)
#define fn(x,a,b) for(int x=a; x>b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it:x) cout<<it<<" ";
#define debug(x) cerr << #x << " is " << x << endl;
#define w(x) while(x--)
#define r(x) scanf("%d", &x)
#define rl(x) scanf("%ld", &x)
#define rll(x) scanf("%lld", &x)
typedef long long ll;
using namespace std;
template <typename TYPE> void readint(TYPE &x){
x=0; int f=1; char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+c-'0';
x*=f;
}
#define error(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
template<typename... T>
void read(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void write(T ... args){
  ((cout << args << ' '), ...);
  cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 3e3 + 5;
const char nl = '\n';
const int INF = 2e9;
int n, k;
//queue front back push pop
//stack top push pop
ll dp[MAX][MAX];
 ll sol(int n, int k){
  if (n < k) return 0LL;
  if(dp[n][k] != -1) return dp[n][k];
  if (n == k) return 1LL;
  if(k == 0) return 0LL;
  dp[n][k] = (sol(n - 1, k - 1) + sol(n, k * 2))%MOD1;
  return dp[n][k];
  //This belongs to Maestro_Koldo
}
void solve(){
  read(n, k);
  fp(i, 0, MAX) fp(j, 0, MAX) dp[i][j] = -1LL;
  write(sol(n, k));

}
int main(){
cpu();
// int __;
//  cin>>__;
//  while(__--){
//   solve();
//   // cout << nl;
//  }
   solve();
// cout<<nl;

return 0;
}


#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <utility>
#include <climits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define mp make_pair
#define fr first
#define sc second

#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define rep(s, i, n) for (int(i) = (s); (i) < (n); (i)++)
#define repe(s, i, n) for (int(i) = (s); (i) <= (n); (i)++)
#define rrep(s, i, n) for (int(i) = (s); (i) > (n); (i)--)
#define rrepe(s, i, n) for (int(i) = (s); (i) >= (n); (i)--)
#define allof(a) (a).begin(), (a).end()

int res=INT_MAX;
int n;

void cal(vi &a,int index,int xo){
    if(n==index){
        res=min(res,xo);
    }

    int nowor=0;
    rep(index,i,n){
        nowor|=a[i];
        cal(a,i+1,xo^nowor);
    }
}

int main(int argc, char const *argv[])
{
    cin>>n;
    vi a(n);
    rep(0,i,n)cin>>a[i];
    cal(a,0,0);

    cout<<res<<endl;

    return 0;
}

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> A)
{
    ll ans = INF;
    for (int bit = 0; bit < (1 << (N - 1)); bit++)
    {
        vector<ll> stock;
        ll now = A[0];
        for (int i = 0; i < N - 1; i++)
        {
            if (bit & (1 << i))
            {
                now = now | A[i + 1];
            }
            else
            {
                stock.push_back(now);
                now = A[i + 1];
            }
        }
        stock.push_back(now);

        ll score = stock[0];
        for (int i = 1; i < stock.size(); i++)
        {
            score ^= stock[i];
        }

        ans = min(ans, score);
    }

    cout << ans << endl;
}

int main()
{

    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
//using namespace __gnu_pbds;
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define ao(arr) for(auto tengo_copyright:arr) cout<<tengo_copyright<<" ";
#define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];}
#define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<" "; cout<<endl;}
#define ll long long
#define debug cout<<"I AM EXECUTING"<<endl
#define testcases int q_ves; cin>>q_ves; while(q_ves--)
#define vi vector<int>
#define vll vector<long long int>
#define vppo(prs) for(auto x:prs){cout<<x.first<<" "<<x.second<<endl;}
#define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++)
#define formax 1e18
#define formin -1e18
#define watch(x) cout << (#x) << " is " << (x) << endl
#define in(x) ll int x; cin>>x
#define stin(x) string x;cin>>x
//#define ordered_multiset tree<pair<ll int,ll int>, null_type, less<pair<ll int,ll int>>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define out1(a) cout<<a<<endl
#define out2(a,b) cout<<a<<"|"<<b<<endl

string sconvert(ll int n)
{
    stringstream ss;
    ss<<n;
    string str = ss.str();
    return str;
}

void  single() {
    in(n);
    ll int sum=1e18,a=1,b=1,c=1,pot=0;
    ll int res=0;
    if (n==0){out1(0);return;}
    while (1) {
    b = pow(2,pot);
    if(b>n)break;
    a = n/b;
    c = n % (a*b);
    res = a+pot+c;
    if (sum>res){sum=res;}
    pot++;

    }
    out1(sum);

    return;
}

void multiple()
{
    testcases
    {
        single();
    }
}

int main()
{
  IOS;
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  single();
}
//g++ -std=c++11 -O2 -Wall a.cpp -o a

#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#pragma GCC optimize("Ofast")
using namespace         std;
#define                 int long long
#define                 double long double
#define                 fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ArrayFill(arr,a)       memset(arr,a,sizeof arr)
#define                 endl '\n'
#define countBit(x)     __builtin_popcountll(x)
#define all(x)          x.begin() , x.end()
#define ln              cout<<'\n';
using namespace std;
using namespace __gnu_pbds;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> oset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

int ceil(int a,int b){return (a+b-1)/b;}
#define sim template < class c
#define ris return * this
#define dor > debug_ & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug_&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug_ {~debug_() { cerr << endl; }eni(!=) cerr << boolalpha << i; ris; }eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d){*this << "[";for (auto it = d.b; it != d.e; ++it)*this << ", " + 2 * (it == d.b) << *it;ris << "]";}};
#define db(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define debug(x) debug_() << db(x)
int modulo(int a,int b,int c){
    int x=1,y=a%c;
    while(b > 0){
        if(b%2 == 1)
            x=(x*y)%c;
        y = (y*y)%c;
        b = b>>1;
    }
    return  x%c;
}

const int mod = 1e9 + 7ll;
// const int mod = 998244353ll;
const int N = 5001;
const int inf = 1e10;

void solve(){
    int n;
    cin >> n;
    int ans = n;

    for(int i=0;i<=63;i++){
        int x = (1ll<<i);
        int c = i + n/x + n%x;
        ans = min(ans,c);
    }
    cout << ans;
}

signed main(){
    fast;
    int tt{1};
    // cin >> tt;
    for(int ii=1;ii<=tt;ii++){
        // cout << "Case #" << ii << ": ";
        solve();
        ln;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main(){
    double value, currentValue;
    double discount;
    cin >> value;
    cin >> currentValue;

    discount = ((value - currentValue) / value)*100;

    cout << discount;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for(LL i=0;i<(n);i++)

int main()
{
    double a, b;

    cin >> a >> b;

    b = a - b;

    a = b/a;
    a *= 100;

    printf("%.10lf",a);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N;
  cin >> N;
  int sum = 0;
  vector<int> av, bv;
  rep(i, N)
  {
    int A;
    cin >> A;
    av.push_back(A);
  }
  rep(i, N)
  {
    int B;
    cin >> B;
    bv.push_back(B);
  }
  rep(i, N)
  {
    sum += av.at(i) * bv.at(i);
  }
  if (sum == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

// dp[i][0] ---> no. of ways of x[0...i] to get y[i] = 0
//          ---> decision on x[i]
// dp[i][1] ---> no. of ways of x[0...i] to get y[i] = 1
//          ---> decision on x[i]
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int n; cin >> n;
  vector<vector<ll>> dp(n+1, vector<ll>(2, 1));
  for(int i = 1; i <= n; i++){
    string s; cin >> s;
    if(s == "AND"){
      dp[i][0] = 2*dp[i-1][0] + dp[i-1][1];
      dp[i][1] = dp[i-1][1];
    }
    else{
      dp[i][0] = dp[i-1][0];
      dp[i][1] = dp[i-1][0] + 2*dp[i-1][1];
    }
  }
  cout << dp[n][1];
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T>>;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, x;
    cin >> n >> x;
    rep(i,n){
        int a;
        cin >> a;
        if(a != x) cout << a << ' ';
    }
}

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

const int MAXN = 1e5+10;
int sz[MAXN];

int main() {
	int n, x;
	cin >> n >> x;
	for(int i=0; i<n; i++) {
		cin >> sz[i];
	}
	for(int i=0; i<n; i++) {
		if(sz[i]!=x){
			cout << sz[i] << " ";
		}
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n;cin>>n;
    ll a=1e18,b=-1e18,c=0;
    rep(i,n){
        ll x,t;cin>>x>>t;
        if(t==1){
            b+=x;
            a+=x;
            c+=x;
        }else if(t==2){
            chmax(b,x);
            chmax(a,x);
        }else{
            chmin(a,x);
            chmin(b,x);
        }
    }
    ll q;cin>>q;
    rep(i,q){
        ll x;cin>>x;
        ll res=min(max(c+x,b),a);
        cout<<res<<endl;
    }
}

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

#define ll long long int
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define MOD 1000000007
#define MAXN   1000001
#define MODA 998244353
#define all(a)      (a).begin(),(a).end()
#define allr(a)      (a).rbegin(),(a).rend()
const ll INF = numeric_limits<ll>::max() / 4;

ll power(ll a,ll b){
    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a);
        }
        a=(a*a);
        b=b>>1;
    }
    return result;
}

ll power2(ll a,ll b,ll p){
    ll result=1;
    while(b>0){
        int lastbit=(b&1);
        if(lastbit){
            result=(result*a)%p;
        }
        a=(a*a)%p;
        b=b>>1;
    }
    return result%p;
}

ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

vector<ll> Sieve(int n){
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    vector<ll>v;
    for (int p=2; p<=n; p++)
        if (prime[p]) v.pb(p);
    return v;
}

vector<ll> SeiveOfEratosthenes(int n){
    vector<ll>v(n+1,0);
    for(int i=0;i<=n;i++){
        v[i]=i;
    }

    for (int p=2; (p*p)<=n; p++){
        if (v[p] == p){
            v[p]=p;
            for (int i=p*p; i<=n; i += p) {
                v[i] = p;
            }
        }
    }
    return v;
}

vector<ll> SmallestPrimeFactors(int n){
    vector<ll>spf(n+1,0);
    spf[1] = 1;
    for (int i=2; i<=n; i++){
        spf[i] = i;
    }
    for (int i=4; i<=n; i+=2){
        spf[i] = 2;
    }
    for (int i=3; (i*i)<=n; i++){
        if (spf[i] == i){
            for (int j=i*i; j<MAXN; j+=i) {
                if (spf[j] == j){
                    spf[j] = i;
                }
            }
        }
    }
    return spf;
}

void shortest(map<int,vector<pair<int,ll>>>m,int src,int n,ll *dist){
    bool visited[n+1];
    set<pair<ll,int>>s;
    for(int i=0;i<=n;i++){
        dist[i]=-1;
        visited[i]=false;
    }

    s.insert(mp(0ll,src));
    dist[src]=0;
    while(!s.empty()){
        auto t=s.begin();
        ll dis=(*t).F;
        int u=(*t).S;
        s.erase(t);
        if(visited[u]){
            continue;
        }
        visited[u]=true;
        for(auto tt:m[u]){
            int v=tt.F;
            ll w=tt.S;
            if(!visited[v]){
                if(dist[v]!=-1 && dist[v]>dis+w){
                    s.erase(mp(dist[v],v));
                    dist[v]=dis+w;
                    s.insert(mp(dist[v],v));
                }else if(dist[v]==-1){
                    dist[v]=dis+w;
                    s.insert(mp(dist[v],v));
                }
            }
        }
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int ttttt=1;
//    cin>>ttttt;
    for(int tttt=1;tttt<=ttttt;tttt++){
        int n;
        cin>>n;
        ll a=0,b=-INF,c=INF;
        for(int i=0;i<n;i++){
            ll A,t;
            cin>>A>>t;
            if(t==1){
                a+=A;
                b+=A;
                c+=A;
            }else if(t==2){
                b=max(b,A);
                c=max(c,A);
            }else{
                c=min(A,c);
                b=min(A,b);
            }
        }
        ll q;
        cin>>q;
        while(q--){
            ll x;
            cin>>x;
            cout<<min(c,max(b,x+a))<<endl;
        }
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b,c;
  cin >>a>>b>>c;
  int ans=0;
  ans = max(a+b,ans);
  ans = max(a+c,ans);
  ans = max(b+c,ans);
  cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, q, flip = 0;
    string s;
    cin >> n >> s >> q;
    while (q --)
    {
        int t, a, b;
        cin >> t;
        cin >> a >> b;
        a --;
        b --;
        if (t == 2)
            flip = 1 - flip;
        else
        {
            if (flip)
            {
                if (a >= n)
                    a -= n;
                else
                    a += n;
                if (b >= n)
                    b -= n;
                else
                    b += n;
            }
            swap(s[a], s[b]);
        }
    }
    if (flip)
    {
        for (int i = 0; i < n; ++i)
        {
            swap(s[i], s[i + n]);
        }
    }
    cout << s << '\n';
    return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int, int> i_i;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = numeric_limits<ll>::max() / 4;
const ll MOD = 1e9+7;
// using mint = atcoder::modint1000000007;
void chmin(ll& a, ll b){ if(a > b) a = b; }
void chmax(ll& a, ll b){ if(a < b) a = b; }

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

template <typename T>
struct RMQ {
	using Func = function<T(T, T)>;
	const T e;
	int n;
	Func fx;
	// node 0<=i<n-1 n-1<=i 葉
	vector<T> node, lazy;
	RMQ(int n_, T e_, Func func) : n(), e(e_), fx(func), node(n_ * 4, e), lazy(n_ * 4, e) {
		int x = 1;
		while (n_ > x)
			x *= 2;
		n = x;
	}
	void set(int i, T x) { node[i + n - 1] = x; }
	void build() {
		for (int k = n - 2; k >= 0;k--) {
			node[k] = fx(node[2*k+1], node[2*k+2]);
		}
	}
	/* lazy eval */
	void eval(int k) {
		if (lazy[k] == e) return;	 // 更新するものが無ければ終了
		if (k < n - 1) {			 // 葉でなければ子に伝搬
			lazy[k * 2 + 1] = lazy[k];
			lazy[k * 2 + 2] = lazy[k];
		}
		// 自身を更新
		node[k]	= lazy[k];
		lazy[k] = e;
	}
	void update(int a, int b, T x, int k, int l, int r) {
		eval(k);
		if (a <= l && r <= b) {	 // 完全に内側の時
			lazy[k] = x;
			eval(k);
		} else if (a < r && l < b) {  // 一部区間が被る時
			update(a, b, x, k * 2 + 1, l, (l + r) / 2);	 // 左の子
			update(a, b, x, k * 2 + 2, (l + r) / 2, r);	 // 右の子
			node[k] = fx(node[k * 2 + 1], node[k * 2 + 2]);
		}
	}
	void update(int a, int b, T x) { update(a, b, x, 0, 0, n); }
	T query_sub(int a, int b, int k, int l, int r) {
		eval(k);
		if (r <= a || b <= l) {	 // 完全に外側の時
			return e;
		} else if (a <= l && r <= b) {	// 完全に内側の時
			return node[k];
		} else {  // 一部区間が被る時
			T vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
			return fx(vl, vr);
		}
	}
	T query(int a, int b) { return query_sub(a, b, 0, 0, n); }
	/* debug */
	inline T operator[](int a) { return query(a, a + 1); }
	void print() {
		for (int i = 0; i < 2 * n - 1; ++i) {
			cout << (*this)[i];
			if (i != n) cout << ",";
		}
		cout << endl;
	}
};

int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

	ll N, Q;
	cin >> N;
	ll a[N], t[N];
	rep(i,0,N) cin >> a[i] >> t[i];
	cin >> Q;
	ll x[Q];
	rep(i,0,Q) cin >> x[i];

	ll low = -INF, high = INF, add = 0;
	for (ll i = 0;i < N;i++) {
		// if (t[i] == 1) {
		// 	high += a[i];
		// 	low += a[i];
		// 	add += a[i];
		// }
		// if (t[i] == 2) {
		// 	chmax(low, a[i]);
		// 	chmax(high, a[i]);
		// }
		// if (t[i] == 3) {
		// 	chmin(high, a[i]);
		// 	chmin(low, a[i]);
		// }
		if(t[i] == 1){
            low += a[i];
            high += a[i];
            add += a[i];
        }
        else if(t[i] == 2){
            chmax(low, a[i]);
            chmax(high, a[i]);
        }
        else{
            chmin(low, a[i]);
            chmin(high, a[i]);
        }
	}
	for (ll i = 0;i < Q;i++) {
		cout << min(max(low, x[i]+add), high) << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 123;
int n;
int a[maxn];
int out[12345][maxn];
string s;

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	++n;
	cin >> s;
	F1 (i, n) cin >> a[i];
}

void solve()
{
	int ans = 12345;
	F1 (i, n - 1) ans = min(ans, abs(a[i] - a[i + 1]));
	int mn = a[1], cur = 1;
	F1 (i, n) if (a[i] < mn) mn = a[i], cur = i;
	for (int i = 1; i <= ans; ++i)
		out[i][cur] = a[cur] / ans;
	for (int i = 1; i <= a[cur] % ans; ++i)
		++out[i][cur];
	for (int i = cur - 1; i >= 1; --i)
	{
		if (a[i] < a[i + 1])
		{
			F1 (j, ans) out[j][i] = out[j][i + 1] - 1;
			priority_queue<pii> p;
			F1 (j, ans) p.push(mp(out[j][i], j));
			F (j, a[i + 1] - a[i] - ans)
			{
				--out[p.top().se][i];
				p.push(mp(out[p.top().se][i], p.top().se));
				p.pop();
			}
		} else
		{
			F1 (j, ans) out[j][i] = out[j][i + 1] + 1;
			priority_queue<pii, vector<pii>, greater<pii>> p;
			F1 (j, ans) p.push(mp(out[j][i], j));
			F (j, a[i] - a[i + 1] - ans)
			{
				++out[p.top().se][i];
				p.push(mp(out[p.top().se][i], p.top().se));
				p.pop();
			}
		}
	}
	for (int i = cur + 1; i <= n; ++i)
	{
		if (a[i] < a[i - 1])
		{
			F1 (j, ans) out[j][i] = out[j][i - 1] - 1;
			priority_queue<pii> p;
			F1 (j, ans) p.push(mp(out[j][i], j));
			//dbg(p.top());
			F (j, a[i - 1] - a[i] - ans)
			{
				--out[p.top().se][i];
				p.push(mp(out[p.top().se][i], p.top().se));
				p.pop();
			}
		} else
		{
			//MEOW
			F1 (j, ans) out[j][i] = out[j][i - 1] + 1;
			priority_queue<pii, vector<pii>, greater<pii>> p;
			//dbg(ans);
			F1 (j, ans) p.push(mp(out[j][i], j));
			//dbg(p.top());
			F (j, a[i] - a[i - 1] - ans)
			{
				++out[p.top().se][i];
				p.push(mp(out[p.top().se][i], p.top().se));
				p.pop();
			}
		}
	}
	cout << ans << '\n';
	F1 (i, ans)
	{
		F1 (j, n) cout << out[i][j] << ' ';
		cout << '\n';
	}
}

main()
{
	input();
	solve();
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define PI 2*acos(0.0)
const int mod = 1e9 + 7;
const int sz = 1e7;
#define all(x) x.begin(),x.end()
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) (x/gcd(x,y))*y
using namespace std;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

ll n, m;

int main()
{
	optimize();

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, a, b, c, d, l, x, y, u, v, cn = 0, cs = 1;
	string str;

	cin >> str;

	for (int i = 0; i < str.size(); )
	{
		if (str[i] == 'Z' && str[i + 1] == 'O' && str[i + 2] == 'N' && str[i + 3] == 'e')
		{
			cn++;
			i += 4;
		}
		else
			i++;
	}
	cout << cn << endl;
}

#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;
    template<class t>
    void output(t a){
        if(was_output)cout << " ";
        cout << a;
        was_output = true;
    }
    void outendl(){
        was_output = false;
        cout << endl;
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    void out(t x){
        cout << x;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

    long long lcm(long long a,long long b){
        return a / gcd(a,b) * b;
    }
}

using namespace templates;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string str = in<string>();
    int cnt = 0;
    rep(i,str.size()){
        if(str.substr(i,4)=="ZONe")++cnt;
    }
    cout << cnt << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main() {
	double a, b;
	cin >> a >> b;

	int c = a - b;
	cout << (c / a)*100;
	return 0;
}


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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int N = 2020;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n,m; cin >> n >> m;
    int s = 0;
    forn(_,n) {
        int x; cin >> x;
        s += x;
    }

    vi inv(s+n+1);
    inv[1] = 1;
    forsn(x,2,si(inv)) {
        inv[x] = ll(MOD - MOD/x) * inv[MOD%x] % MOD;
        assert(ll(inv[x]) * x % MOD == 1);
    }

    ll ans = 1;
    forn(k,s+n) {
        ans = ans * (m+n-k) % MOD;
        ans = ans * inv[k+1] % MOD;
    }
    cout << ans << endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define ll long long
#define MAXN 200005
#define uns unsigned
#define MOD 998244353ll
#define INF 0x7f7f7f7f
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
ll x,y,p,q;
inline ll exgcd(ll a,ll b,ll&x,ll&y){
	if(b==0){x=1,y=0;return a;}
	ll res=exgcd(b,a%b,y,x);
	y-=a/b*x;return res;
}
signed main()
{
	for(int T=read();T--;){
		x=read(),y=read(),p=read(),q=read();
		ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim;
		ll K,F,G=exgcd(p+q,md,K,F);
		for(ll i=x;i<x+y;i++){
			ll b=p,a=p+q,c=((i-b)%md+md)%md;
			ll k=K,f=F,g=G;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=p+q,b=p;
			if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b);
		}
		md=p+q,G=exgcd((x+y)<<1,md,K,F);
		for(ll i=p;i<p+q;i++){
			ll b=x,a=(x+y)<<1,c=((i-b)%md+md)%md;
			ll k=K,f=F,g=G;
			if(c%g!=0)continue;
			c/=g,k=(k*c%md+md)%md,f=md/g,k%=f,a=(x+y)<<1,b=x;
			if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b);
		}
		if(ans>=lim)printf("infinity\n");
		else printf("%lld\n",ans);
	}
	return 0;
}


//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    For(i,n) for(int i=0;i<n;i++)
#define    Forn(i,n) for(int i=1;i<=n;i++)
#define    Fors(i,s) for(int i=0;i<s.size();i++)
#define    all(v) v.begin(),v.end()
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    min4(a,b,c,d)   min(min(a,b),min(c,d))
#define    max4(a,b,c,d)   max(max(a,b),max(c,d))
#define    Max(a)  *max_element(a,a+sizeof(a)/sizeof(a[0]))
#define    Min(a)  *min_element(a,a+sizeof(a)/sizeof(a[0]))
#define    End    return 0
#define    gt     greater<int>()
#define    ll     long long
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    mod    1e9+7 //1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    YES    printf("YES\n")
#define    NO     printf("NO\n")
#define    Erase(s) s.erase(unique(s.begin(),s.end()),s.end())
//%%%%%%%%%%%%%p%%%a%%%r%%%v%%%e%%%z%%%%%%%%%%%%%//

int main()
{
MP;
    //int T;cin>>T;while(T--)
    {
        int a, b;
        cin >> a >> b;
        if (a+b >= 15 and b >= 8) cout << 1 << endl;
        else if (a+b >= 10 and b >= 3) cout << 2 << endl;
        else if (a+b >= 3) cout << 3 << endl;
        else cout << 4 << endl;
    }
    cerr<<endl<<(float)clock()/(float)CLOCKS_PER_SEC<<" sec"<<endl;
End;
}

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

        #define ll long long
        #define pb push_back
        #define printV(v) for(int i=0;i<(int)v.size();i++){cout << v[i]<< " ";} cout << endl
        #define printRev(v) for(int i=(int)v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
        #define sortV(v) sort(v.begin(),v.end())
        #define revV(v) reverse(v.begin(),v.end())

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        //ll mod = 1e9 + 7;
        ll mod = 998244353;
        const int N = 100009;

        void solve(){
            cin >> a >> b >> x >> y;
            if(a  ==  b){
                cout << x << endl;
            }else if(a < b){
                cout << min( ((b-a)*2 + 1)*x, x + (b-a)*y);
            }else{
                cout << min(  ((a-b-1)*2 + 1)*x, x + (a-b-1)*y);
            }
        }

        int main(){
            ios_base::sync_with_stdio(false);

            int cases = 1;
           // cin >> cases;

            while(cases--) solve();
            return 0;

        }


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

int main(){
	int T;
	int n;
	cin>>n;
	vector<ll> a(n);
	ll ta=0,tb=0;
	for(int i=0;i<n;i++){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		ta+=x;
		a[i]=x+y+x;
	}
	sort(a.begin(), a.end(),greater<ll>() );
	int res=0;
	while(tb<=ta){
		tb+=a[res];
		res++;
	}
	//cout<<ta<<" "<<tb<<endl;
	printf("%d\n",res);

	return 0;
}

// Problem: D - Choose Me
// Contest: AtCoder - AtCoder Beginner Contest 187
// URL: https://atcoder.jp/contests/abc187/tasks/abc187_d
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

using ll = long long;
using ld = long double;
using db = double;
using str = string;

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vl = vector<ll>;

#define mp make_pair
#define f first
#define s second

#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back

void divisors(map<int,int>& d,ll N){
	for(int div : {2,3,5}){
		int cnt=1;
		if(N%2==0){
			while((N%2)==0){
				N/=2;
				cnt++;
			}
			d[div]=cnt;
		}
	}
	static array<int,8> increments = {4,2,4,2,4,6,2,6};
	int i=0;
	for(ll div=7;div*div<=N;div+=increments[i++]){
		if((N%div)==0){
			int cnt=1;
			while((N%i)==0){
				N/=i;
				cnt++;
			}
			d[i]=cnt;
		}
		if(i==8)
			i=0;
	}
	if(N>1)
		d[N]=2;
}

ll solve(int T){
	vl town(T);
	ll baseline=0;
	for(int i=0;i<T;i++){
		ll a,b;
		cin>>a>>b;
		town[i]=2ll*a+b;
		baseline-=a;
	}
	sort(town.begin(),town.end());
	while(baseline<=0 && !town.empty()){
		baseline+=town.back();
		town.pop_back();
	}
	return T-(int)town.size();
}

int main(){
	int T;
	cin>>T;
	cout<<solve(T)<<"\n";

	return 0;
}


#include "iostream"
#include "vector"
#include "queue"
#include "stack"
#include "algorithm"
#include "string"
#include "cstring"
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	if (n % 100 == 0) {
		cout << n / 100 << endl;
	}
	else {
		cout << n / 100 + 1 << endl;
	}

}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
typedef long double lld;

#define all(x) (x).begin(), (x).end()
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;

int main(){
    int N;
    cin>>N;
    if(N%100==0)
        cout<<N/100;
    else
        cout<<(N/100)+1;
}


#include<iostream>

using namespace std;

int main()
{
  int a, b, c;
  cin>>a>>b>>c;
  int A, B, C;
  A=7-a;
  B=7-b;
  C=7-c;
  cout<<A+B+C;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

// 宣言は Dijkstra<コストの型> d(頂点数, コストの型の最大値);
template <class T>
struct Dijkstra {
    struct edge {int to; T cost;};
    vv<edge> g;
    vc<T> dist;
    Dijkstra (int n, T INF): g(n), dist(n, INF) {}

    // u -> vにコストwの辺を張る
    void add_edge (int u, int v, T w) {
        g[u].pb({v, w});
    }
    // startから各点への最小コストを返す
    vc<T> get (int start) {
        priority_queue<pair<T, T>, V<pair<T, T>>, greater<pair<T, T>>> que;
        dist[start] = 0;
        que.emplace(0, start);
        while (!que.empty()) {
            int c = que.top().first, v = que.top().second; que.pop();
            if (dist[v] != c) continue;
            for (auto e : g[v]) {
                if (chmin(dist[e.to], c + e.cost)) que.emplace(dist[e.to], e.to);
            }
        }
        return dist;
    }
};

int main () {
    int h, w; cin >> h >> w;
    Dijkstra<ll> d(h*w*2, 2e9);
    rep(i, h) rep(j, w-1) {
        int a; cin >> a;
        d.add_edge(i*w + j, i*w + j+1, a);
        d.add_edge(i*w + j+1, i*w + j, a);
    }
    rep(i, h-1) rep(j, w) {
        int b; cin >> b;
        d.add_edge(i*w + j, (i+1)*w + j, b);
    }
    rep(i, h) rep(j, w) {
        d.add_edge(i*w + j, h*w + i*w + j, 1); // 上の階に行く
        d.add_edge(h*w + i*w + j, i*w + j, 0); // 下の階に降りる
        if (i > 0) d.add_edge(h*w + i*w + j, h*w + (i-1)*w + j, 1); // 上の階で下に移動する
    }
    auto res = d.get(0);
    // int ans = min(res[h*w-1], res[2*h*w-1]);
    ll ans = res[h*w-1]; // 下に移動してゴールにつくことはないから, 2*h*w-1は考えなくていい
    cout << ans << endl;
    return 0;
}