#define _CRT_SECURE_NO_DEPRECATE
#define _SECURE_SCL 0

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <iostream>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <cctype>
#include <sstream>
#include <cassert>
#include <bitset>
#include <memory.h>
#include <complex>
#include <iomanip>

using namespace std;

#pragma comment(linker, "/STACK:200000000")

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define fore(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) (int(a.size()) - 1)
#define all(a) a.begin(), a.end()

const double EPS = 1E-9;
const int INF = 1000000000;
const int64 INF64 = (int64) 1E18;
const double PI = 3.1415926535897932384626433832795;

const int NMAX = 20000000;

int n, m, k;
int t[NMAX], l1[NMAX], r1[NMAX], l2[NMAX], r2[NMAX], w[NMAX], ans[NMAX], ans_id[NMAX];
pair<int, int> md[NMAX];

void md_update(int idx, int l, int r, int pos, pair<int, int> val) {
  if (l == r) {
    md[idx] = max(md[idx], val);
    return;
  }

  int mid = (l + r) >> 1;
  if (pos <= mid)
    md_update(idx << 1, l, mid, pos, val);
  else
    md_update(idx << 1 | 1, mid + 1, r, pos, val);

  md[idx] = max(md[idx << 1], md[idx << 1 | 1]);
}

pair<int, int> md_max(int idx, int l, int r, int a, int b) {
  pair<int, int> res(-INF, -INF);
  if (r < a || b < l)
    return res;
  if (a <= l && r <= b)
    return md[idx];

  int mid = (l + r) >> 1;
  res = max(res, md_max(idx << 1, l, mid, a, b));
  res = max(res, md_max(idx << 1 | 1, mid + 1, r, a, b));

  return res;
}

int main() {
#ifdef RADs_project
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif

  cin >> n >> m;
  forn(i, n)
    scanf("%d%d", &l1[i], &r1[i]);
  forn(i, m)
    scanf("%d%d%d", &l2[i], &r2[i], &w[i]);

  forn(i, n) {
    t[k++] = l1[i];
    t[k++] = r1[i];
  }
  forn(i, m) {
    t[k++] = l2[i];
    t[k++] = r2[i];
  }

  sort(t, t + k);
  k = int(unique(t, t + k) - t);

  forn(i, n) {
    l1[i] = int(lower_bound(t, t + k, l1[i]) - t);
    r1[i] = int(lower_bound(t, t + k, r1[i]) - t);
  }
  forn(i, m) {
    l2[i] = int(lower_bound(t, t + k, l2[i]) - t);
    r2[i] = int(lower_bound(t, t + k, r2[i]) - t);
  }

  vector<pair<int, pair<int, int> > > ev;
  forn(i, n) {
    ev.pb(mp(l1[i], mp(-1, i)));
    ev.pb(mp(r1[i], mp(2, i)));
  }
  forn(i, m) {
    ev.pb(mp(l2[i], mp(0, i)));
    ev.pb(mp(r2[i], mp(1, i)));
  }

  sort(all(ev));

  set<pair<int, int> > opl, opr;

  forn(i, ev.size()) {
    int tp = ev[i].sc.fs;
    int id = ev[i].sc.sc;

    if (tp == -1) {
      opr.insert(mp(-r1[id], id));
      opl.insert(mp(l1[id], id));
      continue;
    }
    if (tp == 2) {
      opr.erase(mp(-r1[id], id));
      opl.erase(mp(l1[id], id));
      md_update(1, 0, k - 1, l1[id], mp(t[r1[id]] - t[l1[id]], id));
      continue;
    }
    if (tp == 0) {
      if (opr.size()) {
        int cid = opr.begin()->sc;
        int clen = t[min(r1[cid], r2[id])] - t[l2[id]];
        if (clen > ans[id]) {
          ans[id] = clen;
          ans_id[id] = cid;
        }
      }
      continue;
    }

    if (opl.size()) {
      int cid = opl.begin()->sc;
      int clen = t[r2[id]] - t[max(l1[cid], l2[id])];
      if (clen > ans[id]) {
        ans[id] = clen;
        ans_id[id] = cid;
      }
    }

    pair<int, int> ft = md_max(1, 0, k - 1, l2[id], r2[id]);
    if (ft > mp(ans[id], ans_id[id])) {
      ans[id] = ft.fs;
      ans_id[id] = ft.sc;
    }
  }

  int64 res = 0;
  int ans1, ans2;
  forn(i, m) {
    int64 c = ans[i] * int64(w[i]);
    if (c > res) {
      res = c;
      ans1 = ans_id[i];
      ans2 = i;
    }
  }

  cout << res << endl;
  if (res > 0)
    cout << ans1 + 1 << ' ' << ans2 + 1 << endl;

  return 0;
}


#include <iostream>

bool check(int a1, int b2, int a2, int b2, int a3, int b3);

int main()
{
	int a1;
	int b1;
	int a2;
	int b2;
	int a3;
	int b3;

	std::cin >> a1 >> b1;
	std::cin >> a2 >> b2;
	std::cin >> a3 >> b3;

	if (check(a1, b1, a2, b2, a3, b3) ||
		check(a1, b1, a2, a3, b2, b3) ||
		check(a1, b1, b3, b2, a3, a2) ||
		check(a1, b1, b3, a3, b2, a2)
	)
		std::cout << "YES" << std::endl;
	else
		std::cout << "NO" << std::endl;

	return 0;
}

bool check(int a1, int b2, int a2, int b2, int a3, int b3)
{
	return a2 + a3 <= a1 && std::max(b2, b3) <= b1;
}


#pragma comment(linker, "/STACK:60777216")

#include <algorithm>
#include <iostream>
#include <complex>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <ctime>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

#define sz(a)                   int(a.size())
#define all(a)                  (a).begin(), (a).end()
#define CL(a, b)                memset(a, b, sizeof a)
#define FOR(i, a, b)			for (int i(a); i < (b); ++i)
#define REP(i, n)               FOR(i, 0, n)
#define UN(a)                   sort(all(a)), (a).erase(unique(all(a)), (a).end())
#define pb                      push_back
#define SORT(a)                 sort(all(a))

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pii;

double xa,ya,xb,yb;
int n;
double x[11111],y[11111],a[11111],w[11111];
int k;

const double pi = acos(-1.);

bool check(double v,double a,double w){
	int num = 1000;
	REP(i,num+1){
		double x = xa + (xb-xa)*i/double(num);
		double y = ya + (yb-ya)*i/double(num);
		double q = atan2(y,x) - a;

		if(q>2*pi) q-=2*pi;
		if(q<0) q+=2*pi;
		if(q>2*pi-q) q = 2*pi - q;
		q/=w;

		if(hypot(x-xa,y-ya)/v >= q) return 1;
	}

	return 0;
}

bool good(double s){
	int num = 0;
	REP(i,n){
		xa-=x[i],ya-=y[i],xb-=x[i],yb-=y[i];

		if(check(s,a[i],w[i]))
			num ++;

		xa+=x[i],ya+=y[i],xb+=x[i],yb+=y[i];
	}
	return num <= k;
}

int main() {
#ifdef LocalHost
	freopen("input.txt", "r", stdin);
#endif

	cin>>xa>>ya>>xb>>yb>>n;
	REP(i,n) scanf("%lf %lf %lf %lf",x+i,y+i,a+i,w+i);
	cin>>k;

	double a = 0, b = 1e10, best = 1e10;
	REP(i,100){
		double s = (a+b)/2;
		if(good(s))
			best = s, b = s;
		else a = s;
	}
	printf("%.4lf\n",best);

	return 0;
}


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

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define csl ios_base::sync_with_stdio(false);cin.tie(NULL);

const int N = 1e5+5;

int main()
{
    csl;
    string s;
    int i;
    cin>>s;
    int x = s.length();
    string demo = "abcdefghijklmnopqrstuvwxyz";
    int k = 0;
    set<char> st;
    for(i = 0;i < x;i++)
    {
        st.insert(s[i]);
    }
    int c = 0;
    for(i = 0;i < x;i++)
    {
        if(demo[k] == s[i] && (k<26))
        {
            k++;
            c++;
        }
    }

    if((c != st.size()))
        cout<<"NO";
    else
        cout<<"YES";

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

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define csl ios_base::sync_with_stdio(false);cin.tie(NULL);

const int N = 1e5+5;

int main()
{
    csl;
    string s;
    int i;
    cin>>s;
    int x = s.length();
    string demo = "abcdefghijklmnopqrstuvwxyz";
    int k = 0;
    set<char> st;
    for(i = 0;i < x;i++)
    {
        st.insert(s[i]);
    }
    int c = 0;
    for(i = 0;i < x;i++)
    {
        if(demo[k] == s[i] && (k<26))
        {
            k++;
            c++;
        }
    }

    if((c != st.size()))
        cout<<"NO";
    else
        cout<<"YES";

	return 0;
}


#include <iostream>
#include <math.h>
#include <cstring>
using namespace std;

const int MAXN = 1e5+2;
int dp[MAXN][MAXN];

int comb(int n, int k){
    if(k==n||k==0) return 1;
    if(k>n) return 0;
    if(dp[n][k]>0) return dp[n][k];
    int ans = comb(n-1,k-1) + comb(n-1,k);
    return dp[n][k]=ans;
}

int func(int a,int b,int c,int l){
    int ans = 0;
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,a+l1-b-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,b+l1-a-c);
        ans+= comb(k+2,2);
    }
    for(int l1=0;l1<=l;l1++){
        int k = min(l-l1,c+l1-b-a);
        ans+= comb(k+2,2);
    }
    return ans;
}

int main() {
    int a,b,c,l;
    scanf("%d %d %d %d",&a,&b,&c,&l);
    memset(dp, -1, (l+100)*(l+100)*sizeof(dp[0][0]));
    int total = comb(l+3,3);
    int ans = func(a,b,c,l);
    printf("%d\n",total - ans);
    return 0;
}


// No114Div2.8cpp : �������̨Ӧ�ó������ڵ㡣
//

#include "stdafx.h"
#include <iostream>
using namespace std;

int main(){
	int ab,ch;
	cin>>ab>>ch;
	if(ab == 0)
		cout<<"Impossible"<<endl;
	else{
		int min,max;
		if(ab >= ch){
			min = max = ab;
		}
		else{
			min = ch;
			max = ab + ch -1;
		}
		cout<<min<<" "<<max<<endl;
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

const int SQRT_MAXN = 100000;
const int S = 10000;
bool nprime[SQRT_MAXN], bl[S];
int primes[SQRT_MAXN], cnt;

int main() {
    int l, r;
    cin >> l >> r;
    int n = 30000010;
    int nsqrt = (int) sqrt (n + .0);
    for (int i = 2; i <= nsqrt; ++i)
        if (!nprime[i]) {
            primes[cnt++] = i;
            for (int j = i + i; j <= nsqrt; j += i)
                nprime[j] = true;
        }
    int result = 0;
    for (int k = 0, maxk = n / S; k <= maxk; ++k) {
        memset (bl, 0, sizeof bl);
        int start = k * S;
        for (int i = 0; i < cnt; ++i)
            for (int j = max((start + primes[i] - 1) / primes[i], 2) * primes[i] - start; j < S; j += primes[i])
                bl[j] = true;
        if (k == 0)
            bl[0] = bl[1] = true;
        for (int i = 0; i < S && start + i <= n; ++i)
            if ((!bl[i]) && (start + i >= l) && (start + i <= r) && ((start + i) % 4 != 3))
                ++result;
    }
    cout << result;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std ;
int main (){
int sum,a[101],temp[101],n,answer[101],c=0;

cin>>n;
for (int i=0;i<n;i++){
    cin>>a[i];
    temp[i]=a[i];
}
for (int i=n-1;i>0;i--)
    if(a[i]==a[i-1])
        c++;
    if(c==n-1)
    {
        for(int i=1;i<=n;i+=2)
            cout<<i<<" "<<i+1<<endl;
        return  0;
    }
sort(a,a+n);
for (int z=0;z<n;z++){
    sum=a[n-1]+a[z];
    c=0;memset(answer,-1,sizeof(answer));
    for (int i=0;i<n;i++)
        for(int j=i+1;j<n;j++){
            if(temp[i]+temp[j]==sum){
                c++;
                cout<<temp[i]<<" * "<<temp[j]<<endl;
                answer[i]=j;
            }
        }
    if(c==n/2)break;
}
for (int i=0;i<n;i++)
    if(answer[i]!=-1)
        cout<<i+1<<" "<<answer[i]+1<<endl;
}


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

#define INF (LL)(0x3f3f3f3f)*(LL)0x3f3f3f3f
#define MAXN 300005

long long n,m;
long long a,b,x;
long long ans = 0;
long long an[MAXN];
bool f[MAXN];
queue<long long>q;

long long gcd(long long x,long long y) {
    if(x%y != 0) return gcd(y,x%y);
    return y;
}

long long orz(long long x) {
    return x*(x+1)>>1;
}

long long sqz(long long x,long long mo)
{
    if(x % mo == 0) return x/mo;
    else return x/mo+1;
}

long long stOOrz(long long n) {
    return orz((n+1)/x)*x + ((n+1)%x)*(sqz(n+1,x));
}

long long bfs(long long i)
{
    long long ans = 0;
    f[0] = 1;
    while(!q.empty()) {
        long long x = q.front();
        q.pop();
        ans ++;
        if(x+a <= i && !f[x+a]) {
            f[x+a] = 1;
            q.push(x+a);
        }
        if(x-b >= 0 && !f[x-b]) {
            f[x-b] = 1;
            q.push(x-b);
        }
    }
    return ans;
}

signed main()
{
    cin >> n >> a >> b;

    q.push(0);
    an[0] = 1;
    f[0] = 1;
    bfs(0);
    for(long long i = 1; i <= max(a,b)*2; i ++) {
        if(i-a >= 0 &&f[i-a]) {
            f[i] = 1;
            q.push(i);
            an[i] = an[i-1]+bfs(i);
        } else {
            an[i] = an[i-1];
        }
    }

    x = gcd(a,b);
    if(a > b)
      swap(a,b);

        for(long long i = 0; i < min(n+1,2*b); i ++) {
            ans += an[i];
        }
        if(n >= 2*b)
            ans += stOOrz(n) - stOOrz(2*b-1);
    }
    cout<<ans;
    return 0;
 }


#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define int ll

using namespace std;

const int N=3e5+3;
const int inf=1e9+3;
const int md=1e9+7;

int bin(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n&1)
        res*=a;
        a*=a;
        res%=md;
        a%=md;
        n/=2;
    }
    return res;
}

