#include <bits/stdc++.h>
#include <set>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 998244353;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<vector<int>> children;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> s(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)cin >> s.at(i).at(j);
  }
  vector<vector<int>> table(h,vector<int>(w,-1));
  queue<pii> q;
  q.push(pii(0,0));
  table.at(0).at(0) = 1;
  bool flag = false;
  int count;
  while(!q.empty()){
    pii tmppair = q.front();
    q.pop();
    int x,y;
    tie(x,y) = tmppair;
    set<pii> se;
    if(x-1 >= 0)se.insert(pii(x-1,y));
    if(x+1 < h)se.insert(pii(x+1,y));
    if(y-1 >= 0)se.insert(pii(x,y-1));
    if(y+1 < w)se.insert(pii(x,y+1));
    for(auto t:se){
      int tx,ty;
      tie(tx,ty) = t;
      if(s.at(tx).at(ty) == '.' && table.at(tx).at(ty) == -1){
        table.at(tx).at(ty) = table.at(x).at(y) + 1;
        q.push(t);
      }
      if(t == pii(h-1,w-1)){
        count = table.at(tx).at(ty);
        flag = true;
        break;
      }
    }
    if(flag) break;
  }
  if(!flag) cout << -1 << endl;
  else{
    int count2 = 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(s.at(i).at(j) == '#')count2++;
      }
    }
    cout << h * w - count - count2 << endl;
  }
}

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

const int N = 200;
const int S = 100005;
const int mo = 1e9 + 7;

int n, x;
int a[N + 5];
int f[N + 5][S + 5];

int main() {
#ifdef Wearry
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

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

  sort(a, a + n, greater<int>());

  f[0][x] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j <= x; ++j) if (f[i][j]) {
      f[i + 1][j % a[i]] = (f[i + 1][j % a[i]] + f[i][j]) % mo;
      f[i + 1][j] = (f[i + 1][j] + 1ll * f[i][j] * (n - 1 - i)) % mo;
    }

  int ans = 0;
  for (int i = 0; i <= x; ++i) {
    ans = (ans + 1ll * f[n][i] * i) % mo;
  }
  cout << ans << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int n, q;
    cin >> n >> q;
    int s[200005], t[200005], x[200005];
    P p[400005];
    for(int i = 0; i < n; i++){
        cin >> s[i] >> t[i] >> x[i];
        p[i * 2] = P(s[i] - x[i], x[i]);
        p[i * 2 + 1] = P(t[i] - x[i], -x[i]);
    }
    sort(p, p + n * 2);
    set<int> st;
    int i = 0;
    while(q--){
        int d;
        cin >> d;
        while(i < n * 2 && p[i].first <= d){
            if(p[i].second > 0) st.insert(p[i].second);
            else st.erase(-p[i].second);
            i++;
        }
        if(st.empty()) cout << -1 << endl;
        else cout << *st.begin() << endl;
    }
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
    int N, Q; cin >> N >> Q;
    vector<tuple<ll, ll, ll>> v(N);
    rep(i, N){
        ll s, t, x; cin >> s >> t >> x;
        v[i] = {x, s, t};
    }
    // map<ll, ll> d;
    set<ll> d;
    map<ll, ll> m;
    rep(i, Q){
        ll tmp; cin >> tmp;
        // d[tmp] = 1;
        d.insert(tmp);
        m[tmp] = -1;
    }
    sort(all(v));
    rep(i, N){
        // auto it1 = lower_bound(all(d), get<1>(v[i])-get<0>(v[i]));
        // auto it2 = lower_bound(all(d), get<2>(v[i])-get<0>(v[i]));
        auto it1 = d.lower_bound(get<1>(v[i])-get<0>(v[i]));
        auto it2 = d.lower_bound(get<2>(v[i])-get<0>(v[i]));
        // while(it1 != it2) {
        //     m[*it1] = x[i];
        //     d.erase(it1);
        // }
        while(it1 != it2){
            // m[it1->first] = get<0>(v[i]);
            m[*it1] = get<0>(v[i]);
            d.erase(it1++);
        }
    }
    for(auto p: m){
        cout << p.second << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  int64_t N, M, p, acc = 0, wac = 0;
  string s;
  cin >> N >> M;
  map<int, int> wa{};
  vector<bool> ac(N, false);
  for (int i = 0; i < M; i++) {
    cin >> p >> s;
    p--;
    if (s == "AC" && !ac[p]) ac[p] = true;
    if (s == "WA" && !ac[p]) wa[p]++;
  }

  for (int i = 0; i < N; i++) {
    if (ac[i]) {
      acc++;
      wac += wa[i];
    }
  }
  cout << acc << " " << wac << endl;
}

#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

std::vector<int> topologicalSort(const Graph &G) {
    int n = (int)G.size();
    std::vector<int> cntIn(n);
    for (auto vec : G) {
        for (int x : vec) {
            cntIn.at(x)++;
        }
    }

    std::vector<int> res;
    std::stack<int> st;
    for (int i=0; i<n; i++) {
        if (cntIn.at(i) == 0) {
            st.push(i);
        }
    }
    while (!st.empty()) {
        int cur = st.top(); st.pop();
        res.push_back(cur);
        for (int x : G.at(cur)) {
            cntIn.at(x)--;
            if (cntIn.at(x) == 0) {
                st.push(x);
            }
        }
    }

    return res;
}

void solve() {
    int n, m;
    cin >> n >> m;
    Graph G(n);
    for (int i=0; i<n+m-1; i++) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).push_back(b-1);
    }

    auto sorted = topologicalSort(G);
    vector<int> res(n, 0);
    for (int x : sorted) {
        for (int nx : G.at(x)) {
            res.at(nx) = x + 1;
        }
    }

    for (int x : res) {
        cout << x << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,n,x,y,z,i=0,ans=0,c=0;
    string s;
    cin >> x >> y >> z;
    cout << z << " "<< x << " "<< y << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;

int main() {
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    int M[H+1][W+1];
    rep3(i,H){
        rep3(j,W){
            if(((i<=B)&&(j<=A))||((i>B)&&(j>A))){
                M[i][j]=1;
            }
            else{
                M[i][j]=0;
            }
        }
    }
    rep3(i,H){
        rep3(j,W){
            if(j!=W){
                cout<<M[i][j];
            }
            else{
                cout<<M[i][j]<<endl;
            }
        }
    }

return 0;
}


// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll x;cin>>x;
   ll res=(x%11<=6)? ((x%11==0)? (x/11)*2:(x/11)*2+1):(x/11)*2+2;
   cout<<res<<endl;
    return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s[0]=='7')
        cout<<"Yes"<<endl;
    else if(s[1]=='7')
        cout<<"Yes"<<endl;
    else if(s[2]=='7')
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

int main(){
  ll N;cin>>N;
  vector<int> A(N);rep(i,N)cin>>A[i];
  map<int,int> m;
  ll ans = 1;
  rep(i,N){
    m[A[i]]++;
    if(A[i]==0){
      ans *= 4 - m[0];
    }
    else{
      ans *= (m[A[i]-1] - m[A[i]] + 1);
    }
    ans %= mod;
  }
  cout << ans << endl;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        if(i==0&&a!=0) {
            cout << -1 << endl;
            return 0;
        }
        if(tmp+1<a) {
            cout << -1 << endl;
            return 0;
        }
        else {
            if(tmp+1>a) {
                ans += a;
            }
            else {
                ans += a-tmp;
            }
        }
        tmp = a;
    }
    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 rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

int  main()
{
	int n;
	cin >> n;
	vector <long> a(n);
	rep(i, n)
		cin >> a[i];
	vector <long> b(n, 0);
	ll sum = 0;
	long max = a[0];
	int i = 0;
	while (i < n)
	{
		if (max < a[i])
			max = a[i];
		else if (a[i] < max)
			sum += max - a[i];
		i++;
	}
	cout << sum << endl;
	return (0);
}

#include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    long long A[N];
    long long count = 0;
    long long sum=0;
    long long ans ;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i] < 0)count++;
        sum += abs(A[i]);
    }

    if(count % 2 == 0){
        ans = sum;
    }
    else{
        ans = 0;
        for(int i=0;i<N;i++){
            ans = max(ans,sum-abs(A[i])*2);
        }
    }
    cout << ans << endl;
}


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

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

#define MAXX 10005

#define PI   3.14159265358979323846264338327950

#define F first
#define S second

#define ll 	 long long int

#define mod  1000000007

int main()
{
	FAST;
	ll n;
	ll a, b;
	cin >> a >> b;
	if(a <= 8 && b <= 8){
		cout << "Yay!";
		return 0;
	}
	cout << ":(";
	return 0;
}

        #include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;
        const int N=500;
        void solve()
        {
            ll i,j,k,n,m,c=0,ans=0;
            string s;
            cin>>n>>m;
            if(abs(n-m)<=16-n-m)
                cout<<"Yay!";
            else cout<<":(";

    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> P;
//-----------------------------------------------------------------------

vector<pair<int,P> > p;

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

    for(int i=1;i<=150;i++){
        for(int j=i+1;j<=150;j++){
            p.pb(make_pair(i*i+j*j,P(i,j)));
        }
    }
    sort(p.begin(),p.end());

    int h,w;
    while(cin>>h>>w,h+w){
        pair<int,P> q=make_pair(h*h+w*w,P(h,w));
        pair<int,P> r=*upper_bound(p.begin(),p.end(),q);
        cout<<r.second.first<<" "<<r.second.second<<endl;
    }
}

