#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<ll> m(n+1);
    for (int j = 0; j < n; j++) {
        m[j + 1] = m[j];
        if (s[j] == 'M')m[j + 1]++;
    }
    vector<ll> c(n + 1);
    for (int j = 0; j < n; j++) {
        c[j + 1] = c[j];
        if (s[j] == 'C')c[j + 1]++;
    }
    vector<ll> crui(n + 1);
    for (int j = 0; j < n; j++) {
        crui[j + 1] = crui[j];
        if (s[j] == 'C')crui[j + 1] += m[j];
    }
    for (int i = 0; i < q; i++) {
        ll v;
        cin >> v;
        ll ans = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == 'D')ans += crui[min(n, j + v)]-crui[j]-m[j]*(c[min(n, j + v)]-c[j]);
        }
        cout << ans << endl;
    }

}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

class unionfind{
  public:
  int Num;
  vector<int> par; //親の番号
  vector<int> height; //木の高さ(ランク)

  unionfind(int N):
    par(vector<int>(N, 0)), height(vector<int>(N, 0)), Num(N) {}

  //初期化
  void init(){
    REP(i, Num){
      par[i] = i;
      height[i] = 0;
    }
  }

  //xの親番号を返す、再帰処理あり
  int root(int x){
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  //xとyの親番号が同一か判定する
  bool same(int x, int y){
    return root(x) == root(y);
  }

  //xとyのある木を結合する
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y) return; //親が同一なら結合済み。

    if(height[x] < height[y]) par[x] = y;
    else {
      par[y] = x;
      if(height[x] == height[y]) height[x]++;
    }
  }
};

int main(){
  int n, k, l;
  cin>>n>>k>>l;
  unionfind ro(n);
  unionfind ra(n);
  map<P, LL> mp;
  ro.init();
  ra.init();
  LL ans, r;
  int t1, t2;
  REP(i, k){
    cin>>t1>>t2;
    --t1;
    --t2;
    ro.unite(t1, t2);
  }

  REP(i, l){
    cin>>t1>>t2;
    --t1;
    --t2;
    ra.unite(t1, t2);
  }

  REP(i, n){
    ++mp[make_pair(ro.root(i), ra.root(i))];
  }
  REP(i, n){
    r=mp[make_pair(ro.root(i), ra.root(i))];
    ECHO(r);
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  string s;
  cin>>s;
  int n=s.size();
  int stack=0,e=0;
  for(int i=0;i<n;i++){
    if(s[i]=='S'){stack++;}
    else if(stack>0){stack--;e++;}
  }
  cout<<n-2*e<<endl;
  return 0;
}

#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);

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

	stack<char> s;
	ll n = x.size();

	rep(i, n) {
		if (s.size() == 0 || x[i] == 'S') s.push(x[i]);
		else if (s.top() == 'S' && x[i] == 'T') s.pop();
		else if (s.top() != 'S' && x[i] == 'T') s.push(x[i]);
	}

	cout << s.size();

	return 0;
}

ll cb(ll a, ll b) {
	ll ans = 1;
	rep(i, b) ans *= (a - i);
	rep(i, b) ans /= (b - i);

	return ans;
}

ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}


#include<bits/stdc++.h>
using namespace std;
int n;
class Dice{
private:
  int right,left,front,back,bottom,now,flag=1;
  int role(int num[6],int num2[6],string str){
    for(int i=0;i<str.size();i++){
      if(num[0]==num2[0]&&num[1]==num2[1]&&num[2]==num2[2]&&num[3]==num2[3]&&num[4]==num2[4]&&num[5]==num2[5]){
	cout<<"No"<<endl;
	flag=0;
	return 0;
      }
      switch(str[i]){
      case 'S':num[1]=now;num[0]=back;num[4]=bottom;num[5]=front;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      case 'W':num[3]=front;num[1]=right;num[2]=back;num[4]=left;front=num[1];left=num[3];back=num[4];right=num[2];break;
      case 'E':num[3]=bottom;num[0]=left;num[2]=now;num[5]=right;now=num[0];left=num[3];bottom=num[5];right=num[2];break;
      case 'N':num[4]=now;num[0]=front;num[1]=bottom;num[5]=back;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      }
      if(num[0]==num2[0]&&num[1]==num2[1]&&num[2]==num2[2]&&num[3]==num2[3]&&num[4]==num2[4]&&num[5]==num2[5]){
	cout<<"No"<<endl;
	flag=0;
	return 0;
      }
    }
  }
public:
  void Scan(int num[100][6]){

    for(int i=0;i<n-1;i++){
      now=num[i][0];right=num[i][2];left=num[i][3];front=num[i][1];back=num[i][4];bottom=num[i][5];
      for(int j=i+1;j<n;j++){
	role(num[i],num[j],"WWWNWWWWNWWWWNWWWNWWWWNNWWWNWWW");
	if(flag==0)
	  return;
      }
    }
    if(flag==1)
      cout<<"Yes"<<endl;
  }
};

int main(){
  Dice dice;
  int a,b;
  cin>>n;
  int num[100][6];
  for(int i=0;i<n;i++)
    for(int j=0;j<6;j++)
      cin>>num[i][j];
  dice.Scan(num);
  return 0;
}

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

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

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> v(n);
    set<ll> s;
    rep(i,n) cin>>v[i];
    rep(i,n) s.insert(v[i]);

    if(v.size()==s.size()) YES;
    else NO;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }
const int INF=1001001001;
const int mod = 1000000007;

int main() {
  int H,W;
  cin>>H>>W;
  vector<string>s(H);
  for(int i=0;i<H;i++){
    cin>>s[i];
  }
  vector<vector<int>>dist(H,vector<int>(W,-1));
  queue<pair<int,int>>q;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i][j]=='#'){q.push(make_pair(i,j));dist[i][j]=0;}
    }
  }
  vector<int>dx={0,0,-1,1};
  vector<int>dy={1,-1,0,0};
  while(!q.empty()){
    auto p=q.front();q.pop();
    int x=p.second,y=p.first;
    for(int k=0;k<4;k++){
      int ny=y+dy[k],nx=x+dx[k];
      if(ny<0||ny>=H||nx<0||nx>=W){continue;}
      if(dist[ny][nx]!=-1){continue;}
      dist[ny][nx]=dist[y][x]+1;
      q.push(make_pair(ny,nx));
    }
  }
  int MAX=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      chmax(MAX,dist[i][j]);
    }
  }
  cout<<MAX<<endl;
  return 0;
}

#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

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

  vector<int> V(N);
  for( int i = 0; i < N; i++ ) cin >> V.at(i);

  int ans = 0;
  for( int l = 0; l <= min(N, K); l++){
    for( int r = 0; l+r <= min(N, K); r++ ){
      priority_queue<int, vector<int>, greater<int>> pq;
      int total = 0;
      for( int i = 1; i <= l; i++ ){ //左の宝石を詰める
        pq.push(V.at(i-1));
        total += V.at(i-1);
      }
      for( int i = 1; i <= r; i++ ){ //右の宝石を詰める
        pq.push(V.at(N-i));
        total += V.at(N-i);
      }
      for( int i = 0; i < max(0LL, K-(l+r)); i++ ){
        if( pq.empty() ) break;
        if( pq.top() < 0 ){
          total -= pq.top();
          pq.pop();
        }
      }
      ans = max(ans, total);
    }
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main(){
  int H,W,i,j,a;scanf("%d%d",&H,&W);
  bool odd[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%d",&a);
      odd[i][j] = a&1;
    }
  }
  bool coin = false;vector<pair<pair<int,int>,pair<int,int>>> v;
  i = 0;j = 0;int ni,nj;
  while(true){
    if((!(i&1)) && j+1 == W){
      ni = i+1;nj = j;
    }
    else if(i&1 && j == 0){
      ni = i+1;nj = j;
    }
    else if(!(i&1)){
      ni = i;nj = j+1;
    }
    else{
      ni = i;nj = j-1;
    }
    if(ni == H) break;
    if(odd[i][j]){
      if(coin == false){
        coin = true;
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
      else{
        coin = false;
      }
    }
    else{
      if(coin == true){
        v.push_back(make_pair(make_pair(i,j),make_pair(ni,nj)));
      }
    }
    i = ni;j = nj;
  }
  printf("%d\n",v.size());
  for(i=0;i<v.size();i++) printf("%d %d %d %d\n",v[i].first.first+1,v[i].first.second+1,v[i].second.first+1,v[i].second.second+1);
}

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

struct memo {
  int x;
  int y;
  int xx;
  int yy;
};

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  rep(i, H)rep(j, W) cin >> a[i][j];
  vector<memo> vec;
  rep(i, H)rep(j, W) {
    if (a[i][j]%2) {
      memo tmp;
      tmp.x = j+1;
      tmp.y = i+1;
      if (j < W-1) {
        tmp.xx = j+2;
        tmp.yy = i+1;
        a[i][j+1]++;
        vec.push_back(tmp);
      }
      else if (i < H-1){
        tmp.xx = j+1;
        tmp.yy = i+2;
        a[i+1][j]++;
        vec.push_back(tmp);
      }
    }
  }
  cout << vec.size() << endl;
  rep(i, vec.size()) {
    cout << vec[i].y << " " << vec[i].x << " " << vec[i].yy << " " << vec[i].xx << endl;
  }
}


