#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}

    ll K,T; cin>>K>>T;
    vector<ll> A(T,0);
    rep(i,T){
        cin>>A[i];
    }
    sort(all(A));
    ll L=A[sz(A)-1];
    rep(i,sz(A)-1){
        L-=A[i];
    }
    cout<<max(L-1,0ll)<<endl;
}

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int k, t;
  cin >> k >> t;

  priority_queue<int> pq;
  rep(i, 0, t) {
    int a;
    cin >> a;
    pq.push(a);
  }

  int ans = 0;
  bool is_first = true, flg = false;
  rep(i, 0, k) {
    if (flg)
      ans++;
    if (pq.size() == 1)
      flg = true;

    if (is_first) {
      int a = pq.top();
      pq.pop();
      a--;
      if (a)
        pq.push(a);
    } else {
      int a = pq.top();
      pq.pop();
      if (!pq.empty()) {
        int b = pq.top();
        pq.pop();
        b--;
        if (b)
          pq.push(b);
      }
      pq.push(a);
    }
    is_first = !is_first;
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)

using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int n;
vvi maze;
vi seen;
vi dTaka;
vi dAo;

void dfs(int x,int length,vi &d) {
  int sz = maze.at(x).size();
  seen.at(x) = 1;
  d.at(x) = min(length,d.at(x));
  rep(i,sz) {
    int nx = maze.at(x).at(i);
    if(!seen.at(nx)) dfs(nx,length+1,d);
  }
}
const int INF = 100100101;

int main() {

  cin >> n;
  int taka,ao;cin >> taka >> ao;
  taka--;ao--;
  maze = vvi(n,vi());

  int m = n-1;
  rep(i,m) {
    int a,b;cin >> a >> b;
    a--;b--;
    maze.at(a).eb(b);
    maze.at(b).eb(a);
  }

seen = vi(n,0);
  dTaka = vi(n,INF);
  dfs(taka,0,dTaka);
  seen = vi(n,0);
  dAo = vi(n,INF);
  dfs(ao,0,dAo);

  int ans = 0;
  rep(i,n) {
    if(dTaka.at(i) < dAo.at(i)) ans = max(ans,dAo.at(i)-1);
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG

int main() {
  int n;
  cin >> n;
  vector<pair<int,int>> a(n);
  vector<pair<int,int>> b(n);
  rep(i,n)
    cin >> a[i].second >> a[i].first;
  sort(a.rbegin(),a.rend());
  rep(i,n)
    cin >> b[i].first >> b[i].second;
  sort(b.begin(),b.end());

  int c=0;
  rep(i,n){
    rep(j,n){
      if((b[i].first>a[j].second)&&(b[i].second>a[j].first)){
        a[j]=make_pair(300,300);
        c++;
        break;
      }
    }
  }

  cout << c << endl;
}


#include <stdio.h>

int main () {
	int a,b;
	int tampung = 1;
	scanf("%d", &a);
	scanf("%d", &b);

	for ( int i = 0 ; i < a; i++) {
		if (tampung <= b) {
			tampung *= 2;
		} else {
			tampung += b;
		}
	}
	printf ("%d\n", tampung);
	return 0;
}

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1};
const int mod = 1e9+7;
const ll N = 1e5+4;

ll n,m;

void solve(){
	vector<int>d;
	cin>>n>>m;
	for(int i=1;i*i<=m;++i){
		if(m%i==0){
			d.pb(i);
			if(m/i!=i)d.pb(m/i);
		}
	}
	sort(all(d));
	reverse(all(d));
	rep(i,sz(d)){
		if(n*d[i]<=m){
			cout<<d[i];
			return;
		}
	}
}

int main(){
	Speed();
	int T=1;
	//cin>>T;
	while(T--)
		solve();
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<map>
#include<algorithm>

using namespace std;
using ll = long long;

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

	map<string, int>ma;

	string tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		ma[tmp]++;
	}

	int M;
	cin >> M;

	for (int i = 0; i < M; i++) {
		cin >> tmp;
		ma[tmp]--;
	}

	int ans = 0;

	for (auto itr : ma) {
		ans = max(itr.second, ans);
	}

	cout << ans << endl;
}

#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N;
vector<LL>A;
vector<LL>xmos;
const LL MOD = 1000000007;

LL solvedp(vector<pair<LL, int>>& vec, LL lasval) {
	LL zero = 1, notz = 0;
	LL zpar = 1, npar = 0;
	for (auto p : vec) {
		if (p.first == 0) {
			zpar = (notz * p.second) % MOD;
			zero += zpar;
			zero %= MOD;
		}
		else {
			npar = (zero * p.second) % MOD;
			notz += npar;
			notz %= MOD;
		}
	}
	if (lasval == 0) {
		return zpar;
	}
	return npar;
}