#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

char ch;
string text;

int main() {
    while(getline(cin,text)){
    	for(int i=0;i<26;i++){
    		for(int j=0;j<text.size();j++){
    			if(text[j]>='a'&&text[j]<='y')text[j]+=1;
    			else if(text[j]=='z')text[j]='a';
    		}
    		int p=text.find("the"),q=text.find("this"),r=text.find("that");
    		if(p!=string::npos||q!=string::npos||r!=string::npos){
    			cout<<text<<endl;
    			break;
    		}
    	}
    }
}


#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 2020;
const int Q = N * N;
const int mod = 1e9 + 7;

using namespace std;

int pw(int x, int n)
{
        int res = 1;
        for(; n > 0; n >>= 1){
                if(n & 1){
                        res = 1ll * res * x % mod;
                }
                x = 1ll * x * x % mod;
        }
        return res;
}

int fac[Q], inv[Q];

void make()
{
        fac[0] = 1;
        for(int i = 1; i < Q; i++) fac[i] = fac[i - 1] * 1ll * i % mod;
        inv[Q - 1] = pw(fac[Q - 1], mod - 2);
        for(int i = Q - 2; i >= 0; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
}

int C(int n, int k)
{
        if(k < 0 || k > n) return 0;
        return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod;
}

void add(int &x, int y)
{
        x += y;
        if(x >= mod){
                x -= mod;
        }
}

int n, k;
int d[N][N];

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

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        make();

        cin >> n >> k;
        if(k == 1){
                cout << 1 << "\n";
                return 0;
        }
        d[0][0] = 1;
        for(int i = 0; i <= n; i++){
                for(int j = i; j <= n; j++){
                        if(i > 0)add(d[i][j], d[i - 1][j]);
                        if(j > 0)add(d[i][j], d[i][j - 1] * 1ll * C(j * (k - 1) + i - 1, k - 2) % mod);
                }
        }
        cout << d[n][n] * 1ll * fac[n] % mod << "\n";
}


#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int l1 = 1, r1 = 2 + ((m - 1)/2) * 2;
    int l2 = r1 + 1, r2 = l2 + 2 + ((m - 2)/2) * 2;
    //cout << l1 << " " << r1 << " " << l2 << " " << r2 << endl;
    while(l1 < r1 && m > 0) {
        cout << l1 << " " << r1 << endl;
        l1++; r1--;
        m--;
    }
    while(l2 < r2 && m > 0) {
        cout << l2 << " " << r2 << endl;
        l2++; r2--;
        m--;
    }

    return 0;
}
// 1 2 3 4 5
// . .
//     .   .

// 1 2 3 4 5 6 7 8
// .     . .   .
//   . .

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    if(m==1){
        cout << "1 2" << endl;
        return 0;
    }

    int i1 = 1;
    int i2 = m + 2;
    for(int diff = m;diff >= 1;diff--){
        cout << i1 << " " << i1 + diff << endl;
        i1++;
        swap(i1,i2);
    }
}


#include <stdio.h>

typedef struct _Gem{
	int x;
	int y;
	bool hit;
} Gem;

static void
pick_gem(Gem* g, int n, int x, int y)
{
	for (int i = 0; i < n; i++) {
		if (!g[i].hit && g[i].x == x && g[i].y == y) {
			g[i].hit = true;
			return;
		}
	}
}

static bool
check_gem(Gem* g, int n)
{
	for (int i = 0; i < n; i++) {
		if (g[i].hit == false) {
			return false;
		}
	}

	return true;
}

int
main(void)
{

	char line[80];
	int n;
	int m;

	Gem g[20];

	char d[30];
	int l[30];

	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			return 1;
		}
		if (sscanf(line, "%d", &n) != 1) {
			return 1;
		}

		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			if (fgets(line, sizeof line, stdin) == NULL) {
				return 1;
			}
			if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) {
				return 1;
			}
			g[i].hit = false;
		}

		if (fgets(line, sizeof line, stdin) == NULL) {
			return 1;
		}
		if (sscanf(line, "%d", &m) != 1) {
			return 1;
		}

		for (int i = 0; i < m; i++) {
			if (fgets(line, sizeof line, stdin) == NULL) {
				return 1;
			}
			if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) {
				return 1;
			}
		}

		int x = 10;
		int y = 10;
		for (int i = 0; i < m; i++) {
			if (d[i] == 'N') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, x, ++y);
				}
			} else if (d[i] == 'S') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, x, --y);
				}
			} else if (d[i] == 'E') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, ++x, y);
				}
			} else {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, --x, y);
				}
			}
		}
		printf("%s\n", (check_gem(g, n) ? "Yes" : "No"));
	}

	return 0;
}

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

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

int main()
{
  while(1){
    int N;
    cin >> N;
    if(N == 0){
      break;
    }else{
      int x, y;
      int planet[21][21];
      fill(&planet[0][0], &planet[21][0], 0);
      REP(i, N){
        cin >> x >> y;
        planet[x][y] = 1;
      }
      int M;
      char d;
      int l;
      int px, py;
      px = py = 10;
      cin >> M;
      REP(i, M){
        cin >> d >> l;
        if(d == 'N'){
          REP(j, l + 1)
            planet[px][py + j] = 0;
          py += l;
        }else if(d == 'E'){
          REP(j, l + 1)
            planet[px + j][py] = 0;
          px += l;
        }
        else if(d == 'S'){
          REP(j, l + 1)
            planet[px][py - j] = 0;
          py -= l;
        }else{
          REP(j, l + 1)
            planet[px - j][py] = 0;
          px -= l;
        }
      }
      int c = 0;
      REP(i, 21)
        REP(j, 21)
          if(planet[i][j])
            c++;
      if(c)
        cout << "No" << endl;
      else
        cout << "Yes" << endl;
    }
  }
}


#include <iostream>
using namespace std;

int main() {
	int R, G, T;

	cin >> R;
	cin >> G;

	T = (2 * G) - R;

	cout << T << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 2000000;
const int MOD = 998244353;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
 int n,m;
 cin>>n>>m;
 COMinit();
 int ans=n*COM(m+n-2,m)%MOD;
 for(int i=m;3*m-2*i>=0;i++){
     ans=(ans + (COM(i+n-1,i) +(MOD - n*COM(i-m+n-1,i-m)%MOD))*COM(n,3*m-2*i)%MOD)%MOD;
 }
 cout<<ans;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define put(x) std::cout << x << endl;
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

// Segment tree
struct F { // min func
  typedef int TT;
  TT d;
  F(TT d=INF):d(d) {}
  F& operator+=(const F& f) {
    mins(d, f.d);
    return *this;
  }
  F operator+(const F& f) const { return F(*this) += f;}
};
struct seg {
  vector<F> d; int n;
  seg(){}
  seg(int mx) {
    n = 1; while (n < mx) n <<= 1;
    d = vector<F>(n<<1);
  }
  void upd(int i) { d[i] = d[i<<1]+d[i<<1|1];}
  F& operator[](int i) { return d[n+i];}
  void init() { for(int i=n-1;i;--i) upd(i);}
  void add(int i, F f) { for (i+=n,d[i]+=f,i>>=1;i;i>>=1) upd(i);}
  void set(int i, F f) { for (i+=n,d[i]=f,i>>=1;i;i>>=1) upd(i);}
  F get(int l, int r) {
    l += n; r += n;
    F lf, rf;
    while (l < r) {
      if (l&1) lf += d[l++];
      if (r&1) rf = d[--r] + rf;
      l >>= 1; r >>= 1;
    }
    return lf += rf;
  }
};

void Main()
{
    ll H, W;
    cin >> H >> W;

    vector<ll> A(H), B(H);
    rep(i, H) cin >> A[i] >> B[i];

    map<int, int> a;
    rep(i, W) a[i] = i;

    seg t(W+5);
    rep(i, W) t.add(i, F(0));

    rep(i, H) {
        ll l = A[i]-1;
        ll r = B[i];

        ll maxX = -1;
        for (auto it = a.lower_bound(l); it != a.end() && it->first < r; a.erase(it++)) {
            maxX = std::max(maxX, (ll)it->second);
            t.set(it->first, F(INF)); // invalid
        }

        if (r < W && maxX >= 0) {
            if (0 == a.count(r)) a[r] = -1;
            a[r] = max(a[r], (int)maxX);
            t.set(r, F(r - a[r]));
        }

        ll res = 1 + i + t.get(0, W).d; // get minimum
        if (res > INF) {
            put(-1);
        }
        else {
            put(res);
        }
    }

}
signed main(){ Main();return 0;}

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

int main() {
    int h, w;
    cin >> h >> w;
    map<int,int> s;
    multiset<int> vals;
    rep(i,w) s[i] = i;
    rep(i,w) vals.insert(0);
    rep(i,h) {
        int l, r;
        cin >> l >> r;
        --l;
        auto it = s.lower_bound(l);
        int mr = -1;
        while (it != s.end() && it->first <= r) {
            mr = max(mr, it->second);
            int x = it->first - it->second;
            vals.erase(vals.find(x));
            s.erase(it++);
        }
        if (mr != -1 && r < w) {
            vals.insert(r - mr);
            s[r] = mr;
        }
        int ans = -1;
        if (vals.size() > 0) {
            ans = *vals.begin() + (i+1);
        }
        cout << ans << endl;
    }
    return 0;
}


#include <cstdio>
//#include <iostream>
//#include <string>

using namespace std;

// cl /EHsc xxx.cpp
int main(int argc, char *argv[])
{
	int n;
	scanf("%d", &n);

	int *ary = new int[n];

	int v;
	int t = n;
	while (t)
	{
		scanf("%d", &v);
		ary[--t] = v;
	}

	for (int j = 0; j < n; j++)
	{
		printf((j == n-1) ? "%d\n" : "%d ", ary[j]);
	}

	delete[] ary;

	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cout << a[n - 1 - i];
        if(i == n - 1) break;
        cout << ' ';
    }
    cout << endl;
}