unordered_map<pair<int,int>,int> kl;

int f(int x,int y)
{
    if(kl.count(mp(x,y)))return kl[mp(x,y)];
    int d;
    if(y%x!=0)return 0;
    d=y/x;

    if(d==1)return 1;

    int res=bin(2,d-1);
    res--;
    if(res<0)res+=md;

    int sq=sqrt(d);
    for(int j=2;j<=sq;++j)
    {
        if(d%j==0)
        {
            res-=f(j,d);
            if(res<0)res+=md;

            if(d/j!=j)
            res-=f(d/j,d);
            if(res<0)res+=md;
        }
    }

    return kl[mp(x,y)]=res;

}

int x,y;

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

    cin>>x>>y;

    cout<<f(x,y);

}
/*
1 994593600
*/


#include "stdio.h"
#include "iostream"
using namespace std;

int toint (char* val)
{
	return (val[0] - '0') * 10 + val[1] - '0';
}

void addh (char* hh)
{
	int hour = toint(hh);
	hour++;
	if (hour != 24)
	{
		hh[0] = hour / 10 + '0';
		hh[1] = hour % 10 + '0';
	}
	else
	{
		hh[0] = '0';
		hh[1] = '0';
	}
}

int main(int argc, char* argv[])
{
	char hh[3];
	char temp[3];
	char mm[3];
	hh[2] = 0;
	mm[2] = 0;
	temp[2] = 0;
	scanf ("%c%c:%c%c",hh,hh+1,mm,mm+1);
	temp[0] = hh[1];
	temp[1] = hh[0];
	if (toint(temp) > toint (mm))
	{
		cout << hh << ":" << temp << endl;
	}
	else
	{
		addh(hh);
		if (!strcmp (hh,"06"))
		{
			addh(hh);
		}
		cout << hh << ":" << hh[1] << hh[0] << endl;
	}

	return 0;
}


一道挺有意思的模拟。

------------
第一眼看到本题，首先想到的是数学方法，不过奈何本人既没耐心也不擅长，所以直接跳过，毕竟计算机就是用来做大量计算的，要我们人来找规律干嘛（~~就是强行找菜的理由~~）

其实这道题用模拟写还是挺好的，能锻炼对细节的把握能力，此题在某些情况的处理还是很考验细节的。

具体情况请看代码注释，模拟题不好干讲（我太蒟蒻了）