#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(0, i, N)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    ll ans = 0;
    rep(0, i, N)
    {
        x -= a.at(i);
        if (x < 0)
        {
            break;
        }
        ans++;
    }
    if (x > 0)
    {
        ans--;
    }
    cout << ans << endl;
}

#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;
}

int main(){
	int x=read(),y=read(),ans=0;
	if (x==1) ans+=300000;
	if (y==1) ans+=300000;
	if (x==2) ans+=200000;
	if (y==2) ans+=200000;
	if (x==3) ans+=100000;
	if (y==3) ans+=100000;
	if (x==1&&y==1) ans+=400000;
	printf("%d\n",ans);
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

bool check(ll x, ll pos) { return (x & (1LL << pos)); }

vector <ll> v;

ll gelim(ll X)
{
    ll ind = 0;
    for(ll i = 60; i >= 0; i--)
    {
        if((X >> i & 1) == 0)
        {
            ll x = ind;
            while(x < v.size() && !check(v[x], i)) x++;
            if(x == v.size()) continue;
            swap(v[ind], v[x]);
            for(ll j = 0; j < v.size(); j++)
            {
                if(j != ind && check(v[j], i)) v[j] ^= v[ind];
            }
            ind++;
        }
    }
    ll ans = 0;
    for(ll i = 0; i < v.size(); i++) ans ^= v[i];
    return ans;
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,x;
    cin >> n;
    ll all = 0;
    for(ll i = 0; i < n; i++)
    {
        cin >> x;
        all ^= x;
        v.push_back(x);
    }
    sort(v.rbegin(), v.rend());
    ll ans = gelim(all);
    cout << ans + (ans ^ all);
}

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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	int n,d[6];
	cin>>n;
	int i,j;
	set<long long>s;
	for(i=0;i<n;i++){
		for(j=0;j<6;j++)cin>>d[j];
		long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
		if(s.find(x)!=s.end()){
			cout<<"No"<<endl;
			return 0;
		}else{
			dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
			di.all_rolls(s);
		}
	}
	cout<<"Yes"<<endl;
}


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

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

  int n = -1;
  for(int i = 0;i < s.size();i++){
    if(s.at(i)=='A'){
      n = i;
      break;
    }
  }

  int m = -1;
   for(int j = 0;j < s.size();j++){
    if(s.at(j)=='C'){
      m = j;
      if(n+1==m){
        break;
      }
    }
  }

  if(n >= 0 && m >= 0 && n+1==m){
    cout << "Yes" << endl;
  }

  else{
    cout << "No" << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;
  int pos = s.find("AC");
  if (pos != string::npos) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 2e3+5,mod = 998244353;
int n,k,C[MAXN<<1][MAXN<<1],bit[MAXN<<1];
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
il Init(){
	C[0][0]=1,bit[0]=1;
	for(ri i=1;i<=4000;++i){
		C[i][0]=1;
		for(ri j=1;j<=i;++j) C[i][j]=add(C[i-1][j],C[i-1][j-1]);
		bit[i]=mul(bit[i-1],2);
	}
}
it Solve(int x,int y,int z){
	int res=0;
	for(ri i=0;i<=z&&i<=x;++i)
		if(y+i-1>=0) inc(res,mul(mul(C[x][i],C[y+z-1][i+y-1]),bit[i]));
	return res;
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(k),read(n),Init();
	for(ri i=2;i<=2*k;++i){
		int cnt=0;
		for(ri j=1;j<=k;++j) cnt+=(i-j>=1&&i-j<=k);
		if(i&1) print(Solve(cnt>>1,k-cnt,n)),puts("");
		else print(add(Solve(cnt>>1,k-cnt,n-1),Solve(cnt>>1,k-cnt,n))),puts("");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll L, R;
  cin >> L >> R;
  /*
  ll sa = R - L;
  L %= 2019;
  R %= 2019;
  if (L == 0 || L == 2018) cout << 0 << endl;
  else if (sa < 2019 - L) cout << (L * (L + 1)) % 2019 << endl;
  else cout << 0 << endl;
  */
  int ans = 2018;
  R = min(R, L + 4038);
  for (ll i = L; i <= R; i++){
    for (ll j = i + 1; j <= R; j++){
      int x = i*j%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;

void y(bool c) {
	if (c)print("Yes");
	else print("No");
}

void solve() {
	int N, M, V, P; cin >> N >> M >> V >> P;
	vector<int>v(N);
	REP(i, N)cin >> v[i];
	VSORT(v);
	int ok = N-1, ng = -1;
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		int val = v[mid] + M;
		int rem = M * V - M;
		rem -= M * mid;
		rem -= M * (P - 1);

		FOR(i, mid + 1, N-P+1) {
			if (v[i] <= val) {
				rem -= (val - v[i]);
			}
		}
		if (rem <= 0&&val>=v[N-P])ok = mid;
		else ng = mid;
	}
	REP(i, N) {
		if (v[i] == v[ok]) {
			ok = i;
			break;
		}
	}
	print(N - ok);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll>
#define vl vector<ll>
#define vvl vector< vector<ll> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> >
#define mll map<ll, ll>
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll n, m, v, p;
        cin>>n>>m>>v>>p;
        vl vec(n);
        rep(i, n)   cin>>vec[i];
        sort(all(vec));
        vl pref(n);
        ll cur = 0;
        rep(i, n){
            cur += vec[i];
            pref[i] = cur;
        }
        ll ans = 0;
        rep(i, n){
            ll nv = v;
            nv -= (i+1);
            bool poss = false;
            ll j = upper_bound(all(vec), vec[i] + m) - vec.begin();
            if(n - j >= p)  continue;
            else{
                nv -= (n - j);
                if(v <= 0)  {ans++;poss = true;}
                else{
                    ll np = p - (n - j) - 1;
                    if(j - i - 1 <= np) ans++;
                    else{
                        nv -= np;
                        ll del = (j - np - 1 - i)*(vec[i] + m) - (pref[j-np-1] - pref[i]);
                        if(del >= nv*m) ans++;
                    }
                }
            }
        }
        cout<<ans;
    }
}


#include<cstdio>
#include<vector>
#include<algorithm>
#define MAXN 200006
using namespace std;
int u,v,deep[MAXN],n,m,sum[MAXN],vis[MAXN],ok;
long long a,q,p,ans;
vector<int> road[MAXN];
void DFS(int x,int father)
{
	vis[x]=1;
	sum[x]=1;
	deep[x]=deep[father]+1;
	for(int i=0;i<(int)road[x].size();i++)
	{
		int nex=road[x][i];
		if(nex==father) continue;
		if(vis[nex])
		{
			if((deep[nex]+deep[x])%2==0) ok=0;
			continue;
		}
		DFS(nex,x);
		sum[x]+=sum[nex];
	}
}
int main()
{
	//freopen("squared.in","r",stdin);
	//freopen("squared.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		road[u].push_back(v);
		road[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		ok=1;
		DFS(i,0);
		if(sum[i]==1) a++;
		else
		{
			if(ok==0) p++;
			else q++;
		}
	}
	ans=a*a+2*a*(n-a)+p*p+p*q*2+2*q*q;
	printf("%lld",ans);
}

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> ac(n),pena(n);
    REP(i,m){
        int x;
        string y;
        cin >> x >> y;
        x--;
        if(ac[x]) continue;
        if(y=="AC"){
            ac[x]=1;
        }else{
            pena[x]++;
        }
    }
    int wa=0;
    REP(i,n){
        if(ac[i]) wa+=pena[i];
    }
    printf("%d %d",accumulate(ALL(ac),0),wa);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

template<int row,int col>
struct BinaryMatrix{
    bitset<col> dat[row];
    int r,c;
    BinaryMatrix(size_t r,size_t c):r(r),c(c){}
    bitset<col> &operator[](int i){return dat[i];}
    const bitset<col> &operator[](int i) const{return dat[i];}
    void Gauss_Jordan(int extended=0){
        vector<int> used(r,0);
        for (int j=0;j<c;++j){
            if (extended&&j==c-1) break;
            int p=-1;
            for (int i=0;i<r;++i){
                if (!used[i]&&dat[i][j]){p=i; break;}
            }
            if (p==-1) continue;
            for (int i=0;i<r;++i){
                if (i!=p&&dat[i][j]) dat[i]^=dat[p];
            }
            used[p]=1;
        }
    }
};

const int MAX_N=1e5+10,MAX_B=61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<int> cnt(MAX_B,0),can(MAX_B,0);
    ll ans=0;
    BinaryMatrix<MAX_B,MAX_N+1> BM(MAX_B,N+1);
    for (int i=MAX_B-1;i>=0;--i){
        rep(j,N) if (A[j]&(1LL<<i)) ++cnt[i];
        if (cnt[i]&1) ans+=1LL<<i;
        else if (cnt[i]>0){
            can[i]=1;
            rep(j,N) if (A[j]&(1LL<<i)) BM[MAX_B-1-i][j]=1;
            BM[MAX_B-1-i][N]=1;
        }
    }
    BM.Gauss_Jordan(1);
    rep(i,MAX_B){
        if (!can[MAX_B-1-i]) continue;
        int ok=0;
        rep(j,N) if (BM[i][j]==1) ok=1;
        if (BM[i][N]==0) ok=1;;
        if (ok) ans+=(2LL<<(MAX_B-1-i));
    }
    cout << ans << endl;
}

#include <iostream>
#include <algorithm>
#include <array>
#include <set>
#include <vector>
#include <climits>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> graph[n];
    array<int, 3> points[n];
    int cost[n];
    for (int i = 0; cin >> points[i][0] >> points[i][1]; i++) {
        points[i][2] = i;
        cost[i] = INT_MAX;
    }
    sort(points, points + n, [](const array<int, 3>& left, const array<int, 3>& right) {
        return left[0] < right[0];
    });
    for (int i = 1; i < n; i++) {
        auto dist = min(abs(points[i - 1][0] - points[i][0]), abs(points[i - 1][1] - points[i][1]));
        graph[points[i - 1][2]].emplace_back(points[i][2], dist);
        graph[points[i][2]].emplace_back(points[i - 1][2], dist);
    }
    sort(points, points + n, [](const array<int, 3>& left, const array<int, 3>& right) {
        return left[1] < right[1];
    });
    for (int i = 1; i < n; i++) {
        auto dist = min(abs(points[i - 1][0] - points[i][0]), abs(points[i - 1][1] - points[i][1]));
        graph[points[i - 1][2]].emplace_back(points[i][2], dist);
        graph[points[i][2]].emplace_back(points[i - 1][2], dist);
    }
    long long result = 0;
    set<int> mst = {0};
    set<pair<int, int>> set;
    auto update = [&](const vector<pair<int, int>>& nodes) {
        for (auto& p : nodes) {
            if (mst.find(p.first) != end(mst)) {
                continue;
            }
            if (cost[p.first] > p.second) {
                set.erase({cost[p.first], p.first});
                cost[p.first] = p.second;
                set.emplace(p.second, p.first);
            }
        }
    };
    update(graph[0]);
    do {
        auto current = set.begin()->second;
        auto weight = set.begin()->first;
        set.erase(set.begin());
        mst.emplace(current);
        result += weight;
        update(graph[current]);
    } while (!set.empty());
    cout << result;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
const int INF=0x3f3f3f3f;
const int maxn=1e5+7;
int n;
string s;
int main()
{
	cin>>n;
	cin>>s;
	bool ok=0;
	string op;
	for(int st=0;st<2;st++)
	{
		for(int ed=0;ed<2;ed++)
		{
			op=(st?"S":"W");
			for(int i=0;i<s.length()-1;i++)
			{
				char pre=(i?op[i-1]:(ed?'S':'W'));
				char cur=op[i];
				if(s[i]=='o')
				{
					if(cur=='S')
						op+=pre;
					else op+=(pre=='W'?'S':'W');
				}
				else{
					if(cur=='W')
						op+=pre;
					else op+=(pre=='W'?'S':'W');
				}
				//dbg(st,ed,i);
	//			dbg(op);
			}
			char edd=(ed?'S':'W');
			if(edd==op[s.length()-1])
			{
				if(s[s.length()-1]=='o')
				{
					char pre=op[s.length()-2];
					if((pre==op[0]&&edd=='S')||(pre!=op[0]&&edd=='W'))
					{
						ok=1;
						break;
					}
				}
				else{
					char pre=op[s.length()-2];
					if((pre==op[0]&&edd=='W')||(pre!=op[0]&&edd=='S'))
					{
						ok=1;break;
					}
				}
			}
		}
		if(ok) break;
	}
	if(!ok) cout<<"-1\n";
	else cout<<op<<'\n';
}


//by rng_59
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <memory.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

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

bool col[1000010];
bool row[1000010];
const int mod = 1e9+7;
int main(){
	int N,M;
	long long ans = 1;
	cin >> N >> M;
	REP(i,N) {
		int a;
		cin >> a;
		if(row[a]) {
			cout << 0;
			return 0;
		}
		row[a] = 1;
	}
	REP(i,M) {
		int b;
		cin >> b;
		if(col[b]) {
			cout << 0;
			return 0;
		}
		col[b] = 1;
	}
	int c=0,r=0;
	for(int i=N*M; i>0; i--) {
        int tc = c,tr = r;
        if(col[i]) {
			tc = 1;
			c++;
		}
        if(row[i])  {
			tr = 1;
			r++;
		}
        if(col[i] || row[i]) ans *= (tc*tr)%mod;
        else ans *= (tc*tr-(N*M-i))%mod;
		ans %= mod;
    }
	cout << ans%mod << endl;
	return 0;
}

#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	string S=in<string>();
	string WS[8];
	REP(i,8) WS[i].resize(N,'_');
	REP(i,4) WS[i][0]='S';
	if(S[0]=='o'){
		WS[0][1]='S';
		WS[0][N-1]='S';
		WS[1][1]='W';
		WS[1][N-1]='W';
		REP(i,2) WS[i+2].clear();
	}
	else{
		WS[2][1]='S';
		WS[2][N-1]='W';
		WS[3][1]='W';
		WS[3][N-1]='S';
		REP(i,2) WS[i].clear();
	}
	REP(i,4) WS[i+4][0]='W';
	if(S[0]=='x'){
		WS[4][1]='S';
		WS[4][N-1]='S';
		WS[5][1]='W';
		WS[5][N-1]='W';
		REP(i,2) WS[i+6].clear();
	}
	else{
		WS[6][1]='S';
		WS[6][N-1]='W';
		WS[7][1]='W';
		WS[7][N-1]='S';
		REP(i,2) WS[i+4].clear();
	}

	for(int i=1;i<N-2;i++){
		REP(j,8){
			if(WS[j].empty()) continue;
			if(S[i]=='o'){
				if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1];
				else if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
			}
			else{
				if(WS[j][i]=='W') WS[j][i+1]=WS[j][i-1];
				else if(WS[j][i]=='S') WS[j][i+1]=WS[j][i-1]=='W'?'S':'W';
			}
		}
	}

	for(int i=N-2;i<N;i++){
		REP(j,8){
			if(WS[j].empty()) continue;
			if(S[i]=='o'){
				if(WS[j][i]=='S'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
						WS[j].clear();
					}
				}
				else if(WS[j][i]=='W'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
						WS[j].clear();
					}
				}
			}
			else{
				if(WS[j][i]=='S'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='S') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='W')){
						WS[j].clear();
					}
				}
				else if(WS[j][i]=='W'){
					if((WS[j][i-1]=='S' && WS[j][(i+1)%N]=='W') || (WS[j][i-1]=='W' && WS[j][(i+1)%N]=='S')){
						WS[j].clear();
					}
				}
			}
		}
	}

	for(auto& x:WS){
		if(!x.empty()){
			out(x);
			return 0;
		}
	}

	out(-1);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