#include <stdio.h>

int main(){
	int date[11];
	for(int i = 0; i < 10; i++){
		scanf("%c", &date[i]);
	}

	for(int i = 0; i < 10; i++){
		date[3] = '8';
		printf("%c", date[i]);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(void){

    //*
    string a;
    cin >> a ;
    //*/

    a.at(3) = '8';

    /*
    vector<int> vec(4);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

    sort(vec.begin(), vec.end());
    */

    /*
    if(a == 0){
        cout << "" << endl;
    } else if(a > 0){
        cout << "" << endl;
    } else {
        cout << "" << endl;
    }
    */

    cout << a << endl;

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;
using Graph = vector<vector<int>>;

static long long INF = (1LL<<62);

LL N, M;
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> M;

	if(N == 1){
		printf("%lld\n", M);
		return 0;
	}

	vector<LL> D;
	for(LL d = 2; d * d <= M; d++){
		if((M % d) == 0){
			D.push_back(d);
			D.push_back(M/d);
		}
	}
	sort(D.begin(), D.end());

	long long ans = 1;
	for(int i=D.size()-1; i>=0; i--){
		if( (M / D[i]) >= N && D[i] > ans){
			ans = D[i];
		}
	}

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

#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N >> M;
  int n = M/N;
  for(int i=n;i>0;i--)
  {
    if((M-(N-1)*i)%i==0)
    {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


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

class Dice_c{

private:
  int me[4];
  int topbot[2]; // top,bottom

public:
  void Input();
  void Roll(char c);
  void Output();

};

int main(){

  Dice_c dice;
  char com;

  dice.Input();

  while(1){
    scanf("%c",&com);

    if(com=='\n')
      break;

    dice.Roll(com);

  }

  dice.Output();

  return 0;
}

///////////////////////////////////////

void Dice_c::Input(){

  cin >> me[1] >> topbot[1] >> me[2] >> me[0] >> topbot[0] >> me[3];
  getchar();

}

void Dice_c::Roll(char c){

  int tmp;

  if(c == 'W'){
    tmp = me[0];
    me[0]=me[1] , me[1]=me[2] , me[2]=me[3] , me[3]=tmp;
  }
  else if(c == 'E'){
    tmp = me[3];
    me[3]=me[2] , me[2]=me[1] , me[1]=me[0] , me[0]=tmp;
  }
  else if(c == 'N'){
    tmp = topbot[1];
    topbot[1]=me[3] , me[3]=topbot[0] , topbot[0]=me[1] , me[1]=tmp;
  }
  else{
    tmp = topbot[0];
    topbot[0]=me[3] , me[3]=topbot[1] , topbot[1]=me[1] , me[1]=tmp;
  }

  /*
  cout << "  " << topbot[0] << endl;
  for(int i=0; i<4; i++)
    cout << me[i] << ' ';
  cout << endl << "  " << topbot[1] << endl;
  */

}

void Dice_c::Output(){

  cout << me[1] << endl;

}

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

class Dice{
	int top, n, s, e, w;
public:
	Dice();
	void roll(char dir);
	int getTop();
};

Dice::Dice(){
	top = 1;
	n = 5;
	s = 2;
	e = 3;
	w = 4;
}

void Dice::roll(char dir){
	switch (dir){
	case 'N':
		n = top;
		top = s;
		s = 7 - n;
		break;
	case 'S':
		s = top;
		top = n;
		n = 7 - s;
		break;
	case 'E':
		e = top;
		top = w;
		w = 7 - e;
		break;
	case 'W':
		w = top;
		top = e;
		e = 7 - w;
		break;
	}
}

int Dice::getTop(){
	return top;
}

int main(void){
	int num[6];
	string str;
	Dice dice;

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

	cin >> str;

	for (int i = 0; i < str.size(); i++){
		dice.roll(str[i]);
	}

	cout << num[dice.getTop()-1] << "\n";

	return 0;
}


#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n;

inline PA Get(int d,ll c){
	if (c==1) return {d,0};
	PA tmp=Get(d,c/2);
	tmp.se=(tmp.se*2+1+(tmp.fi*2>=10));
	if (tmp.fi*2>=10) tmp.fi=(tmp.fi*2)/10+(tmp.fi*2)%10;
		else tmp.fi*=2;
	if (c&1){
		tmp.se=tmp.se+1+(tmp.fi+d>=10);
		tmp.fi=(tmp.fi+d)/10+(tmp.fi+d)%10;
	}
	return tmp;
}

int main(){
	n=read();
	ll x=0,ans=0;
	For(i,1,n){
		ll d=read(),c=read();
		PA tmp=Get(d,c);
		ans+=tmp.se;
		if (i!=1) ans++;
		ans+=(x+tmp.fi>=10);
		x=(x+tmp.fi)/10+(x+tmp.fi)%10;
		//printf(" %lld %lld\n",x,ans);
	}
	printf("%lld\n",ans);
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
ll c[200100], d[200100];

int main() {
	int m;
	cin >> m;
	rep(i,m) cin >> d[i] >> c[i];
	ll s = 0, len = 0;
	rep(i,m) {
		s += c[i] * d[i];
		len += c[i];
	}
	ll ans = (len-1) + ((s-1)/9);
	cout << ans << endl;

	return 0;
}


#include <iostream>
using namespace std;
int main(){
	long long int n,i=1,a=0;
	cin >> n;
	while (i <= n) {
		if (i % 3 != 0 && i % 5 != 0)
			a += i;
		i++;
	}
	cout << a;
}

///f. fizzbuzz sequence
#include <stdio.h>
#include <math.h>

int main()
{
    long long int n;
    scanf("%lld",&n);
    long long int d3,d5,d15;
    d3=n/3; d5=n/5; d15=n/15;

    long long sum = (n*(n+1)-3*d3*(d3+1)-5*d5*(d5+1)+15*d15*(d15+1))/2;
    printf("%lld",sum);
    return 0;
}


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

int main(){
    map<string, int> weekday;
    weekday["SUN"] = 0;
    weekday["MON"] = 1;
    weekday["TUE"] = 2;
    weekday["WED"] = 3;
    weekday["THU"] = 4;
    weekday["FRI"] = 5;
    weekday["SAT"] = 6;

    string day;
    std::cin >> day;

    std::cout << 7 - weekday[day];

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	int ans=log10(n)+1;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0){
			ans=max(log10(i)+1,log10(n/i)+1);
		}
	}
	cout << ans << endl;
	return 0;
}


//Partition

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

bool IsPrime(int num){
    if(num<2)return false;
    else if(num==2)return true;
    else if(num%2==0)return false;
    double sqrtNum=sqrt(num);
    for (int i=3;i<=sqrtNum;i+=2)if(num%i==0)return false;
    return true;
}

signed main (){
    int n,m,ans=1;cin>>n>>m;
    if(n==1){cout<<m<<nnn;return 0;}
    if(IsPrime(m)){cout<<1<<nnn;return 0;}
    for(int i=2;i*i<1000001000;i++){
        if(m%i==0&&m/i>=n){
            ans=max(ans,i);
            if(i>=n){
                ans=max(ans,m/i);
            }
        }
    }
    cout<<ans<<nnn;
    return 0;
}


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

int main() {
  int N,k;
  cin >> N >>k;
  int sum;
  if(k==1){
	sum = N+1;
  }
  else if(k==2||k==3||k==4){
    if (N==1){
      sum = 2;
    }
    else{
    sum = 4 + k*(N-2);
    }
  }
  else if(k==5||k==6||k==7){
    if (N==1){
      sum = 2;
    }
    else if(N==2){
      sum = 4;
    }
    else{
    sum = 8 + k*(N-3);
    }
  }
  else{
    if (N==1){
      sum = 2;
    }
    else if (N==2){
      sum = 4;
    }
    else if (N==3){
      sum = 8;
    }
    else{
    sum = 16 + k*(N-4);
    }
  }
  cout<<sum<<endl;
}

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

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

  int x = 1;

  for (int i = 0; i < N; i++) { // iのスコープはforの終わりまで

    if( x * 2 <= x + K ){
      x *= 2;

    }

    else {
      x += K;

    }
  }

  cout << x <<endl;
}


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

int main(){
  char s[3];
  cin>>s[0]>>s[1]>>s[2];
  int max=0, locmax=0;
  for(int i=0;i<3;i++){
    if(s[i] == 'R'){
      locmax++;
    }
    else{
      locmax=0;
    }
    if(locmax>max){
      max=locmax;
    }
  }
  cout<<max;
}

#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 n, l;
    cin >> n >> l;
    vector<int> d(n);
    for (int i = 1; i <= n; i++) {
        d[i-1] = l+i-1;
    }
    int all = 0;
    rep(i,n) all += d[i];
    int ans = 0;
    int mn = 10000;
    rep(i,n) {
        int dall = all-d[i];
        if (abs(all-dall) < mn) {
            mn = abs(all-dall);
            ans = dall;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

enum Diceface {
	DICETOP,
	DICEFRONT,
	DICERIGHT,
	DICELEFT,
	DICEBACK,
	DICEBOTTOM,
	DICENUM
};

class Dice {
private:
	int *face;
public:
	Dice( ) { face = new int[DICENUM]; }
	Dice( int top, int front, int right, int left, int back, int bottom ) {
		face = new int[DICENUM];

		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	}
	~Dice( ) {
		delete [ ] face;
	}
	void setFace( int top, int front, int right, int left, int back, int bottom ) {
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;

		return;
	}
	void roll( char cmd ) {
		int t;
		if( 'E' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICELEFT];
			face[DICELEFT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICERIGHT];
			face[DICERIGHT] = t;
		} else if( 'N' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEFRONT];
			face[DICEFRONT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEBACK];
			face[DICEBACK] = t;
		} else if( 'S' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICEBACK];
			face[DICEBACK] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICEFRONT];
			face[DICEFRONT] = t;
		} else if( 'W' == cmd ) {
			t = face[DICETOP];
			face[DICETOP] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEBOTTOM];
			face[DICEBOTTOM] = face[DICELEFT];
			face[DICELEFT] = t;
		} else if( 'M' == cmd ) {
			t = face[DICEBACK];
			face[DICEBACK] = face[DICERIGHT];
			face[DICERIGHT] = face[DICEFRONT];
			face[DICEFRONT] = face[DICELEFT];
			face[DICELEFT] = t;
		}
		return;
	}
	int getFace( int diceface ) {
		return face[ diceface ];
	}

	bool isDiff( Dice &dice ) {
		int cnt;
		string cmd = "MMMMNMMMMWMMMMWMMMMWMMMMNMMMM";

		for( int i=0; i<cmd.length(); i++ ) {
			if( dice.getFace( DICETOP ) == face[ DICETOP ] ) {
				for( cnt=0; cnt<DICENUM; cnt++ ) {
					if( dice.getFace( cnt ) != face[ cnt ] ) { break; }
				}
				if( DICENUM == cnt ) { break; }
			}
			dice.roll( cmd[i] );
		}

		if( DICENUM == cnt ) {
			return false;
		} else {
			return true;
		}
	}

};