int main() {
	cin >> N;
	LL xsum = 0;
	xmos.push_back(0);
	for (int i = 0; i < N; ++i) {
		LL tmp;
		cin >> tmp;
		A.push_back(tmp);
		xsum ^= tmp;
		xmos.push_back(xsum);
	}
	/*vector<LL>dp(N + 1);
	dp[1] = 1;
	LL odd = 1, eve = 0;
	for (int i = 2; i <= N; ++i) {
		if (i % 2) {
			dp[i]++;
			dp[i] += eve;
			dp[i] %= MOD;
			odd += dp[i];
			odd %= MOD;
		}
		else {
			dp[i] += odd;
			eve += dp[i];
			eve %= MOD;
		}
	}*/
	if (xsum != 0) {
		vector<pair<LL, int>>nowarr;
		for (int i = 1; i <= N; ++i) {
			if (xmos[i] == 0) {
				nowarr.push_back({ 0,1 });
			}
			if (xmos[i] == xsum) {
				nowarr.push_back({ xsum,1 });
			}
		}
		LL ans = solvedp(nowarr, xsum);
		cout << ans << endl;
	}
	else {
		map<LL, int>zerolas;
		map<LL, vector<pair<LL, int>>>arrs;
		int zerocnt = 0;
		LL zerotwo = 1;
		for (int i = 1; i <= N; ++i) {
			if (xmos[i] == 0) {
				zerocnt++;
				if (i < N) {
					zerotwo *= 2;
					zerotwo %= MOD;
				}
			}
			else {
				if (zerocnt != zerolas[xmos[i]]) {
					arrs[xmos[i]].push_back({ 0,zerocnt - zerolas[xmos[i]] });
					zerolas[xmos[i]] = zerocnt;
				}
				arrs[xmos[i]].push_back({ xmos[i],1 });
			}
		}
		LL ans = zerotwo;
		for (auto& elm : arrs) {
			if (elm.second.back().second != 0) {
				elm.second.push_back({ 0,1 });
			}
			ans += solvedp(elm.second, 0);
			ans %= MOD;
		}
		cout << ans << endl;
	}
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
using lli = long long int;
template <typename T>
vector<T> read_vector(int n) {
  vector<T> result(n);
  for (auto& a : result) cin >> a;
  return result;
}
template <typename T>
vector<T> read_vector() {
  int n;
  cin >> n;
  return read_vector<T>(n);
}

int main() {
  ios_base::sync_with_stdio(false);
  auto v = read_vector<int>();
  bool valid = v[0] == 0;
  for (int i = 1; i < v.size(); ++i) valid &= v[i] <= v[i - 1] + 1;
  if (!valid) {
    cout << -1;
    return 0;
  }
  lli cost = 0;
  int prev = 0;
  reverse(all(v));
  for (auto a : v) {
    prev = max(0, prev - 1);
    if (a < prev) {
      cout << -1;
      return 0;
    } else if (a > prev) {
      cost += a;
    }
    prev = a;
  }
  cout << cost;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[214514];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	ll ans=0;
	if(a[0]!=0)cout<<-1<<endl;
	else{
		ll cnt=1;
		for(int i=1;i<=n;i++){
			if(a[i]==a[i-1])cnt++;
			else if(a[i]>a[i-1]){
				if(a[i]-a[i-1]>1){
					cout<<-1<<endl;
					return 0;
				}
				ans+=(cnt-1)*a[i-1];
				cnt=1;
			}else{
				ans+=cnt*a[i-1];
				cnt=1;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <ctime>
#include <map>
#include <queue>
#include <functional>

using namespace std; using ll=long long; using P=pair<ll,ll>; const int INF=1e9; const ll LNF=1e18;

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

  bool ok = false; int ans[n];
  for(int i=0;i<4;i++) {
    fill(ans, ans+n, -1);
    ans[0]=i/2, ans[1]=i%2;

    for(int j=2;j<n;j++) {
      ans[j] = ans[j-2] ^ (s[j-1]=='x') ^ (ans[j-1]==1);
      // ひつじさんが「o」→同じひと
    }

    bool o1 = (ans[n-1] ^ (s[0]=='x') ^ (ans[0]==1)) == ans[1];
    bool o2 = (ans[n-2] ^ (s[n-1]=='x') ^ (ans[n-1]==1)) == ans[0];
    if (o1 && o2) {ok=true; break;}
  }
  if (ok) {
    for(int i=0;i<n;i++) {
      if (ans[i]==0) cout<<"S";
      else cout<<"W";
    }cout<<endl;
  } else {
    cout<<-1<<endl;
  }
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvl vector<vector<long long>>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define vpli vector<pair<long long, int>>
#define vs vector<string>
#define deb(x) cout << x << endl;
#define all(x) x.begin(), x.end()
vector<vvi> dp;
int M = 1e9 + 7;
vi k;
int d;
void modadd(int &a, int b)
{
    a = (a + b) % M;
    if(a<0)
        a+= M;
}

int helper(int pos, bool full, int sum)
{
    if (pos == k.size())
        return (sum == 0);
    if (dp[pos][full][sum] != -1)
        return dp[pos][full][sum];
    int limit = (full ? (k[pos]) : (9));
    int ans = 0;
    for (int i = 0; i <= limit; i++)
    {
        modadd(ans, helper(pos + 1, full && (i == limit), (sum+i)%d ) );
    }
    dp[pos][full][sum] = ans;
    return ans;
}

void solve()
{
    string s;
    cin >> s >> d;
    k.resize(s.size());
    for (int i = 0; i < s.size(); i++)
    {
        k[i] = s[i] - '0';
    }
    dp.resize(s.size());
    for (vvi &t : dp)
    {
        t.resize(2);
        for (vi &u : t)
        {
            u.resize(d+1);
            for (int &x : u)
                x = -1;
        }
    }
    cout << ((helper(0, 1, 0)-1+M)%M)<<endl;
}

int main()
{
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

const int N = 1e5+34;

int a[N];

void solve() {
    int n; scanf("%d", &n);
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a+i);
        sum += abs(a[i]-a[i-1]);
    }
    sum += abs(a[n]);
    debug(sum);
    for (int i = 1; i <= n; ++i) {
        int cur = sum-abs(a[i]-a[i-1]);
        if (i == n) {
            cur -= abs(a[i]);
            cur += abs(a[i-1]);
        } else {
            cur -= abs(a[i+1]-a[i]);
            cur += abs(a[i+1]-a[i-1]);
        }
        printf("%d\n", cur);
    }
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <cstring>

#define NOT_DEFINED 2
#define NORMAL 1
#define IRREGULAR 0

using namespace std;

typedef struct {
    int battery;
    int motor;
    int cable;
    bool hasSucceeded;
} Query;

struct IsSuccess {
    bool operator()(Query &a, Query &b) const {
        return (a.hasSucceeded < b.hasSucceeded);
    }
};

char parts[300];

int main() {
    while (1) {
        int i, a, b, c;
        int N;
        priority_queue<Query, vector<Query>, IsSuccess> queries;

        scanf("%d %d %d", &a, &b, &c);
        if (a == 0 && b == 0 && c ==0) {
            return 0;
        }

        scanf("%d", &N);
        for (i=0;i<N;i++) {
            int i, j, k ,r;
            Query query;

            scanf("%d %d %d %d", &i, &j, &k, &r);
            query.battery = i-1;
            query.motor = j-1;
            query.cable = k-1;
            query.hasSucceeded = r;

            queries.push(query);
        }

        memset(parts, NOT_DEFINED, 300);

        while (!queries.empty()) {
            int i, j, k, r;
            Query query = queries.top();

            i = query.battery;
            j = query.motor;
            k = query.cable;
            r = query.hasSucceeded;

            if (r) {
                parts[i] = NORMAL;
                parts[j] = NORMAL;
                parts[k] = NORMAL;
            } else {
                if (parts[i] == NORMAL && parts[j] == NORMAL) {
                    parts[k] = IRREGULAR;
                }

                if (parts[j] == NORMAL && parts[k] == NORMAL) {
                    parts[i] = IRREGULAR;
                }

                if (parts[k] == NORMAL && parts[i] == NORMAL) {
                    parts[j] = IRREGULAR;
                }
            }

            queries.pop();
        }

        for (i=0;i<a+b+c;i++) {
            printf("%d\n", parts[i]);
        }
    }
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

//??°?????????lowlink???????????????????????¢????????¨??????????????????
//?¨??????? O(|V|+|E|)
void lowlink(vector<int>graph[], int n, vector<int>&low, vector<pair<int, int>>&br, vector<int>&jnt) {
	low.resize(n);
	vector<int>ord(n);//DFS?????????
	vector<bool>vis(n);//?¨???????????????????
	//?????°????????????
	function<void(int, int, int&)>dfs = [&](int v, int p, int &k) {
		vis[v] = true;
		ord[v] = k++;
		low[v] = ord[v];
		bool joint = false;
		int cnt = 0;
		for (auto nxt : graph[v]) {
			if (!vis[nxt]) {
				cnt++;
				dfs(nxt, v, k);
				low[v] = min(low[v], low[nxt]);
				if (p >= 0 && ord[v] <= low[nxt]) joint = true;
				if (ord[v] < low[nxt])br.push_back({ min(v,nxt),max(v,nxt) });
			}
			else if (nxt != p) {
				low[v] = min(low[v], ord[nxt]);
			}
		}
		if (p < 0 && cnt > 1) joint = true;
		if (joint) jnt.push_back(v);
	};
	int k = 0;
	for (int i = 0; i < n; ++i)
		if (!vis[i])dfs(i, -1, k);
}

int N, M;
vector<int>graph[123456];

int main(void)
{
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int s, t;
		cin >> s >> t;
		graph[s].push_back(t);
		graph[t].push_back(s);
	}
	vector<int>low, jnt;
	vector<pair<int, int>>br;
	lowlink(graph, N, low, br, jnt);
	sort(jnt.begin(), jnt.end());
	for (int i : jnt) {
		cout << i << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using i64 = long;
struct BitVector
{
  vector<uint64_t> v;
  vector<int> r;
  BitVector(){}
  void build(){
    r.assign((int)v.size() + 1, 0);
    for(int i = 0; i < (int)v.size(); ++i)
      r[i + 1] = r[i] + __builtin_popcountll(v[i]);
  }
  bool access(int x){
    return (v[x >> 6] >> (x & 63)) & 1;
  }
  // [0, x)の1の出現回数
  int rank(int x){
    return r[x >> 6] + __builtin_popcountll(v[x >> 6] & ((1uLL << (x & 63)) - 1));
  }
  int rank(int x, bool fl){
    return fl ? rank(x) : x - rank(x);
  }
};
template <typename T, int W>
struct WaveletMatrix
{

  array<BitVector, W> bv;
  array<int, W> zero_cnt;

  WaveletMatrix(vector<T>& a){
    int n = a.size();
    vector<T> v(a);
    for(int i = W - 1; i >= 0; --i){
      vector<uint64_t> b((n >> 6) + 1, 0);
      vector<T> v1, v2;
      for(int j = 0; j < n; ++j){
        ((v[j] >> i) & 1 ? v2 : v1).push_back(v[j]);
        b[j >> 6] |= uint64_t((v[j] >> i) & 1) << (j & 63);
      }
      for(int j = 0; j < (int)v.size(); ++j)
        v[j] = (j < (int)v1.size() ? v1[j] : v2[j - (int)v1.size()]);
      bv[i].v = move(b);
      bv[i].build();
      zero_cnt[i] = bv[i].rank(n, 0);
    }
  }

  // [l, r)内のxの数
  int count(int l, int r, T x){
    for(int i = W - 1; i >= 0; --i){
      bool fl = (x >> i) & 1;
      int st = bv[i].rank(l, fl);
      int en = bv[i].rank(r, fl);
      l = (fl ? zero_cnt[i] : 0) + st;
      r = (fl ? zero_cnt[i] : 0) + en;
    }
    return r - l;
  }

  // [l, r)内で[0, x)を満たす値の数
  int count_lower(int l, int r, T x){
    int cnt = 0;
    for(int i = W - 1; i >= 0; --i){
      bool fl = (x >> i) & 1;
      int st = bv[i].rank(l, fl);
      int en = bv[i].rank(r, fl);
      if(fl){
        st += zero_cnt[i];
        en += zero_cnt[i];
        cnt += (bv[i].rank(r, 0) - bv[i].rank(l, 0));
      }
      l = st, r = en;
    }
    return cnt;
  }

  // [l, r)内で[x, y)を満たす値の数
  int count_range(int l, int r, T x, T y){
    return count_lower(l, r, y) - count_lower(l, r, x);
  }

  // 0-indexedでk番目に小さいものを返す
  T kth_min(int l, int r, int k){
    T ans = 0;
    for(int i = W - 1; i >= 0; --i){
      int st = bv[i].rank(l, 0);
      int en = bv[i].rank(r, 0);
      if(en - st <= k){
        k -= en - st;
        l = zero_cnt[i] + bv[i].rank(l, 1);
        r = zero_cnt[i] + bv[i].rank(r, 1);
        ans |= (1uLL << i);
      }
      else{
        l = st, r = en;
      }
    }
    return ans;
  }

  // [l, r)でのx以上最小値
  pair<T, bool> predecessor(int l, int r, T x){
    int idx = count_lower(l, r, x);
    if(idx == r - l){
      return make_pair((1uLL << W) - 1, false);
    }
    return make_pair(kth_min(l, r, idx), true);
  }

  // [l, r)でのx以下最大値
  pair<T, bool> successor(int l, int r, T x){
    int idx = count_lower(l, r, x + 1);
    if(idx == 0)
      return make_pair(0, false);
    return make_pair(kth_min(l, r, idx - 1), true);
  }
};
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main()
{
  int N=IN(),Q=IN(),mn=N,mx=0,C[N],temp[N];
  vector<int>direction(N);
  rep(i,N){C[i]=IN();mn=mn<C[i]?mn:C[i];mx=mx>C[i]?mx:C[i];temp[i]=N;}
  rep(i,N){direction[N-1-i]=temp[C[N-1-i]-1];temp[C[N-1-i]-1]=N-1-i;}
  WaveletMatrix<int,20> wm(direction);
  while(Q--){int l=IN()-1,r=IN();OUT(wm.count_range(l,r,r,N+1));}
}


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

int main() {
  int n,k;cin>>n>>k;
  int ans = 0; if (n%k > 0) ans++;
  cout << ans << endl;
}

#include <iostream>

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;

  if(N % K == 0){
    cout << "0" << endl;
  }else{
    cout << "1" << endl;
  }
  return 0;
}


#include <algorithm>
#include <cstdio>

static const size_t n_max = 200000;
static int S[n_max], L[n_max], R[n_max];
static long long c = 0;

void merge_sort(size_t i, size_t j) {
  switch (j - i) {
    case 0:
    case 1:
      break;
    case 2:
      if (S[i+1] < S[i]) {
        c++;
        std::swap(S[i], S[i+1]);
      }
      break;
    default:
      size_t k = (i + j) / 2;
      merge_sort(i, k);
      merge_sort(k, j);
      std::copy(S + i, S + k, L);
      std::copy(S + k, S + j, R);
      for (size_t l = i, p = 0, q = 0;; l++) {
        if (p < k - i && q < j - k) {
          if (L[p] <= R[q])
            S[l] = L[p++];
          else {
            c += k - i - p;
            S[l] = R[q++];
          }
        } else if (p < k - i)
          S[l]= L[p++];
        else if (q < j - k)
          S[l] = R[q++];
        else
          break;
      }
      break;
  }
}

int main() {
  size_t n;
  scanf("%zu", &n);
  for (size_t i = 0; i < n; i++)
    scanf("%d", S + i);
  merge_sort(0, n);
  printf("%lld\n", c);
  return 0;
}

#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin>>N;
  vector<int> L(N);
  rep(i,N) cin>>L[i];

  int ans = 0;
  for(int i=0; i<N; ++i) {
    for(int j=i+1; j<N; ++j) {
      for(int k=j+1; k<N; ++k) {
        if((L[i] != L[j]) && (L[j] != L[k]) && (L[i] !=L[k])) {
          if((abs(L[i]-L[j]) < L[k]) && (L[k] < (L[i]+L[j]))) {
            ++ans;
          }
        }
      }
    }
  }
  cout << ans << endl;
}


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

int k[101];
char s[101];
int main() {
	vector<char>v;
	for (char c = 'a'; c <= 'z'; c++)v.push_back(c);
	for (char c = 'A'; c <= 'Z'; c++)v.push_back(c);
	int n;
	while (scanf("%d", &n), n) {
		rep(i, n)scanf("%d", &k[i]);
		scanf("%s", s);
		int len = strlen(s);
		rep(i, len) {
			s[i] = v[(find(v.begin(), v.end(), s[i]) - v.begin() + 52 - k[i%n]) % 52];
		}
		puts(s);
	}
}

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

#define KEY_NUM 100

char process_key(char c, int key) {

    int num=0;
    //cout << "[" << c << "," << key << "," << num << "]";
    if ('a' <= c && c <= 'z') {
        num = 25 - (int)('z' - c);
    }
    if ('A' <= c && c <= 'Z') {
        num = 51 - (int)('Z' - c);
    }
    num = (num - key + 104) % 52;
    if ( 0 <= num && num <= 25) {
        c = 'a' + num;
    }
    if (26 <= num && num <= 51) {
        c = 'A' + (num - 26);
    }
    //cout << "[" << c << "," << key << "," << num << "]";
    return c;
}

int main(void) {
    string s;
    int n;
    int keys[KEY_NUM];
    while (cin >> n, n) {
        for (int i=0; i<n; i++) {
            cin >> keys[i];
        }
        cin >> s;
        //cout << n << endl;
        for (int i=0; i<s.size(); i++) {
            //cout << process_key(s[i], keys[i % n]) << "_";
            cout << process_key(s[i], keys[i % n]);
        }
        //cout << s << endl;
        cout << endl;
    }
}


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <array>

using namespace std;

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

vector<long> vec;
bool prime(int x)
{
	for(int i = 2; i <= sqrt(x); i++)
	{
		if(x%i == 0)
			return 0;
	}
	return 1;
}
long MAXN = 500;
long A[503][503];
long gcd(long a, long b) {return (b)? gcd(b,a%b) : a;}
long lcm(long a, long b)
{
	if(a == b && b == 0) return 0;
	else if(a == 0) return b;
	else if(b == 0) return a;
	else return a/gcd(a,b)*b;
}

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	for(int i = 2; i <= 10000; i++)
		if(prime(i))
			vec.push_back(i);

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

	int idx = 0;
	for(int i = 1; i <= MAXN; i+=2)
	{
		int x = 1, y = i;
		while(y <= MAXN)
			A[x++][y++] = vec[idx];
		idx++;
	}
	for(int i = 3; i <= MAXN; i+=2)
	{
		int x = i, y = 1;
		while(x <= MAXN)
			A[x++][y++] = vec[idx];
		idx++;
	}
	for(int i = 1; i <= MAXN; i+=2)
	{
		int x = 1, y = i;
		while(y >= 1 && x <= MAXN)
			A[x++][y--] *= vec[idx];
		idx++;
	}
	for(int i = MAXN; i >= 2; i-=2)
	{
		int x = i, y = MAXN;
		while(y >= 1 && x <= MAXN)
			A[x++][y--] *= vec[idx];
		idx++;
	}

	long mx = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(A[i][j] == 0) A[i][j] = lcm(lcm(A[i-1][j],A[i][j-1]),lcm(A[i+1][j],A[i][j+1]))+1;
			// mxnax(A[i][j],mx);
			printf("%lld", A[i][j]);
			if(j < n) printf(" ");
		}
		printf("\n");
	}
	// printf("%lld\n", mx);
}

#include<bits/stdc++.h>
#define rg register
#define oo 0x7fffffff
#define ll long long
using namespace std;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		{
			fh=-1;
			jp=getchar();
		}
	while (jp>='0'&&jp<='9')
		{
			out=out*10+jp-'0';
			jp=getchar();
		}
	return out*fh;
}
const int MAXN=5e2+10;
const int MAXM=1e5+10;
int n;
ll Mat[MAXN][MAXN];
int pcnt=0,prime[MAXM],vis[MAXM];
void Linear_Shaker()
{
	for(rg int i=2;i<=MAXM;++i)
		{
			if(!vis[i])
				prime[++pcnt]=i;
			for(rg int j=1;i*prime[j]<=MAXM;++j)
				{
					vis[i*prime[j]]=1;
					if(i % prime[j]==0)
						break;
				}
		}
}
ll GCD(ll x,ll y)
{
	return y==0? x: GCD(y,x%y);
}
ll LCM(ll x,ll y)
{
	return x / GCD(x,y) * y;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	if(n==2)
		{
			printf("4 7\n23 10");
			return 0;
		}
	Linear_Shaker();
	for(rg int i=1;i<=n;++i)
		for(rg int j=1;j<=n;++j)
			Mat[i][j]=1ll;
	for(rg int i=1;i<=n;++i)
		for(rg int j=1;j<=n;++j)
			{
				if((i&1)==(j&1))
					{
						Mat[i][j]=1ll* prime[(i+j)/2] * prime[(i+n+1-j)/2+n];
						Mat[i+1][j]=LCM(Mat[i+1][j],Mat[i][j]);
						Mat[i-1][j]=LCM(Mat[i-1][j],Mat[i][j]);
						Mat[i][j+1]=LCM(Mat[i][j+1],Mat[i][j]);
						Mat[i][j-1]=LCM(Mat[i][j-1],Mat[i][j]);
					}
			}
	for(rg int i=1;i<=n;++i)
		for(rg int j=1;j<=n;++j)
			printf("%lld%c",(i&1)==(j&1)?Mat[i][j]:Mat[i][j]+1,j==n?'\n':' ');
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

class dice{
    private:
    int s[6];
    int top;
    int bottom;
    int r_side;
    int l_side;
    int face;
    int rev;

    public:
    dice(){
        top = 0;
        bottom = 5;
        r_side = 2;
        l_side = 3;
        face = 1;
        rev = 4;
        s[0] = 1;
        s[1] = 2;
        s[2] = 3;
        s[3] = 4;
        s[4] = 5;
        s[5] = 6;
    }

    dice(int a[5]){
        top = 0;
        bottom = 5;
        r_side = 2;
        l_side = 3;
        face = 1;
        rev = 4;
        REP(i, 6) s[i] = a[i];
    }

    dice(int x, int y, int z, int u, int v, int w){
        top = 0;
        bottom = 5;
        r_side = 2;
        l_side = 3;
        face = 1;
        rev = 4;
        s[0] = x;
        s[1] = y;
        s[2] = z;
        s[3] = u;
        s[4] = v;
        s[5] = w;
    }

    int get_top() {
        return s[top];
    }

    int get_bottom(){
        return s[bottom];
    }

    int get_r_side(){
        return s[r_side];
    }

    int get_l_side(){
        return s[l_side];
    }

    int get_face(){
        return s[face];
    }

    int get_rev(){
        return s[rev];
    }

    int set_top(int i) {
        top = i;
        bottom = 5 - top;
        r_side = (i+1)%5;
        l_side = 5 - r_side;
        face = (i+2)%5;
        rev = 5 - face;
        return s[top];
    }

    int rotate_r(int i) {
        while(i<0)
            i+=4;
        i %= 4;
        REP(j, i){
            int temp = face;
            face = r_side;
            r_side = rev;
            rev = l_side;
            l_side = temp;
        }
        return s[top];
    }

    int roll_r(int i) {
        while(i<0)
            i+=4;
        i %= 4;
        REP(j, i){
            int temp = top;
            top = l_side;
            l_side = bottom;
            bottom = r_side;
            r_side = temp;
        }
        return s[top];
    }

    int roll_f(int i){
        while(i<0)
            i+=4;
        i %= 4;
        REP(j, i){
            int temp = top;
            top = face;
            face = bottom;
            bottom = rev;
            rev = temp;
        }
        return s[top];
    }

};

int main() {
    int in[6];
    REP(i, 6) cin >> in[i];
    dice d = dice(in);
    string roll;
    cin >> roll;
    while(roll.size() != 0){
        string order = roll.substr(0, 1);
        if(order == "E")
            d.roll_r(1);
        else if(order == "S")
            d.roll_f(-1);
        else if(order == "N")
            d.roll_f(1);
        else if(order == "W")
            d.roll_r(-1);
        roll = roll.substr(1);
    }
    cout << d.get_top() << endl;
    return 0;
}

#include <stdio.h>

struct Dice
{
	int n[6];
};

Dice InputDice()
{
	Dice d;
	for(int i = 0; i < 6; ++i)
	{
		scanf("%d", &d.n[i]);
	}

	return d;
}

Dice SetDice(int a, int b, int c, int d, int e, int f)
{
	Dice dice;
	dice.n[0] = a;
	dice.n[1] = b;
	dice.n[2] = c;
	dice.n[3] = d;
	dice.n[4] = e;
	dice.n[5] = f;

	return dice;
}

Dice Roll(Dice dice, char dir)
{
	switch(dir)
	{
		case 'N':
			return SetDice(dice.n[1], dice.n[5], dice.n[2], dice.n[3], dice.n[0], dice.n[4]);
		case 'S':
			return SetDice(dice.n[4], dice.n[0], dice.n[2], dice.n[3], dice.n[5], dice.n[1]);
		case 'W':
			return SetDice(dice.n[2], dice.n[1], dice.n[5], dice.n[0], dice.n[4], dice.n[3]);
		case 'E':
			return SetDice(dice.n[3], dice.n[1], dice.n[0], dice.n[5], dice.n[4], dice.n[2]);
	}
}

bool IsSame(Dice a, Dice b)
{
	for(int i = 0; i < 6; ++i)
	{
		if(a.n[i] != b.n[i])
		{
			return false;
		}
	}

	return true;
}

bool IsEqual(Dice a, Dice b)
{
	char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";

	for(int i = 0; i < 24; ++i)
	{
		b = Roll(b, cmd[i]);
		if(IsSame(a, b))
		{
			return true;
		}
	}

	return false;
}

int FindTop(Dice a, int top, int front)
{
	char cmd[25] = "NNNNWNNNWNNNENNNENNNWNNN";

	for(int i = 0; i < 24; ++i)
	{
		a = Roll(a, cmd[i]);
		if(a.n[0] == top && a.n[1] == front)
		{
			return a.n[2];
		}
	}

	return -1;
}

int main()
{
	Dice D = InputDice();
	char cmd[128];
	scanf("%s", cmd);

	for(int i = 0; cmd[i] != 0; ++i)
	{
		D = Roll(D, cmd[i]);
	}

	printf("%d\n", D.n[0]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<int> S[MAX],color(MAX,0),odd,even;

void DFS(int u){
    int cnt=1;
    bool ok=true;
    stack<int> ST;
    color[u]=1;
    ST.push(u);

    while(!ST.empty()){
        int a=ST.top();
        ST.pop();
        for(int i=0;i<S[a].size();i++){
            int b=S[a][i];
            if(color[b]==0){
                if(color[a]==1){
                    color[b]=2;
                    ST.push(b);
                    cnt++;
                }else{
                    color[b]=1;
                    ST.push(b);
                    cnt++;
                }
            }else if(color[a]==color[b]){
                ok=false;
            }
        }
    }

    if(ok) even.push_back(cnt);
    else odd.push_back(cnt);

    return;
}

int main(){

    int N,M;cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        S[a].push_back(b);
        S[b].push_back(a);
    }

    for(int i=0;i<N;i++){
        if(S[i].size()==0||color[i]) continue;
        DFS(i);
    }

    int rem=N;

    ll ans=0;

    for(int i=0;i<odd.size();i++){
        rem-=odd[i];
    }

    for(int i=0;i<even.size();i++){
        rem-=even[i];
    }

    ans+=odd.size()+even.size()*2;
    ans+=ll(N)*ll(N)-ll((N-rem))*ll((N-rem));

    ans+=ll(4)*ll(even.size())*ll((even.size()-1))/2;
    ans+=ll(2)*ll(even.size())*ll(odd.size());
    ans+=ll(2)*ll(odd.size())*ll((odd.size()-1))/2;

    cout<<ans<<endl;
    //cout<<rem<<" "<<odd.size()<<" "<<even.size()<<endl;

}

#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long n,m,i,j,x,y,flag,book[100005],sd[100005],sum,c,p,ans;
long long top,nex[400005],to[400005],fir[100005];
void lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
void ss(int v,int w){
	sd[v]=w;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(sd[to[top1]]==0)
			ss(to[top1],w+1);
		else if(sd[v]>sd[to[top1]]){
			if((sd[v]-sd[to[top1]]&1)==0)
				flag=1;
		}
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();m=read();
   	for(i=1;i<=m;i++){
		x=read();y=read();
		lj(x,y);
		lj(y,x);
		book[x]=1;
		book[y]=1;
	}
	for(i=1;i<=n;i++)
		if(book[i]==0)
			sum++;
	for(i=1;i<=n;i++)
		if(book[i]==1&&sd[i]==0){
			flag=0;
			ss(i,1);
			if(flag==1)
				p++;
			else
				c++;
		}
	ans=sum*n*2-sum*sum+c*c*2+p*(p+c*2);
	pus(ans,2);
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  string a,b,c;
  cin>>a>>b>>c;

  ll ans=0;
  REP(i,n){
    map<ll,ll> m;
    m[a[i]-'a']+=1;
    m[b[i]-'a']+=1;
    m[c[i]-'a']+=1;

    ll h=0;
    REP(j,26)
      h=max(h,m[j]);
    ans+=3-h;
    //cout<<n-h<<endl;
  }

  cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,ans;
string a,b,c;
int main()
{
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i])
		{
			if(!(a[i]==b[i]&&b[i]==c[i]))
			{
				ans++;
			}
		}
		else
		{
			ans+=2;
		}
	}
	cout<<ans;
}


#include <bits/stdc++.h>

using namespace std;

int main ()
{
    int k,x;

    cin >> k >> x ;

    for(int i=1; i<k*2; i++){
        cout << x-k+i << " " << flush;
    }
        cout << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "E:\CP\Debugger\debugger.h"
#else
#define debug(x...)
#endif
#define int long long
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define TC int tc; cin>>tc; for(int cn=1; cn<=tc; ++cn)
const int mx = 2e6+2, neg = -1e6, pos = 1e6;
bitset<mx> vis;

signed main(){
    int k, x;
    cin>>k>>x;

    int st = (x-k+1 >= neg? x-k+1: neg);
    int ed = (x+k-1 <= pos? x+k-1: pos);

    for(int i= st; i<=ed; ++i)
        cout<<i<<' ';

    return 0;
}


#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  int a = (s[0] - '0');
  int b = (s[1] - '0');
  int c = (s[2] - '0');
  int d = (s[3] - '0');
  for(int op1 = -1; op1 <= 1; op1 += 2)
  for(int op2 = -1; op2 <= 1; op2 += 2)
  for(int op3 = -1; op3 <= 1; op3 += 2)
  {
    if (a + b * op1 + c * op2 + d * op3 == 7)
    {
      cout << a;
      cout << (op1 == -1 ? '-' : '+');
      cout << b;
      cout << (op2 == -1 ? '-' : '+');
      cout << c;
      cout << (op3 == -1 ? '-' : '+');
      cout << d;
      cout << "=7";
      return;
    }
  }
}

int main()
{
  fastio;
  solve();

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

    string input;
    int tmp = 0;
    char op[3] = {'+','+','+'};

    cin >> input;

    for(int bit = 0; bit < (1<< 3); bit++){
        tmp = 0;
        for(int i = 0;i<3;i++){
            if(bit & (1 << i)){
                op[i] = '-';
                tmp += (input[i+1] - '0') * (-1);
            }else{
                op[i] = '+';
                tmp += (input[i+1] - '0');
            }
        }
        tmp += input[0] - '0';
        if(tmp == 7)break;
    }

    for(int i = 0; i<3;i++){
        cout << input[i] << op[i];
    }

    cout << input[3] << "=7" << endl;

    return 0;
}


// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
          int a,b,c;
          cin>>a>>b>>c;
          swap(a,b);
          swap(a,c);
          cout<<a<<" "<<b<<" "<<c;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

vector<char> ans(100100, '.');
int n;
string s;

void swcheck(vector<char> &sw) {
    for(int i = 1; i < n; ++i) {
        if(s.at(i) == 'o') {
            if(sw.at(i) == 'S') {
                if(sw.at(i-1) == 'S') sw.at(i+1) = 'S';
                else sw.at(i+1) = 'W';
            }else {
                if(sw.at(i-1) == 'S') sw.at(i+1) = 'W';
                else sw.at(i+1) = 'S';
            }
        }else {
            if(sw.at(i) == 'S') {
                if(sw.at(i-1) == 'S') sw.at(i+1) = 'W';
                else sw.at(i+1) = 'S';
            }else {
                if(sw.at(i-1) == 'S') sw.at(i+1) = 'S';
                else sw.at(i+1) = 'W';
            }
        }
    }
}

bool lacheck(vector<char> &sw) {
    if(sw.at(0) == sw.at(n)) {
        if(s.at(0) == 'o') {
            if(sw.at(0) == 'S') {
                if(sw.at(n-1) == sw.at(1)) return true;
            }else {
                if(sw.at(n-1) != sw.at(1)) return true;
            }
        }else {
            if(sw.at(0) == 'S') {
                if(sw.at(n-1) != sw.at(1)) return true;
            }else {
                if(sw.at(n-1) == sw.at(1)) return true;
            }
        }
    }
    return false;
}

void swprint(vector<char> &sw) {
    for(int i = 0; i < n; ++i) {
        if(i == n-1) cout << sw.at(i) << endl;
        else cout << sw.at(i);
    }
}

int main() {
    cin >> n >> s;
    ans.at(0) = 'S'; ans.at(1) = 'S';
    swcheck(ans);
    if(lacheck(ans)) {
        swprint(ans); return 0;
    }
    ans.at(0) = 'S'; ans.at(1) = 'W';
    swcheck(ans);
    if(lacheck(ans)) {
        swprint(ans); return 0;
    }
    ans.at(0) = 'W'; ans.at(1) = 'S';
    swcheck(ans);
    if(lacheck(ans)) {
        swprint(ans); return 0;
    }
    ans.at(0) = 'W'; ans.at(1) = 'W';
    swcheck(ans);
    if(lacheck(ans)) {
        swprint(ans); return 0;
    }
    cout << -1 << endl;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int main()
{
	string s;
	for (; getline(cin, s); )
	{
		stringstream ss;
		ss << s;

		vector<int> l(10);
		int v0, v1;

		for (int i = 0; i < 10; i++)
		{
			ss >> l.at(i);
			ss.ignore();

			l.at(i) *= 1000;
		}

		int d0 = 0;
		int d1 = accumulate(l.begin(), l.end(), 0);

		ss >> v0;
		ss.ignore();

		ss >> v1;

		for (; d0 < d1;)
		{
			d0 += v0;
			d1 -= v1;
		}

		int ll = 0;
		int x = 0;
		for (int i = 0; i < 10; i++)
		{
			ll += l.at(i);
			if (ll >= d0)
			{
				x = i + 1;
				break;
			}
		}

		cout << x << endl;
	}
}

#include <stdio.h>

int main(void){
	int n, a[100], i, j;
	char c, s[53] = {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++)
			scanf("%d",&a[i]);
		getchar();
		for(i = 0;(c = getchar()) != '\n';i++){
			for(j = 0;j < 52;j++){
				if(s[j] == c)
					printf("%c",s[(52 + j - a[i % n]) % 52]);
			}
		}
		printf("\n");
	}
	return 0;
}


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

int main(){
	string s;
	int n;
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++){
		getline(cin,s);
		while (1){
			int index = s.find("Hoshino");
			if (index == -1) break;
			s.replace(index,7,"Hoshina");
		}
		cout << s << endl;
	}
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){

  string S;
  cin>>S;
  if(S[0]!='A'){

    cout<<"WA";
    return 0;
  }
  bool Cflag=0;
  if('a'<=S[1]&&S[1]<='z'){
  }
  else{

    cout<<"WA";
    return 0;
  }
  for(size_t i=2;i<=S.length()-2;i++){

    if(S[i]=='C'){

      if(Cflag==1){

        cout<<"WA";
        return 0;
      }
      Cflag=1;
    }
    else if('a'<=S[i]&&S[i]<='z'){
    }
    else{

      cout<<"WA";
      return 0;
    }
  }
  if('a'<=S[S.length()-1]&&S[S.length()-1]<='z'&&Cflag==1){

  }
  else{
    cout<<"WA";
    return 0;
  }
  cout<<"AC";
  return 0;
}