#define chor(x,y) x = (x||y);

const int INF = 1001001001;

int main(){
	int h ,w; cin >> h >> w;
	vector<vi>a, b, c; a = b = c = vector<vi>(h, vi(w));
	rep(i,h) rep(j,w) cin >> a[i][j];
	rep(i,h) rep(j,w) cin >> b[i][j];
	rep(i,h) rep(j,w) c[i][j] =  a[i][j] - b[i][j];
	int bias = 7000;
	vector<vector<vector<bool>>> dp(h,vector<vector<bool>>(w,vector<bool>(14000, false)));
	dp[0][0][bias+c[0][0]] = true;
	rep(i,h)rep(j,w)rep(k, 14000){
		int d = c[i][j];
		if(i>0 && (k-d>0 && k-d<14000)) chor(dp[i][j][k], dp[i-1][j][k-d]);
		if(i>0 && (k+d>0 && k+d<14000)) chor(dp[i][j][k], dp[i-1][j][k+d]);
		if(j>0 && (k-d>0 && k-d<14000)) chor(dp[i][j][k], dp[i][j-1][k-d]);
		if(j>0 && (k+d>0 && k+d<14000)) chor(dp[i][j][k], dp[i][j-1][k+d]);

		// if(dp[i][j][k]) cout << i << " " << j <<" " <<k<<endl;
	}
	int ans = INF;
	rep(i,14000){
		if(dp[h-1][w-1][i]) ans = min(ans, abs(i-bias));
	}
	// rep(i, 14000){
	// 	if(dp[h-1][w-1][i])cout <<i<< endl;
	// }
	cout << ans <<endl;
}