int main( )
{
	int t, f, r, l, ba, bo;
	int n;

	cin>>n;
	Dice *dice = new Dice[n];
	if( NULL == dice ) { return 0; }

	int cnt = 0;
	while( cnt < n ) {
		cin>>t>>f>>r>>l>>ba>>bo;
		dice[ cnt++ ].setFace( t, f, r, l, ba, bo );
	}

	bool isDiff = false;
	for( int i=0; i<n-1; i++ ) {
		for( int j=i+1; j<n; j++ ) {
			if( !( isDiff = dice[i].isDiff( dice[j] ) ) ) { break; }
		}
		if( !isDiff ) { break; }
	}
	if( isDiff ) {
		cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}

	delete [ ] dice;

	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a % b == 0){
    cout << "0\n";
    return 0;
  }
  cout << "1\n";
}

#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#include <functional>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const ll mod = 1000000000 + 7; //10^9

int main() {
    int N, L;
    cin >> N >> L;
    vector<int> abs_taste(N);
    int eat = 300;
    int c;
    for (int i = 0; i < N; i++)
    {
        abs_taste[i] = abs(L + i);
        if(abs_taste[i] < eat){
            eat = abs_taste[i];
            c = i;
        }
    }
    int sum = N * (L - 1) + (1 + N) * N / 2;
    int ans = sum - (L + c );
    cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const ll INF = 1LL<<60;

int main(){
    int d;
    ll g;
    cin >> d >> g;
    VP q(d);
    rep(i,d) cin >> q[i].first >> q[i].second;

    VI p(d);
    rep(i,d) p[i] = i;

    ll ans = INF;
    do{
        VI pp(d);
        rep(i,d) pp[p[i]] = i;

        ll gg = g;
        ll cnt = 0;
        rep(i,d){
            int j = pp[i];
            ll pc = (j + 1) * 100;
            ll num = min((ll)q[j].first, ((gg + (pc-1)) / pc));
            cnt += num;

            gg -= pc * num;
            gg -= q[j].second;

            if (gg <= 0) break;
        }

        ans = min(ans, cnt);

    } while(next_permutation(all(p)));

    cout << ans << endl;
    return 0;
}

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

int main() {
    int d, g;
    cin >> d >> g;
    int p[d], c[d];
    int sum = 0, num_mn = 1001;
    bool ach;
    for (int i = 0; i < d; i++) cin >> p[i] >> c[i];

    for (int bit = 0; bit < (1 << d); bit++) {
        int num_tmp = 0;
        sum = 0;
        ach = false;
        for (int i = 0; i < d; i++) {
            if (bit & (1 << i)) {
                num_tmp += p[i];
                sum += ((i + 1) * 100 * p[i] + c[i]);
            }
        }
        // cout << "1st sum:" << sum << " num_tmp:" << num_tmp << endl;
        if (sum < g) {
            for (int i = d - 1; i >= 0; i--) {
                if (!(bit & (1 << i))) {
                    if (g - sum <= (i + 1) * 100 * (p[i] - 1)) {
                        ach = true;
                        num_tmp += ((g - sum) / ((i + 1) * 100));
                        if ((g - sum) % ((i + 1) * 100) != 0) num_tmp++;
                        break;
                    } else {
                        sum += (i + 1) * 100 * (p[i] - 1);
                        num_tmp += (p[i] - 1);
                    }
                }
            }
        } else
            ach = true;
        if (!ach) num_tmp = 1001;
        num_mn = min(num_mn, num_tmp);
    }

    cout << num_mn << endl;

    return 0;
}


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

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

  int N,M;
  cin>>N>>M;
  vector<bool> isAC(N, false);
  vector<int> check(N,0);
  int wans=0, cans=0;
  int p;
  string s;
  for(int i=0; i<M; i++){
    cin>>p>>s;
    if(isAC.at(p-1)) continue;
    else{
      if(s=="AC"){
        isAC.at(p-1) = true;
        cans++;
        wans+=check.at(p-1);
      }
      else{
        check.at(p-1)++;
      }
    }
  }
  cout<<cans<<" "<<wans<<"\n";
}

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

#include <cmath>    //floor ceil
#include <cstdlib>  //abs
#include <cstdio>
#include <climits>  //INT_MAX
#include <cstring>
#define endl "\n"
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define lli long long int
#define MOD 1000000007
#include <map>
#define mp make_pair
#define mii map<int,int>
/*---------------------------------------------------CODE STARTS FROM HERE---------------------------------------------------*/