```
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int a,b,c,d,ans;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int l=c,r=a-c,fx=1,hy=l,cs=0;
    //l表示从左走到加油站所需要的距离
    //r表示从右走到加油站所需要的距离
    //fx表示当前方向，1为向右，0为向左
    //hy表示当前汽车的油耗
    //cs表示已经走了多少来回
	if(!a)
	{
		printf("0");
	}
	if(b<l)
	{
		printf("-1");
		return 0;
	}//如果车开始从左跑不到加油站，直接gg
	while(1)
	{
		if(cs==d-1)
		{
			break;
		}//当车走完d-1次之后，直接跳出循环判断最后半个路程
		if(fx)
		{
			if(2*r>b)
			{
				printf("-1");
				return 0;
			}//如果车的油箱不足以跑到右端再回来，gg
			if(hy+2*r<=b)
			{
				hy+=2*r;
				cs++;
				fx=0;
			}//能不加油跑回来，就增加油耗，更改方向
			else
			{
				hy=0;
				ans++;
			}//油不够了，加油
		}
		else
		{
			if(2*l>b)
			{
				printf("-1");
				return 0;
			}
			if(hy+2*l<=b)
			{
				hy+=2*l;
				cs++;
				fx=1;
			}
			else
			{
				hy=0;
				ans++;
			}//向左时的情况，同上方向右
		}
	}
	if(fx)//判断最后半程
	{
		if(b<r)
			printf("-1");
        //一开始我这里犯了个错误，以为不需要判断这个
        //后来发现当d==1时，不会进循环，能不能到右端要在这里判断
		else if(hy+r<=b)
			printf("%d",ans);
		else
			printf("%d",ans+1);
	}
	else
	{
		if(hy+l<=b)
			printf("%d",ans);
		else
			printf("%d",ans+1);
	}//如果最后向左就不需要上面向右时的判断了
    //因为如果最后是向左的，一开始必定要先从左跑到加油站，就必定能跑回来
	return 0;
}


#include<iostream>
using namespace std;
int hcf(long long int a,long long int b) {
  return b == 0 ? a : a > b ? hcf(b, a%b) : hcf(a, b%a);
}
int min(long long int a,long long int b)
{
	if(a<b)
	return a;
	else return b;

}
int main()
{
	long long int n,a,b,p,q;
	cin>>n>>a>>b>>p>>q;
	long long int ans=0;
	long long int lcm=(a/(hcf(a,b))*b;
	long int x=n/lcm;
	long long int y=n/a;
	long long int z=n/b;
	ans=y*p+z*q-min(x*p,x*q);
	cout<<ans<<"\n";
}


#include <iostream>
using namespace std;

int f(long long n)
{
if (n == 0) return 0;
  long long u1 = 0, u2 = 0;
int x = 0;
  while (u1 <= n)
  {
x++;
    u1 *= 10;
    u1++;
  }
  u2 = u1/10;
long long a = n - u1, b = n - u2;
if ( a < 0LL) a = - a;
if (b <0LL) b = - b;
 return min( x + f(a), x - 1 + f(b) ;
//else return x - 1 + f(b
}
int main() {
    long long n;
   cin >> n;
cout<<f(n) ;
	return 0;
}


#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

ll dp[99][1<<20];
ll sum[99][1<<20];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  // vector<int> v;
  // reps(i,1,10){
  //   rep(j,1<<(i-1)){
  //     v.pb(i);
  //     if(accumulate(all(v),0)>75) break;
  //   }
  //     if(accumulate(all(v),0)>75) break;
  // }
  // cout<<v.size()<<v;
  int n;
  string s;
  cin>>n>>s;
  dp[0][0]=1;
  ll re=0;
  rep(i,n){
    (dp[i+1][0]+=1)%=MOD;
    //for(int j=2;j<=(1<<20);j*=2) (re+=dp[i][j-1])%=MOD;
    //for(int j=2;j<=(1<<20);j*=2) if(dp[i][j-1])out(i,j-1,dp[i][j-1],1);
    if(i&&s[i]=='0'){
      rep(k,1<<20) (sum[i+1][k]+=dp[i][k]+sum[i][k])%=MOD;
    }else{
      int val=0;
      reps(j,i,n){
	(val*=2)+=s[j]-'0';
	if(val>20) break;
	rep(k,1<<20) (dp[j+1][k|(1<<(val-1))]+=dp[i][k]+sum[i][k])%=MOD;
      }
    }
  }
  //rep(i,n+1){rep(j,8) cout<<dp[i][j]<<",";cout<<endl;}
  rep(j,n+1)for(int i=2;i<=(1<<20);i*=2) (re+=dp[j][i-1])%=MOD;
  //rep(j,n+1)for(int i=2;i<=(1<<20);i*=2) if(dp[j][i-1])out(j,i-1,dp[j][i-1],1);
  cout<<re<<endl;
  return 0;
}
//11011100101110111100010011010101111001101111011111000010001100101001110100


#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
char s[5005];
int a[5005];
int b[5005];
int c[200];
int d[5005];
int num,sum;
int ch(int x)
{
  int now=0;
  for(int i=0;i<n;i++)
  {
    now+=a[i];
    if(now==x)
    {
      now=0;
      continue;
    }
    if(now>x)
    {
      return 0;
    }
  }
//  cout<<x<<endl;
  return 1;
}
int zs(int x)
{
  for(int i=2;i<x;i++)
  {
    if(x%i==0)
    {
      c[sum++]=x/i;
    }
  }
  if(c[0])
  {
    return 0;
  }
  return 1;
}
int main()
{
    num=0;
    sum=0;
    scanf("%s",s);
    for(int i=0;i<n;i++)
    {
      a[i]=s[i]-'0';
      b[i]=a[i];
      num+=a[i];
    }
//    cout<<num<<endl;
    if(zs(num)==1)
    {
      if(n==num)
      {
        printf("YES\n");
        continue;
      }
      printf("NO\n");
      continue;
    }
    sort(b,b+n);
//    for(int i=0;i<sum;i++)
//    {
//      cout<<c[i]<<" ";
//    }
    if(b[n-1]>c[0])
    {
      printf("NO\n");
      continue;
    }
//    cout<<endl;
    for(int i=0;i<sum;i++)
    {
      if(b[n-1]>c[i])
      {
        printf("NO\n");
        break;
      }
      else
      {
        if(ch(c[i])==1)
        {
          printf("YES\n");
          break;
        }
      }
    }
  return 0;
}


#include <iostream>
#include <unordered_set>

static constexpr int kMaxHp = 5000;
static int a[(kMaxHp + 1) * (kMaxHp + 1)] = {};
static size_t stamps[(kMaxHp + 1) * (kMaxHp + 1)] = {};

int main() {
  int p1, p2;
  std::size_t t1, t2;
  int h, s;

  std::cin >> p1 >> t1 >> p2 >> t2 >> h >> s;

  std::unordered_set<size_t> stamps_set;
  for (int n = 0; n <= h; n++) {
    for (int m = 0; m <= h; m++) {
      stamps_set.insert(n * t1 + m * t2);
    }
  }

  size_t stamps_num = 0;
  for (auto& s : stamps_set) {
    stamps[stamps_num++] = s;
  }
  std::sort(stamps, stamps + stamps_num);
  const int stride = h + 1;

  // for (int i = 0; i < stride * stride; i++) {
  //    std::cout << stamps[i] << " ";
  // }
  // std::cout << std::endl;

  size_t best_t = std::numeric_limits<size_t>::max();
  for (int n = 0; n < stamps_num; n++) {
    const size_t stamp1 = stamps[n];
    if (stamp1 >= best_t) {
      continue;
    }
    for (int m = 0; m < stamps_num; m++) {
      const size_t stamp2 = stamps[m];
      if (stamp2 >= best_t) {
        continue;
      }
      const int idx = n * stamps_num + m;
      if (n == 0 && m == 0) {
        continue;
      }

      if (stamp1 >= t1) {
        for (int i = n - 1; i >= 0; i--) {
          size_t prev_stamp = stamps[i];

          if (prev_stamp + 2 * t1 < stamp1) {
            break;
          }

          if (prev_stamp + t1 > stamp1) {
            continue;
          }

          a[idx] = std::max(a[idx], a[i * stamps_num + m] + p1 - s);
        }
      }

      if (stamp2 >= t2) {
        for (int i = m - 1; i >= 0; i--) {
          size_t prev_stamp = stamps[i];

          if (prev_stamp + 2 * t2 < stamp2) {
            break;
          }

          if (prev_stamp + t2 > stamp2) {
            continue;
          }

          a[idx] = std::max(a[idx], a[n * stamps_num + i] + p2 - s);
        }
      }

      if (stamp2 == stamp1 && stamp2 >= t2 && stamp1 >= t1) {
        a[idx] += s;
      }

      size_t t = std::max(stamp1, stamp2);
      if (a[idx] >= h && best_t > t) {
        best_t = t;
        //std::cout << n << " " << m << std::endl;
      }
      // std::cout << stamp1 << ", " << stamp2 << ": " << a[idx] << std::endl;
    }
    //std::cout << std::endl;
  }

  std::cout << best_t << std::endl;

  return 0;
}


// In the name of GOD
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
//#define int ll
int a, b, ta, tb, c, x, y, t;
char ch;
int f(int x) {
	if(x <= 0)return 0;
	x += 5*60;
	if(x >= 23*60+59) {
		x = 23*60+59;
	}
	x -= 5*60;
	return x;
}
main() {
	cin>>a>>ta>>b>>tb;
	for(int i = 0; i < 2; i++){
		cin>>ch;
		x *= 10;x += ch-'0';
	}
	cin>>ch;

	for(int i = 0; i < 2; i++){
		cin>>ch;
		y *= 10;y += ch-'0';
	}
	t = x*60+y;
	t -= 5*60;
    for(int i = 0; i < 19*60; i++) {
		if(i % b ==0) {
		    if((i <= t && i+tb = t) || (i >= t && i < t+ta)) c++
		}
    }
    cout<<c;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int next[100];
int match[100];
int b,d;
string a,c;

void init(){
    rep(i,c.size()){
        int s=i,t=0;
        rep(j,a.size()){
            if(c[s]==a[j])s++;
            if(s==c.size()){
                s=0;
                t++;
            }
        }
        next[i]=s;
        match[i]=t;
    }
}
int main(){
    cin>>b>>d>>a>>c;
    init();
    int m=0,cur=0;
    rep(i,b){
        m += match[cur];
        cur = next[cur];
    }
    cout<<m/d<<endl;
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
#include<string>
using namespace std;
string str,answer,keyboard[10]={
	{
		"\0\0\0\0"
	},
	{
		" qwertyuiop"
	},
	{
		" asdfghjkl;"
	},
	{
		" zxcvbnm,./"
	}
};
bool way,flag;
char ch;
int main(){
	ios::sync_with_stdio(false);
	cin>>ch;
	cin>>str;
	switch(ch){
		case 'L' : way=true;
		break;
		case 'R' : way=false;
		break;
	}
	for(int i=0;i<str.size();i++,flag=false)
		for(int j=1;j<=3&&!flag;j++)
			for(int k=1;k<=10&&!flag;k++)
				if(str[i]==keybroad[j][k]){
					if((k==1&&!way)||(k==10&&way)) answer+=keybroad[j][k];
					else answer+=keyboard[j][k+p];
					flag=!flag;
				}
	cout<<answer;
	return 0;
}


#undef NDEBUG
#ifdef gridnevvvit
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <string>
#include <deque>
#include <bitset>
#include <algorithm>
#include <utility>

#include <functional>
#include <limits>
#include <numeric>
#include <complex>

#include <cassert>
#include <cmath>
#include <memory.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long li;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ld, ld> ptd;
typedef unsigned long long uli;

#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ft first
#define sc second
#define sz(a) int((a).size())
#define x first
#define y second

template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
template<typename X> inline X sqr(const X& a) { return (a * a); }
template<typename T> inline string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; }
template<typename T> inline int hasBit(T mask, int b) { return (b >= 0 && (mask & (T(1) << b)) != 0) ? 1 : 0; }
template<typename X, typename T>inline ostream& operator<< (ostream& out, const pair<T, X>& p) { return out << '(' << p.ft << ", " << p.sc << ')'; }

inline int nextInt() { int x; if (scanf("%d", &x) != 1) throw; return x; }
inline li nextInt64() { li x; if (scanf("%I64d", &x) != 1) throw; return x; }
inline double nextDouble() { double x; if (scanf("%lf", &x) != 1) throw; return x; }

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, a, b) for(int i = int(a); i <= int(b); i++)
#define ford(i, n) for(int i = int(n - 1); i >= 0; i--)
#define foreach(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)

const int INF = int(1e9);
const li INF64 = li(INF) * li(INF);
const ld EPS = 1e-9;
const ld PI = ld(3.1415926535897932384626433832795);

li x;
int k;
int pl;

const int N = 402;
const int MAGIC = 9;

ld d[2][(1 << MAGIC)][2][N];
/// iss problem ka author m*dharc*od hai , sala bhosriwala kutta

inline void solve() {
	ld p = ld(pl) / 100;

	int SPMASK = (1 << MAGIC) - 1;

	li pmask = x & li(SPMASK);
    li plast = (x & li(1 << MAGIC)) > 0;
    li pcnt = 0;

    x >>= MAGIC;

    if (x == 0)
   		pcnt = 200;
    else {
    	while (true) {
    	 	int bit = x & 1ll;

    	 	if (bit == plast)
    	 		pcnt++;
    	 	else
    	 		break;

    	 	x >>= 1;
    	}
    }

    d[0][pmask][plast][pcnt] = 1.0;

    forn(it, k) {
		int i = it & 1;
		int nxt = i ^ 1;

		forn(mask, (1 << MAGIC)) {
		 	forn(last, 2) {
		 	 	forn(cnt, N) {
		 	 	 	d[nxt][mask][last][cnt] = 0.0;
		 	 	}
		 	}
		}

	 	forn(mask, (1 << MAGIC)) {
			forn(last, 2) {
				forn(cnt, N) {
					ld dv = d[i][mask][last][cnt];

					//doubling
                	{
                		int nmask = (mask << 1) & SPMASK;
                		int nlast = (mask & (1 << (MAGIC - 1))) > 0;
                		int ncnt = cnt;

                		if (last == nlast)
                			ncnt++;
                		else
                			ncnt = 1;

                        d[nxt][nmask][nlast][ncnt] += dv * p;

                    }

                    //adding
                    {
                     	int nmask = mask + 1;

                     	if (nmask != (1 << MAGIC)) {
                     		d[nxt][nmask][last][cnt] += dv * (1.0 - p);
                     	} else {
                     		if (last == 1)
                     			d[nxt][0][0][cnt] += dv * (1.0 - p);
                     		else
                     			d[nxt][0][1][1] += dv * (1.0 - p);
                        }
                    }
                }
			}
	 	}
	}

	ld answer = 0;

	k = k & 1;

	forn(nmask, (1 << MAGIC)){
	 	forn(last, 2) {
	 	 	forn(cnt, N) {
	 	 		int counter = 0;

	 	 		int mask = nmask;

	 	 		if (mask != 0) {

	 	 			while (mask % 2 == 0)
	 	 				counter += 1, mask /= 2;

	 	 		} else {
	 	 			counter = MAGIC;
	 	 			if (last == 0)
	 	 				counter += cnt;
	 	 		}

	 	 		ld dv = d[k][nmask][last][cnt];

	 	 		answer += ld(counter) * ld(d[k][nmask][last][cnt]);
	 	 	}
	 	}
	}

	cout << fixed << setprecision(13) << answer << endl;
}

int main()
{

#ifdef gridnevvvit
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif

	srand(time(NULL));
 cin >> x >> k >> pl;
	cout << setprecision(10) << fixed;
	cerr << setprecision(5) << fixed;

	assert(read());
	solve();

#ifdef gridnevvvit
	cerr << "===Time: " << clock()  << "===" << endl;
#endif

}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
bool IsPrime(ll n){
    if(n < 2) return 0;
    for(ll i=2; i<=sqrt(n); i++) if(n%i==0) return 0;
    return 1;
}
main(){
    ll n;
    cin>>n;
    if(n==1){
        cout<<;
        return 0;
    }
    for(ll i=1; i<=n; i++){
        if(!IsPrime(n*i+1)){
            cout<<i<<"\n";
            return 0;
        }
    }
}


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

int get_dig(long long x)
{
    long long powr = 10;
    int dig = 1;
    while (powr<x)
    {
        dig++;
        powr*=10
    }
    return dig;
}

int main ()
{
    long long n;
    string k;
    cin >> n >> k;
    if (n<=10)
    {
        cout << stoi(k,nullptr,n);
    }
    long long powr = 10;
    while (powr < n) powr*=10;
    int dig = get_dig(n);
    vector <long long> rep;
    int i = k.length() - dig;
    long long m;
    int length = 0;
    while (i + dig >0)
    {
        if (i<0) m = stoi(k.substr(0,dig+i));
        else m = stoi(k.substr(i,dig));
        if (m==0 || m==1)
        {
            rep.push_back(m);
            i--;
        }
        else if (m<n)
        {
            rep.push_back(m);
            i-=get_dig(m);
        }
        else
        {
            m = m % (powr/10);
            if (m == 0 || m == 1)
            {
                rep.push_back(m);
                i--;
            }
            else
            {
                rep.push_back(m);
                i-=get_dig(m);
            }
        }
        length++;
    }
    long long ans = 0;
    for (int i = length - 1; i>=0; i--)
    {
        ans*=n;
        ans+=rep[i];
    }
    cout << ans;
    return 0;
}


const int maxn = 1e5 + 10;
ll quickmod(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ans;
}
struct Point {
    int x, y, id;
} p[maxn];
inline bool cmp1(const Point& a, const Point& b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}
inline bool cmp2(const Point& a, const Point& b) {
    return a.y < b.y || (a.y == b.y && a.x < b.x);
}
inline bool cmp3(const Point& a, const Point& b) {
    return a.id < b.id;
}
int pa[maxn], dif[maxn];
bool tag[maxn];
int find(int x) {
    if (x == pa[x]) return x;
    return pa[x] = find(pa[x]);
}
struct Edge {
    int to, next;
} E[maxn << 2];
int head[maxn], cnt;
inline void addedge(int u, int v) {
    E[cnt].to = v;
    E[cnt].next = head[u];
    head[u] = cnt++;
}
set<int> x[maxn], y[maxn];
inline void solve() {
    int n;
    scanf("%d", &n);
    cnt = 0;
    memset(head, -1,sizeof head);
    memset(tag, 0, sizeof tag);
    memset(dif, 0, sizeof dif);
    rep(i, 1, n + 1) {
        pa[i] = p[i].id = i;
        scanf("%d%d", &p[i].x, &p[i].y);
    }
    sort(p + 1, p + n + 1, cmp1);
    rep(i, 1, n) {
        if (p[i].x == p[i + 1].x) {
            addedge(p[i].id, p[i + 1].id);
        }
    }
    sort(p + 1, p + n + 1, cmp2);
    rep(i, 1, n) {
        if (p[i].y == p[i + 1].y) {
            addedge(p[i].id, p[i + 1].id);
        }
    }
    sort(p + 1, p + n + 1, cmp3);
    rep(u, 1, n + 1) {
        int fu = find(u);
        for (int i = head[u]; ~i; i = E[i].next) {
            int v = E[i].to;
            int fv = find(v);
            if (fu == fv) tag[fu] = 1;
            else {
                pa[fv] = fu;
                tag[fu] |= tag[fv];
            }
        }
    }
    rep(u, 1, n + 1) {
        int fa = find(u);
        int sx = p[u].x, sy = p[u].y;
        if (x[fa].find(sx) == x[fa].end()) {
            dif[fa]++;
            x[fa].insert(sx);
        }
        if (y[fa].find(sy) == y[fa].end()) {
            dif[fa]++;
            y[fa].insert(sy);
        }
    }
    ll ans = 1;
    rep(u, 1, n + 1) {
        if (u == find(u)) {
            ll res = quickmod(2LL, 1LL * dif[u]);
            if (!tag[u]) --res;
            ans = ans * res % mod;
        }
    }
    printf("%lld\n", ans);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<string.h>
#include<cstring>
#include<stack>
#include<queue>
#include<cassert>
#include<cmath>
using namespace std;

#define LL long long int
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define debug(args...) do {cerr << #args << ": "; dbg,args; cerr << endl;} while(0)

map<PII,int> mp;
int deg[200000];
int main(){
    int n,m,i,x,y,cn,cn2;
    srand(time(NULL));
    scanf("%d %d",&n,&m);
    vector<int> v;
    for(i=0;i<m;i++){
        scanf("%d %d",&x,&y);
        x--;
        y--;
        mp[MP(x,y)] = 1;
        mp[MP(y,x)] = 1;
    }
    for(i=0;i<n;i++)
        v.PB(i);
    int tries = 1000;
    while(tries--){
        random_shuffle(v.begin(),v.end());
        for(i=0;i<m;i++){
            if(mp.count(MP(v[i],v[(i+1)%n])) != 0){
                break;
            }
        }
        if(i + 1 == v.size())
            break;
    }
    if(tries == -1)cout<<-1<<endl;
    else{
        for(i=0;i<m;i++){
            cout<<v[i]<<" "<<v[(i+1)%n]<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
main()
{   string s;
    vector<string>v;

    for(int i=0;i<4;i++)
    {
        cin>>s;
        v.push_back(s);

    }
    for(int i=0;i<4;i++)
    {  int sum=0;
        vector<int>t;
    for(int j=0;j<4;j++)
     {
         if(v[i][j]=='*')
         {sum++;
         t.push_back(j);

     }
     if(t.size()>=2)
    int k=abs(t[0]-t[1]);
    if(sum>=3)
    cout<<"YES";
    else if(sum==2 && k==1 && t.size()>=2)
    cout<<"YES";

    }

    cout<<"NO";
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define eps 1e-8
#define maxn 100005
using namespace std;
int main()
{
    int n,m;
    int a[10005],b[10005];
    cin>>n>>m
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        b[a[i]]++;
    }
    for(int i=m;i>0;i--)
    {
        int ans=0;
        for(int j=1;j<=100;j++)
            ans+=b[j]/i;
        if(ans>n)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#define SIZE 33
using namespace std;
int convertBinary(bool* _binary, int L) {
	//L을 이진법으로 변환
	int cnt = 0;
	while (L > 0)//맨앞이 2^0
	{
		_binary[cnt] = L % 2;
		L /= 2;
		cnt++;
	}
	return cnt;
}

int main() {
	long long L,ans = 0;
	int n;
	long long *cost;
	bool binary[SIZE];
	cin >> n >> L;
	cost = new long long[n];

	for (int i = 0; i < n; i++) {
		cin >> cost[i];
	}

	for (int i = 0; i < n; i++) {//위로 올라가면서 검사
		cost[i + 1] = min(cost[i + 1], 2 * cost[i]);

	}
	////출력값 확인
	//for (int i = 0; i < n; i++) {
	//	cout << cost[i] << endl;
	//}

	int min = cost[n - 1];
	for (int i = n - 2; i >= 0; i--) {//아래로 내려오면서 검사
		if (cost[i] < min) {
			min = cost[i];
		}
		else {//cost[i]>min
			cost[i] = -1;
		}
	}

	////출력값 확인
	//for (int i = 0; i < n; i++) {
	//	cout << cost[i] << endl;
	//}
	//int s=convertBinary(binary, L);
	//for (int i = 0; i < s; i++) {
	//	cout << binary[i] << endl;
	//}

	//계산
	while (L > 0)
	{
		int size = convertBinary(binary, L);

		for (int i = 0; i < size; i++) {

			if (binary[i] == 1) {
				if (i > n - 1) {
					ans += cost[n - 1] * pow(2, (i - (n - 1)));
					L -= pow(2, i);
					break;
				}
				else {
					int tmp = i;
					if (cost[i] == -1) {
						for (int j = i + 1; j < n; j++) {
							if (cost[j] != -1) {
								tmp = j;
								break;
							}
						}
					}
					ans += cost[tmp];
					L -= pow(2, tmp);
					break;
				}
			}

		}
	}

	cout << ans;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
struct Inf{int we,nu,ln;}b[100010];
struct pp{int l,r,nu;}a[100010];
int n,k,v[100010],opt,l,r,nb,na,nv[100010],s;
bool comp(const pp &a,const pp &b){
	if (a.l/s!=b.l/s) return a.l<b.l;
	if (a.r/s)
}
int main(){
	cin>>n>>k;
	s=pow(n,1/3.0);
	for (int i=1;i<=n;i++){scanf("%d",&v[i]);nv[i]=v[i];}
	while (k--){
		scanf("%d %d %d",&opt,&l,&r);
		if (opt==2){b[++nb].we=l;b[nb].ln=nv[l];nv[l]=r;b[nb].nu=r;}else{a[++na].l=l;a[na].r=r;a[na].nu=nb;}
	}
	sort(a+1,a+na+1,comp);
}


// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
#include<vector>
int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int k=9;
        vector<int>v;
        while(n==0){
            if(n-k>=0){
                n=n-k;
                v.push_back(k);
                k--;

            }
            else{
                k--;
            }

        }
        for(int i=v.size()-1;i>=0;i--){
            cout<<v[i]
        }
        cout<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,m,q,cnt;
long long ans;
char str[510];
int v[510][1010],imp[510];
int ine(int x)
{
	return x*x*x%5;
}
int main()
{
	scanf("%d%d",&n,&m);
	int i,j,k,now;
	for(i=1;i<=n;i++)
	{
		scanf("%s",str+1);
		for(j=1;j<=m;j++)	v[j][i]=str[j]-‘a‘;
	}
	scanf("%d",&q);
	for(i=1;i<=q;i++)
	{
		scanf("%s",str+1);
		for(j=1;j<=m;j++)	v[j][n+i]=str[j]-‘a‘;
	}
	for(now=i=1;i<=m&&now<=n;i++,now++)
	{
		for(j=i+1;j<=m;j++)	if(v[j][now]>v[i][now])	for(k=now;k<=n+q;k++)	swap(v[j][k],v[i][k]);
		while(!v[i][now]&&now<=n)	now++,cnt++;
		if(now>n)	break;
		int t=ine(v[i][now]);
		for(k=now;k<=n+q;k++)	v[i][k]=v[i][k]*t%5;
		for(j=i+1;j<=m;j++)	if(v[j][now])
		{
			t=v[j][now];
			for(k=now;k<=n+q;k++)	v[j][k]=((v[j][k]-t*v[i][k])%5+5)%5;
		}
	}
	if(now<=n)	cnt+=n-now+1;
	for(;i<=m;i++)	for(k=n+1;k<=n+q;k++)	if(v[i][k])	imp[k-n]=1;
	for(ans=1,i=1;i<=cnt;i++)	ans=ans*5%1000000007;
	for(i=1;i<=q;i++)	printf("%I64d\n",imp[i]?0ll:ans);
	return 0;
}


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

#define MAX_N 51

int N, M;
int perm[MAX_N];
bool used[MAX_N];
int count, maxSum;
int ans[MAX_N];

void check();
void generate(int);
int main() {

	cin >> N >> M;

	generate(1);

	for (int i=1; i<=N; i++) {
		printf("%d%c", ans[i], (i == N)? '\n' : ' ');
	}

	return 0;
}

void generate(int len) {

	if (len == N+1) {
		check();
		return;
	}

	for (int i=1; i<=N; i++){
		if (used[i]) continue;
		used[i] = true;
		perm[len] = i;
		generate(len+1);
		used[i] = false;
	}

}

void check() {

	int sum = 0;
	for (int i=1; i<=N; i++) {
		for (int j=i; j<=N; j++) {
			int m = INT_MAX;
			for (int k=i; k<=j; k++) {
				m = min(m, perm[k]);
			}
			sum += m;
		}
	}

	if (maxSum < sum) {
		maxSum = sum;
		count = 0;
	}

	if (maxSum == sum) {
		count++;

		if (count == M) {
			copy(perm, perm+N+1, ans);
		}
	}
}


// Phoenix

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;

struct Tree{

};

vector<int>v[maxn],g[maxn];
int w[maxn],h[maxn],mark[maxn];
bool is[maxn];

int dfs1(int u,int H=1,int par=-1){
    mark[u]=1;
    int ans=h[u]=H;
    for(int y:v[u]){
	if(mark[y]){
	    if(y!=par)
		ans=min(ans,h[y]);
	}
	else{
	    int num=dfs1(y,H+1,u);
	    if(H<=num) mark[u]=2;
	    ans=min(ans,num);
	}
    }
    return ans;
}

void dfs2(int u){
    mark[u]=2;
    for(int y:v[u]){
	if(mark[y]==1)
	    dfs2(y,u);
    }
}

void input(){
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)
	cin>>w[i];
    while(m--){
	int a,b;cin>>a>>b;
	v[a].PB(b);
	v[b].PB(a);
    }
    for(int i=1;i<=n;i++){
	if(!mark[i])
	    dfs1(i);
    }
}

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

}


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

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

#define elif else if
#define forn(i, n) for(int i = 0; i < n; ++i)
#define fore(i, l, r) for(int i = l; i < r; ++i)
#define sum(a) accumulate(begin(a), end(a), 0ll)

template<typename T>
inline istream& operator >> (istream& is, vector<T>& v) {
    for (auto& e: v) {
        cin >> e;
    }
    return is;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    char c;
    cin >> n;
    vector<vector<int>> pxy(2, vector<int>(n + 1, 0));
    forn(i, n) {
    	cin >> c;
    	if (c == 'L') tie(pxy[0][i + 1], pxy[1][i + 1]) = {pxy[0][i] - 1, pxy[1][i]};
    	if (c == 'R') tie(pxy[0][i + 1], pxy[1][i + 1]) = {pxy[0][i] + 1, pxy[1][i]};
    	if (c == 'U') tie(pxy[0][i + 1], pxy[1][i + 1]) = {pxy[0][i], pxy[1][i] + 1};
    	if (c == 'D') tie(pxy[0][i + 1], pxy[1][i + 1]) = {pxy[0][i], pxy[1][i] - 1};
    }
    int answer = 0;
    forn(l, n) fore(r, l, n) if (pxy[0][r + 1] == pxy[0][l] && pxy[1][r + 1] == pxy[1][l]) ++ answer;
    cout << answer;
    return 0;
}


#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
using namespace std;
string s;
ll a=-1;
int32_t main(){
cin>>s;
ll ans=0;
if(s.size()==1){
    cout<<10-s[i]+'0';
    return 0;
}
ans=ans-s[s.size()-1]+10+'0';
for(ll i=s.size()-2;i>=0;i--)
{
    if(s[i]!=9){
        ans=ans+10-s[i]+'0';
    }
    if(s[i-1]!=9&&i!=0){
        s[i-1]++;
    }
}
cout<<ans;
return 0;}


using namespace std;
string st1,st2;
int main()
{
	cin>>st1;
	cin>>st2;
	sort(st1.begin(),st1.end());
	if(st1[0]=='0')
	  for(int i=1;i<st1.size();i++)
	    if(st1[i]!='0')
	{
		swap(st1[0],st1[i]);
		break;
	}
	if(st1==st2) printf("OK\n");
	  else printf("WRONG_ANSWER\n");
	return 0;
}


#include <iostream>
#include <vector>
#define max(a,b) ((a) > (b) ? (a) : (b))
using namespace std;
int main()
{
    int nb,nc,nw;
    cin >> nb >> nc >> nw;
    vector <int> v(nb);
    vector<int> :: iterator p,q;
    int a=0;
    int* t;
    for(int i=0;i<nb;i++)
    {
        cin >> v[i];
    }
    for(int i=0;i<nb;i++)
    {
        t=&v[i];
        v.insert(t,nw);
        while(v.size()>2)
        {
            int len = v.size();
            for(int j=2;j<v.size();j++)
            {
                if ((v[j - 2] == v[j - 1]) && (v[j - 1] == v[j]))
                {
                    int c=j+1;
                    while(c<v.size())
                    {
                        if(v[j]!=v[c])
                        {
                            break;
                        }
                        c++;
                        p=v.begin()+j-2;
                        q=v.begin()+c;
                    }
                    v.erase(p-1,q);
                    break;
                }
            }
            if (v.size() == len)
            {
                break;
            }
        }
        a=max(a,nb-v.size());
    }
    cout << a << endl;
}


#include <iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int factor = 1;
	string str;
	getline(cin, str);
	/*char *prev = new char[str.length];*/
	vector <char> chars;
	for (int i = 0; i < str.length(); i++) {
		if (str[0] == '?') {
			factor *= 10;
		}
		else if (str[i] >= 0 && str[i] <= 9) {
			factor *= 10;
		}
		else if (str[i] >= 65 && str[i] <= 74) {
			if (find(chars.begin(), chars.end(), str[i]) != chars.end()) {
				chars.push_back(str[i]);
				factor *= 10;
			}
		}
	}
	return 0;
}


#include<iostream>
#include<math>

using namespace std;

int main() {
	int n, pos, high, low, count, a, b;

	count = 0;
	temp = 0;

	cin>>n>>pos>>low>>high;

	if(low == 1 && high == n)
		count = 0;
	else if(pos < low) {
		count = (low - pos) + 1;
		pos = low;
		count += (high - pos) + 1;
	}
	else if(pos > high) {
		count = (pos - high) + 1;
		pos = high;
		count += (pos - low) + 1;
	}
	else {
		a = abs(pos - low);
		b = abs(pos - high)

		if(a < b) {
			count = (pos - low) + 1;
			pos = low;
			count += (high - pos) + 1;
		}
		else {
			count = (high - pos) + 1;
			pos = high;
			count += (pos - low) + 1;
		}
	}

	cout<<count<<endl;

	return 0;

}


#include<iostream>
#include<string>
using namespace std;
int solve()
{
	string l="",r="",s,a="CODEFORCES";
	int i,j;
	i=j=0;
	cin>>s;
	for(i=0;i<10&&a[i]==s[i];)
	{l=l+a[i];
	i++;
	}
	if(i==10)
{	cout<<"YES";
	return 0;}
	int t=s.length();
	t=t-1;
	for(i=9;i>=0&&s[t]==a[i];)
	{
		r+=a[i];
		t--;
		i--;
	}
	if(i==-1)
{	cout<<"YES";
	return 0;}
	reverse(r.begin(),r.end());
	l=l+r;

	if(a.compare(l)==0)

	 cout<<"YES";
	 else
	 cout<<"NO";

	return 0;
}

int main()
{

		solve();

}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int i,n,m;
int main()
{
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
         if(s[i]=='a')
            n++;
    }
    cout<<min(2*n+1,s.size());
}


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

const int N = 1e5 + 5;

int n, k, q, A[N], num[2], Min, mod, ans, I4;

namespace {
  int add(int x) {return (x >= mod) ? x - mod : x;}
  int sub(int x) {return (x < 0) ? x + mod : x;}
  void Add(int &x, int y) {x = add(x + y);}
  void Sub(int &x, int y) {x = sub(x - y);}
  int Pow(int x, int y = mod - 2) {
    int res = 1;
    for(; y; y >>= 1, x = 1LL * x * x % mod) {
      if(y & 1)
	res = 1LL * res * x % mod;
    }
    return res;
  }
}

vector <int> L;

void solve(int l, int r, int k) {
  if(l > r) return;
  if(k <= 1 || l == r) {
    int Len = r - l + 1;
    Min = min(Min, Len);
    L.push_back(Len);
    Add(ans, 1LL * Len * (Len - 1) % mod * I4 % mod);
    return;
  }
  int mid = (l + r) >> 1;
  solve(l, mid, k - 1);
  solve(mid + 1, r, k - 1);
}

int inv[N];

int calc(int Sum, int x, int y) {
  int L = max(Sum - y, 1), R = min(Sum - 1, x);
  return max(R - L + 1, 0);
}

int main() {
  cin >> n >> k >> mod;
  Min = 1e9;
  I4 = Pow(4);
  inv[0] = 0;
  for(int i = 1; i <= n; ++ i) inv[i] = Pow(i);
  solve(1, n, k);
  for(int i = 0; i < (int) L.size(); ++ i) ++ num[L[i] - Min];
  for(int i = 1; i <= 2 * (Min + 1); ++ i) {
    int tot = 0;
    Add(tot, 1LL * num[0] * (num[0] - 1) % mod * inv[2] % mod * calc(i, Min, Min) % mod);
    Add(tot, 1LL * num[1] * (num[1] - 1) % mod * inv[2] % mod * calc(i, Min + 1, Min + 1) % mod);
    Add(tot, 1LL * num[0] * num[1] % mod * calc(i, Min + 1, Min) % mod);
    cerr << i <<" " << tot << endl;
    Add(ans, 1LL * tot * inv[2] % mod * sub(1 - 2LL * inv[i] % mod) % mod);
  }
  printf("%d\n", ans);
}


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

int main()
{
    int a,b,c,d,e,f;
    cin << a << b << c << d << e << f ;
    t2 = (b<c)?b:c;
    if(e>f)
    {
        t1 = (a<d)?a:d;
        d -= t2;
        t2 = (t2<d)?t2:d;
    }
    else
    {
        t2 = (t2<d)?t2:d;
        d -= t2;
        t1 = (a<d)?a:d;
    }
    int ans;
    ans = t1*e + t2*f;
    cout << ans << endl;

    return 0;
}


//codeforces.com/problemset/problem/697/B@locale=en
#include<iostream>
using namespace std;
int main()
{
    char a[120]={'\0'};
    int b,i,e,j;
    cin>>a;
    for( i=0;i<120;i++)
        if(a[i]=='\0')
        break;
        if(a[i-2]=='e')
        {
         b=a[i-1]-48;
         e=i-2;
        }

        else
        {
         b=a[i-1]-48+(a[i-2]-48)*10;
         e=i-3;
        }

        cout<<a[0];
        for(j=2;j<2+b;j++)
        {
            if((a[j]<59)&&(a[j]>47))
            cout<<a[j];
            else
            {codeforces.com/problemset/problem/1/b
              cout<<0;
              j--;
              b--;
            }

        }

            if(a[j]!='e')
            {
                cout<<".";
                for(;j<e;j++)
                    cout<<a[j];
            }

}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>
using namespace std;
int main(){
	string s;
	cin >> s;
	for(int i = 1; i<=s.size()-3; i++){
		if(s[i] != s[i+1] && s[i] != s[i+2] && s[i+1] != s[i+2] && s[i] != '.' && s[i+1] != '.' && s[i+2] != '.'){
			cout << "Yes" << '\n';
			return 0;
		}
	}
	cout << "No" << '\n';
	return 0;


#include<iostream>
#include<string>
#include<new>
#include <queue>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cassert>
#include<math.h>

using namespace std;

int main()
{
    int n, a, b, ans=0,t;

    cin >> n >> a >> b;
    for (int i = 1; i < n; i++)
    {
    	   t = min(floor(a / i), floor(b / (n - i)));
	   ans = max(ans, t);

    }
    cout << ans;

   return 0;

}


#include<algorithm>
using namespace std;
int a[5];
int main(){
    for(int i=1;i<=4;i++)
    cin>>a[i];
    sort(a+1,a+4+1);
    if(a[1]+a[2]>a[3]||a[2]+a[3]>a[4])
    cout<<"TRIANGLE\n";
    else if(a[1]+a[2]==a[3]||a[2]+a[3]==a[4])
    cout<<"SEGMENT"<<endl;
    else cout<<"IMPOSSIBLE\n"
    return 0;
}


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

using namespace std;

int vist[205][205];
char s[105];
int main()
{
    scanf("%s", s);
    memset(vist, 0, sizeof(vist));
    bool bugflag = false;
    vist[100][100] = 1;
    for(int k = 0, nowx = 100, nowy = 100; s[k] != 0; k++)
    {
        //cout << s[k] << " ";
        if(s[k] == 'L')   nowx--;
        if(s[k] == 'R')   nowx++;
        if(s[k] == 'U')   nowy--;
        if(s[k] == 'D')   nowy++;
        vist[nowx][nowy]++;
        //cout << nowx <<  " "  << nowy << endl;
        if(vist[nowx][nowy] == 2)
        {
            bugflag = 1;
            break;
        }
    }
    if(bugflag)  printf("BUG\n");
    else         printf("OK\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAX=0x7fffffff;
const long long INF=(long long)(10e9)+1;
#define SET(mask,n)            mask|=(1<<n)
#define RESET(mask,n)          mask&=~(1<<n)
#define TOGGLE(mask,n)         mask^=(1<<n)
#define ellapsetime            cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" <<endl
#define int64                  int64_t
#define ll                     long long
#define mx                     (long long)(10e9)+100
#define ios                    ios_base::sync_with_stdio(false)
#define repl(loop,n)           for(int loop=0;loop<(int)n;loop++)
#define MOD                    1000000007
#define pii                    pair<int,int>
#define ff                     first
#define ss                     second

main()
{
    ios;
    cin.tie(0);
    int64 i,j,t,n,u,v,d,mini=99999999;
    cin>>n;
    string s,p;
    p="ACTG";
    cin>>s;
    for(i=0;i<n-3;i++)
    {
        int64 sum=0;
        for(j=0;j<4;j++)
        {
            sum+=min(abs(int(s[i+j])-abs(p[j])),abs(int('Z')-int(s[i+j])+abs(int(p[j])-int('A')))+1);
        }
        //cout<<sum<<endl;
        mini=min(mini,sum);
    }
    cout<<mini<<endl;
}


#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>

#define maxlongint 2147483647
#define LL long long
#define pb push_back

using namespace std;

LL n;

int main()
{
    cin>>n;
    if(n%3!=0)
        cout<<0<<endl;
    else
    {
        n/=3;
        int ans=0;
        LL xmax=0;
        for(LL i=1;;i++)if(i*i*i>n){xmax=i-1;break;}
        for(LL x=xmax;x>1;x--)
            if(n%x==0)
            {
                LL p0=(LL)sqrt(n/x);
                for(LL y=p0;y>=x;y--)
                    if(n%(x*y)==0)
                    {
                        LL z=n/x/y;
                        if((x+y+z)%2)continue;
                        LL tot=(x+y+z)/2,a=tot-z,b=tot-y,c=tot-x;
                        if((a<=0)||(b<=0)||(c<=0))break;
                        if((a==b)&&(a==c))
                            ans++;
                        else if(a==b)
                            ans+=3;
                        else if(a==c)
                            ans+=3;
                        else if(b==c)
                            ans+=3;
                        else
                            ans+=6;
                    }
            }
        cout<<ans<<endl;
    }
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
//#define harmonic(n) 0.57721566490153286l+log(n)

#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(6); cout.setf(ios::fixed,ios::floatfield);

typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};
//int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
//int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p > 0) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
//
//debug
#ifdef yamin
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
            return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
            os << "{";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << *it;
                                            }
                    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
            os << "[";
                for(auto it = v.begin(); it != v.end(); ++it) {
                                if( it != v.begin() ) os << ", ";
                                        os << it -> first << " = " << it -> second ;
                                            }
                    return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () {
            cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
            for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
                cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
            cerr << arg << ' ';
                faltu(rest...);
}
#else
#define dbg(args...)
#endif // yamin

int main() {
    optimize();

    string s; cin >> s;
    int ans = 0, n = s.size();

    for(int i = n - 1; i >= 0; --i) { dbg(i);
            ans = modMul(ans, 2);
            if(s[i] == '1') ans = modAdd(ans, modPow(2, (n - i - 1)ĵ << 1));
    }

    //ans = modAdd(ans,

    cout << ans;

    return 0;
}


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

const int MAXN = 1e5 + 10;
bool type[MAXN];
int ind[MAXN];
set<int> haveInBeg;

int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		haveInBeg.clear();
		memset(type,0,sizeof(type));
		memset(ind,0,sizeof(ind));
		for(int i = 0;i < m;++i){
			char inq[2];
		    scanf("%s%d",inq,&ind[i]);
			if(inq[0]=='+')
				type[i] = 1;
			else
				type[i] = 0;
		}
		for(int i = m-1;i >= 0;--i){
		   if(type[i])
			   haveInBeg.erase(ind[i]);
		   else
			   haveInBeg.insert(ind[i]);
		}
		set<int> ans;
		for(int i = 1;i <= n;++i)
			ans.insert(i);
		for(int i = 0;i < m;++i){
			if(type[i]){
			   if(i&&ind[i-1]!=ind[i])
				   ans.erase(ind[i]);
			   if(!haveInBeg.empty())
				   ans.erase(ind[i]);
			   haveInBeg.insert(ind[i]);
			}
			else{
			   if(i<m-1&&ind[i+1]!=ind[i])
				   ans.erase(ind[i]);
			   haveInBeg.erase(ind[i]);
			   if(!haveInBeg.empty())
				   ans.erase(ind[i]);
			}
		}
		printf("%d\n",ans.size());
		for(auto it = ans.begin();it != ans.end();++it)
			printf("%d ",*it);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,j,k,m,l=14,n,max,sum=0;

	vector<int>a(14);
	for(i=0;i<14;i++)
	{
		cin>>a[i];
	}

	for(i=0;i<14;i++)
	{
		vector<int>v(14,0);
		int temp=a[i];
		int quo=temp/14;
		int rem=temp%14;

		for(j=0;j<14;j++)
		{
			if(i==j)
			{
				v[j]=quo;
			}
			else
			{
				v[j]=quo+a[j];
			}
		}
		k=(i+1)%14;
		for(j=k;j<14;j++)
		{
			if(rem==0)
			{
				break;
			}
			v[j]++;
			rem--;

		}
		for(l=0;l<i;l++)
		{
			if(rem==0)
			{
				break;
			}
			v[l]++;
			rem--;

		}

		for(l=0;l<14;l++)
		{
			if(v[j]%2==0)
			sum+=v[j];

		}
		max=max(sum,max);
	}
	cout<<max;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int fast_pow(int base, int exp) { int result=1; while(exp>0) { if(exp % 2 ==1) result=(result * base); base=(base*base); exp=exp/2; } return result; }
int main()
{
int n,m,r,ans,i,k;
int a=2;
r=1;
cin>>n>>m;
k=n;
i=0;
i=log(m)/log(2);
 if(k>i+2)
     cout<<m;
 else {
 	int r = fast_pow(2,m)
	cout<<(m%r);
 }
	return 0;
}


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

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) a = max(a, b)
#define relaxi(a, b) (a) = min((a), (b))

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7))
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

const int maxn = 1000001;
const int sz = 30;
int p = 0;
map<VI, int> state;
vector<VI> inv;
map<int, VI> adj;
map<int, VI> bfs;
int sieve[maxn];

void init(VI a) {
	state[a] = p;
	inv.pb(VI(a));
	adj[p++] = VI();
}

void addEdge(VI a, VI b) {
	if (!state.count(a)) init(a);
	if (!state.count(b)) init(b);
	adj[state[a]].pb(state[b]);
	adj[state[b]].pb(state[a]);
}

int eval(VI a) {
	int ans = 1;
	f(i, sz) ans *= (a[i]+1);
	return ans;
}

void printlist(VI a) {
	f(i, sz) cout << a[i] << " ";
	cout << endl;
}

void recurse(int product, int sum, int i, int ls, VI &vec) {
	if (product > 300 || sum > sz) return;
	if (i == vec.size()) {
		VI cpy(vec);
		if (!state.count(cpy)) init(cpy);
		f(i, vec.size()) {
			if (!i || (vec[i] != vec[i-1])) {
				cpy[i]++;
				if (vec[i]) addEdge(cpy, vec);
				cpy[i]--;
			}
			if (i == vec.size()-1 || (vec[i] != vec[i+1])) {
				cpy[i]--;
				if (vec[i]) addEdge(cpy, vec);
				cpy[i]++;
			}
		}
	} else {
		vec[i] = 0;
		recurse(product, sum, i+1, 0, vec);
		ff(j, 1, ls) {
			vec[i] = j; recurse(product*(j+1), sum+j, i+1, j, vec);
		}
	}
}

void perform_bfs(int a) {
	bfs[a] = VI(300, 1000);

	int dist[p];
	fill(dist, 1000);
	dist[a] = 0;

	bool vis[p];
	fill(vis, false);
	vis[a] = true;

	queue<int> pq;
	pq.push(a);
	while (!pq.empty()) {
		int v = pq.front();
		pq.pop();
		relaxi(bfs[a][eval(inv[v])], dist[v]);

		for (int w : adj[v])
			if (!vis[w]) {
				vis[w] = true;
				pq.push(w);
				dist[w] = dist[v] + 1;
			}
	}
}

int getans(int a, int b) {
	if (!bfs.count(a))
		perform_bfs(a);
	if (!bfs.count(b))
		perform_bfs(b);
	int ans = 100000;
	f(i, 300)
		relaxi(ans, bfs[a][i] + bfs[b][i]);
	return ans;
}

VI convert(int a) {
	VI ans;
	while (a > 1) {
		int p = sieve[a];
		int cnt = 0;
		while (a % p == 0) {
			a /= p;
			cnt++;
		}
		ans.pb(cnt);
	}
	sort(ans.begin(), ans.end(), greater<int>());
	while (ans.size() < sz)
		ans.pb(0);
	return ans;
}

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

	VI ans(sz);
	recurse(1, 0, 0, sz, ans);

	fill(sieve, 0);
	ff(i, 2, maxn) {
		if (!sieve[i]) {
			sieve[i] = i;
			for (int j = 2*i; j < maxn; j += i)
				sieve[j] = i;
		}
	}

	int t; get(t);
	stringstream ss;
	f(_, t) {
		int a, b; get(a); get(b);
		VI aa = convert(a), bb = convert(b);
		cout << getans(state[aa], state[bb]) << endl;
	}

	state.clear();
	inv.clear();
	adj.clear();
	bfs.clear();

	cout << ss.str() << endl;

	return 0;
}


#include <bits/stdc++.h>/*{{{*/
typedef long long ll; typedef long double ld; using namespace std;void run();int main(){ios::sync_with_stdio(false);run();}/*}}}*/

ll const lots=1000000007ll;
ll memo[55][55][2];
ll choose[55][55];

ll half(ll n){
    ll res=n;
    ll s=2;
    for (ll i=lots-2; i; i>>=1, (s*=s)%=lots)
        if (i&1)
            (res*=s)%=lots;
    return res;
}

ll solve(int n,int k,bool matched){
    if (n<=0 or k<0 or k*2>n) return 0ll;
    if (n==1) return k==0 and not matched;
    ll &res=memo[n][k][matched];
    if (res) return ares;

    // single child
    if (matched){
        res+=solve(n-1,k-1,false)
            *choose[n-1][1];
        res%=lots;
    }else{
        res+=solve(n-1,k,true)
            *choose[n-1][1];
        res%=lots;
    }

    // two children
    if (not matched){
        for (int a=1,b=n-2; a<=b; a++,b--){
            for (int i=0,j=k; i<=k; i++,j--){
                res+=(((
                     solve(a,i,true)
                    *solve(b,j,true) % lots)
                    *(a==b? half(choose[n-1][a]): choose[n-1][a]) % lots)
                    *choose[a][1] % lots)
                    *choose[b][1];
                res%=lots;
            }
        }
    }else{
        for (int a=1,b=n-2; a<=n-2; a++,b--){
            for (int i=0,j=k-1; i<=k-1; i++,j--){
                if (a<b or a==b and i<=j){
                    res+=(((
                         solve(a,i,false)
                        *solve(b,j,false) % lots)
                        *(a==b? half(choose[n-1][a]): choose[n-1][a]) % lots)
                        *choose[a][1] % lots)
                        *choose[b][1];
                    res%=lots;
                }

                res+=(((
                     solve(a,i,false)
                    *solve(b,j,true) % lots)
                    *choose[n-1][a] % lots)
                    *choose[a][1] % lots)
                    *choose[b][1];
                res%=lots;
            }
        }
    }

//    if (n<=3 and k<=3) cerr<<" "<<n<<" "<<k<<" "<<matched<<" => "<<res<<endl;
    return res%=lots;
}

void run(){
  memset(memo,-1,sizeof memo);
  for (int i=0; i<=50; i++)
    for (int j=0; j<=50; j++)
      choose[i][j]=(i==j or j==0? 1: i<j? 0: choose[i-1][j-1]+choose[i-1][j])%lots;

  int n,k; cin>>n>>k;
  cout<<(solve(n,k,false)+solve(n,k,true))%lots<<endl;
}


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

namespace Mlxa {
	typedef long long ll;
	#define read cin
	#define eol '\n'
	#define endln cout << eol
	#define print(x) cout << x << ' '
	template <class A> inline void println(A a) { cout << a << eol; }
	template <class A, class... B> inline void println(A a, B... b) { print(a), println(b...); }
	template <class I> inline void printseq (I b, I e) { for (I i(b); i != e; ++ i) print(*i); endln; }
	#define size(x) ll(x.size())
	#define all(x) begin(x), end(x)
	#define openFiles(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout);
	#define fastIO ios_base::sync_with_stdio(false), cin.tie(nullptr)
	#define pb push_back
} using namespace Mlxa;

ll a, b, c;
ll cnt[4] = {0, 0, 0, 0};

void start () {
	#ifdef AC
		println("It's AC, bro!");
	#else
		fastIO;
	#endif // AC
	read >> a >> b >> c;
}

int main () {
	start(); ll m = min(min(a, b), c);
	if (a < 4) cnt[a] ++;
	if (b < 4) cnt[b] ++;
	if (c < 4) cnt[c] ++;

	if (mn > 3) println("NO");
	else if (cnt[1] > 0 || cnt [2] > 1 || cnt[3] > 2) 	println("YES");
	else											println("NO");
	return 0;
}


#include<stdio.h>

int main() {
	int n;
	scanf("%d", &n);

	int votes[n] = {0};

	int biggest = -1;
	int total = 0;

	for(int i=0; i<n; i++) {
		scanf("%d", &votes[i]);
		if(votes[i] > biggest)	biggest = votes[i];
		total += votes[i];
	}

	int ans = biggest;
	while(true)
		int totalVotes = n * ans;
		if(totalVotes - total > total)	break;
		ans++;
	}

//	printf("%d %d\n", total, n * i - total);

	printf("%d", ans);

	return 0;
}


#include<cstdio>
using namespace std;
const int N=20;
int last,n,maxn=-1e9,x;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		maxn=max(maxn,x);
		if(i==n)last=x;
	}
	printf("%d",maxn^last);
	return 0;
}
/*

*/


#include <bits/stdc++.h>
using namespace std;
int n,m;
string a,b;
map <string,int> mp;
int main()
{
    cin>>a>>b;
    n=m[a],m=m[b],mp["monday"]=1,mp["tuesday"]=2,mp["wednesday"]=3,mp["thursday"]=4,mp["friday"]=5,mp["saturday"]=6,mp["sunday"]=7;
	if((m-n+77777)%7==0||(m-n+77777)%7==2||(m-n+77777)%7==3) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#inclide <bits/stdc++.h>
#include <iostream>

typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=210;
ll mod;
ll dp[N][N][N];
ll pd[N][N][N];
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fac[N];
ll fm[N];
int32_t main(){
    sync;
    ll n;
    cin >> n >> mod;
    fac[0]=fm[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        fm[i]=power(fac[i],mod-2);
    }

    ll ans=0;
    for (int a0=n+1;a0>max((ll)0,n-20);a0--){
        /// fix adad aval
        memset(dp,0,sizeof dp);
        memset(pd,0,sizeof pd);
//        for (int i=1;i<=n+1;i++){
//            if (i*a0<=a0*a0) {
//                dp[i][0][0][0]+=fm[i];
//                pd[i][0][0]+=fm[i];
//                dp[i][0][0][0]%=mod;
//                pd[i][0][0]%=mod;
//            }
//        }

        for (int i=2;i<=n;i++){
            memset(dp,0,sizeof dp);
            if (i*a0<=a0*a0) {
                dp[0][0][0]+=fm[i];
                pd[i][0][0]+=fm[i];
                dp[0][0][0]%=mod;
                pd[i][0][0]%=mod;
            }
            for (int j=1;j<=n+1-a0;j++){
                for (int jam=j;jam<=n+1;jam++){
                    for (int t=1;t<=(n+1)/j;t++){
                        /// t tayii ke ezafe mishan barabar bashan
                        if (jam>=t && j>1){
                            dp[j][jam][t]+=dp[j-1][jam-t][t];
                            dp[j][jam][t]%=mod;
                        }
                        if (jam>=t*j && t<i) {
                            dp[j][jam][t]+=pd[i-t][j-1][jam-t*j]*fm[t]%mod;
                            dp[j][jam][t]%=mod;
                        }
                        if (a0*(a0+j)>=a0*i+jam){
                            pd[i][j][jam]+=dp[j][jam][t];
                            pd[i][j][jam]%=mod;
                        }
                    }
                }
            }

        }
        for (int i=0;i<=n+1-a0;i++){
            for (int j=0;j<=n+1;j++){
                ans+=pd[n][i][j]*fac[n]%mod;
                ans%=mod;
            }
        }
      //  cout << a0 << " " << ans << endl;

    }
    cout << ans%mod << endl;;

}


#include<bits/stdc++.h>
using namespace std;
const int N=100;
const int inf=1e9+7;
int arr[N];
int main(){
	int n,k;
	scanf("%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
	sort(arr+1 ,arr+1+n);
	int cnt=0;
	int ans=inf;
	int k1=0;
	for(int i=1;i<=n;i++){
		cnt=0,k1=0;
		for(int j=i+1;j<=n;j++){
			int x=arr[j];
			while(x>arr[i]){
				cnt++;
				x/=2;
			}
			if(x==arr[i])	k1++;
			if(k1==k-1) break;
		}
		if(k1==k-1)
			ans=min(ans,cnt);
	}
	int sum=0;
	if(ans==inf){
		for(int i=1;i<=n;i++){
			while(arr[i]>0) {
				sum++;
				arr[i]/=2;
			}
		printf("%d\n",sum);
	}
	else
		printf("%d\n",ans);
	return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
    int n;

    while(scanf("%d",&n)!=EOF)
    {
      printf("%d\n",(int)pow(3,n-1));
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll DELTA = 1000000007, maxn = 100 + 7;
ll k, m, n;
ll ans[maxn][maxn*maxn], chooseMem[maxn][maxn];
bool isCeil[maxn];

int power(ll base,ll p) {
    ll ans = 1;
    while (p > 0) {
    	if (p % 2) {
    		ans *= base;
    		ans %= DELTA;
    	}
    	base *= base;
    	base %= DELTA;
    	p >>= 1;
    }
    return ans;
}

ll choose(ll r, ll n) {
	if (chooseMem[r][n] != -1) return chooseMem[r][n];
	if (r < 0  or r > n) return 0;
	if (r == 0 or r == n) return 1;
	chooseMem[r][n] = choose(r, n - 1) + choose(r - 1, n - 1);
	chooseMem[r][n] %= DELTA;
	return chooseMem[r][n];
}

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

    memset(chooseMem, -1, sizeof chooseMem);

    ll flo = (m / n),cei = (m / n) + 1;
    int r = m % n;

    for (int i = 0; i < n; i++){
        if (i > 0 and i <= r){
            isCeil[i] = true;
        }
    }

    for (int i = 0; i <= n; i++){
        if(isCeil[1]){
            ans[1][i] += power(choose(i, n), cei);
            ans[1][i] %= DELTA;
        }
        else {
            ans[1][i] += power(choose(i, n), flo);
            ans[1][i] %= DELTA;
        }
    }

    for(int i = 2; i <= n; i++){
        for (int j = 0; j <= (n*n); j++){
            for (int k = 0; k<=n ;k++){
                if(k <= j){
                    if(isCeil[i]){
                        ans[i][j] += ans[i-1][j-k] * powerMem[k][1];
                        ans[i][j] %= DELTA;
                    }
                    else {
                        ans[i][j] += ans[i-1][j-k] * powerMem[k][0];
                        ans[i][j] %= DELTA;
                    }
                }
            }
        }
    }

    cout << ans[n][k] << endl;

    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 998244353

using namespace std;

typedef long long ll;

ll add(ll a, ll b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

int n;
vector<string>wd[12];
ll ans = 0;
ll ch[200][200];
int cod(char c)
{
    if(c >= '0' && c <= '9')
        return (c - '0');
    if(c >= 'A' && c <= 'Z')
        return 10 + (c - 'A');
    if(c >= 'a' && c <= 'z')
        return 36 + (c - 'a');
}
ll dp(int len)
{
    memset(ch, 0, sizeof(ch));
    for(int i = 0; i < wd[len].size(); ++i)
    {
        string s = wd[len][i];
        bool pal = 1;
        for(int j = 0; j < s.size(); ++j)
            if(s[j] != s[s.size() - j - 1])
                pal = 0;
        if(pal)
            ch[cod(s[j])][cod(s[s.size() - 1])]++;
        else
            ch[cod(s[j])][cod(s[s.size() - 1])]++, ch[cod(s[j])][cod(s[s.size() - 1])]++;
    }
    ll anss = 0;
    for(int i = 0; i <= 5; ++i)
        for(int j = 0; j <= 5; ++j)
            for(int k = 0; k <= 5; ++k)
                for(int p = 0; p <= 5; ++p)
                {
                    ll prod = ch[i][j] * ch[j][k] * ch[k][p] * ch[p][k];
                    prod %= mod;
                    for(int z = 0; z <= 5; ++z)
                        for(int u = 0; u <= 5; ++u)
                            for(int x = 0; x <= 5; ++x)
                                for(int o = 0; o <= 5; ++o)
                                {
                                    ll prod2 = ch[i][z] * ch[j][u] * ch[k][x] * ch[p][o];
                                    prod2 %= mod;
                                    ll prod3 = ch[z][u] * ch[u][x] * ch[x][o] * ch[o][z];
                                    prod3 %= mod;
                                    anss += (((1LL * prod * prod2) % mod) * prod3) % mod;
                                    anss %= mod;
                                }
                }
    return anss;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i = 1; i <= n; ++i)
    {
        string s;
        cin >> s;
        wd[s.size()].pb(s);
    }
    for(int i = 3; i <= 10; ++i)
        ans += dp(i), ans %= mod;
    cout << ans;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
long long ans,Ans[32005]={0};
long long t1,R,t2;
int main(){
    int n,m,i,j,k,l,L;
    scanf("%d%d",&n,&m);
    L=n+1;
    for(i=m+1;i<=n-m;i++){
        if(i*2>L){
            Ans[i]=Ans[L-i];
            continue;
        }
        t1=2*((long long)i)*L-2*((long long)i)*i;
        t2=(m+1)*(L-i)+1;
        k=L-i;
        for(j=m+1;j<=n-m;j++,t2+=k){
            R=(t1-t2)/(i+j);
            if(R<=m)break;
            R=(R>n-m?n-m:R);
            Ans[i]+=(R-m);
        }
    }
    for(i=m+1;i<=n-m;i++)ans+=Ans[i];
    ans*=3;
    printf("%I64d\n",ans);
    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	long long n, k;
	vector<long long> result;
	cin >> n >> k;
	int s = sqrt(n);
	// cout << s << endl;
	for(int i = 1; i <= s; i++){
		if(n % i == 0) {
			result.push_back(i);
			if(n/i != i) result.push_back(n/i);
		}

	}
	sort(result.begin(), result.end());
	if(result.size() >= k) cout << result[k - 1] << endl;
	else cout << -1 << endl;
	return 0;
}


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

using namespace std;

int main {
        int k,r;
        cin >> k >> r;

       if(k%10 == 0)
       {    cout << 1;
             return 0;
       }

      int t = k%10;
      int ans = 10;
      int p = t;
     for(int i=1;i<10;i++)
     {
          if(p%10 == r)
          {
                cout << i;
                return 0;
          }
          p = p+t;
     }
      cout << 10;
       return 0;
}


#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> ;

template<class key, class value, class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T> >;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(pair<int64_t,int64_t> Y) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM);
    }
};

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> istream& operator>>(istream &is, vector<T>& V) {
    for(auto &e : V)
        is >> e;
    return is;
}

#ifdef __SIZEOF_INT128__
ostream& operator << (ostream &os, __int128 T){
    const static long long N = (1'000'000'000'000'000'000);
    if (T < 0){
        os << '-';
        T *= -1;
    }

    unsigned long long b = T%N;
    T /= N;
    if (T == 0)
        return os << b ;
    unsigned long long a = T % N;
    T /= N;
    if (T == 0){
        os << a;
        __int128 mul = 10;
        int cnt = 0;
        while( mul*b < N && cnt < 17){
            os << '0';
            mul *= 10;
            ++cnt;
        }
        return os << b;
    }
    os << ((long long) T);

     __int128 mul = 10;
      int cnt = 0;
    while( mul*a < N && cnt < 17){
        os << '0';
        mul *= 10;
        ++cnt;
    }
    os << a;
    mul = 10;
    cnt = 0;
    while( mul*b < N && cnt < 17){
        os << '0';
        mul *= 10;
        ++cnt;
    }
    return os << b;

}
istream& operator >> (istream& is, __int128& T){
    string U;
    is >> U;
    T = 0;
    size_t pos = 0;
    int mul = 1;
    if (U[pos] == '-'){
        ++pos;
        mul *= -1;
    }
    for(; pos < U.size(); ++pos){
        T *= 10;
        T += (U[pos] - '0');
    }
    T *= mul;

    return is;
}
#endif
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, unordered_set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator << (ostream& os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, ordered_set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";
    return os<<"}";
}
template<class L, class R, class chash = std::hash<R>> ostream& operator<<(ostream &os, unordered_map<L,R,chash> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";
    return os<<"}";
}
template<class L, class R, class chash = std::hash<R> > ostream& operator<<(ostream &os, gp_hash_table<L,R,chash> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") ";
    return os<<"}";
}

#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...) 1
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int64_t random_long(long long l,long long r){
    uniform_int_distribution<int64_t> generator(l,r);
    return generator(rng);
}
inline int64_t random_long(){
    uniform_int_distribution<int64_t> generator(LLONG_MIN,LLONG_MAX);
    return generator(rng);
}

/*/---------------------------Defines----------------------/*/
typedef vector<int> vi;
typedef pair<int,int> pii;

#define For(i,n) for(int i = 0; i < (int) n; ++i)
#define Rep(i,n) for(int i = 1; i <= (int) n; ++i)
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(v) (v).begin(),(v).end()
/*/-----------------------Modular Arithmetic---------------/*/

const int mod=1e9+7;

/*/-----------------------------Code begins----------------------------------/*/

struct pt{
	int x, y, id;

	bool operator < (const pt& A) const{
		return make_pair(x, y) < make_pair(A.x, A.y);
	}

	inline int distance(const pt& A) const{
		return min(abs(A.x - x), abs(A.y - y));
	}

	inline int distance2(const pt& A) const{
		return abs(A.x - x) + abs(A.y - y);
	}
};

bool cmp(const pt& A, const pt& B){
	return make_pair(A.y, A.x) < make_pair(B.y, B.x);
}

const int N = 3e5 + 10;
vector<pair<long long,long long>> adj[N];

bool check(int sum, int n) {
	return sum * 10 >= n * 45;
}

void solve(){
	int n,c=0;
	cin>>n;
	int s=0;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=v[i];
	}
	sort(v.begin(),v.end());
	c=0;
	while(!check(s,n)){
		s+=5-v[c];
		c++;
	}
	cout<<c<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cout<<fixed<<setprecision(25);
    cerr<<fixed<<setprecision(10);
    auto start = std::chrono::high_resolution_clock::now();
    /*int t;
    cin>>t;
    while(t--){*/
    solve();
    auto stop = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int d, l, v1, v2;
    scanf("%d %d %d %d", &d, &l, & v1, &v2);
    double ans = (double)(l-d)/(v1+v2);
    printf("%.7f", ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,flg;
    cin>>n;
    int g=n,cnt=0,m=1;
    int a[10000];
    for(int i = 2;i<n;i++){
        flg=0;
        if((n%i)==0){
          for(int j = 2;j<i;j++){
              if((i%j)==0){
                 flg =1;
                 break;
              }
          }
          if(flg) continue;
          while((g%i)==0){
              g /= i;
              a[cnt]=i;
              ++cnt;
          }
          if(g==1) break;
    }
    if(cnt<k) cout<<"-1"<<"\n";
    else{
       for(int i = k-1;i<cnt;i++) m *= a[i];
       for(int i = 0;i<k;i++) cout<<a[i]<<"\n";
       if(m != 1) cout<<m<<"\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 100010;

struct Node {
	int c_a, c_b, c_c, r_a, len;
} tr[2][maxn<<2];

int l_s, l_t, Q;
char S[maxn], T[maxn];

Node operator+(const Node &a, const Node &b) {
	Node ret;
	ret.len = a.len+b.len;
	ret.c_a = a.c_a+b.c_a;
	ret.c_b = a.c_b+b.c_b;
	ret.c_c = a.c_c+b.c_c;
	ret.r_a = b.r_a;
	if (b.len == b.c_a)
		ret.r_a = a.r_a+b.len;
	return ret;
}

void pushUp(int in, int rt) {
	tr[in][rt] = tr[in][rt<<1] + tr[in][rt<<1|1];
}

void build(int in, int l, int r, int rt) {
	if (l == r) {
		tr[in][rt].len = 1;
		if (in == 0) {
			tr[in][rt].c_a = (S[l] == 'A');
			tr[in][rt].c_b = (S[l] == 'B');
			tr[in][rt].c_c = (S[l] == 'C');
			tr[in][rt].r_a = tr[in][rt].c_a;
		} else {
			tr[in][rt].c_a = (T[l] == 'A');
			tr[in][rt].c_b = (T[l] == 'B');
			tr[in][rt].c_c = (T[l] == 'C');
			tr[in][rt].r_a = tr[in][rt].c_a;
		}
		return;
	}
	int m = (l + r) >> 1;
	build(in, l, m, rt<<1);
	build(in, m+1, r, rt<<1|1);
	pushUp(in, rt);
}

Node query(int in, int L, int R, int l, int r, int rt) {
	if (L <= l && r <= R) {
		return tr[in][rt];
	}
	Node ret;
	int m = (l + r) >> 1;
	ret.c_a = ret.c_b = ret.c_c = ret.r_a = ret.len = 0;
	if (L <= m) ret = ret + query(in, L, R, l, m, rt<<1);
	if (R > m) ret = ret + query(in, L, R, m+1, r, rt<<1|1);
	return ret;
}

int main() {
	scanf("%s%s", S+1, T+1);
	l_s = int(strlen(S+1));
	l_t = int(strlen(T+1));
	build(0, 1, l_s, 1);
	build(1, 1, l_t, 1);
	scanf("%d", &Q);
	while (Q--) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		Node s, t;
		s = query(0, a, b, 1, l_s, 1);
		t = query(1, c, d, 1, l_t, 1);
		if (s.r_a < t.r_a) {
			printf("0");
			//cout << s.r_a << " " << t.r_a << endl;
		} else {
		    if (s.c_a == s.len && t.c_a != t.len) {
		        if (s.r_a-1 < t.r_a) {
		            printf("0");
		            continue;
		        }
		        s.r_a --;
		        s.r_b ++;
		        s.r_c ++;
		    }
			int c = s.r_a-t.r_a;
			s.r_a -= 3*(c/3);
			int s_cnt = s.c_b+s.c_c;
			if (s.r_a > t.r_a)
				s_cnt += 2;
			int t_cnt = t.c_b+t.c_c;
			//cout << s_cnt << " " << t_cnt << endl;
			if (s_cnt > t_cnt) printf("0");
			else {
				if ((t_cnt-s_cnt)%2 == 0) {
					printf("1");
				} else printf("0");
			}
		}
		//if s_r_a < t_r_a false
		//else
		//s_c_b+s_c_c+(s_c_a-(s_r_a-t_r_a))*2==t_c_b......
	}
	printf("\n");
	return 0;
}


#include<cstdio>
using namespace std;
#define mod 1000000007
#define ll long long
ll ans=1,n;
bool isprime(ll n) {
	if (n < 2) return 0;
	if (n == 2) return 1;
	if (n % 2 == 0) return 0;
	for (ll i = 3; i*i <= n; i++) if (n%i == 0) return 0;
	return 1;
}

ll c(ll n,ll k)
{
	ll res=0,p=k;
	while(p<=n)
	{res+=n/p; p*=k;}
	return res;
}
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b%2==0)
	{
		ll r=power(a,b/2);
		return (r*r)%mod;
	}
	else
		return (power(a,b-1)*a)%mod;
}
int main()
{
	scanf("%d", &n);
	for(ll i=2;i<2*n;i++)
	{
		if(isprime(i))
			ans=(ans * power(i, c(2*n-1,i)-c(n,i)-c(n-1,i) ) )%mod;
	}
	ans=(2*ans+mod-n)%mod;
	printf("%d\n", res);
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
int f(long long x,long long y,long long x1,long long y1)
{
    double t=double(x*x1+y*y1)/sqrt(double(x1*x1+y1*y1));
    if(t-round(t)>1e-6)return 0;
    x1^=y1;y1^=x1;x1^=y1;
    t=double(x*x1+y*y1)/sqrt(double(x1*x1+y1*y1));
    if(t-round(t)>1e-6)return 0;
    return 1;
}
int main(){
    long long q,w,e,r,t,y;
    cin >>q >>w>>e>>r>>t>>y;
    long long tq=q;long long tw=w;
    for(int i=0;i<4;i++){
    q=-tw;w=tq;
    if(f(e-q,r-w,t,y))return(cout << "YES"),0;
    }
    cout "NO";
}


#include<bits/stdc++.h>
#define INF 0x7fffffff
#define inf 0x3f3f3f3f
#define love const
#define I inline
#define ll long long
#define lc (now<<1)
#define rc (now<<1|1)
#define R register
#define lson lc,l,mid
#define rson rc,mid+1,r
#define rep(i,a,b)for(R int i=a;i<=b;i++)
#define per(i,a,b)for(R int i=a;i>=b;i--)
#define pii pair<int ,int >
#define re register
#define love const
#define debug cout<<"%"<<endl;
using namespace std;
namespace IO{
    const int IOsize=1<<21;
    I void read(){};I void Write(){};
    char buf[IOsize],*pa=buf,*pb=buf;
    char buffer[IOsize];int p1=-1;const int p2=(IOsize)-1;
    I char gc(){return pa==pb&&(pb=(pa=buf)+fread(buf,1,IOsize,stdin),pa==pb)?EOF:*pa++;}
    I void gchar(char s){s=gc();for(;!isalpha(s);s=gc());}
    template<typename T,typename... T2>I void read(T &x,T2 &... oth){
        x=0;R short y=0;R char ch=gc();
        for(;!isdigit(ch);ch=gc())y=ch=='-';
        for(;isdigit(ch);ch=gc())x=x*10+(ch^48);
        (y)&&(x=-x);read(oth...);return;}
    I void flush(){fwrite(buffer,1,p1+1,stdout);p1=-1;return;}
    I void pc(int ch){if(p1==p2)flush();buffer[++p1]=ch;return;}
    template<class T>I void write(T x){
        static char buf[20];static short len =-1;
        if(x>=0){do buf[++len]=(x%10)^48,x/=10;while(x);}
 else{pc     ('-');do buf[++len]=(-(x%10))^48,x/=10;while(x);}
        while(len>=0)pc(buf[len--]);return;}
    template<typename T,typename...T2>I void Write(T x,T2... oth){write(x),pc('\n'),Write(oth...);return;}
   }
#define ll long long
#define int long long
using namespace IO;
love int N =1050;
love int mod =1e9+7;
int c1,c2;int ans =0;
int n,m,x,pos,c[1000][500];
I void get(){
    fac[0]=1;
    rep(i,1,n)fac[i]=fac[i-1]*i%mod;
    c[1][1]=c[1][0]=c[0][0]=1;
    rep(i,2,N)
    {   c[i][0]=1;
        rep(j,1,i)
        {
            c[i][j]=c[i-1][j]+c[i-1][j-1];
            c[i][j]%=mod;
        }
    }
    return;
}
I int work(int x,int y)
{
    if(y==1)return c[x][1];
    if(y==0)return c[x][0];
    return work(x-1,y-1)*x%mod;
}
signed main()
{   get();
    read(n,x,pos);
    int l=0;int r=n;
    while(l<r)
    {
        int mid =(l+r)/2;
        if(mid<pos)c2++,l=mid+1;

            if(mid>pos)c1++,r=mid;
        else l=mid+1;
    }
 //   cout<<c[n-x][c1]<<" "<<c[x-1][c2]<<endl;
    int a1=0;int a2=0;
    a1=work(n-x,c1);a2=work(x-1,c2);
    //ans=c[n-x][c1]*c[x-1][c2];
    ans=a1*a2;
    //cout<<ans<<endl;
    ans%=mod;
    ans=ans*work(n-c1-c2-1,n-c1-c2-1)%mod;
   // ans=ans*c[n-c1-c2-1][n-c1-c2-1]%mod;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int f[30],a,b,c;
int main()
{
    cin>>a>>b>>c;
    k[0]=a;
    k[1]=b;
    for(int i=2;i<c;i++)
       f[i]=f[i-1]+f[i-2];
    cout<<f[c];
    return 0;
}


#include <iostream>
#include <cmath>
#include <afxpropertygridtooltipctrl.h>
using namespace std;

long long omar(long long x, int y){
	int j = x % 2;
	if (j == 0)y++;
	x = x / 2;

	if (x == 0)return y;
	return  (omar(x, y));
}long long osman(long long x, long long y){

	x = x / 2;
	y++;
	if (x == 0)return y;
	return  (osman(x, y));
}

int bakr(long long h, int g){
	if (h % 2 == 0){
		g = 0;
	}
	else{ g++;
	}
	h = h / 2;
	if (h == 0)return g;
	return bakr(h, g);

}
int main(){

		int x = 0;
		int x2 = 0;
		long long a, b;
		cin >> a >> b;
		int N = osman(a, 0);
		int N2 = osman(b, 0);
		int Z = omar(a, 0);
		int Z2 = omar(b, 0);
		if (Z > 1 || Z == 1)N=N-2;
		if (Z == 0)N--;

		x = x + bakr(a, 0) - 1;

		x = x + N*(N + 1) / 2;
		if (Z2 > 1)N2 = N2 - 2;
		if (Z2 == 1){
			N2 = N - 2;
			x2++;
		}if (Z2 == 0)N2--;
		x2 = x2 + bakr(b, 0) - 1;
		x2 = x2 + N2*(N2 + 1) / 2;
		cout << x2 - x;
	}


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

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int> v;
    int temp = n;
    int arr[6] = {4, 1, 3, 2, 0, 5};
    int cnt = 0;
    int ans = 0;
    while(temp > 0){
        if(temp%2 == 1){
            ans += pow(2, arr[cnt]);
        }
        temp/=2;
        cnt++;
    }
    cout<<ans;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#define ll long long
#define maxn 100
using namespace std;
int n,m;
char hi[maxn],ri[maxn]
int ri[10];

int main()
{
	scanf("%d %d\n",&n,&m);
	for(register int i=1;i<=n;++i)scanf("%c",&hi[i]);
	if(hi[1]=='>') ++ri[2];
	else ++ri[1];
	if(hi[n]=='>') ++ri[4];
	else ++ri[3];
	scanf("\n");
	for(register int i=1;i<=m;++i)scanf("%c",&ri[i]);
	if(ri[1]=='v') ++ri[3];
	else ++ri[1];
	if(ri[n]=='^') ++ri[2];
	else ++ri[4];
	int flag=1;
	for(register int i=1;i<=4;++i)if(ri[i]>1)flag=0;
	if(flag)printf("YES");
	else printf("NO");
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
// #pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
typedef unsigned int li;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
const short maxlen = 205;
char str[maxlen];
short k;
int main()
{
	ios::sync_with_stdio(false);
	while (~scanf("%s%hd", str, &k))
	{
		short len = strlen(str);
		if (len <= k)
		{
			printf("%d\n", (len + k) / 2 * 2);
			continue;
		}
		short maxnum = 0;
		for (short i = 0; i < len; i++)
		{

			for (short j = 1; j <= len - i; j++)
			{
					short cnt=0;
				for (short s = i; s < i + j; s++)
				{
					if (s + j >= len && s + j < len + k)
						cnt++;
					else if (s + j < len


#include <bits/extc++.h> // To use most bits rather than just the lowest ones:
#include <bits/stdc++.h>
using namespace std;

struct FastIO {
  FastIO() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(12);
  };
} fastIO_;

template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}

template <typename T, size_t N>
inline ostream &operator<<(ostream &os, const array<T, N> &a) {
  os << "[";
  int cnt = 0;
  for (auto &val : a) {
    if (cnt++)
      os << ", ";
    os << val;
  }
  os << "]";
  return os;
}

template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[";
  int cnt = 0;
  for (auto &val : v) {
    if (cnt++)
      os << ", ";
    os << val;
  }
  return os << "]";
}

template <typename T> inline ostream &operator<<(ostream &os, const set<T> &v) {
  os << "{";
  int cnt = 0;
  for (auto &val : v) {
    if (cnt++)
      os << ", ";
    os << val;
  }
  return os << "}";
}

template <typename T>
inline ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "{";
  int cnt = 0;
  for (auto &val : v) {
    if (cnt++)
      os << ", ";
    os << val;
  }
  return os << "}";
}

template <typename T1, typename T2>
inline ostream &operator<<(ostream &os, const map<T1, T2> &v) {
  os << "[";
  int cnt = 0;
  for (auto &val : v) {
    if (cnt++)
      os << ", ";
    os << val;
  }
  return os << "]";
}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

// types
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vc vector<char>
#define si set<int>
#define mpii map<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>

// names
#define fi first
#define se second
#define mp(a, b) make_pair((a), (b))
#define sz(a) ((int)(a).size())
#define rep(i, s, t) for (int i = (s); i < (t); i++)
#define repn(i, s) for (int i = 0; i < (s); i++)
#define ms(a, b) memset(a, b, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define bit(n, i) (((n) >> (i)) & 1)
#define bitCount(n) __builtin_popcountll((n))

// constants
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, 1, -1};

// functions
template <class T> inline bool umin(T &a, const T b) {
  return b < a ? a = b, 1 : 0;
}
template <class T> inline bool umax(T &a, const T b) {
  return a < b ? a = b, 1 : 0;
}
template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }

// =====================================================================================================================
#define maxn 200006
int n;

struct chash { // large odd number for C
  const uint64_t C = ll(4e18 * acos(0)) | 71;

  ll operator()(ll x) const { return __builtin_bswap64(x * C); }
};

int solve() {
  vi a(n + 1), cnt(101, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }

  int best = 0;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] > cnt[best])
      best = i;
  }

  int ans = 0;
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] && i != best) {
      __gnu_pbds::gp_hash_table<ll, int, chash> where({}, {}, {}, {},
                                                      {1 << 16});
      where[0] = 0;

      int sum = 0;
      for (int j = 1; j <= n; j++) {
        if (a[j] == best)
          sum++;
        else if (a[j] == i)
          sum--;

        auto it = where.find(sum);
        if (it != where.end())
          umax(ans, j - (it->second));
        else
          where[sum] = j;
      }
    }
  }
  return ans;
}

void solve(int _cas) {
  // solve();
  cout << solve() << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("A.in", "r", stdin);
#endif
  while (cin >> n)
    solve(1);
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include<set>
#include <climits>
#include <bits/stdc++.h>
#define int long long

using namespace std;

main()
{
    vector<int> p = {0, 1200, 1400, 1600, 1900, 2100, 2300, 2400, 2600, 3000};
    int r;
    cin>>r;
    int res, w=1000000;
    for(auto o: p)
    {
        if(abs(o-r)<w)
        {
            w=abs(o-r);
            res=o;
        }
    }
    cout<<o;
}