#define alphanso                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(NULL)
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main()
{
	alphanso;
	int n, k, i, gcd = 0, x, mx = INT_MIN;
	cin >> n >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> x;
		gcd = __gcd(gcd, x);
		mx = max(mx, x);
	}
	if (mx < k)
		cout << "IMPOSSIBLE";
	else
		!(k % gcd) ? cout << "POSSIBLE" : cout << "IMPOSSIBLE";
	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int n,m;cin>>n>>m;
	int maxi = 0;

	for(int i = 1;i*i<=m;i++)
	{
		if(m%i) continue;

		int b = m/i;

		if(b >= n) maxi = max(maxi , i);

		if(i >= n) maxi = max(maxi , b);
	}

	cout<<maxi<<endl;

	return 0;
}


#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	long long int total = 0;

	for (int i = 1; i <= n; i++){
		if (i % 3 != 0 && i % 5 != 0){
			total += i;
		}
	}
	printf("%lld", total);

}

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	ll x;
	ll ans=0LL;
	cin >>x;
	ans += x / 500 * 1000;
	x %= 500;
	ans += x / 5 * 5;
	cout<<ans<<endl;
}


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

int n,a[1010][1010],h[1000100],dist[1000100];
vector<int>to[1000100];

int encode(int i, int j){
  if(i>j)swap(i,j);
  return i*n+j;
}