int main ()
{
    int n,m,ac=0,p=0;
    cin>>n>>m;
    int a[n],wa[n];
    for (int i=0;i<n;i++) a[i]=0,wa[i]=0;
    while(m--)
    {
        int x;
        string s;
        cin>>x>>s;
        if(a[x-1]==0 && s=="AC") { a[x-1]=1; ac++; p += wa[x-1];}
        else if(a[x-1]==0 && s=="WA") wa[x-1]++;
        //debug(wa[x-1]);
    }
    printf("%d",ac);
    printf(" ");
    printf("%d",p);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L

int main() {
	int N;
	cin >> N;
	long long sum = 0;
	for (int ii = 1; ii <= N; ii++) {
		if (ii % 3 == 0 && ii % 5 == 0) {
			continue;
		}
		if (ii % 3 == 0 || ii % 5 == 0) {
			continue;
		}
		sum += ii;
	}
	cout << sum << endl;
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int main() {
	string d[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	string x;
	cin >> x;
	for (int i = 0; i < 7; ++i) {
		if (d[i] == x) {
			PRI(7 - i);
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
intt gcd(intt a, intt b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b)
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = res * a;
      a = a * a;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) {
   if ((n==0)||(n==1))
      return 1;
   else
      return (n*fact(n-1))%mod;
}

void go()
{
#ifndef ONLINE_JUDGE
  freopen("IN.txt","r",stdin);
  freopen("OUT.txt","w",stdout);
  #endif
}

int main(){
	go();
	fast_io
  int n;cin>>n;
  vi a(n),b(n);
  for0(i,n){
    cin>>a[i];
  }
  for0(i,n){
    cin>>b[i];
  }
  reverse(all(b));
  int l=0,r=0;
  while(b[r]!=a[r] && r<n){
    r++;l++;
  }
  if(r==n){
    cout << "Yes" <<"\n";
    for(auto it: b)
      cout << it <<" ";
    cout << "\n";
  }
  else{
    while(r<n && a[r]==b[r])
      r++;
    int need=r-l;
    int j=0,left=l,right=r;
    while(j<left && l<r && need){
      if(b[j]!=b[l] && a[j]!=b[l]){
        swap(b[j],b[l]);
        need--;
        l++;
        j++;
      }
      else
        break;
    }
    j=n-1;
    while(j>=right && l<right && need){
      if(b[j]!=b[l] && a[j]!=b[l]){
        swap(b[j],b[l]);
        need--;
        l++;
        j--;
      }
      else
        break;
    }
    if(need)
      cout << "No" <<"\n";
    else{
      cout << "Yes" <<"\n";
      for(auto it: b)
        cout << it <<" ";
      cout << "\n";
    }
  }

}

/*
*/

//9c(n-2)*2

#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

class Dice
{
public:
    int label[6], tmp;

    void in()
    {
        rep(i, 6) scanf("%d", &label[i]);
    }

    void rollS()
    {
        tmp = label[0];
        label[0] = label[4];
        label[4] = label[5];
        label[5] = label[1];
        label[1] = tmp;
    }

    void rollN()
    {
        tmp = label[0];
        label[0] = label[1];
        label[1] = label[5];
        label[5] = label[4];
        label[4] = tmp;
    }

    void rollE()
    {
        tmp = label[0];
        label[0] = label[3];
        label[3] = label[5];
        label[5] = label[2];
        label[2] = tmp;
    }

    void rollW()
    {
        tmp = label[0];
        label[0] = label[2];
        label[2] = label[5];
        label[5] = label[3];
        label[3] = tmp;
    }

    void sideturn()
    {
        tmp = label[1];
        label[1] = label[2];
        label[2] = label[4];
        label[4] = label[3];
        label[3] = tmp;
    }
};

bool check2(Dice d1, Dice d2)
{
    bool c = true;
    FOR(i, 1, 5)
    {
        c = c && d1.label[i] == d2.label[i];
    }

    return c;
}

bool check1(Dice d1, Dice d2)
{
    bool b = false;

    if (d1.label[0] == d2.label[0] && d1.label[5] == d2.label[5])
    {
        rep(i, 4)
        {
            b = b || check2(d1, d2);
            d2.sideturn();
        }
    }
    return b;
}

bool isSame(Dice d1, Dice d2)
{
    bool a = false;

    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollE();
    a = a || check1(d1, d2);
    d2.rollN();
    a = a || check1(d1, d2);

    return a;
}

int main()
{
    int n;
    bool ans = false;
    scanf("%d", &n);
    Dice dice[n];
    rep(i, n) dice[i].in();

    rep(i, n)
    {
        FOR(j, i + 1, n)
        {
            ans = ans || isSame(dice[i], dice[j]);
        }
    }

    if (ans)
        printf("No\n");
    else
        printf("Yes\n");
}


////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n)
    {
        c=0,a=MX;
        rep(i,n)
        {
            cin>>x;
            if(x<a)c++,a=x;
        }
        cout<<c<<en;
    }
    return 0;
}

// Problem : C - Low Elements
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli t,n,i,k=1e6;
	cin>>n;
	vector<lli>v;
	for(i=0;i<n;i++){
		cin>>t;
		v.pb(t);
	}
	t=0;
	for(i=0;i<n;i++){
		if(v[i]<k)
		t++;
		k=min(k,v[i]);
	}
	cout<<t;
	return 0;
}


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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long

#define pii pair<int,int >
#define vec vector<int >

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

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n;ll ans;
char s[maxn];
map<pair<string,string > ,int > t;

void dfs1(int x,string a,string b) {
    if(x==n+1) {t[mp(a,b)]++;return ;}
    dfs1(x+1,a+s[x],b),dfs1(x+1,a,s[x]+b);
}

void dfs2(int x,string a,string b) {
    if(x==n) {ans+=t[mp(a,b)];return ;}
    dfs2(x-1,a+s[x],b),dfs2(x-1,a,s[x]+b);
}

int main() {
    read(n);scanf("%s",s+1);
    dfs1(1,"","");
    dfs2(2*n,"","");
    printf("%lld\n",ans);
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define all(a) a.begin(),a.end()
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; }
using namespace std;

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

    int n; string s; cin>>n>>s;
    map<pair<string,string>,int> mp;
    rep(i,1<<n){
        string t="",u="";
        rep(j,n){
            if((1<<j)&i)t=s[j+n]+t;
            else u=s[j+n]+u;
        }
        mp[pair<string,string>(t,u)]++;
    }
    int ans=0;
    rep(i,1<<n){
        string t="",u="";
        rep(j,n){
            if((1<<j)&i)t+=s[j];
            else u+=s[j];
        }
        ans+=mp[pair<string,string>(t,u)];
    }
    cout<<ans<<endl;

}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
using ll = long long int;
int main()
{
    int x, y;
    cin >> x >> y;

    int prize = 0;

    if (x <= 3) {
        prize += (4-x) * 100000;
    }
    if (y <= 3) {
        prize += (4-y) * 100000;
    }
    if (x == 1 && y == 1) {
        prize += 400000;
    }
    cout << prize << endl;
}

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

int main(){
    int x,y;
    cin >> x>>y;
    vector<int> a(206);

    a.at(1)=300000;
    a.at(2)=200000;
    a.at(3)=100000;

    if((x==1)&&(y==1)){
        cout << 1000000 <<endl;
    }
    else{
        cout << a.at(x) + a.at(y) << endl;
    }
    return 0;
}


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

int main()
{
    int K, T;
    cin >> K >> T;

    priority_queue<pair<int, int>> q;
    int ai;
    for (int i = 0; i < T; i++)
    {
        cin >> ai;
        q.push(make_pair(ai, i + 1));
    }

    int res = 0;
    int prev = 0;
    for (int i = 0; i < K; i++)
    {
        pair<int, int> p0 = q.top();
        q.pop();

        if (p0.second == prev)
        {
            if (q.empty())
            {
                res += p0.first;
                break;
            }
            else
            {
                pair<int, int> p1 = q.top();
                q.pop();
                p1.first--;
                prev = p1.second;
                if (p1.first > 0)
                {
                    q.push(p1);
                }
            }
        }
        else
        {
            p0.first--;
            prev = p0.second;
        }

        if (p0.first > 0)
        {
            q.push(p0);
        }
    }
    cout << res << endl;
}

#include <algorithm>
#include <iostream>

using namespace std;
int main() {
  int K, a, M{};
  cin >> K >> a;
  while (cin >> a) M = max(M, a);
  cout << max(0, 2 * M - K - 1) << endl;
}


#include<bits/stdc++.h>

using namespace std;
const int MAXN=10005;
int P=1e9+7,d,len;
char k[MAXN];
long long a[MAXN],dp[10005][105];

long long dfs(int pos,int tot,bool lim)
{
//	cout<<pos<<' '<<tot<<' '<<lim<<endl;
	if(pos==len+1)
	{
		if(tot==0)	return 1;
		return 0;
	}
	if(!lim&&dp[pos][tot]!=-1) return dp[pos][tot];

	long long ret=0 ,  up=lim?a[pos]:9  ;

	for(int i=0;i<= up  ;++i)
	{
		ret=(ret+dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ))%P;

		//(ret+=dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ) )%=P;
	}

	if(!lim) dp[pos][tot]=ret;
	return ret;
}

int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%s",k+1);
	scanf("%d",&d);
	len=strlen(k+1);
	for(int i=1;i<=len;++i)
	{
		a[i]=k[i]-'0';
	}

	long long ans=(dfs(1,0,1)-1+P)%P;
	printf("%lld\n",ans);
	return 0;
}

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

long long MOD = 1000000007;

int  main(){
    //input
    long long D;
    string S;
    cin >> S;
    cin >> D;
    long long keta=S.length();
    long long N[keta];
    long long i,k, digit;
    long long j;
    for(i=0; i<keta; i++){
        N[i]=(long long)(S[i]-'0');
    }

    //calc
    long long dp[keta][2][D];
    for(i=0; i<keta; i++){
        for(j=0; j<=1; j++){
            for(k=0; k<D; k++){
                dp[i][j][k]=0;
            }
        }
    }
    for(digit=0; digit<10; digit++){
        if(digit<N[0]){
            dp[0][1][digit%D]++;
        }else if(digit==N[0]){
            dp[0][0][digit%D]++;
        }
    }
    for(i=0; i<keta-1; i++){
        for(j=0; j<=1; j++){
            for(k=0; k<D; k++){
                for(digit=0; digit<(j?10:N[i+1]+1); digit++){
                    dp[i+1][j||(digit<N[i+1])][(k+digit)%D]+=dp[i][j][k];
                    dp[i+1][j||(digit<N[i+1])][(k+digit)%D]%=MOD;
                }
            }
        }
    }

    cout << (dp[keta-1][0][0]+dp[keta-1][1][0]-1+MOD)%MOD << endl;
    system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint mod_pow(int i,int j)
{
  mint x=i;
  mint y=(j%2)? x:1;
  j/=2;
  while(j!=0)
  {
    x=x*x;
    if(j%2)
    {
      y=(y.x==1)? x:x*y;
    }
    j/=2;
 }
 return y;
}
int main()
{

  int n;
  cin>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  mint ans=0;
  for(int i=0;i<64;i++)
  {
    int z=0;
    int o=0;
    for(int j=0;j<n;j++)
    {
      ll t=1L<<i;
      if(t&a[j])o+=1;
      else z+=1;
    }
    //cout<<i<<" "<<o<<" "<<z<<endl;
    ans+=(mod_pow(2,i)*z*o);

  }
  cout<<ans.x<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_N = 100009;

int N, A[MAX_N];

int same_hat[MAX_N]; // same_hat[i]: 同色の帽子をi人が被っているような色の種類数

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];

    REP(i, N) same_hat[i] = 0;
    same_hat[0] = 3;

    ll num_comb = 1;

    REP(i, N) {
        num_comb = num_comb * same_hat[A[i]] % MOD;
        same_hat[A[i]]--;
        same_hat[A[i] + 1]++;
    }

    PRINT(num_comb);

    return 0;
}


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