#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <unordered_set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

using namespace std;

const int B = 12750;
bitset<B> dp[81][81];
int vs[81][81];

int main(void) {
  int h, w;
  scanf("%d%d", &h, &w);
  REP(i, h) {
    REP(j, w) {
      scanf("%d", &vs[i][j]);
    }
  }
  REP(i, h) {
    REP(j, w) {
      int v;
      scanf("%d", &v);
      vs[i][j] = abs(vs[i][j]-v);
    }
  }
  // cerr << "> " << vs[0][0] << endl;
  dp[0][0].set(vs[0][0]);
  REP(i, h) {
    REP(j, w) {
      if(i == 0 && j == 0) {
        continue;
      }
      int v = vs[i][j];
      auto &s = dp[i][j];
      bitset<B> b;
      if(i-1 >= 0) {
        b = dp[i-1][j];
      }
      if(j-1 >= 0) {
        b |= dp[i][j-1];
      }
      s = b << v;
      s |= b >> v;
      REP(x, v) {
        if(b[x]) {
          s.set(v - x);
        }
      }
      // cerr << s << endl;
    }
  }
  const auto &s = dp[h-1][w-1];
  REP(i, B) {
    if(s[i]) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


//32
#include<iostream>
#include<algorithm>
#include<numeric>
#include<functional>

using namespace std;

int main(){
  int p[2][10];
  for(int i=0;i<2;i++){
    for(int j=0;j<10;j++){
      cin>>p[i][j];
    }
  }
  for(int i=0;i<2;i++){
    sort(p[i],p[i+1],greater<int>());
    cout<<accumulate(p[i],p[i]+3,0)<<((i==0)?' ':'\n');
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

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

int m, n;

int main(void)
{
	Array w(10), k(10);
	readAll(w); readAll(k);
	sort(ALL(w)); sort(ALL(k));
	int ws = 0, ks = 0;
	for (int i = 0; i < 3; i++)
	{
		ws += w[9 - i];
		ks += k[9 - i];
	}
	cout << ws << ' ' << ks << endl;
	return 0;
}


#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
	string s;
	while (getline(cin, s)){
		int n = s.length();
		while (1){
			if (s.find("the") != string::npos)break;
			if (s.find("this") != string::npos)break;
			if (s.find("that") != string::npos)break;
			REP(i, n){
				if ('a' <= s[i] && s[i] <= 'z'){
					s[i]++;
					if (s[i] > 'z')s[i] -= 26;
				}
			}
		}
		cout<<s<<endl;
	}
}


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

bool isOK(vector<int> v) {
	for (int i = 0; i < 8; i++) {
		for (int j = i + 1; j < 8; j++) {
			if (abs(v[j] - v[i]) == j - i) {
				return false;
			}
		}
	}
	return true;
}

int main()
{
	int k;
	cin >> k;
	vector<int> x(k), y(k);
	for (int i = 0; i < k; i++) {
		cin >> x[i] >> y[i];
	}
	vector<int> v = { 0, 1, 2, 3, 4, 5, 6, 7 };
	do {
		bool OK = true;
		for (int i = 0; i < k; i++) {
			if (v[x[i]] != y[i]) {
				OK = false;
			}
		}
		if (OK && isOK(v)) {
			break;
		}
	} while (next_permutation(v.begin(), v.end()));
	vector<string> res(8, "........");
	for (int i = 0; i < 8; i++) {
		res[i][v[i]] = 'Q';
	}
	for (int i = 0; i < 8; i++) {
		cout << res[i] << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i= (a); i<(b); i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

const long long INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
typedef long long ll;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
int n;
vector<vector<int>> board(8,vector<int>(8,0));

void change(vector<vector<int>> &board,int h,int w,int num){
    REP(i,8){
        board[h][i]+=num;board[i][w]+=num;
    }
    board[h][w]-=num*3;
    //右上
    for(int i=h-1;i>=0;i--){
        if(h-i+w<0 || h-i+w>7)continue;
        board[i][h-i+w]+=num;
    }
    //右下
    for(int i=h+1;i<=7;i++){
        if(h-i+w<0 || h-i+w>7)continue;
        board[i][h-i+w]+=num;
    }
    //左上
    for(int i=h-1;i>=0;i--){
        if(w-(h-i)<0 || w-(h-i)>7)continue;
        board[i][w-(h-i)]+=num;
    }
    //左下
    for(int i=h+1;i<=7;i++){
        if(w-(h-i)<0 || w-(h-i)>7)continue;
        board[i][w-(h-i)]+=num;
    }
}

void setqueen(int q,vector<int>queen,vector<vector<int>>board){
    if(q==8){
        REP(i,8){
            int h=queen[i];
            char ans[]="........";
            ans[h]='Q';
            cout << ans << endl;
        }
        exit(0);
    }
    if(queen[q]!=-1){
        setqueen(q+1,queen,board);
    } else {
        for(int i=0;i<8;i++){
            if(board[q][i]<1){
                queen[q]=i;
                change(board,q,i,1);
                setqueen(q+1,queen,board);
                change(board,q,i,-1);
            }
        }
    }
}

signed main () {
    scanf("%d",&n);
    vector<int> queen(8,-1);
    REP(i,n){
        int a,b;scanf("%d %d",&a,&b);
        //a--;b--;
        queen[a]=b;
        change(board,a,b,1);
    }
    setqueen(0,queen,board);
}


//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define REP2(i,a,b) for(int i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(int i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数

//ライブラリ挿入

const int H_MAX=80;
const int W_MAX=80;
const int A_MAX=80;
const int B_MAX=80;

vector<vector<vector<bool>>> dp(H_MAX+1,vector<vector<bool>>(W_MAX+1,vector<bool>(1+A_MAX*(H_MAX+W_MAX),false)));

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> A(H,vector<int>(W)),B(H,vector<int>(W));
    REP(i,H){
        REP(j,W){
            cin>>A[i][j];
        }
    }

    REP(i,H){
        REP(j,W){
            cin>>B[i][j];
        }
    }
    dp[0][0][0]=true;
    dp[1][0][0]=true;
    dp[0][1][0]=true;

    REP(i,H){
        REP(j,W){
            REP(v,1+A_MAX*(H_MAX+W_MAX)){
                if(abs(v-abs(A[i][j]-B[i][j]))<=A_MAX*(H_MAX+W_MAX)){
                    dp[i+1][j+1][v]=dp[i+1][j+1][v]||dp[i][j+1][abs(v-abs(A[i][j]-B[i][j]))];
                    dp[i+1][j+1][v]=dp[i+1][j+1][v]||dp[i+1][j][abs(v-abs(A[i][j]-B[i][j]))];
                }
                if(v+abs(A[i][j]-B[i][j])<=A_MAX*(H_MAX+W_MAX)){
                    dp[i+1][j+1][v]=dp[i+1][j+1][v]||dp[i][j+1][v+abs(A[i][j]-B[i][j])];
                    dp[i+1][j+1][v]=dp[i+1][j+1][v]||dp[i+1][j][v+abs(A[i][j]-B[i][j])];
                }
            }
        }
    }
    REP(v,1+A_MAX*(H_MAX+W_MAX)){
        if(!dp[H][W][v]) continue;
        cout << v <<endl;
        return 0;
    }
}

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

int main(){
    int n, k; cin >> n >> k;
    vector<double> p(200000);
    for(int i=0; i<n; i++) cin >> p[i];

    vector<int> sigma(1000);
    sigma[0] = 1;
    for(int i=1; i<1000; i++){
        sigma[i] = sigma[i-1]+(i+1);
    }
    for(int i=0; i<n; i++){
        p[i] = sigma[p[i]-1] / p[i];
    }
    double MAX = 0;
    double tmp = 0;
    for(int i=0; i<k; i++) tmp += p[i];
    MAX = tmp;
    for(int i=1; i<=n-k; i++){
        tmp = tmp - p[i-1] + p[i+k-1];
        if(tmp > MAX){
            MAX = tmp;
        }
    }
    printf("%.12f\n", MAX);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fo(i,a,b) for (int i=a;i<=b;i++)
#define fd(i,a,b) for (int i=a;i>=b;i--)
#define fi first
#define se second
#define mkp make_pair

typedef long long ll;

const int N=1100000;

int n,ans,flag,s[N],t[N],pos[N],a[N],b[N];

int read()
{
	int ret=0,sig=1;
	char c;
	while (c=getchar(),(c<'0'||c>'9')&&c!='-');
	if (c=='-') sig=-1;
	else ret=c-'0';
	while (c=getchar(),c>='0'&&c<='9') ret=ret*10+c-'0';
	return ret*sig;
}

int main()
{
	n=read();
	fo(i,1,n)
	{
		char c;
		while (c=getchar(),c<'a'||c>'z');
		s[i]=c-'a'+1;
	}
	fo(i,1,n)
	{
		char c;
		while (c=getchar(),c<'a'||c>'z');
		t[i]=c-'a'+1;
		if (s[i]!=t[i]) flag=1;
	}
	if (!flag)
	{
		printf("0\n");
		return 0;
	}
	int w=n+1;
	b[0]=1;
	fd(i,n+1,1)
		if (t[i]!=t[i-1])
		{
			b[++b[0]]=i-1;
			while (w&&(w>i||s[w]!=t[i])) w--;
			if (!w)
			{
				printf("-1\n");
				return 0;
			}
			a[++a[0]]=w;
		}
	int tail=1;
	fo(i,2,a[0])
	{
		while (tail<a[0]&&a[tail+1]-(i-tail-1)>=b[i]) tail++;
		ans=max(ans,i-tail);
	}
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define N 110
#define INF 0x3f3f3f3f
using namespace std;
typedef struct {
    int w;
    int s;
    int e;
}Edge;
Edge edge[N*N];
int m[N][N];
int father[N];
int n;
int k = 0;  //edge的下标
int result = 0;
int findfather(int x){
    return x == father[x] ? x : findfather(father[x]);
}
int cmp(Edge a, Edge b){
    return a.w < b.w;
}
void Kruscal(){
    for(int u = 0; u < k; u++){
        int s = edge[u].s;
        int e = edge[u].e;
        if(findfather(s) != findfather(e)){
            father[findfather(e)] = s;
            result += edge[u].w;
        }
    }
    printf("%d\n", result);
}
int main(){

    scanf("%d", &n);
    for(int i = 1; i <= n; i++) father[i] = i;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            int b;
            scanf("%d", &b);
            m[i][j] = b;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n ;j++){
            if(m[i][j] != -1) {
                edge[k].w = m[i][j];
                edge[k].s = i;
                edge[k].e = j;
                k++;
            }
        }
    }
    sort(edge, edge+k, cmp);
    Kruscal();
    return 0;
}


/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
*/
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define ff              first
#define ss              second

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )
#define RFOR(i,e,s)     for( LL i = e ; i>=s ; i-- )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("WA.txt","w",stdout)

#define DEBUG(x)        cerr<<#x<<" = "<<x<<endl
#define PRINTALL(v)     {cerr<<endl<<"Printing: "<<#v<<endl;for(LL i = 0 ; i<v.size(); i++) DEBUG(v[i]); cerr<<endl;}

using namespace std;

LL f[2019];

int main(){

    LL L,R;
    SL(L); SL(R);

    for( LL i = L ; i<= min(R,L+2019-1) ;i++ ) f[ i % 2019 ]++;

    LL mn = 1e18;
    for( LL i = 0 ; i<2019 ; i++ ){
        for( LL j = i+1 ; j<2019 ; j++ ){
            if( f[i] && f[j] ) mn = min(mn,(i*j)%2019);
        }
    }
    cout<<mn<<endl;

return 0;}

#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

const int mod = 2019;
const int INF = 1e16;
int main() {
	ll l, r;
	cin >>l >>r;
	ll ans(INF);
	for (ll i = l; i < r; ++i) {
		for (ll j = l + 1; j <= r; ++j) {
			ll ii = i % mod;
			ll jj = j % mod;
			ll can = ii * jj;
			can %= mod;
			ans = min(ans, can);
			if (ans == 0) {
				cout << 0;
				return 0;
			}
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
constexpr ll mod = 1e9+7;
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), num(N+1, 0);
    rep(i, 0, N) cin >> A[i];
    ll ans = 1;
    num[0] = 3;
    rep(i, 0, N){
        ans *= num[A[i]];
        num[A[i]]--;
        num[A[i]+1]++;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back

using namespace std;

ll n;
ll a[350];
ll dp[350][302*302 + 2];
ll dp1[350][302*302];
const ll mod = 998244353;
ll ME(ll x,ll nn,ll M)
{
    ll result=1;
    while(nn>0)
    {
        if(nn % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        nn=nn/2;
    }
    return result;
}
ll solve(ll id, ll sum)
{
        if(sum < 0) return 0LL;
        if(id == n+1){
                if(sum == 0) return 1LL;
                return 0;
        }
        ll &ret = dp[id][sum];
        if(ret != -1) return ret;
        ret = solve(id+1, sum - a[id]);
        ret = (ret + 2*solve(id+1 , sum))%mod;
        return ret;
}
ll solve2(ll id ,ll sum)
{
        if(sum<0) return 0;
        if(id == n+1) {
                if(sum == 0) return 1LL;
                return 0;
        }
        ll &ret = dp1[id][sum];
        if(ret != -1) return ret;
        ret = solve2(id+1, sum);
        ret = (ret + solve2(id+1, sum-a[id]))%mod;
        return ret;
}
int main()
{
        cin >> n;
        ll sum=0;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
                sum += a[i];
        }
        ll ans = ME(3,n,mod);
        ans = (ans * ME(3LL , mod-2,mod))%mod;
        memset(dp,-1,sizeof dp);
        for(ll i=(sum+1)/2; i <= sum; i++) {
                ans = (ans - solve(1 , i) + mod)%mod;
        }
        //memset(dp,-1,sizeof dp);
        if(sum%2 == 0){
        memset(dp1,-1,sizeof dp1);
        ans = (ans + solve2(1 , (sum)/2))%mod;
        }
        ans = (ans*3LL)%mod;
        cout << ans << endl;
        return 0;
}


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

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int mx = -101;
    int my = 101;
    rep(i, n) {
        int x1;
        cin >> x1;
        mx = max(mx, x1);
    }
    rep(i, m) {
        int y1;
        cin >> y1;
        my = min(my, y1);
    }
    if(mx >= y || my <= x) cout << "War" << endl;
    else if(mx < my) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}

#define  mx 200004
#define base 193ll

typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){
    int n, m , x, y;
    I2(n, m);
    I2(x, y);

    int ar[n+2];
    int br[m+2];

    for(int i = 1; i <= n; i++){
        I(ar[i]);
    }
    for(int j = 1; j <= m; j++){
        I(br[j]);
    }

    sort(ar + 1, ar + n + 1);
    sort(br + 1 , br + m + 1);

    for(int i = x + 1; i <= y; i++){
        if(i > ar[n] && i <= br[1]){
            PC("No War");
            NL;
            return 0;
        }
    }

    PC("War");
    NL;
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct edge{
    int to;
    int cap;
    int rev;
};
struct Dinic{
    int V;
    vector<int> level, used;
    vector<vector<edge>> G;
    Dinic(int N){
        V = N;
        used.resize(V, 0);
        level.resize(V, -1);
        G.resize(V);
    }
    void add(int u, int v, int c){
        edge e1 = {v, c, (int)G[v].size()};
        G[u].push_back(e1);
        edge e2 = {u, 0, (int)G[u].size() - 1};
        G[v].push_back(e2);
    }
    void bfs(int s){
        level.assign(V, -1);
        queue<int> q;
        q.push(s);
        level[s] = 0;
        while(!q.empty()){
            int v = q.front();
            q.pop();
            for(edge e: G[v]){
                if(e.cap > 0 && level[e.to] < 0){
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int s, int t, int f){
        if(s == t) return f;
        for(int &i = used[s]; i < (int)G[s].size(); i++){
            edge &e = G[s][i];
            if(e.cap > 0 && level[e.to] > level[s]){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int solve(int s, int t){
        int flow = 0;
        int INF = 1e9;
        while(1){
            bfs(s);
            if(level[t] < 0) return flow;
            used.assign(V, 0);
            int f;
            while((f = dfs(s, t, INF)) > 0) flow += f;
        }
    }
};

int main(){
    int N;
    cin >> N;
    Dinic Ford(2 * N + 2);
    int can[N][N];//can[i][j] = 1でペアが作れる
    vector<int> a(N), b(N), c(N), d(N);
    for(int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < N; i++) cin >> c[i] >> d[i];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] < c[j] && b[i] < d[j]) can[i][j] = 1;
            else can[i][j] = 0;
        }
    }
    for(int i = 0; i < N; i++){
        Ford.add(2 * N, i, 1);
        Ford.add(N + i, 2 * N + 1, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(can[i][j]) Ford.add(i, N + j, 1);
        }
    }
    int ans = Ford.solve(2 * N, 2 * N + 1);
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
int main(void){
  int n;
  cin>>n;
  vector<P> red,blue;
  for(int i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    red.push_back({a,b});
  }
  for(int i=0;i<n;i++){
    int c,d;
    cin>>c>>d;
    blue.push_back({c,d});
  }
  sort(blue.begin(),blue.end());
  vector<bool> tf(n,false);
  int cnt=0;
  for(int i=0;i<n;i++){
    int bx=blue[i].first;
    int by=blue[i].second;
    int y=-1000;
    int x=-1;
    for(int j=0;j<n;j++){
      if(tf[j]){
        continue;
      }
      int rx=red[j].first;
      int ry=red[j].second;
      if(bx<rx){
        continue;
      }
      if(by<ry){
        continue;
      }
      if(y<ry){
        x=j;
        y=ry;
      }
    }
    if(x!=-1){
      ++cnt;
      tf[x]=true;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int>   PI;
typedef vector<int> VI;
typedef long long int LL;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    n=(2*n);
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i+=2)
    {
        ans=ans+a[i];
    }
    cout<<ans;
	return 0;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() {
    cout << '\n';
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> a(2 * n);
    for (Int i = 0; i < 2 * n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    Int res = 0;
    for (Int i = 0; i < 2 * n; i += 2) {
        res += a[i];
    }
    print(res);
}

int main() {
    solve();
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b)
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

bool is_prime(ll n) {
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return n != 1;
}

int main()
{
    int k, x; cin >> k >> x;
    for (int i = x - k +1; i <= x + k -1; i++) {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 1e18
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

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

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

// End of Gennady-Korotkevich's template

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 998244353LL;

int main() {
	IOS;
	int n, k; cin >> n >> k;
	vector<double> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] = (a[i] + 1) / 2;
	}
	double sum = 0;
	double mx = -1;
	for (int i = 0; i < k; i++) {
		sum += a[i];
	}
	mx = sum;
	for (int i = k; i < n; i++) {
		sum += a[i];
		sum -= a[i - k];
		mx = max(mx, sum);
	}
	cout << fixed << setprecision(10);
	cout << mx;
}


#include <bits/stdc++.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

int n;

int main() {
	read(n);
	print(180 * (n - 2));
}

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

int main(void){
   long long A,B,K;
   cin>>A>>B>>K;
   for(int i=0;i<K;i++){
      if(i%2==0){
         if(A%2!=0){
            A-=1;
         }
         B+=A/2;
         A/=2;
      }else{
         if(B%2!=0){
            B-=1;
         }
         A+=B/2;
         B/=2;
      }
   }
   cout<<A<<" "<<B<<endl;
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
 int main()
 {
     int x,y,i,j,n;
     deque<int >v;
     cin >> n;
     for(i = 0 ;i<n ;i++)
     {
         cin >> x;
         deque<int >:: iterator it;
         it = upper_bound(v.begin(),v.end(),x);
         if(v.begin()== it)
            v.push_front(x);
         else
            v[it -v.begin()]==x ;
     }
     cout<<v.size()<<endl;
 }

#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=610;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
bool vis[N][N];
int n,d1,d2;
void solve (int d)
{
	int t=0;
	while (d%4==0) d/=4,++t;
	if (d&1)
	{
		for (int i=0; i< n; i++)
			for (int j=0; j< n; j++)
				if (((i>>t)+(j>>t))&1) vis[i][j]=1;
	}
	else
	{
		for (int i=0; i< n; i++) if ((i>>t)&1)
			for (int j=0; j< n; j++)
				vis[i][j]=1;
	}
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(d1),sc(d2); int m=n*n; n<<=1;
	solve (d1);
	solve (d2);
	for (int i=0; i< n; i++)
		for (int j=0; j< n; j++) if (!vis[i][j])
		{
			printf ("%d %d\n",i,j);
			if (!--m) return 0;
		}

    return 0;
}


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

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    cout<<max(0,(n-h+1)*(n-w+1))<<endl;
    return 0;
}

// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> v(2);
    cin >> v[0] >> v[1];
    int ans = 0;
    if (v[0] == 1 && v[1] == 1) {
        ans += 400000;
    }
    REP(i, 2) {
        if (v[i] == 1) {
            ans += 300000;
        } else if (v[i] == 2) {
            ans += 200000;
        } else if (v[i] == 3) {
            ans += 100000;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int n, x[1<<18], y[1<<18];
char d[1<<18];

void Rotate(){
  for(int i = 1; i <= n; i++){
    int cx = y[i],cy = 200000-x[i],cz;
    if(d[i] == 'U') cz = 'R';
    if(d[i] == 'R') cz = 'D';
    if(d[i] == 'D') cz = 'L';
    if(d[i] == 'L') cz = 'U';
    x[i] = cx; y[i] = cy; d[i] = cz;
  }
}

vector<pair<int,char>> v1[1<<19];
vector<pair<int,char>> v2[1<<19];

int solve_01(){
  int ans = (1 << 24);
  for(int i = 0; i <= 500000; i++) v1[i].clear();
  for(int i = 1; i <= n; i++){
    if(!(d[i] == 'R' || d[i] == 'U')) continue;
    v1[x[i]+y[i]].push_back(make_pair(x[i],d[i]));
  }
  for(int i = 0; i <= 500000; i++){
    sort(v1[i].begin(),v1[i].end());
    for(int j = 0; j < (int)v1[i].size() - 1; j++){
     if(!(v1[i][j].second == 'R' && v1[i][j+1].second == 'U')) continue;
     ans = min(ans,v1[i][j+1].first - v1[i][j].first);
    }
  }
   return ans * 10;
}

int solve_02(){
  int ans = (1 << 24);
  for(int i = 0; i <= 500000; i++) v2[i].clear();
  for(int i = 1; i <= n; i++){
    if(!(d[i] == 'L' || d[i] == 'R')) continue;
    v2[y[i]].push_back(make_pair(x[i],d[i]));
  }
  for(int i = 0; i <= 500000; i++){
    sort(v2[i].begin(),v2[i].end());
    for(int j = 0; j < (int) v2[i].size()-1; j++){
      if(!(v2[i][j].second == 'R' && v2[i][j+1].second == 'L')) continue;
      ans = min(ans,v2[i][j+1].first - v2[i][j].first);
    }
  }
  return ans*5;
 }

 int main(){
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> d[i];
  int fans = (1 << 24);
  for(int i = 1; i <= 4; i++){
    int val1 = solve_01(); fans = min(fans,val1);
    int val2 = solve_02(); fans = min(fans,val2);
    Rotate();
  }
  if(fans == (1 << 24)) cout << "SAFE" << endl;
  else cout << fans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	int h,w,n;
	cin>>h>>w>>n;
	int z = max(h,w);
	cout<<(n+z-1)/z<<"\n";
	return 0;
}

#include <iostream>
using namespace std;

void ask(int left, int right, bool male) {
	int mid = (left + right) / 2;
	cout << mid << endl;
	string s;
	cin >> s;
	if (s == "Vacant") return;
	if (((mid - left) % 2 == 0) == (male == (s == "Male"))) ask(left, mid - 1, male);
	else ask(mid + 1, right, s == "Male");
}

int main() {
	int N;
	cin >> N;
	cout << 0 << endl;
	string s;
	cin >> s;
	if (s == "Vacant") return 0;
	ask(1, N - 1, s == "Male");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
queue<char>a,b,c;
int main(){
 string al , bo ,chr ;
 cin >> al ;
 cin >> bo ;
 cin >> chr ;
 for(int i=0;i<al.size();i++){
    a.push(al[i]);
 }
 for(int i=0;i<bo.size();i++){
    b.push(bo[i]);
 }
 for(int i=0;i<chr.size();i++){
    c.push(chr[i]);
 }
 char curr = a.front();
 a.pop();
 while(true){
     if(curr=='a'){
        if(a.empty()){
          cout << "A" <<endl;
          return 0;
        }
        curr = a.front();
        a.pop();
     }
     else if(curr=='b'){
        if(b.empty()){
          cout << "B" <<endl;
          return 0;
        }
        curr=b.front();
        b.pop();
     }
     else if(curr=='c'){
        if(c.empty()){
          cout << "C" <<endl;
          return 0;
        }
        curr=c.front();
        c.pop();
     }
 }

 return  0;
}

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

int main() {
    string s[3];
    rep(i, 3) cin >> s[i];

    int t = 0;
    vector<int> idx(3);
    while (true) {
        if (s[t].size() == idx[t]) {
            cout << char('A' + t) << endl;
            return 0;
        }
        t = s[t][idx[t]++] - 'a';
    }

    return 0;
}


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

vector<ll> num(1010,0);
vector<bool> prime(1010,true);//iが素数ならtrue(エラトステネスの篩)
void isprime(){
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=1010;i++){
        if(!prime[i]){continue;}
        for(ll j=i*i;j<=1010;j+=i){
            prime[j]=false;
        }
    }
    return;
}

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

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

    for(ll i=2;i<=n;i++){//n以下の連続整数の素因数個数を数える
        ll number=i;
        for(ll j=2;j<=i;j++){
            if(prime[j]==true){
                while(number%j==0){
                    num[j]++;
                    number/=j;
                }
            }
        }
    }

    ll ans=1;
    for(ll i=2;i<=n;i++){//約数個数を計算
        ans*=(num[i]+1);
        ans%=mod;
    }

    cout<<ans<<endl;

    return 0;
}

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

const double pi=3.14159265;
int main(){
  int n;
  cin>>n;
  if(n==0){
    cout<<0<<endl;
    return 0;
  }
  string s;
  int p=n;
  int q;
  while(p!=1){
    q=abs(p%(-2));
    if(p<0) p--;
    p/=(-2);
    s+=q+'0';
  }
  cout<<1;
  rep(i,s.size()){
    cout<<s[s.size()-i-1];
  }
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int n=a.size();
  int m=b.size();
  int l=c.size();
  if(a[n-1]==b[0] && b[m-1]==c[0])cout << "YES" << endl;
  else cout << "NO" << endl;

}

#include<stdio.h>
int d,t,s;
int main()
{
	scanf("%d %d %d", &d, &t, &s);
	d=d+s-1;
	if(t>=(d/s))printf("Yes");
	else printf("No");
}


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

#define ll long long
#define pll pair<ll,ll>

#define left 2*node+1
#define right left+1
#define mid (s+e>>1)

const ll N=5e5+5;
vector<ll> T[4*N];

void build(ll A[], ll node, ll s, ll e){
	if(s==e){
		T[node].push_back(A[s]);
		return;
	}
	build(A, left, s, mid);
	build(A, right, mid+1, e);
	merge(T[left].begin(), T[left].end(), T[right].begin(), T[right].end(), back_inserter(T[node]));
}

ll query(ll node,ll s, ll e, ll x, ll y){
	if(e<s || s>y || e<x)
		return 0;
	if(x<=s && e<=y){
		ll a=upper_bound(T[node].begin(), T[node].end(), y)-T[node].begin();
		return T[node].size()-a;
	}
	ll p1=query(left, s, mid, x, y);
	ll p2=query(right, 1+mid,e, x, y);
	return p1+p2;
}

int main(){

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

	ll n, q;
	cin>>n>>q;
	ll A[n];
	ll B[n];
	for(ll i=0;i<n;i++)
		cin>>A[i];
	map<ll,ll> M;
	for(ll i=n-1;i>=0;i--){
		if(M.count(A[i]))
			B[i]=M[A[i]];
		else
			B[i]=INT_MAX;
		M[A[i]]=i;
	}

	build(B,0,0, n-1);

	while(q--){
		ll x, y;
		cin>>x>>y;
		ll ans=query(0,0,n-1,x-1,y-1);
		cout<<ans<<"\n";
	}

}

#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){
    int n,q;
    cin >> n>> q;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> pi(n+1,-1);
    vector<vector<int>> ps(n);
    rep(i,n){
        int l = pi[a[i]];
        if (l != -1) ps[l].push_back(i);
        pi[a[i]] = i;
    }//赤矢印
    vector<vector<P>> qs(n);//青点
    rep(qi,q) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        qs[l].emplace_back(r,qi);
    }
    vector<int> ans(q);
    BIT<int> d(n);
    for (int x = n-1; x >= 0; --x) {//平面走査
        for (int y : ps[x]) d.add(y,1);
        for (P query : qs[x]) {
            int r = query.first, i = query.second;
            ans[i] = (r-x+1) - d.sum(r);
        }
    }
    rep(i,q) cout << ans[i] << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}

char SWswap(char c){
    if (c == 'S') return 'W';
    else return 'S';
}

bool out(string S, string s){
    int N = S.size();
    if (s[N-1] == 'o'){
        if (S[N-1] == 'S' && S[0] == S[N-2]){
            return true;
        }
        else if (S[N-1] == 'W' && S[0] != S[N-2]){
            return true;
        }
    }
    else {
        if (S[N-1] == 'S' && S[0] != S[N-2]){
            return true;
        }
        else if (S[N-1] == 'W' && S[0] == S[N-2]){
            return true;
        }
    }
    return false;
}

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

int N;
string s;
cin >> N >> s;

VS ans{"SS", "SW", "WS", "WW"};
for(string S: ans){
    rep(i, 1, N-1){
        if (s[i] == 'o'){
            if (S[i] == 'S') S.push_back(S[i-1]);
            else S.push_back(SWswap(S[i-1]));
        }
        else { // s[i] == 'x'
            if (S[i] == 'S') S.push_back(SWswap(S[i-1]));
            else S.push_back(S[i-1]);
        }
    }

    if (s[0] == 'o'){
        if ((S[0] == 'S' && S[1] == S[N-1]) || (S[0] == 'W' && S[1] != S[N-1]))
            if (out(S, s)){
                cout << S + "\n";
                return 0;
            }
    }
    else {
        if ((S[0] == 'S' && S[1] != S[N-1]) || (S[0] == 'W' && S[1] == S[N-1]))
            if (out(S, s)){
                cout << S + "\n";
                return 0;
            }
    }

}

cout << "-1\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．

#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

int main()
{
	int n; cin >> n;
	vector<int> a(n); rep(i, n)cin >> a[i];
	if (a[0] != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i < n; ++i)
	{
		if (a[i] > a[i - 1] + 1)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	ll res = 0;
	for (int i = 1; i < n; ++i)
	{
		if (a[i] == a[i - 1] + 1)++res;
		else res += a[i];
	}
	cout << res << endl;
}


#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

struct Combination
{
    int maxn;
    vector<ll> fmemo;
    vector<ll> imemo;
    vector<ll> ifmemo;

    Combination(int maxn) : maxn(maxn){
        fmemo.resize(maxn + 1);
        imemo.resize(maxn + 1);
        ifmemo.resize(maxn + 1);
        for(ll i = 1; i <= maxn; i++){
            imemo[i] = modpow(i, MOD - 2);
        }
    }

    ll fact(ll n){
        if(n == 0) return 1;
        if(fmemo[n]) return fmemo[n];
        return fmemo[n] = n * fact(n - 1) % MOD;
    }

    ll ifact(ll n){
        if(n == 0) return 1;
        if(ifmemo[n]) return ifmemo[n];
        return ifmemo[n] = imemo[n] * ifact(n - 1) % MOD;
    }

    ll com(ll n, ll k){
        if(k > n) return 0;
        if(k == n || k == 0) return 1;
        return (fact(n) * ifact(k) % MOD) * ifact(n - k) % MOD;
    }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    Combination com(n * m);
    ll c = com.com(n * m - 2, k - 2);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(i + j == 0) continue;
            if(i == 0 || j == 0) ans = (ans + c * (i + j) % MOD * (n - i) * (m - j) % MOD) % MOD;
            else ans = (ans + c * (i + j) % MOD * (n - i) * (m - j) * 2 % MOD) % MOD;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

const int N=2e5+5,MOD=1e9+7;

long long fac[N],infac[N];

long long poww(long long x,long long y)
{
	if(y==0) return 1;
	if(y&1) return (x*poww(x,y-1))%MOD;
	return poww((x*x)%MOD,y/2);
}

long long nck(int n,int k)
{
	return (((fac[n]*infac[k])%MOD)*infac[n-k])%MOD;
}

long long get(int a,int b,int c,int d)
{
	int tot=(c-a)+(d-b);
	return nck(tot,c-a);
}

int main()
{
	fac[0]=infac[0]=1;
	for(int i=1;i<N;i++)
	{
		fac[i]=(fac[i-1]*i)%MOD;
		infac[i]=poww(fac[i],MOD-2);
	}
	int n,m,a,b;
	cin >> n >> m >> a >> b;
	long long ans=0;
	for(int i=0;i<n-a;i++)
	{
		ans+=get(0,0,i,b-1)*get(i,b,n-1,m-1);
		ans%=MOD;
	}
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <cmath>
using namespace std;
const long long MAX = 10000000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    long long a, b;
    cin >> a >> b;
    map<long long, long long> v;
    long long tmpb = b;
    for(long long i=2;i*i<=b;i++) {
        while(tmpb % i == 0) {
            tmpb /= i;
            v[i] += 1;
        }
    }
    if(tmpb!=1) v[tmpb] += 1;
    long long ans = 1;
    for(auto m:v) {
        //cout << m.first << " " << m.second << endl;
        ans = (ans * COM(m.second+a-1, a-1))%MOD;
    }
    cout << ans << endl;
}
/*
2 2 3

a1b2 b1b2 c1c2
a1+b1+b2 = 2
a2+b2+c2 = 1
*/

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

int main() {
  int s,t;
  cin>>s>>t;
  cout<<2*t-s<<endl;
}


#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100][100],b[100],c[100],m,n;
  int mn;
  while(cin>>n>>m&&n+m){
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	a[i][j]=200000000;
    for(i=0;i<m;i++){
      int p,q,r;
      cin>>p;
      if(p){
	cin>>p>>q>>r;
	p--;
	q--;
	a[p][q]=a[q][p]=min(a[p][q],r);
      }else{
	cin>>p>>q;
	p--;
	q--;
	memset(b,-1,sizeof(b));
	b[p]=1;
	c[p]=0;
	for(j=0;j<n;j++){
	  if(j!=p)
	    c[j]=c[p]+a[p][j];
	}
	for(;;){
	  mn=q;
	  for(j=0;j<n;j++){
	    if(b[j]==-1&&c[mn]>c[j])
	      mn=j;
	  }
	  if(mn==q)
	    break;
	  b[mn]=1;
	  for(j=0;j<n;j++)
	    c[j]=min(c[j],c[mn]+a[mn][j]);
	}
	if(c[q]==200000000)
	  cout<<-1<<endl;
	else
	  cout<<c[q]<<endl;
      }
    }
  }
  return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int cost[101][101];
int d[101];
bool used[101]={};
int n,k;
#define INF 10000000
int V;
void dijkstra(int s){
	fill(d,d+101,INF);
	fill(used,used+101,false);
	d[s]=0;
	while(1){
		int c=-1;
		for(int u=0;u<V;u++){
			if(!used[u] && (c==-1 || d[u]<d[c])){
				c=u;
			}
		}
		if(c==-1){
			break;
		}
		used[c]=true;
		for(int i=0;i<V;i++){
			d[i]=min(d[i],d[c]+cost[c][i]);
		}
	}
}
int main(){
	while(1){
	scanf("%d %d",&n,&k);
	if(!(n+k)) break;
	for(int i=0;i<101;i++){
		for(int j=0;j<101;j++){
			cost[i][j]=INF;
		}
	}
	V=n;
	for(int i=0;i<k;i++){
		int q;
		scanf("%d",&q);
		if(q){
			int r,o,p;
			scanf("%d %d %d",&r,&o,&p);
			cost[r-1][o-1]=min(p,cost[r-1][o-1]);
			cost[o-1][r-1]=min(p,cost[o-1][r-1]);
		}else{
			int r,p;
			scanf("%d %d",&r,&p);
			dijkstra(r-1);
			if(d[p-1]==INF){
				printf("%d\n",-1);
			}else{
				printf("%d\n",d[p-1]);
			}
		}
	}
	}
	return 0;
}


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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

void rec(vector<vector<int>> &b, int k, vector<vector<vector<int>>> &res){
	int n = b.size();
	int mx = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++) mx=max(mx, b[i][j]);
	}
	int si=0, sj=0;
	if(mx>0){
		bool done = false;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(b[i][j]==mx){
					si = i;
					sj = j;
					done=true;
					break;
				}
			}
			if(done) break;
		}
	}

	int x = -1;
	bool ok = true;
	for(int i=0; i<n; i++){
		set<int> a;
		for(int j=0; j<n; j++){
			if(b[i][j]>0) a.insert(b[i][j]);
		}
		if(x<0) x = a.size();
		if(a.size()>k) return;
		if(x!=a.size()){
			if(i<si) return;
			ok = false;
		}
	}
	for(int i=0; i<n; i++){
		set<int> a;
		for(int j=0; j<n; j++){
			if(b[j][i]>0) a.insert(b[j][i]);
		}
		if(a.size()>k) return;
		if(x!=a.size()) ok = false;
	}
	if(ok && x==k){
		res.push_back(b);
		return;
	}

	for(int i=si; i<n; i++){
		for(int j=(i==si?sj:0); j<n; j++){
			if(i+1<n&&b[i][j]==0&&b[i+1][j]==0){
				b[i][j] = b[i+1][j] = mx+1;
				rec(b, k, res);
				if(res.size()) return;
				b[i][j] = b[i+1][j] = 0;
			}
			if(j+1<n&&b[i][j]==0&&b[i][j+1]==0){
				b[i][j] = b[i][j+1] = mx+1;
				rec(b, k, res);
				if(res.size()) return;
				b[i][j] = b[i][j+1] = 0;
			}
		}
	}
}

vector<vector<vector<int>>> naive(int n, int k){
	vector<vector<vector<int>>> ret;
	vector<vector<int>> b(n, vector<int>(n));
	rec(b, k, ret);
	return ret;
}

string x3[3] = {
	"aab",
	"c.b",
	"cdd",
};

string x4[4] = {
	"aabc",
	"ddbc",
	"efgg",
	"efhh",
};

string x5[5] = {
	"..abc",
	"..abc",
	"ddeef",
	"ggh.f",
	"iihjj",
};

string x6[6] = {
	"abc...",
	"abc...",
	"d.eeff",
	"dghh..",
	".g.ijj",
	"kk.ill",
};

string x7[7] = {
	"abc....",
	"abc....",
	"def....",
	"def....",
	"g..hhii",
	"g..jjkk",
	".llmmnn",
};

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;

	if(n<=2){
		cout << -1 << endl;
		return 0;
	}

	if(n==3){
		for(int i=0; i<3; i++) cout << x3[i] << endl;
		return 0;
	}

	int k = n%4+4;
	int l = n/4-1;
	for(int i=0; i<l; i++){
		for(int j=0; j<4; j++){
			cout << string(i*4, '.') << x4[j] << string(n-4*(i+1), '.') << endl;
		}
	}
	if(k==4){
		for(int j=0; j<4; j++){
			cout << string(n-4, '.') << x4[j] << endl;
		}
	} else if(k==5){
		for(int j=0; j<5; j++){
			cout << string(n-5, '.') << x5[j] << endl;
		}
	} else if(k==6){
		for(int j=0; j<6; j++){
			cout << string(n-6, '.') << x6[j] << endl;
		}
	} else if(k==7){
		for(int j=0; j<7; j++){
			cout << string(n-7, '.') << x7[j] << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
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 FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  ll ans = 1;
  int c[3];
  REP(i, 3) c[i] = 0;
  REP(i, n) {
    int a;
    cin >> a;
    int t = 0, p = 0;
    REP(j, 3) if(c[j] == a) {
      t++; p = j;
    }

    ans = (ans * t) % mod;
    c[p]++;
  }

  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
    cin>>N;
  map<int64_t,int64_t>M;
  for(int i=0;i<N;i++){
  int64_t a; cin>>a;a*=-1;
    if(M.count(a))
      M.at(a)++;
    else
      M[a]=1;
   }int64_t ans=0;
  for(auto p:M){
  auto k=p.first;
    auto v=p.second;
    k*=-1;int64_t a=1;
    for(int i=0; ;i++){
    if(k<a)break;
      else
        a*=2;
    }int64_t b=a-k; b*=-1;
    if(-k==b)
      ans+=v/2;
    else{
    if(M.count(b)){
    int64_t c=min(v,M.at(b)); ans+=c;
      M.at(b)-=c;
    }
    }
   }cout<<ans<<endl;
  return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));

    map<int,vi> mp;
    rep(i,n) mp[a[i]].push_back(i);
    vi used(n,0);
    int ans = 0;
    rrep(i,n){
        if(used[i]) continue;
        int lsb = __builtin_ffsll(a[i]) - 1;
        int msb = (31 - __builtin_clz(a[i]));
        int x = 1 << lsb;
        REP(j,lsb,msb){
            if((a[i]&(1<<j)) == 0) x |= 1<<j;
        }
        if(mp.count(x)){
            if(mp[x].size() == 0) continue;
            if(mp[x].back() == i){
                mp[x].pop_back();
                if(mp[x].size() == 0) continue;
            }
            int idx = mp[x].back();
            used[idx] = 1;
            mp[x].pop_back();
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}