int main(){
  cin>>n;
  rep(i,n)rep(j,n-1){
    cin>>a[i][j];
    a[i][j]--;
  }
  rep(i,n)rep(j,n-2){
    int v=encode(i,a[i][j]);
    int u=encode(i,a[i][j+1]);
    to[v].push_back(u);
    h[u]++;
  }
  stack<int>st;
  rep(i,n*n)if(h[i]==0)st.push(i),dist[i]=1;
  while(st.size()){
    int v=st.top(); st.pop();
    for(int u:to[v]){
      h[u]--;
      if(h[u]==0)st.push(u);
      dist[u]=max(dist[u],dist[v]+1);
    }
  }
  int mx=0,in=0;
  rep(i,n*n)mx=max(mx,dist[i]);
  rep(i,n*n)in=max(in,h[i]);
  if(in!=0)cout<<-1<<endl;
  else cout<<mx<<endl;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

Int P[5050];
pair<int, int> A[5050];

int main() {
  int N = in();
  P[0] = 0;
  for (int u = 1; u <= N; ++u) {
    P[u] = INFLL;
  }
  for (int i = 0; i < N; ++i) {
    A[i].first = in();
    A[i].second = in();
  }
  sort(A, A + N, [] (const pair<int, int>& a, const pair<int, int>& b) {
    return a.first + a.second < b.first + b.second;
  });

  for (int i = 0; i < N; ++i) {
    int H = A[i].first;
    int Z = A[i].second;
    for (int u = i; u >= 0; --u) {
      if (P[u] <= H) {
        chmin(P[u + 1], P[u] + Z);
      }
    }
  }

  int res = 0;
  for (int u = 0; u <= N; ++u) {
    if (P[u] < INFLL) {
      chmax(res, u);
    }
  }
  printf("%d\n", res);

  return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

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

	return 0;
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#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 <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

constexpr int MAX_N = 200200;
constexpr LL mod = 1e9 + 7;

LL mul[MAX_N];
LL inv[MAX_N];

LL POW_MOD(LL N, LL P, LL M) {
    LL ret = 1;
    while (P > 0) {
        if (P & 1LL) ret = (ret * N) % M;
        N = (N * N) % M;
        P >>= 1LL;
    }
    return ret;
}

void setup() {
    mul[0] = mul[1] = 1;
    inv[0] = inv[1] = 1;
    for (LL i = 2; i <= MAX_N - 2; i++) {
        mul[i] = mul[i - 1] * i;
        mul[i] %= mod;
        inv[i] = POW_MOD(mul[i], mod - 2, mod);
    }
}

LL nCr_mod(LL n, LL r) {
    if (n < r) return 0;
    return mul[n] * inv[r] % mod * inv[n - r] % mod;
}

int main() {

    int H, W, A, B;
    cin >> H >> W >> A >> B;

    setup();

    LL ans = 0;

    int y = H - A - 1;
    int x = B;
    while (y >= 0 && x < W) {
        LL n = y + x;
        LL r = y;
        ans += (nCr_mod(n, r) * nCr_mod(W - x - 1 +  H - y - 1, H - y - 1)) % mod;
        ans %= mod;
        y--;
        x++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

struct data_t {
	int height;
	int width;
	int dia;

	bool operator<( const data_t& right) const {
		if (dia == right.dia) {
			return (height < right.height);
		}
		else {
			return ((dia == right.dia) || (dia < right.dia));
		}
	}
};

int main(void) {
	int h,w;
	int ind = 0;
	cin >> h;
	cin >> w;
	int lim = ((149-1)*149)/2;
	std::vector<data_t> all(lim);

	for (int i = 1; i < 150; i++) {
		for (int j = i+1; j < 151; j++) {
			all[ind].height = i;
			all[ind].width = j;
			all[ind].dia = pow(i,2) + pow(j,2);
			ind++;
		}
	}

	std::sort(all.begin(), all.end());

	while (h!=0||w!=0) {
		int d = pow(h,2) + pow(w,2);
		bool find = false;
		bool pro = false;
		for (int i = 0; i < lim && !find; i++) {
			if (pro) {
				cout << all[i].height << " " << all[i].width << endl;
				find = true;
			}
			else {
				if (h == all[i].height && w == all[i].width) {
					pro = true;
				}
			}
		}
		cin >> h;
		cin >> w;
	}

	return 0;
}

/*
My heart’s beating faster
I know what I’m after

I’ve been standing here my whole life
Everything I’ve seen twice
Now it’s time I realized
It’s spinning back around now
On this road I’m crawlin’
Save me 'cause I’m fallin’
Now I can’t seem to breathe right
'Cause I keep runnin' runnin' runnin' runnin'
Runnin' runnin' runnin' runnin'
Runnin' from my heart
*/

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

#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define slow_as_snail ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end()

const ll mod = 1000000007;
#define mx 10000005
const ll mxi = 100005;

int main()
{
    slow_as_snail;
    ll n,l;
    cin>>n>>l;
    if(abs(l)>n)
    {
        if(l<0)
        {
            l = abs(l);
            ll tm = l*(l+1)/2;
            tm = -1*tm;
            // cout<<tm<<"\n";
            ll tmp = (abs(l)-n+1) * (abs(l)-n+2)/2;
            cout<< tm + tmp;
        }
        else
        {
            ll tm = l+n-1;
            ll tmp = l*(l+1)/2;
            cout<<tm*(tm+1)/2 - tmp;
        }
    }
    else if(abs(l)<n)
    {
        if(l>0)
        {
            ll tm = l+n-1;
            ll tmp = l*(l+1)/2;
            cout<<tm*(tm+1)/2 - tmp;
        }
        else
        {
            l = abs(l);
            ll tm = l*(l+1)/2;
            ll tmp = (n-l-1)*(n-l)/2;
            cout<<tmp-tm;
        }
    }
    else
    {
        if(l<0)
        {
            l = abs(l);
            ll tmp = l*(l+1)/2;
            tmp = -1*tmp;
            cout<<tmp+1;
        }
        else
        {
            ll tm = l+n-1;
            ll tmp = l*(l+1)/2;
            cout<<tm*(tm+1)/2 - tmp;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<ll> V(n); rep(i, n) cin >> V[i];
  ll ans = 0;
  rep(i, k+1) rep(j, k+1) {
    int rem = k-(i+j);
    if(rem < 0) continue;
    if(i+j > n) continue;
    priority_queue<ll, vector<ll>, greater<ll>> q;
    rep(ii, i) q.push(V[ii]);
    rep(jj, j) q.push(V[n-1-jj]);
    rep(kk, rem) {
      if(q.empty()) break;
      if(q.top() >= 0) break;
      q.pop();
    }
    ll sum = 0;
    while(!q.empty()) {
      sum += q.top();
      q.pop();
    }
    chmax(ans, sum);
  }
  cout << ans << endk;
  return 0;
}

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

template <typename T,typename U>
struct compressor{
	vector<pair<T,U>> v;
	void add(T x,U y){
		v.emplace_back(x,y);
	}

	void compress(bool stable = false){

		if(stable){
			stable_sort(v.begin(),v.end(),[&] (pair<T,U> a,pair<T,U> b){
				return a.first < b.first;
			}
			);
		}
		else sort(v.begin(),v.end());

		vector<pair<T,U>> t;
		rep(i,v.size()){
			if(t.size()!=0 && t.back().first == v[i].first){
				t.back().second = func(t.back().second,v[i].second);
			}
			else{
				t.push_back(v[i]);
			}
		}
		swap(v,t);

	}

	U func(U a,U b){
		return a+b;
	}

	U e(){
		return 0;
	}

	int size(){
		return v.size();
	}

	pair<T,U> get(int p){
		return v[p];
	}

	U operator[] (T &x){
		auto it = lower_bound(v.begin(),v.end(),make_pair(x,e()));
		if(it==v.end() || it->first!=x){
			if(it!=v.begin()){
				it--;
			}
		}
		if(it==v.end() || it->first!=x){
			return e();
		}
		else return it->second;
	}

	U operator[] (T x){
		auto it = lower_bound(v.begin(),v.end(),make_pair(x,e()));
		if(it==v.end() || it->first!=x){
			if(it!=v.begin()){
				it--;
			}
		}
		if(it==v.end() || it->first!=x){
			return e();
		}
		else return it->second;
	}
};

bool f = false;
compressor<pair<string,string>,int> get(string S){
	int N = S.size();
	compressor<pair<string,string>,int> C;
	for(int i=0;i<(1<<N);i++){
		string s="",t="";
		for(int j=0;j<N;j++){
			if((i>>j)&1)s+=S[j];
			else t+=S[j];
		}
		reverse(t.begin(),t.end());
		if(f)swap(s,t);
		C.add(make_pair(s,t),1);
	}
	f=true;
	C.compress();
	return C;
}

int main(){

	int N;
	cin>>N;

	string S;
	cin>>S;

	compressor<pair<string,string>,int> C0 = get(S.substr(0,N)),C1 = get(S.substr(N));

	long long ans = 0;

	rep(i,C0.size()){
		ans += (long long)C0.get(i).second * C1[C0.get(i).first];
	}

	cout<<ans<<endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }

int main()
{
        ll N, K;
        cin >> N >> K;
        cout << N - K +1 << endl;
}

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

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

    if (a < 9 && b < 9) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<vector<pair<int,int>>> G(20);

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

    rep(i,n){
        int a;
        cin>>a;
        rep(j,a){
            int x,y;
            cin>>x>>y;
            x--;
            G[i].push_back({x,y});
        }
    }

    int ans=0;
    rep(bit,1<<n){
        int tmp=0;
        bool ok=true;
        rep(i,n){
            if(bit & 1<<i){
                tmp++;
                rep(j,G[i].size()){
                    int x=G[i][j].first;
                    int y=G[i][j].second;
                    if(y==0 && bit & 1<<x) ok=false;
                    else if(y==1 && !(bit & 1<<x)) ok=false;
                }
            }
        }

        if(ok) ans=max(ans,tmp);
    }

    cout<<ans<<endl;
}

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

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

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

  vector<int>A(N);
  vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2)));

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    for (int j = 0; j < A.at(i); j++) {
      for (int k = 0; k < 2; k++) {
        cin >> data.at(i).at(j).at(k);
      }
    }
  }

  int Max = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 15); tmp++) {
    bitset<15> s(tmp);  // 最大20個なので20ビットのビット列として扱う

    if (N < 15 && s.test(N)) {
      break;
    }
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int count = 0;
    int honest = 0;

    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        honest++;
        for (int j = 0; j < A.at(i); j++) {
          int B = data.at(i).at(j).at(0) - 1;
          if (s.test(B)){
            if (data.at(i).at(j).at(1) == 0){
              count++;
            }
          }
          else {
            if (data.at(i).at(j).at(1) == 1){
              count++;
            }
          }
        }
      }
    }
    if (count == 0){
      if (honest > Max){
        Max = honest;
      }
    }
  }

  cout << Max << endl;
}