int main() {
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> a(n);
  a[0]=0;
  rep(i,1,n){
    if(s[i-1]=='A' && s[i]=='C') {
     a[i]= a[i-1]+1;
    }
    else a[i]=a[i-1];
  }
//  rep(i,0,n) cout << a[i] << ' ';

  rep(i,0,q){
    int l,r;
    cin >> l >> r;
    l--; r--;
    cout << a[r] - a[l] << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll D, G;
    cin >> D >> G;
    vec p(D), c(D);
    loop(i, D) cin >> p[i] >> c[i];
    ll ans = 1e9;
    loop(bit, 1 << D)
    {
        ll ac = 0;
        ll score = 0;
        bool check = false;
        loop(i, D) if (flagon(bit, i))
        {
            ac += p[i];
            score += p[i] * (i + 1) * 100;
            score += c[i];
            if (score >= G)
            {
                check = true;
                break;
            }
        }
        if (check)
        {
            ans = min(ans, ac);
            continue;
        }
        //もしも基準点に達していなければ、いままで選択していないなかでもっとも配点の高いシリーズから解いていく
        //もしも基準を満たせなかったら諦める
        bool check2 = false;
        for (ll i = D - 1; i >= 0; i--)
        {
            if (flagoff(bit, i))
            {
                loop(j, p[i])
                {
                    score += 100 * (i + 1);
                    ac++;
                    if (j == p[i] - 1)
                        score += c[i];
                    if (score >= G)
                    {
                        check2 = true;
                        break;
                    }
                }
                break;
            }
        }
        if (check2)
            ans = min(ans, ac);
    }
    putout(ans);
    return 0;
}


#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,M;
  cin >> N;
  map<string,int> blue;
  string s;
  for(int i=0;i<N;++i){
    cin >> s;
    if(blue.count(s)) blue.at(s)++;
    else blue[s]=1;
  }
  cin >> M;
  map<string,int> red;
  for(int i=0;i<M;++i){
    cin >> s;
    if(red.count(s)) red.at(s)++;
    else red[s]=1;
  }

  int ans=-200;
  for(auto p: blue){
    auto word=p.first;
    auto value=p.second;
    if(red.count(word)){
      ans=max(ans,value-red.at(word));
    }
    else ans=max(ans,value);
  }

  if(ans<0) cout << 0 << endl;
  else cout << ans << endl;

  return 0;
}

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

/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair

/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())

/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;

/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int n; cin >> n;
  map<string,int> red, blue;

  rep(i, n) {
    string s; cin >> s;
    ++red[s];
  }

  int m; cin >> m;
  rep(i, m) {
    string s; cin >> s;
    ++blue[s];
  }

  int ans = 0;
  for (auto e : red) {
    int score = e.se;
    score -= blue[e.fi];

    chmax(ans, score);
  }

  cout << ans << endl;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> r,g,b;

    for(int i = 0; i < n; i++) {
        char x;
        cin >> x;
        if(x=='R') r.push_back(i+1);
        if(x=='G') g.push_back(i+1);
        if(x=='B') b.push_back(i+1);
    }

    ll ans = r.size()*g.size()*b.size();
    if(ans==0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0; i < r.size(); i++) {
        for(int j = 0; j < g.size(); j++) {
            int y=lower_bound(b.begin(),b.end(),g[j]+g[j]-r[i])-b.begin();
            if(y!=b.size()){
                if(b[y]==g[j]+g[j]-r[i]) ans--;
            }
            y=lower_bound(b.begin(),b.end(),r[i]+r[i]-g[j])-b.begin();
            if(y!=b.size()){
                if(b[y]==r[i]+r[i]-g[j]) ans--;
            }

            if((r[i]+g[j])%2==0){
                y=lower_bound(b.begin(),b.end(),(r[i]+g[j])/2)-b.begin();
                if(y!=b.size()){
                if(b[y]==(r[i]+g[j])/2) ans--;
                }
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    for (int ix=0; ix<n; ix++) {
        int out=0,score=0;
        int hit[] = {0,0,0};
        string event;
        while (out<3) {
            cin>>event;
            if (event=="HIT") {
                if (hit[2]==1) score++;
                if (hit[1]==1) hit[2]=1;
                if (hit[0]==1) hit[1]=1;
                hit[0]=1;
            }
            else if (event=="HOMERUN") {
                for (int i=0; i<3; i++) {
                    score+=hit[i];
                    hit[i]=0;
                }
                score++;
            }
            else if (event=="OUT") {
                out++;
            }
        }
        printf("%d\n",score);
    }
}

#include<stdio.h>
int main(){
  int n,a[101],t,i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
scanf("%d",&a[i]);
  }
  for(j=i-1;j>=0;j--){

    if(j==0){printf("%d",a[j]);
      printf("\n");}
    else printf("%d ",a[j]);

  }
  return 0;
}


#define  REP(i, s, e) for (int i = s; i <= e; i++)
#define DREP(i, s, e) for (int i = s; i >= e; i--)
#define DEBUG fprintf(stderr, "Passing [%s] in Line %d\n", __FUNCTION__, __LINE__)

#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)

#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 4000 + 10, MOD = 998244353;

int n, k, tot[maxn];
long long fac[maxn], Inv[maxn];
inline int C(int n, int m) {return fac[n] * Inv[m] % MOD * Inv[n-m] % MOD;}

int power_pow(long long base, int b)
{
	long long ans(1);
	while (b)
	{
		if (b & 1) (ans *= base) %= MOD;
		(base *= base) %= MOD;
		b >>= 1;
	}
	return ans;
}
#define inv(x) power_pow(x, MOD - 2)
inline void init()
{
	fac[0] = 1;
	REP(i, 1, 4000) fac[i] = fac[i-1] * i % MOD;
	Inv[4000] = inv(fac[4000]);
	DREP(i, 3999, 0) Inv[i] = Inv[i+1] * (i+1) % MOD;
}

int main()
{
#ifdef CraZYali
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
#endif
	init();
	cin >> k >> n;
	REP(i, 1, k) tot[i+1]++, tot[i+k+1]--;
	REP(i, 1, k + k) tot[i] += tot[i-1];
	REP(i, 2, k + k)
    {
		int cnt = tot[i] + 1 >> 1, ans(0);
		const int lim = min(cnt, n >> 1);
		REP(j, 0, lim)
			(ans += (j & 1 ? -1ll : 1ll) * C(cnt, j) * C(n-j-j+k-1, k-1) % MOD) %= MOD;
        printf("%d\n", (ans + MOD) % MOD);
    }
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 998244353
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define N 100010
ll fac[N],inv[N],ivf[N];
ll C(ll n,ll k){
    if(n<k)return 0;
  if(n<0||k<0)return 0;
    return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
    //if(k==0)return 1;
    return C(n+k-1,k);
}
ll P(ll n,ll k){
    return fac[n]*ivf[n-k]%mod;
}
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}
ll solve(ll a,ll b,ll n){
    ll res=0;
    for(ll p=0;p<=b;p++){
	ll cur=C(b,p)*po(2,p)%mod;
	mul(cur,H(a+p,n-p));
	mad(res,cur);
    }
  //cout<<"#"<<a<<" "<<b<<" "<<n<<" "<<res<<endl;
    return res;
}
int main(){
    fac[0]=ivf[0]=inv[1]=1;
    for(int i=1;i<N;i++){
	if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
	fac[i]=fac[i-1]*i%mod;
	ivf[i]=ivf[i-1]*inv[i]%mod;
    }
  ll k,n; cin>>k>>n;
  for(ll i=2;i<=2*k;i++){
      ll a,b;
      a=abs(k-i+1);
      b=(k-a)/2;
      ll ans=solve(a,b,n);
      if(i%2==0){
	  mad(ans,solve(a,b,n-1));
      }
      if(ans<0)ans+=mod;
      cout<<ans<<endl;
  }
  return 0;
}


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    int a[n+1];
    rep(i,n) cin >> a[i+1];
    int ans[n+1];
    rep(i,n) ans[i+1] = 0;
    //rep(i,n) cout << a[i] << endl;
    for(int i = n; i >= 1; --i) {
        //printf("OK\n");
        for(int j = i; j <= n; j += i) {
            ans[i] = (ans[i]+ans[j])%2;
        }
        ans[i] = (ans[i]+a[i])%2;
        //printf("OK2\n");
    }
    //rep(i,n) cout << ans[i+1] << endl;
    int cnt = 0;
    rep(i,n) {
        if(ans[i+1]) cnt++;
    }
    if (cnt) {
        cout << cnt << endl;
        rep(i,n) {
            if (ans[i+1]) {
                printf("%d\n", i+1);
            }
        }
    } else cout << 0 << endl;
    return 0;
}

#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;

    vi a(N + 1, 0);
    FOR(i, 1, N + 1) cin >> a[i];

    vi b(N+1, 0);
    REVFOR(i, N / 2 + 1, N + 1) {
        b[i] = a[i];
    }

    REVFOR(i, 1, N / 2 + 1) {
        int cnt = 0;
        for(int j = i; j <= N; j += i) {
            cnt += b[j];
        }

        if ((cnt & 1) != a[i]) b[i] = 1;
    }

    int m = accumulate(ALL(b), 0);
    print(m);
    if (m == 0) return 0;

    FOR(i, 1, N+1) if(b[i]) cout << i << " ";
    cout << endl;

}


#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    int m,n,o;
    cin>>a>>b>>c;
    m=a;
    n=b;
    o=c;

    b=m;
    a=o;
    c=n;

    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && c <= b || b <= c && c <= a ? "Yes" : "No") << endl;
    return 0;
}


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

int main()
{
    long long int N, i, div, result;
    cin >> N;
    vector<long long int> A_sum(N);
    vector<long long int> A(N);
    div = 1;
    for (i = 0; i < 9; i++)
    {
        div *= 10;
    }
    div += 7;
    for (i = 0; i < N; i++)
    {
        cin >> A[i];
        A[i] = A[i] % div;
    }
    A_sum[N - 1] = A[N - 1];
    for (i = N - 2; i > 0; i--)
    {
        A_sum[i] = A_sum[i + 1] + A[i];
        A_sum[i] = A_sum[i] % div;
    }
    result = 0;
    for (i = 0; i < N - 1; i++)
    {
        result += A[i] * A_sum[i + 1];
        result = result % div;
    }
    cout << result << endl;
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const int MOD=1000000007;
int INF=100100100100100;
int a[200010];
int ans[200010];
signed main(){
  int n;cin>>n;
  int cnt=0;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  for(int i=n;i>=1;i--){
    int sum=0;
    for(int j=2*i;j<=n;j+=i){
      sum+=ans[j];
    }
    ans[i]=(sum+a[i])%2;
    if(ans[i])cnt++;
  }
  cout<<cnt<<endl;
  for(int i=1;i<=n;i++){
    if(ans[i])cout<<i<<endl;
  }
  return 0;
}


#pragma GCC optimize ("Ofast")
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << "  ";
    __f(comma + 1, args...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(it,vv) for(auto &it : vv)
#define prep(it,vv) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    set<int>ss;
    int n = 3;
    rep(i, n)
    {
        int a; cin >> a;
        ss.insert(a);
    }
    if (ss.size() == 2) cout << "Yes" << endll;
    else cout << "No" << endll;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c) {
        cout << "Yes" << "\n";
    } else if (c == b && b != a) {
        cout << "Yes" << "\n";
    } else if (c == a && b != a) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }

}


#include<iostream>
#include<algorithm>
#include<numeric>
#include<map>
#include<set>

int const MAXN = 2e5;
int a[MAXN], b[MAXN], N, k;
int c[MAXN-1], d[MAXN+MAXN-2];
int rank[MAXN+MAXN-1];
int tmp[MAXN+MAXN-1];
int sa[MAXN+MAXN-1];

bool comp_sa(int i, int j) {
  if(rank[i]!=rank[j]) return rank[i] < rank[j];
  int ri = i+k <= N+N-2? rank[i+k]: -1;
  int rj = j+k <= N+N-2? rank[j+k]: -1;
  return ri < rj;
}

int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> a[i];
  for(int i = 0; i < N; ++i) std::cin >> b[i];
  for(int i = 0; i < N-1; ++i) c[i] = a[i]^a[i+1];
  for(int i = 0; i < 2*N-2; ++i) d[i] = b[i%N]^b[(i+1)%N];
  std::set<int> ans;
  // SA
  std::copy_n(d, 2*N-2, rank); rank[2*N-2] = -1;
  std::iota(sa, sa+2*N-1, 0);
  for(k = 1; k <= 2*N-2; k += k) {
    std::sort(sa, sa+2*N-1, comp_sa);
    tmp[sa[0]] = 0;
    for(int i = 1; i <= 2*N-2; ++i) {
      tmp[sa[i]] = tmp[sa[i-1]] + (comp_sa(sa[i-1], sa[i])? 1: 0);
    }
    std::copy_n(tmp, 2*N-1, rank);
  }
  int lb = std::partition_point(sa, sa+2*N-1, [&](int i) {
    // d[i, 2*N-2) < c[0, N-1)
    for(int j = 0; j+i < 2*N-2 && j < N-1; ++j) {
      if(d[j+i] != c[j]) return d[j+i] < c[j];
    }
    return 2*N-2-i < N-1;
  }) - sa;
  int ub = std::partition_point(sa, sa+2*N-1, [&](int i) {
    // d[i, 2*N-2) < c[0, N-1) or d[i, i+N-1) == c[0, N-1)
    for(int j = 0; j+i < 2*N-2 && j < N-1; ++j) {
      if(d[j+i] != c[j]) return d[j+i] < c[j];
    }
    return true;
  }) - sa;
  for(int i = lb; i < ub; ++i) {
    ans.insert((N-sa[i])%N);
  }
  // ans
  for(auto k: ans) {
    int x = a[0]^b[(N-k)%N];
    std::cout << k << " " << x << std::endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
inline char Get(){
	static char ch; ch = getchar();
	while (ch != '\n' && ch != '0' && ch != '1' && ch != '?') ch = getchar();
	if (ch == '\n') return '*';
	return ch;
}
const int P = 1e9 + 7;
inline void upd(int &x,int v){ x = (x+v>=P)?(x+v-P):(x+v); }
int f[9],g[9],nxt[9][2];
inline int getnxt(int s,int v){
	int cnt1 = s / 3,cnt0 = s % 3;
	if (v == 1){ if (!cnt0) cnt1 = min(2,cnt1+1); else --cnt0; }
	else{ if (cnt0 == 2) cnt0 = 0; ++cnt0; }
	return cnt1 * 3 + cnt0;
}

inline void DP(char c){
	int i;
	for (i = 0; i < 9; ++i) g[i] = f[i],f[i] = 0;
	for (i = 0; i < 9; ++i) if (g[i]){
		if (c != '1') upd(f[nxt[i][0]],g[i]);
		if (c != '0') upd(f[nxt[i][1]],g[i]);
	}
}

int main(){
	int i,j;
	for (i = 0; i < 9; ++i) for (j = 0; j < 2; ++j) nxt[i][j] = getnxt(i,j);
	f[0] = 1;
	char c; while ((c=Get())!='*') DP(c);
	int ans = 0;
	for (i = 0; i < 9; ++i) if (i / 3 >= i % 3) upd(ans,f[i]);
	cout << ans << '\n';
	return 0;
}


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

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

    int l;
    long stocks = 1000;

    for (long long i = 1; i*i <= n; i++) {
        if (n % i != 0) continue;
        l = log10(n/i) + 1;
        if (l < stocks) stocks = l;

    }

    cout << stocks << endl;

}

#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int R; cin >> R;
  if (R < 1200) cout << "ABC" << endl;
  else if (R < 2800) cout << "ARC" << endl;
  else               cout << "AGC" << endl;
}


#include<iostream>
#include<string>
using namespace std;
int conv(char r)
{
	if(r=='I') return 1;
	if(r=='V') return 5;
	if(r=='X') return 10;
	if(r=='L') return 50;
	if(r=='C') return 100;
	if(r=='D') return 500;
	if(r=='M') return 1000;
	else return 0;
}

int main()
{
	string in;
	while(cin>>in)
	{
		int ans=0;
		for(int i = 1; i < in.size(); ++i)
		{
			int right=conv(in[i]);
			int left=conv(in[i-1]);
			if(!right||!left) continue;
			if(left<right)
			{
				ans+=right-left;
				in[i]=in[i-1]='0';
			}
		}
		for(int i = 0; i < in.size(); ++i)
		{
			ans+=conv(in[i]);
		}
		cout<<ans<<endl;
	}
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef pair<int, int> ii;
typedef pair<long long, int> li;
typedef pair<long long, pair<int, int> > lii;

const int N = 2e5 + 5;
const long long inf = 1e18 + 123;
int n, a[N], d;
long long ans;
vector<ii> vec;
vector<lii> edge;

struct Bit1 {
    vector<li> node;
    Bit1 (int sz = 0) {
        node.assign(sz + 5, li(inf, 0) );
    }
    void update (int pos, li val) {
        for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val);
    }
    li get (int pos) {
        li ret = li(inf, 0);
        for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
        return ret;
    }
};