#include <iostream>
using namespace std;

struct Node {
    Node *parent;
    Node *left;
    Node *right;
    int key;
};

Node *NIL, *root;

void init() {
    root = NIL;
}

void insert(int key) {
    Node *y = NIL;
    Node *x = root;
    while (x != NIL) {
        y = x;
        if (key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    Node *node = (Node *)malloc(sizeof(Node));
    node->parent = y;
    node->key = key;
    node->left = NIL;
    node->right = NIL;
    if (y == NIL) {
        root = node;
    } else if (key < y->key) {
        y->left = node;
    } else {
        y->right = node;
    }
}

Node* find(int key) {
    Node *x = root;
    while (x != NIL && x->key != key) {
        if (key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    return x;
}

void attachNodeToParent(Node *node, Node *attached) {
    if (node->parent->left == node) {
        node->parent->left = attached;
    } else {
        node->parent->right = attached;
    }
}

Node* findNextNode(Node *node) {
    Node *x;
    if (node->right != NIL) {
        x = node->right;
        while(x->left != NIL) {
            x = x->left;
        }
    } else {
        Node *y = node;
        x = node->parent;
        while(y == x->right) {
            y = x;
            x = x->parent;
        }
    }

    return x;
}

void deleteNode(Node *node) {
    if (node == NIL) {
        return;
    }

    Node *deleted;
    if (node->left == NIL || node->right == NIL) {
        deleted = node;
    } else {
        deleted = findNextNode(node);
    }

    Node *child;
    if (deleted->left != NIL) {
        child = deleted->left;
    } else {
        child = deleted->right;
    }

    if (child != NIL) {
        child->parent = deleted->parent;
    }

    if (deleted->parent == NIL) {
        root = child;
    } else if (deleted->parent->left == deleted) {
        deleted->parent->left = child;
    } else {
        deleted->parent->right = child;
    }

    if (deleted != node) {
        node->key = deleted->key;
    }

    free(deleted);
}

void printByPreorder(Node *node) {
    if (node == NIL) {
        return;
    }

    cout << " "<< node->key;
    printByPreorder(node->left);
    printByPreorder(node->right);
}

void printByInorder(Node *node) {
    if (node == NIL) {
        return;
    }

    printByInorder(node->left);
    cout << " "<< node->key;
    printByInorder(node->right);
}

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

    init();

    string command;
    int key;
    for (int i = 0; i < n; i++) {
        cin >> command;
        if (command == "insert") {
            cin >> key;
            insert(key);
        } else if (command == "find") {
            cin >> key;
            Node *node = find(key);
            if (node != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        } else if (command == "delete") {
            cin >> key;
            Node *node = find(key);
            deleteNode(node);
        } else {
            printByInorder(root);
            cout << endl;
            printByPreorder(root);
            cout << endl;
        }
    }

    return 0;
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int M;
vector<int> D; vector<ll> C;
int n = 0;
ll ans = 0;

ll memo[10][10] ={};
ll calcC(int n, int m){
    if(memo[n][m] != 0) return memo[n][m];
    deque<int> que;
    que.pb(n);
    rep(i, 9) que.pb(m);
    ll ret = 0;
    while(que.size() > 1){
        int a = que[0];
        int b = que[1];
        que.pop_front();
        que.pop_front();
        if(a+b >= 10){
            que.push_front((a+b)%10);
            que.push_front(1);
        }
        else{
            que.push_front(a+b);
        }
        ret++;
    }
    return memo[n][m] = ret;
}

void calc(deque<int> &que){
    while(que.size() > 1){
        int a = que[0];
        int b = que[1];
        que.pop_front();
        que.pop_front();
        if(a+b >= 10){
            que.push_front((a+b)%10);
            que.push_front(1);
        }
        else{
            que.push_front(a+b);
        }
        ans++;
    }
}

signed main(){
    cin >> M;
    rep(i, M){
        int d; ll c;
        cin >> d >> c;
        if(d == 0){
            ans += c;
        }
        else{
            if(n == 0){
                n = d;
                c--;
            }
            if(c > 0){
                D.pb(d);
                C.pb(c);
            }
        }
    }

    rep(i, D.size()){
        ll k = C[i] / 9;
        ans += k * calcC(n, D[i]);
        deque<int> d;
        d.pb(n);
        rep(j, C[i]-9*k) d.pb(D[i]);
        calc(d);
        n = d.front();
    }
    cout << ans << endl;
}


#include <cstdio>
#include <algorithm>
const int N = 6e3+5;
int n, P, f[N][N<<1], ans; void fix(int &x) { x<P?0:x-=P; }
int main()
{
    scanf("%d%d", &n, &P), n *= 3, f[0][N] = 1;
    for(int i = 0; i < n; ++i) for(int j = -i; j <= i; ++j)
        fix(f[i+1][j+1+N]+=f[i][j+N]),
        fix(f[i+2][j-1+N]+=f[i][j+N]*(i+1ll)%P),
        fix(f[i+3][j+N]+=f[i][j+N]*(i+1ll)*(i+2ll)%P);
    for(int i = 0; i <= n; ++i) fix(ans+=f[n][i+N]); printf("%d\n", ans);
    return 0;
}

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

set<ll> primeFactorization( ll n ){
  set<ll> a = {1};
  while( n != 1 ){
    ll root = (ll)sqrt(n);
    for(ll i=2;i<=n;++i){
	  if( i > root ){
        a.insert(n);
        n /= n;
        break;
      }
      if( n%i == 0 ){
        a.insert(i);
        n /= i;
        break;
      }
    }
  }
  return a;
}

int main() {
  ll a,b;cin >> a >> b;
  ll num = __gcd(a,b);
  set<ll> array = primeFactorization(num);

  //for( auto p : array ) cout << p << endl;
  cout << array.size() << endl;
  return 0;
}


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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int w, h;
int board[21][21];
int ans = INF;
bool valid(int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; }
void print() {
    rep(y, h) {
        rep(x, w) printf("%d ", board[y][x]);
        printf("\n");
    }
}
void dfs(int y, int x, int cnt) {
    // printf("debug: %d %d %d\n", y, x, cnt);
    // print();
    if (cnt == 10) return;
    rep(k, 4) {
        int ny = y;
        int nx = x;
        if (!valid(ny + dy[k], nx + dx[k])) continue;
        if (board[ny + dy[k]][nx + dx[k]] == 1) continue;
        while (1) {
            if (!valid(ny + dy[k], nx + dx[k])) break;
            ny += dy[k];
            nx += dx[k];
            if (board[ny][nx] == 3) {
                ans = min(cnt + 1, ans);
                return;
            }
            if (board[ny][nx] == 1) {
                board[ny][nx] = 0;
                dfs(ny - dy[k], nx - dx[k], cnt + 1);
                board[ny][nx] = 1;
                break;
            }
        }
    }
}
int main() {
    while (cin >> w >> h, w) {
        ans = INF;
        rep(i, h) rep(j, w) cin >> board[i][j];
        rep(y, h) rep(x, w) if (board[y][x] == 2) dfs(y, x, 0);
        if (ans == INF) ans = -1;
        cout << ans << endl;
    }
    return 0;
}

#include <iostream>
using namespace std;

int f[102][102];

bool dfs(int ys,int xs,int yg,int xg,int c){
  if(f[ys][xs]!=c)return 0;

  if(ys==yg && xs==xg)return 1;;

  f[ys][xs]=0;

  bool flag=0;
  flag += dfs(ys+1,xs,yg,xg,c);
  flag += dfs(ys-1,xs,yg,xg,c);
  flag += dfs(ys,xs+1,yg,xg,c);
  flag += dfs(ys,xs-1,yg,xg,c);
  return flag;
}

void set(int c,bool d,int x,int y){
  if(d==0){
    for(int i=0; i<4; i++){
      f[y][x+i]=c;
      f[y+1][x+i]=c;
    }
  }else if(d==1){
    for(int i=0; i<4; i++){
      f[y+i][x]=c;
      f[y+i][x+1]=c;
    }
  }
}
;
int main(){
  while(1){

  int w,h;
  cin >> w >> h;
  if(w==0 && h==0)break;

  int xs,ys;
  cin >> xs >> ys;
  int xg,yg;
  cin >> xg >> yg;
  int n;
  cin >> n;

  for(int i=0; i<n; i++){
    bool d;
    int c,x,y;
    cin >> c >> d >> x >> y;
    set(c,d,x,y);
  }

  if(dfs(ys,xs,yg,xg,f[ys][xs])){
    cout << "OK\n";
  }else{
    cout << "NG\n";
  }
  }

  return 0;
}


#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll kai(vector<ll> A, ll key) {
	ll an = 0;
	rep(i, A.size()) {
		an += (A.at(i) - 1) / key;
	}
	return an;
}
// index が条件を満たすかどうか
bool isOK(int index,vector<ll> A, int K) {
	if (kai(A,index) <= K) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(ll MA,vector<ll> A,ll K) {
	int left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = MA; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, A,K)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll HP[4];
int main() {
	ll H, W, A, B,an=0;
	cin >> H >> W >> A >> B;
	prenCkModp(H + W);
	for (ll i = 1; i <= H - A; i++) {
		an += (nCk(i + B-2, i-1) * nCk(H - i + W - B-1, W - B-1)) % mod;
	}
	cout << an % mod << endl;
}

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

typedef long long LL;

const int N = 3e5;
const LL MOD = 1e9+7;

inline LL dmod(LL x){
	return x%MOD;
}

LL fakto[N+5];

void pre(){
	fakto[0] = 1LL;
	for(int i=1;i<=N;i++){
		fakto[i] = dmod(fakto[i-1]*(LL)(i));
	}
	return;
}

LL fe(LL x, LL y){
	if(y==0) return 1LL;
	LL ret = fe(x,y/2);
	ret = dmod(ret*ret);
	if(y&1){
		ret = dmod(ret*x);
	}
	return ret;
}

LL nCr(LL x, LL y){
	LL tmp = dmod(fakto[y]*fakto[x-y]);
	tmp = fe(tmp,MOD-2);
	tmp = dmod(tmp*fakto[x]);
	return tmp;
}

LL step(int x, int y, int a, int b){
	int dx = a-x;
	int dy = b-y;
	int tot = dx+dy;
	return nCr(tot,dx);
}

int h,w,a,b;
int main(){
	pre();
	cin >> h >> w >> a >> b;
	LL ret = 0LL;
	for(int i=1;i<=h-a;i++){
		LL tmp = step(1,1,i,b);
		tmp = dmod(tmp*step(i,b+1,h,w));
		ret = dmod(ret+tmp);
	}
	cout << ret << endl;
	return 0;
}


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

int m = 0;
int count = 0;
int G[1000000];

void trace(int a[], int size) {
    for (int i = 0; i < size; ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", a[i]);
    }
    printf("\n");
}

void InsertionSort(int A[], int N, int g) {
    for (int i = g; i < N; ++i) {
        int key = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > key) {
            A[j+g] = A[j];
            j = j - g;
            count++;
        }
        A[j + g] = key;
    }
}

void ShellSort(int A[], int N) {
    int g = 0;
    while(true) {
        g = 3 * g + 1;
        if (g > N) { break; }
        G[m] = g;
        ++m;
    }
    for (int i = m - 1; i >= 0; --i) {
        InsertionSort(A, N, G[i]);
    }

}

int main() {
    int N;
    int A[1000000];

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

    ShellSort(A, N);

    printf("%d\n", m);
    for (int i = m - 1; i >= 0; --i) {
        printf("%d", G[i]);
        if (i > 0) printf(" ");
    }
    printf("\n");
    printf("%d\n", count);
    for (int i = 0; i < N; i++) {
        printf("%d\n", A[i]);
    }
    return 0;
}

#include<iostream>
using namespace std;

 int InsertionSort(int* a, int n, int g)
{
	int tmp, j, count = 0;
	for (int i = g; i < n; i++)
	{
		tmp = a[i];
		for (j = i - g; j >= 0 && a[j] > tmp; j -= g)
		{
			a[j + g] = a[j];
			count++;
		}
		a[j + g] = tmp;
	}
	return count;
}

int ShellSort(int* a, int n)
{
	int m, g[100],count = 0;
	for (m = 1; m * m * m <= n; m++)
		continue;
	m--;
	cout << m << endl;
	for (int i = 0; i < m; i++)
	{
	    g[i] = (m - i) * (m - i);
		if (i)
			cout << " ";
		cout << g[i];
	}
	for (int i = 0; i < m; i++)
		count += InsertionSort(a, n, g[i]);

	return count;
}

int main()
{
	int n, a[1000000], count;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	count = ShellSort(a, n);
	cout << endl << count << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << endl;

	return 0;
}


#include <iostream>
using namespace std;

int main(){
  while(true){
    int e;
    cin >> e;
    if(e == 0) break;

    int m;
    m = e;

    for(int z = 0 ; z * z * z <= e ; z++){
      for(int y = 0 ; y * y + z * z * z <= e ; y++){
	int x = e - z * z * z - y * y;
	if(m > x + y + z) m = x + y + z;
      }
    }
    cout << m << endl;
  }
}


#include<bits/stdc++.h>

using namespace std;
using P = pair<int,int>;

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

bool isBigger(P a, P b){
    // return a > b
    return (a.first > b.first) && (a.second > b.second);
}

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

    vector<P> A(N);
    vector<P> B(N);

    rep(i,N){
        cin >> A.at(i).first;
        cin >> A.at(i).second;
    }
    rep(i,N){
        cin >> B.at(i).first;
        cin >> B.at(i).second;
    }

    sort(A.begin(), A.end(), [](P left, P right)->bool{if(left.second == right.second)return left.first > right.first;
                                                        else return left.second > right.second;});
    sort(B.begin(), B.end(), [](P left, P right)->bool{if(left.first == right.first)return left.second < right.second;
                                                        else return left.first < right.first;});

    // cout << "A:" << endl;
    // for(P p : A)cout << p.first << " " << p.second << endl;

    // cout << "B:" << endl;
    // for(P p : B)cout << p.first << " " << p.second << endl;

    int res = 0;
    vector<bool> usedA(N,false);
    rep(i,N){
        P b = B.at(i);
        rep(j,N){
            if(usedA.at(j))continue;
            P a = A.at(j);
            if(isBigger(b,a)){
                // printf("make pair: a(%d, %d)\tb(%d, %d)\n", a.first, a.second, b.first, b.second);
                usedA.at(j) = true;
                res++;
                break;
            }
        }
    }

    cout << res << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num;
    while(cin>>num){
        char str;
        int hand[14]={};
        hand[num]++;
        for(int i=0;i<4;i++){
            cin>>str>>num;
            hand[num]++;
        }
        bool four=0,three=0,two[2]={};
        for(int i=1,j=0;i<14;i++){
            if(hand[i]==4)four=1;
            else if(hand[i]==3)three=1;
            else if(hand[i]==2){
                two[j]=1;
                j++;
            }
        }
        if(four)cout<<"four card"<<endl;
        else if(three&&two[0])cout<<"full house"<<endl;
        else if(three)cout<<"three card"<<endl;
        else if(two[1])cout<<"two pair"<<endl;
        else if(two[0])cout<<"one pair"<<endl;
        else{
            bool kawa=0;
            for(int i=1;i<=10;i++){
                if(hand[i]==1){
                    for(int j=0;j<5;j++){
                        if(j+i>13&&hand[1]!=1)break;
                        else if(j+i<14&&hand[i+j]!=1)break;
                        if(j==4)kawa=1;
                    }
                }
            }
            if(kawa)cout<<"straight"<<endl;
            else cout<<"null"<<endl;
        }

    }
}


#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    string s;
    cin >> s;

    transform(s.begin(), s.end(), s.begin(), [](char c) { return c - '0'; });

    int64_t n = s.size();
    vector<vector<int64_t>> dp(2, vector<int64_t>(n + 1));
    dp[0][0] = 0;
    dp[1][0] = 1;
    for (auto i : irange(0L, n)) {
        dp[0][i + 1] = min(dp[0][i] + s[i], dp[1][i] + (10 - s[i]));
        dp[1][i + 1] = min({dp[0][i] + s[i] + 1, dp[1][i] + (10 - s[i] - 1)});
    }

    cout << dp[0][n] << endl;
}

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

template<typename T>
class BinaryIndexedTree2D {
    int H;
    int W;
    std::vector<std::vector<T> > data2d;
public:
    BinaryIndexedTree2D(int H, int W) : H(H), W(W) {
        data2d.resize(H + 1, std::vector<T>(W + 1, 0));
    }

    T sum(int h, int w) {
        T res = 0;
        for (int i = h; i > 0; i -= i & -i) {
            for (int j = w; j > 0; j -= j & -j) {
                res += data2d[i][j];
            }
        }
        return res;
    }

    /**
     * 左上の座標(h1, w1), 右下の座標(h2, w2) に含まれる値の累積和
     */
    T sum(int h1, int w1, int h2, int w2) {
        return sum(h2, w2) - sum(h1 - 1, w2) - sum(h2, w1 - 1) + sum(h1 - 1, w1 - 1);
    }

    void add(int h, int w, ll x) {
        for (int i = h; i <= H; i += i & -i) {
            for (int j = w; j <= W; j += j & -j) {
                data2d[i][j] += x;
            }
        }
    }
};

ll N;
BinaryIndexedTree2D<ll> bit( 100, 100 );
constexpr ll base = 20;

int main() {
  std::cin >> N;

  ll ans = 0;

  rep( i, N ) {
    std::string A;
    std::cin >> A;

    bool fst = true;
    ll p = A.size();
    ll ten = 1;
    ll s = 0, num = 0;

    if( A.find('.') != std::string::npos ) repd( i, A.size() ) {
      if( A[i] != '0' ) {
        if( fst ) {
          p = i;
        }

        fst = false;
      }

      if( !fst && A[i] != '.' ) {
        num += (A[i]-'0')*ten;
        ten *= 10;
      }

      if( A[i] == '.' ) {
        s = p-i;
      }
    } else {
      rep( i, A.size() ) {
        num *= 10;
        num += A[i]-'0';
      }

      s = 0;
    }

    //std::cout << P(num, s) << endl;

    ll two = 0, five = 0;

    while( num % 2 == 0 ) {
      num /= 2;
      ++two;
    }

    while( num % 5 == 0 ) {
      num /= 5;
      ++five;
    }

    //std::cout << P(two-s, five-s) << endl;

    ans += bit.sum( -(two-s)+base, -(five-s)+base, 98, 98 );
    //std::cout << "sum: " << P(-(two-s)+base, -(five-s)+base) << endl;

    bit.add( two-s+base, five-s+base, 1 );
    //std::cout << "added: " << P(two-s+base, five-s+base) << endl;
  }

  std::cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>

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

    std::string s;
    std::getline(std::cin, s);
    std::vector<bool> dict(26, false);
    for (char c : s)
        dict[c - 'a'] = true;
    std::string r = "None";
    for (std::size_t i = 0; i < dict.size(); ++i) {
        if (!dict[i]) {
            r = i + 'a';
            break;
        }
    }
    std::cout << r << std::endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int n1 , n2;
	vector<int> val1 , val2 , ans;
	int input;

	cin >> n1 >> n2;

	for (int i = 0; i < n1; i++)
	{
		cin >> input;
		val1.push_back(input);
		ans.push_back(0);
	}
	for (int i = 0; i < n2; i++)
	{
		cin >> input;
		val2.push_back(input);
	}

	for (int i = 0; i < n2; i++)
	{
		for (int j = 0; j < n1; j++)
		{
			if (val2[i] >= val1[j])
			{
				ans[j]++;
				break;
			}
		}
	}

	int Max = -100;
	int index = -1;

	for (int i = 0; i < ans.size(); i++)
	{
		if (ans[i] > Max)
		{
			Max = ans[i];
			index = i;
		}
	}

	cout << index + 1 << endl;

	return 0;
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string S; cin >> S;
    const int N = S.size();
    int K; cin >> K;
    int res = 0;
    vector<vector<vector<int>>> dp(K+1, vector<vector<int>>(N, vector<int>(N, 0)));
    for(int d=N-1;d>=0;d--){
        for(int i=0;i+d<N;i++){
            int j = i+d;
            for(int k=0;k<=K;k++){
                if(k < K && S[i] != S[j]){
                    res = max(res, dp[k][i][j] + 2);
                    if(i+1 < N && j > 0){
                        dp[k+1][i+1][j-1] = max(dp[k+1][i+1][j-1], dp[k][i][j] + 2);
                    }
                }
                if(S[i] == S[j]){
                    res = max(res, dp[k][i][j] + (i==j ? 1 : 2));
                    if(i+1 < N && j > 0){
                        dp[k][i+1][j-1] = max(dp[k][i+1][j-1], dp[k][i][j] + (i==j ? 1 : 2));
                    }
                }
                if(i+1 < N) dp[k][i+1][j] = max(dp[k][i+1][j], dp[k][i][j]);
                if(j > 0) dp[k][i][j-1] = max(dp[k][i][j-1], dp[k][i][j]);
            }
        }
    }
    cout << res << endl;
}


/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=1e2;
int A[N+10];
int main(){
	int n=read(),m=read(),cnt=0;
	for (int i=1;i<=m;i++)	A[i]=read(),cnt+=A[i]&1;
	if (cnt>2){
		printf("Impossible\n");
		return 0;
	}
	for (int i=1;i<=m;i++)	if (A[i]&1)	swap(A[1]&1?A[m]:A[1],A[i]);
	if (m==1){
		if (A[1]==1){
			printf("1\n1\n1\n");
			return 0;
		}
		printf("%d\n2\n1 %d\n",A[1],A[1]-1);
		return 0;
	}
	for (int i=1;i<=m;i++)	printf("%d",A[i]),putchar(i==m?'\n':' ');
	printf("%d\n%d ",m-(A[m]==1),A[1]+1);
	for (int i=2;i<m;i++)	printf("%d ",A[i]);
	if (A[m]!=1)	printf("%d\n",A[m]-1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

	int N;
	while(cin>>N,N){
		vector<int> vi(N*N,0),vi2(N*2+1,0);
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				int num;
				cin>>num;
				vi[i*N+j]=num;
				sum+=num;
			}
			vi2[i]=sum;
		}
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				sum+=vi[i+j*N];
				printf("%5d",vi[i*N+j]);
			}
			printf("%5d\n",vi2[i]);
			vi2[N*2]+=vi2[i];
			vi2[N+i]=sum;
		}
		for(int i=0;i<=N;i++){
			printf("%5d",vi2[N+i]);
		}
		cout<<endl;
	}

	return 0;
}


#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // dist between two elements
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // 小数点を10桁まで表示
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1001001001;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;};
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); };

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 71
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

PI solve(string &s) {
  int n = s.size();
  vvi table(26);
  rep(i, 0, 26) {
    char ch = 'a'+i;
    rep(j, 0, n) {
      if (s[j] == ch) table[i].pb(j);
    }
  }

  rep(i, 0, 26) {
    rep(j, 0, table[i].size()-1) {
      if (table[i][j+1]-table[i][j] < 3) {
        return make_pair(table[i][j]+1,table[i][j+1]+1);
      }
    }
  }

  return make_pair(-1, -1);
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  PI ans = solve(s);
  cout << ans.first << " " << ans.second << endl;

  return 0;
};

#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    forn(i, n - 1){
        if (s[i] == s[i + 1]){
            cout << i + 1 << ' ' << i + 2 << '\n';
            return;
        }
    }
    forn(i, n - 2){
        if (s[i] == s[i + 2]){
            cout << i + 1 << ' ' << i + 3 << '\n';
            return;
        }
    }
    cout << "-1 -1\n";
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}