struct Bit2 {
    vector<li> node;
    Bit2 (int sz = 0) {
        node.assign(sz + 5, li(inf, 0) );
    }
    void update (int pos, li val) {
        pos = (int)node.size() - pos;
        for (; pos < (int)node.size(); pos += pos & -pos) node[pos] = min(node[pos], val);
    }
    li get (int pos) {
        pos = (int)node.size() - pos;
        li ret = li(inf, 0);
        for (; pos > 0; pos -= pos & -pos) ret = min(ret, node[pos]);
        return ret;
    }
};

struct Dsu {
    vector<int> pSet, szSet;
    Dsu (int _n = 0) {
        pSet.assign(_n + 5, 0); for (int i = 0; i < (int)pSet.size(); ++i) pSet[i] = i;
        szSet.assign(_n + 5, 1);
    }
    int findSet (int i) { return i == pSet[i] ? i : pSet[i] = findSet(pSet[i]); }
    bool unionSet (int i, int j) {
        i = findSet(i);
        j = findSet(j);
        if (i == j) return false;
        if (szSet[i] > szSet[j]) swap(i, j);
        szSet[j] += szSet[i];
        pSet[i] = j;
        return true;
    }
};

long long cost (int i, int j) { return 1LL * abs(i - j) * d + a[i] + a[j]; }

int main () {
    scanf("%d %d", &n, &d);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        vec.pb(ii(a[i], i) );
    }
    sort(vec.begin(), vec.end() );

    Bit1 bit1(n);
    Bit2 bit2(n);

    for (auto _ : vec) {
        int i = _.se;
        li tmp1 = bit1.get(i), tmp2 = bit2.get(i);
        if (tmp1.se) edge.pb(lii(cost(tmp1.se, i), ii(tmp1.se, i) ) );
        if (tmp2.se) edge.pb(lii(cost(tmp2.se, i), ii(tmp2.se, i) ) );
        bit1.update(i, li(a[i] - 1LL * i * d, i) );
        bit2.update(i, li(a[i] + 1LL * i * d, i) );
    }
    sort(edge.begin(), edge.end() );

    Dsu dsu(n);

    for (auto _ : edge) {
        if (dsu.unionSet(_.se.fi, _.se.se) ) ans += _.fi;
    }

    cout << ans;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//世界の皆は頭ええな

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

	ll N, D;
	cin >> N >> D;
	ll kotae = (N - 1) * D;
	ll A[200001], C[200001];
	C[0] = 1e18;
	rep1(i, N) {
		cin >> A[i];
		kotae += A[i];
		C[i] = min(C[i - 1] + D, A[i]);
	}
	ll mae = 1e18;
	for (int i = N - 1; i > 1; i--) {
		mae = min(mae + D, A[i + 1]);
		ll kari = min(mae, C[i - 1]) + D;
		kotae += min(A[i], kari);
	}
	co(kotae);

	Would you please return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	ll N; cin >> N;
	vector<pair<ll,ll>> ran(N);
	vector<ll> u(2), v(2,1e10);
	for (int i = 0; i < N; i++) {
		cin >> ran[i].first >> ran[i].second;
		if (u[0] < ran[i].first) {
			swap(u[0], u[1]);
			u[0] = ran[i].first;
		}
		else if (u[1] < ran[i].first)u[1] = ran[i].first;
		if (v[0] > ran[i].second) {
			swap(v[0], v[1]);
			v[0] = ran[i].second;
		}
		else if (v[1] > ran[i].second)v[1] = ran[i].second;

	}

	sort(ran.begin(), ran.end());
	vector<pair<ll, ll>> left(N);
	left[0] = ran[0];
	for (int i = 1; i < N; i++) {
		left[i].first = ran[i].first;
		left[i].second = min(left[i - 1].second, ran[i].second);
	}

	vector<pair<ll, ll>> right(N);
	right[N - 1] = ran[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		right[i].first = right[i + 1].first;
		right[i].second = min(right[i + 1].second, ran[i].second);
	}

	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ll temp = max((ll)0, left[i].second - left[i].first + 1);
		temp += max((ll)0, right[i + 1].second - right[i + 1].first + 1);
		ans = max(ans, temp);
		//cout << "i=" << i << " temp=" << temp << endl;
	}
	if (u[0] < u[1])swap(u[0], u[1]); //cout << "u[0]=" << u[0] << " u[1]=" << u[1] << endl;
	if (v[0] > v[1])swap(v[0], v[1]); //cout << "v[0]=" << v[0] << " v[1]=" << v[1] << endl;
	for (int i = 0; i < N; i++) {
		ll p = (ran[i].first != u[0] ? u[0] : u[1]), q = (ran[i].second != v[0] ? v[0] : v[1]);
		ans = max(ans, max((ll)0, q - p + 1) + ran[i].second - ran[i].first + 1);
		//cout << "i=" << i << " ans=" << ans ;
		//cout << " p=" << p << " q=" << q << endl;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++

vi to[100005];
// abc148 f

vi dist;
int n;

void dfs(int v, int d=0, int p=-1) {
  dist[v] = d;
  for (int u: to[v]) {
    if (u == p) continue;
    dfs(u,d+1,v);
  }
}

vi getDist(int v) {
  dist = vi(n);
  dfs(v);
  return dist;
}
int main() {
  int t, a; cin >> n >> t >> a;
  t--; a--;
  rep(i,n-1) {
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vi distA = getDist(a);
  vi distT = getDist(t);

  int ans=0;
  rep(i,n) {
    if (distA[i] > distT[i]) {
      chmax(ans, distA[i]);
    }
  }
  ans--;
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int psum[505][505];
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	while(m--){
		int l,r;
		cin>>l>>r;
		psum[r][l]++;
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) psum[i][j]+=psum[i][j-1];
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) psum[i][j]+=psum[i-1][j];
	}
	while(q--){
		int l,r;
		cin>>l>>r;
		cout<<psum[r][n]-psum[r][l-1]<<'\n';
	}
}

#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

int n,N;
ll s[4000][2],a,b;
string d;

int main(){
    while(cin>>N){
	if(N==0)return 0;
	for(int i=0;i<4000;i++){
	    for(int j=0;j<2;j++){
		s[i][j]=0;
	    }
	}
	int m=0;
	for(int i=0;i<N;i++){
	    cin>>n>>a>>b;
	    int flag=0;
	    for(int j=0;j<m;j++)if(s[j][0]==n){s[j][1]+=a*b;flag=1;}
	    if(flag==0){s[m][0]=n;s[m][1]=a*b;m++;}
	}
	int flag2=0;
	for(int i=0;i<m;i++)if(s[i][1]>999999){cout<<s[i][0]<<endl;flag2=1;}
	if(flag2==0)cout<<"NA"<<endl;
    }
}


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

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  if(N==1)
    cout<<"Hello World"<<endl;
  else
    cout<<A+B<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,a,b; cin >> n;
  if (n == 2) {
    int a,b;
    cin>>a>>b;
    COUT(a+b);
  } else COUT("Hello World");
  return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

bool f(int a, int b, int c)
{
	if(a == 2 && b == 1 && c == 1) return true;
	if(a == 1 && b == 2 && c == 1) return true;
	if(a == 1 && b == 1 && c == 2) return true;

	return false;
}

int main()
{
    for(int a, b, c; cin >> a >> b >> c && (a || b || c); )
	{
		vint S(a+b+c, 2);

		int N;
		cin >> N;

		vector<pair<pint, pint> > tests(N);
		rep(i, N)
		{
			cin >> tests[i].first.first >> tests[i].first.second;
			cin >> tests[i].second.first >> tests[i].second.second;

			if(tests[i].second.second == 1)
			{
				S[tests[i].first.first-1] = 1;
				S[tests[i].first.second-1] = 1;
				S[tests[i].second.first-1] = 1;
			}
		}

		rep(i, N)
		{
			if(f(S[tests[i].first.first-1], S[tests[i].first.second-1], S[tests[i].second.first-1]))
			{
				if(S[tests[i].first.first-1] == 2) S[tests[i].first.first-1] = 0;
				if(S[tests[i].first.second-1] == 2) S[tests[i].first.second-1] = 0;
				if(S[tests[i].second.first-1] == 2) S[tests[i].second.first-1] = 0;
			}
		}

		rep(i, a+b+c) cout << S[i] << endl;
	}
}

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

int main(){
    int a,b,c;
    while(cin>>a>>b>>c,a||b||c){
        int n,parts[500],input[10000][4],bd;
        for(int i=0;i<500;i++) parts[i]=2;
        cin>>n;
        for(int _i=0;_i<n;_i++){
            for(int _j=0;_j<4;_j++){
                cin>>input[_i][_j];
            }
            if(input[_i][3]==1){
                for(int i=0;i<3;i++){
                    parts[input[_i][i]]=1;
                }
            }
            for(int i=0;i<=_i;i++){
                if(input[i][3]==1) continue;
                bd=-1;
                for(int j=0;j<3;j++){
                    if(parts[input[i][j]]==2 && bd==-1) bd=input[i][j];
                    else if(parts[input[i][j]]!=1){
                        bd=-1;
                        break;
                    }
                }
                if(bd!=-1) parts[bd]=0;
            }
        }
        for(int i=1;i<=a+b+c;i++){
            printf("%d\n",parts[i]);
        }
    }
    return 0;
}