#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// ABC052 C - Factors of Factorial
// 2020.06.13

ll MOD = 1e9+7;

map<ll, ll> PrimeFac(ll n){
  map<ll, ll> mp;
  ll cnt = 0;
  while(n%2 == 0){
    n /= 2;
    cnt++;
  }
  if(cnt != 0) mp[2] = cnt;
  for(ll i = 3; i*i <= n; i += 2){
    cnt = 0;
    while(n%i == 0){
      n /= i;
      cnt++;
    }
    if(cnt != 0) mp[i] = cnt;
  }
  if(n != 1) mp[n] = 1;
  return mp;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N; cin >> N;
  if(N == 1){
    cout << 1 << endl;
    return 0;
  }
  map<ll, ll> res;
  for(ll i = 2; i <= N; i++){
    map<ll, ll> tmp;
    tmp = PrimeFac(i);
    for(auto j : tmp){
      res[j.first] += j.second;
      res[j.first] %= MOD;
    }
  }
  ll ans = 1;
  for(auto i : res){
    ans = (ans*(i.second+1))%MOD;
  }
  ans %= MOD;
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
#define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

signed main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep (i, 1, n + 1) {
        int k = i;
        for (int j = 2; j * j <= k; j++) {
            while (k % j == 0) {
                k /= j;
                mp[j]++;
            }
        }
        mp[k]++;
    }
    int ans = 1;
    const int mod = 1e9 + 7;
    for (auto p : mp) {
        // cout << p.first << " : " << p.second << "\n";
        if (p.first == 1) continue;
        ans = ans * (p.second + 1) % mod;
        // cout << ans << "\n";
    }
    cout << ans << "\n";
}


#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 <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    string s; cin >> s;
    int n = s.size();

    map<char,int> mp;
    rep(i,n) mp[s[i]]++;

    rep(i,26){
        if(!mp[char (i+97)]){
            cout << s + char(i+97) << endl;
            return 0;
        }
    }
    if(s == "zyxwvutsrqponmlkjihgfedcba") cout << -1 << endl;
    else {
        for(int i = n-1; i >= 1; i--){
            if(s[i-1] < s[i]){
                rep(j,i-1){
                    cout << s[j];
                }
                for(int j = n-1; j>=1;j--){
                    if(s[i-1] < s[j]){
                        cout << s[j];
                        return 0;
                    }
                }
                return 0;
            }
        }
    }
}

#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
    ll lower_bound(ll X){
        if(sum(N)<X) return -1;
        ll ret=0,memo=1,sum=0;
        while(memo*2<=N) memo*=2;
        while(memo>0){
            if(memo+ret<=N&&sum+bit[memo+ret]<X){
                sum+=bit[memo+ret];
                ret+=memo;
            }
            memo/=2;
        }
        return ret+1;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r]%MOD;
}
signed main(){
    string S; cin>>S;
    if(S.size()==26){
        if(S=="zyxwvutsrqponmlkjihgfedcba"){
            cout<<-1<<endl;
            return 0;
        }
        std::set<char> set;
        set.insert(S[25]);
        per(i,24,0){
            if(*set.rbegin()>S[i]){
                for(auto p:set){
                    if(p>S[i]){
                        S=S.substr(0,i)+p;
                        break;
                    }
                }
                break;
            }
            set.insert(S[i]);
        }
    }
    else{
        vector<bool> F(26,1);
        rep(i,0,S.size()) F[S[i]-'a']=0;
        rep(i,0,26){
            if(F[i]){
                S+=i+'a';
                break;
            }
        }
    }
    cout<<S<<endl;
}


#include<cstdio>
const int N=1e5+5;
int n,i,a[N],ans;
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
	for (n=read(),i=1;i<=n;i++) a[i]=read();
	if (n==1){puts("Second");return 0;}
	for (;;){
		int k0=0,k1=0,x;
		for (i=1;i<=n;i++)
			if (a[i]&1) k1++,x=i; else k0++;
		if (k0&1){ans^=1;break;}
		if (k1>1||a[x]==1) break;
		a[x]--;int k=a[1];ans^=1;
		for (i=2;i<=n&&k>2;i++) k=gcd(k,a[i]);
		for (i=1;i<=n;i++) a[i]/=k;
	}
	puts(ans?"First":"Second");
}

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

using namespace std;

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool solve(int N, vector<int>& A) {
    if (N == 1) return false;

    // 総和の偶奇
    int parity = accumulate(A.begin(), A.end(), 0, [](int init, int a) { return (init + (a & 1)) & 1; });

    // Nが偶数の場合、和の偶奇がそのまま勝敗になる
    if ((N & 1) == 0) return parity != 0;

    // Nが奇数の場合も、和が偶数なら絶対勝てる
    if (parity == 0) return true;

    // 奇数を前に持っていく
    sort(A.begin(), A.end(), [](int a, int b) { return (a & 1) > (b & 1); });
    // 奇数が複数個ある、あるいは唯一の奇数が1(減らせない)なら負け
    if (A[0] == 1 || (A[1] & 1) != 0) return false;
    // そうでなければ、唯一の奇数を減らしてワンチャンに賭ける
    --A[0];
    int g = accumulate(A.begin(), A.end(), 0, gcd<int>);
    for (auto& a : A) a /= g;
    return !solve(N, A);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto& a : A) cin >> a;
    cout << (solve(N, A) ? "First" : "Second") << endl;
    return 0;
}


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

int main(){
  string str;

  while(getline(cin,str)){
    int flg = 0;

    while(true){
      for(int i = 0 ; i < str.length() ; i++){
	string key1 = str.substr(i,3),key2 = str.substr(i,4);
	if(key1 == "the" || key2 == "that" || key2 == "this") flg = 1;
      }

      if(flg) break;
      else{
	for(int j = 0 ; j < str.length() ; j++){
	  if('a' <= str[j] && str[j] <= 'z'){
	    str[j] -= 'a' - 'A';
	    str[j] = (char)('A'+(str[j]-'A'+26+1)%26);
	    str[j] += 'a' - 'A';
	  }
	  else continue;
	}
      }
    }
    cout << str << endl;
  }

  return 0;
}

#include<stdio.h>
int main()
{
	int h,w,k,omen;
	scanf("%d %d %d",&h,&w,&k);
	if(h > w) omen = h;
	else omen = w;
	int count = 1;
	for(int i = omen;i<k;i += omen)
	{
		count++;
	}
	printf("%d\n",count);
	return 0;
}


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

int main() {
  int a = 0,b = 0;
  cin >> a >> b;
  a--;
  b--;
  cout << (b + (a - 1)) / a << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

int main(){
    int n; cin>>n;
    string s; cin>>s;
    vector<int> p(n);
    if(s[0]=='E') p[0]=-1;
    else p[0]=1;
    rep(i,n-1){
        if(s[i+1]=='E') p[i+1]=-1;
        else p[i+1]=1;
        p[i+1]+=p[i];
    }
    auto an=min_element(btoe(p));
    int ba=an-p.begin();
    int ans=0;
    rep(i,n){
        if(i<ba){
            if(s[i]=='W') ans++;
        }
        else if(i>ba){
            if(s[i]=='E') ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

struct Point{
	int x,y,idx;
	bool operator<(const Point& rhs)const{
		return x==rhs.x?y<rhs.y:x<rhs.x;
	}
}P[100];

bool bad(const Point& p1,const Point& p2,const Point& p3){
	return 1LL*(p3.x-p1.x)*(p2.y-p1.y)-1LL*(p2.x-p1.x)*(p3.y-p1.y)<=0;
}
vector<Point> convex(int n){
	sort(P,P+n);
	vector<Point> res;
	for(int i=0;i<n;i++){
		while(res.size()>=2&&bad(res[res.size()-2],res[res.size()-1],P[i]))
			res.pop_back();
		res.emplace_back(P[i]);
	}
	for(int i=n-2,t=res.size();i>=0;i--){
		while(res.size()>t&&bad(res[res.size()-2],res[res.size()-1],P[i]))
			res.pop_back();
		res.emplace_back(P[i]);
	}
	res.pop_back();
	return res;
}
double ans[100];
const double pi = acos(-1);
inline double dist(int x,int y){
	return sqrt(1LL*x*x+1LL*y*y);
}
double calc(const Point& p1,const Point& p2,const Point& p3){
	long long int dot=1LL*(p3.x-p2.x)*(p2.x-p1.x)+1LL*(p3.y-p2.y)*(p2.y-p1.y);
	double tmp=dot/(double)dist(p2.x-p1.x,p2.y-p1.y)/(double)dist(p3.x-p2.x,p3.y-p2.y);
	double ang = acos(tmp);
	return ang/(2*pi);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>P[i].x>>P[i].y,P[i].idx=i;
	auto res = convex(n);
	if(res.size()==2){
		ans[res[0].idx]=0.5;
		ans[res[1].idx]=0.5;
	}
	else{
		for(int j=0;j<res.size();j++){
			int i=(j+(res.size()-1))%res.size();
			int k=(j+1)%res.size();
			ans[res[j].idx] = calc(res[i],res[j],res[k]);
		}
	}
	cout<<fixed<<setprecision(10);
	for(int i=0;i<n;i++)
		cout<<ans[i]<<'\n';
}

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

struct UnionFind{
	std::vector<int> data;

	UnionFind(int n){
		data.assign(n, -1);
	}

	bool unite(int x, int y){
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}

	int find(int k){
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}

	int size(int k){
		return -data[find(k)];
	}
};

int main() {
	int n; scanf("%d", &n);
	std::vector<std::pair<i64, int>> X, Y;
	for(int i = 0; i < n; i++) {
		int x, y; scanf("%d%d", &x, &y);

		X.push_back({x, i});
		Y.push_back({y, i});
	}
	sort(begin(X), end(X)); sort(begin(Y), end(Y));

	std::vector<std::pair<i64, std::pair<int, int>>> edges;
	for(int i = 0; i < n - 1; i++) {
		edges.push_back({X[i + 1].first - X[i].first, {X[i].second, X[i + 1].second}});
		edges.push_back({Y[i + 1].first - Y[i].first, {Y[i].second, Y[i + 1].second}});
	}
	sort(begin(edges), end(edges));

	i64 ans = 0;
	UnionFind uf(n);
	for(auto e: edges) {
		int x = e.second.first, y = e.second.second;
		if(uf.unite(x, y)) ans += e.first;
	}
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
    int N;
    cin >> N;
    vector<double> a(N);
    REP(i,N) cin >> a[i];

    double av = accumulate(ALL(a),double(0))/N;
    int ans  = 0;
    double shortest = INF;
    REP(i,N) {
        if (chmin(shortest,abs(av-a[i]))) {
            ans = i;
        }
    }

    cout << ans << endl;

    return 0;
}

#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define REV(x) reverse(ALL(x))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using Pll_ll = pair<ll, ll>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

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

int main(){
    int N, sum(0); cin >> N;
    VI a(N);
    REP(i, N){
        cin >> a[i];
        sum += a[i];
    }
    int ans = -1, dif(INF);
    REP(i, N){
        if(dif > abs(N*a[i] - sum)){
            dif = abs(N*a[i] - sum);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>

#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>

using namespace std;
//const char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
// input - given string
// You need to update in the given string itself i.e. in input. No need to return or print.

int solver() {
    // Write your code here
    int n;
    cin>>n;

    int l;
    cin>>l;
    //vector<int> my;
    int freq[10];
    for(int i=0;i<=9;i++)
    {
        freq[i]=0;
    }
    for(int i=0;i<l;i++)
    {
        int x;
        cin>>x;
      //  my[i]=x;
        freq[x]=1;
    }
    //cout<<my[0];
    for(int j=n;j<100000;j++)
    {
        int num=j;
        bool k=true;
        while(num>0)
        {
            int m=num%10;
            if(freq[m]==1)
            {
                k=false;
                break;
            }
            num=num/10;
        }
        if(k)
        {
            return j;
        }

    }
    return 0;

}

int main() {
    int n=1;
    //cin>>n;
    while(n--)
    {
        cout<<solver();
    }
}

#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n, K;
    cin >> n >> K;
    vector<int> bad(10, false);
    for (int i = 0; i < K; ++i) {
        int x;
        cin >> x;
        bad[x] = true;
    }

    int mn = 10;
    for (int k = 0; k < 10; ++k) {
        if (!bad[k]) {
            mn = k;
            break;
        }
    }

    string s = to_string(n);
    n = s.length();
    for (int i = 0; i < n; ++i) {
        int d = s[i] - '0';
        if (bad[d]) {
            while (i >= 0) {
                bool done = false;
                d = s[i] - '0';
                for (int j = d + 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s[i] = (char) ('0' + j);
                        for (int k = i + 1; k < n; ++k) {
                            s[k] = (char)('0' + mn);
                        }
                        done = true;
                        break;
                    }
                }
                if (done) {
                    break;
                }
                --i;
            }

            if (i < 0) {
                for (int j = 1; j < 10; ++j) {
                    if (!bad[j]) {
                        s = string(1, (char)('0' + j));
                        break;
                    }
                }
                s += string(n, (char)('0' + mn));
            }

            break;
        }
    }

    cout << s << '\n';

    return 0;
}


#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 100
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {}
};

int n;
vector<edge> G[MAX_N];

int Prim() {
	int res = 0;
	vector<bool> used(n, false);
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, 0));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (used[v]) continue;
		used[v] = true;
		res += p.first;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			que.push(P(e.cost, e.to));
		}
	}
	return res;
}

int main()
{
	cin >> n;
	for (int i = 0, c; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> c;
			if (c != -1)
				G[i].push_back(edge(j, c));
		}
	}
	cout << Prim() << endl;
	return 0;
}

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

int P[10010];
void init(int N){
  for (int i=0; i<N; i++) P[i] = i;
}
int root (int a){
  if (P[a] == a) return a;
  else {
    P[a] = root(P[a]);
    return P[a];
  }
}
bool is_same_set(int a, int b){
  return root(a) == root(b);
}
void unite(int a, int b){
  P[root(a)] = root(b);
}

int main(){
  int N;
  cin >> N;
  pair <int, int> edge[10010];
  for (int i=0; i<N; i++){
    for (int j=0; j<N; j++){
      cin >> edge[i*N+j].first;
      edge[i*N+j].second = i*N+j;
    }
  }
  sort(edge, edge+N*N);
  init(N);
  int ans = 0;
  int b = 0;
  for (int k=0; k<N*N; k++){
    while(edge[k].first < 0) k++;
    int i = edge[k].second / N;
    int j = edge[k].second % N;
    if (is_same_set(i,j)){}
    else{
      unite(i,j);
      ans += edge[k].first;
    }
  }
  cout << ans << endl;
}


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

typedef complex<double> Point;
typedef vector<Point> VP;
#define X real()
#define Y imag()
const double EPS = 1e-9;
const double PI = acos(-1.0);
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

namespace std {
    bool operator<(const Point a, const Point b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

double dot(Point a, Point b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Point a, Point b) {
    return a.X*b.Y - a.Y*b.X;
}

int ccw(Point a, Point b, Point c) {
    b -= a;  c -= a;
    if (cross(b,c) >  EPS) return +1;  // counter clockwise
    if (cross(b,c) < -EPS) return -1;  // clockwise
    if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
    if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
    return 0;                          // a--c--b on line or a==c or b==c
}

VP convexHull(VP ps) {  // 元の点集合がソートされていいならVP&に
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  VP ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;  // 余計な点も含むなら == -1 とする
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

int main(void){
    VP vp;
    int n;
    cin>>n;
    rep(i,n){
        double x,y;
        cin>>x>>y;
        vp.push_back(Point(x,y));
    }

    VP ch = convexHull(vp);
    int m = ch.size();
    vector<double> range;
    rep(i,m){
        range.push_back(arg(ch[(i+1)%m]-ch[i]) - arg(ch[i]-ch[(m+i-1)%m]));
    }

    rep(i,n){
        bool inConvex = true;
        rep(j,m){
            if(vp[i] == ch[j]){
                inConvex = false;
                printf("%.10f\n", acos(cos(range[j]))/(2.0*PI));
                break;
            }
        }
        if(inConvex) printf("0.0\n");
    }

    return 0;
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<tuple>
using namespace std;
#define fr(i,n) for(int i=0;i<n;i++)
typedef double db;
typedef tuple<bool,db> bod;
db Pi = 3.14159265358979;

db st(db t){
  t+=4*Pi;
  while(t>=0) t-=2*Pi;
  t+=2*Pi;
  return t;
}

bod J(db a,db b){
  if(a<=Pi){
    return make_tuple(!(a<=b && b<a+Pi),a+Pi-b);
  }
  else{
    return make_tuple(!(a<=b || b<a-Pi),st(a+Pi-b));
  }
}

int main(){
  int n,q,r;
  bool f;
  db x[100],y[100],m[100][100],M;
  cin >> n;
  if(n==2){
    cout<<0.5<<endl<<0.5<<endl;
    return 0;
  }
  fr(i,n) cin>>x[i]>>y[i];
  fr(i,n){
    fr(j,n){
      if(i != j){
        m[i][j]=st(atan2(x[j]-x[i],y[j]-y[i]));
      }
    }
    fr(j,n){
      if(i==j) continue;
      f=0;
      M=2*Pi;
      fr(k,n){
        if(k==i || k==j) continue;
//        cout<<i<<" "<<j<<" "<<k<<" "<<m[i][j]<<" "<<m[i][k]<<endl;
        bod G=J(m[i][j],m[i][k]);
        if(M>get<1>(G)){
          r=k;
          M=get<1>(G);
        }
        if(get<0>(G)){
          f=1;
          break;
        }
      }
      if(!f){
        q=j;
        break;
      }
    }
    if(f) cout<<0.0<<endl;
    else cout<<M/(2*Pi)<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (6e2) + 9;
const int M = (36e4) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

vector < pii > arr[2], ans[4];
int node[N][N];
pii val[M];
vi v[2][M];
int mark[2][M];
bool vis[2][M];
queue < int > q;
int n;

inline void add_edge(int bit, int a, int b, int x, int y)
{
	if(x < 0 || x >= n+n || y < 0 || y >= n+n)
		return;
	v[bit][node[a][b]].pb(node[x][y]);
	return;
}

void bfs(int cur, int bit)
{
	if(vis[bit][cur])
		return;
	while(!q.empty())
		q.pop();
	int z;
	q.push(cur);
	vis[bit][cur] = 1;
	mark[bit][cur] = 0;
	while(!q.empty())
	{
		z = q.front();
		q.pop();
		for(auto x : v[bit][z])
			if(!vis[bit][x])
			{
				vis[bit][x] = 1;
				mark[bit][x] = 1 - mark[bit][z];
				q.push(x);
			}
	}
	return;
}

void solve()
{
	int d1, d2, i, j, k, d, cnt = 0;
	cin >> n >> d1 >> d2;
	fo(i,0,n+n)
		fo(j,0,n+n)
		{
			int d = i*i + j*j;
			if(d == d1)
				arr[0].pb({i,j});
			if(d == d2)
				arr[1].pb({i,j});
		}
	fo(i,0,n+n)
		fo(j,0,n+n)
		{
			node[i][j] = cnt;
			val[cnt] = {i,j};
			cnt++;
		}
	fo(i,0,n+n)
		fo(j,0,n+n)
			fo(k,0,2)
				for(auto x : arr[k])
				{
					add_edge(k,i,j,i+x.F,j+x.S);
					add_edge(k,i,j,i+x.F,j-x.S);
					add_edge(k,i,j,i-x.F,j+x.S);
					add_edge(k,i,j,i-x.F,j-x.S);
				}
	fo(i,0,cnt)
	{
		bfs(i,0);
		bfs(i,1);
	}
	fo(i,0,cnt)
		ans[mark[0][i]*2 + mark[1][i]].pb(val[i]);
	fo(j,0,4)
		if(sz(ans[j]) >= n*n)
		{
			fo(i,0,n*n)
				cout << ans[j][i].F << " " << ans[j][i].S << '\n';
			return;
		}
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file;
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55,mod=1e9+7,inf=2000000000;
int n,a[N];
char s[N];
unordered_map<ll,int>vis[20][20];
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    int up=1<<n;
    for(int i=0;i<up;i++)
    {
        ll sum1=0,sum2=0,a=__builtin_popcount(i),b=n-a;
        for(int j=1;j<=n;j++)
            if(i>>j-1&1)
            sum1=(sum1*2333%mod+s[j]-'a')%mod;
            else sum2=(sum2*2333%mod+s[j]-'a')%mod;
        //cout<<a<<' '<<b<<' '<<sum1*inf+sum2<<endl;
        vis[a][b][sum1*inf+sum2]++;
    }
    reverse(s+1,s+1+n+n);
    ll ans=0;
    for(int i=0;i<up;i++)
    {
        ll sum1=0,sum2=0,a=__builtin_popcount(i),b=n-a;
        for(int j=1;j<=n;j++)
            if(i>>j-1&1)
            sum1=(sum1*2333%mod+s[j]-'a')%mod;
            else sum2=(sum2*2333%mod+s[j]-'a')%mod;
        //cout<<a<<' '<<b<<' '<<sum1*inf+sum2<<endl;
        ans+=vis[b][a][sum2*inf+sum1];
    }
    printf("%lld\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    multiset<int> mst;

    REP(i,n) {
        int a; cin >> a;
        mst.insert(a);
    }

    int ans = 0;
    while(!mst.empty()) {
        auto back = mst.end();
        back--;
        int x = *back;
        mst.erase(back);
        double l2 = log2(x);
        if (l2 == floor(l2)) {
            auto it = mst.find(x);
            if (it != mst.end()) {
                ans++;
                mst.erase(it);
            }
        } else {
            int x2 = pow(2,ceil(l2));
            auto it = mst.find(x2-x);
            if (it != mst.end()) {
                ans++;
                mst.erase(it);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int N;

int f(vector<vector<pair<int, int>>> &data, vi &bit, int n) {
    if (n == 0) {
        int ans = 0;
        bool check = false;
        for (int i = 0; i < N; i++) {
            if (bit[i] == 0) {
                continue;
            }
            ans++;
            for (pair<int, int> p : data[i]) {
                if (bit[p.first - 1] != p.second) {
                    return 0;
                }
            }
        }
        return ans;
    }
    bit[N - n] = 1;
    int a = f(data, bit, n - 1);
    bit[N - n] = 0;
    int b = f(data, bit, n - 1);
    return max(a, b);
}

int main() {
    cin >> N;
    vi a(N);
    vector<vector<pair<int, int>>> data(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        vector<pair<int, int>> v(a[i]);
        for (int j = 0; j < a[i]; j++) {
            int x, y;
            cin >> x >> y;
            v[j] = {x, y};
        }
        data[i] = v;
    }
    vi bit(N, 0);
    int ans = f(data, bit, N);
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define lw(vc,num) lower_bound(vc.begin(), vc.end(), num) - vc.begin();
#define hg(vc,num) upper_bound(vc.begin(), vc.end(), num) - vc.begin();
#define bn(v,x) binary_search (v.begin(), v.end(), x)
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
bool isprime(int n)
{
    if(n == 1) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    for(int i=5; i*i<=n; i+=6){
        if((n%i == 0)||(n%(i+2) == 0)) return false;
    }
    return true;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
int main()
{
    fio;
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && b==c && c==a) || (a!=b && b!=c && c!=a))
        cout<<"No\n";
    else
        cout<<"Yes\n";
    return 0;
}

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

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

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

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

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

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


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

int main(){
    int n; cin>>n;
    vector<int> v;
    for(int i = 1; i <= 2*n; i++){
        int x; cin>>x;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    int res = 0;
    for(int i = 0; i < (2*n)-1; i += 2){
        res += min(v[i], v[i+1]);
    }

    cout<<res<<'\n';
}

//#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
/*#define fast ios_base::sync_with_stdio(0); cin.tie(0)*/
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
const double pi = acos(-1);
typedef long long ll;
int main()
{
	//fast;

	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<min(a,b)+min(c,d);
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

void _main() {
        int n; cin >> n;
        vector<pair<int,int>> a(n);
        for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;

        sort(all(a));
        auto calc = [](vector<pair<int,int>> a) {
                double cnt = 0;
                for (int i = 1; i < a.size(); i++) {
                        double dist = sqrt(pow(a[i].first - a[i - 1].first,2) + pow(a[i].second - a[i - 1].second, 2));
                        cnt += dist;
                }
                return cnt;
        };

        double ans = 0, k = 0;
        sort(all(a));
        do {
                ans += calc(a);
                k++;
        } while (next_permutation(all(a)));

        ans /= k;
        cout << fixed << setprecision(10) << ans;
}

signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int main(){
    int N;
    cin >> N;
    double D[N][N];
    vector<P> c(N);
    rep(i,N) {
	double x,y;
	cin >> x >> y;
	c[i] = make_pair(x,y);
    }
    rep(i,N) {
	rep(j,N) {
	    double x0 = c[i].first;
	    double y0 = c[i].second;
	    double x1 = c[j].first;
	    double y1 = c[j].second;
	    D[i][j] = sqrt((x0-x1)*(x0-x1) + (y0-y1)*(y0-y1));
	}
    }

    vector<int> l(N);
    rep(i,N) l[i] = i;
    double sum = 0;
    double n = 0;

    do{
	n++;
	rep(i,N-1) {
	    sum += D[l[i]][l[i+1]];
	}
    }while(next_permutation(l.begin(),l.end()));

    double ans = sum/n;
    printf("%.12lf\n",ans);

    return 0;
}


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

int main(void){
    vector<int>X(26,0);
    string S;cin>>S;
    for(long long i=0;i<S.size();i++){
        X[(int)S[i]-97]++;
    }
    for(long long i=0;i<26;i++){
        if(X[i]==0){
            int ans=i+97;
            cout<<(char)ans<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

#include <iostream>
using namespace std;
int main() {
    string s;
    cin >> s;
    for (char c='a'; c<='z'; c++) {
        if (s.find(c) == string::npos) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


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

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

 int sum1=min(a,b);
 int sum2=min(c,d);

 int sum=sum1+sum2;
 cout<<sum<<endl;

return 0;
}

#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 <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
  int N;
  cin >> N;
  repe(i, N, 999) {
    string s = to_string(i);
    bool ok = true;
    rep(j, 1, s.size()) if (s[j - 1] != s[j]) ok = false;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

#include <iostream>
using namespace std;
int main(void){
    int n,i;
    cin >> n;
    for(i=n;i<n+111;i++){
        if(i%111==0) break;
    }
    cout << i;
}


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

int main() {
    ll N;
    cin >> N;
    vector<char> name = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
    'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

    ll block = 0;
    vector<int> x;
    while (N>0) {
        N--;
        x.push_back(N%26);
        N /= 26;
    }

    string ans = "";

    for (ll i=x.size()-1; i>=0; i--) {
        ans += name[x[i]];
    }

    cout << ans << endl;
}

#include <iostream>
using namespace std;
int main() {
  int T, t, b{-(1<<30)}, ans{};
  cin >> T >> T;
  while (cin >> t) {
    ans += t < b + T ? t - b : T;
    b = t;
  }
  cout << ans << endl;
}


#include<iostream>
#include<string>
using namespace std;
int data[7];
void N(){int x=data[5];data[5]=data[1];data[1]=data[2];data[2]=data[6];data[6]=x;}
void S(){int x=data[5];data[5]=data[6];data[6]=data[2];data[2]=data[1];data[1]=x;}
void E(){int x=data[3];data[3]=data[1];data[1]=data[4];data[4]=data[6];data[6]=x;}
void W(){int x=data[4];data[4]=data[1];data[1]=data[3];data[3]=data[6];data[6]=x;}
int main(){
  string com;
  for(int i=1;i<=6;++i)cin>>data[i];
  getline(cin,com);
  getline(cin,com);
  for(auto ch:com){
    if(ch=='N')N();
    if(ch=='S')S();
    if(ch=='E')E();
    if(ch=='W')W();
  }
  cout<<data[1]<<endl;
  return 0;
}

// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()

using namespace std;
//using namespace __gnu_pbds;

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

const int N = (int)5e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int n, a[N];
void solve () {
	cin >> n;
	n *= 2;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	sort (a + 1, a + n + 1);
	ll sum = 0;
	for (int i = 1; i <= n; i += 2) sum += a[i];
	cout << sum;
}

main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

void cal(string s, string x, string y, map<pair<string, string>, ll>& a) {
	if(sz(s) == 0) {
		a[mp(x,y)]++;
		return;
	}
	cal(s.substr(1), x + s.substr(0,1), y, a);
	cal(s.substr(1), x, y + s.substr(0,1), a);
}

ll solve(string s, string t) {
	map<pair<string, string>, ll> a, b;
	string x,y;
	x = y = "";
	cal(s,x,y,a);
	cal(t,x,y,b);
	ll ret = 0;
	for(auto e : a) {
		auto key = e.F;
		if(b.find(key) != b.end()) {
			ret += e.S * b[key];
		}
	}
	return ret;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	int n;
	string s;
	cin >> n >> s;
	string t = s.substr(n);
	reverse(all(t));
	cout << solve(s.substr(0,n), t) << '\n';
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

typedef pair<string,string> Ps;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s,a,b;
	cin>>s;
	a=s.substr(0,n),b=s.substr(n,n);
	reverse(begin(b),end(b));
	map<Ps,ll> cnt1,cnt2;
	rep(i,1<<n){
		string k,l;
		rep(j,n){
			if(i & 1<<j){
				k.push_back(a[j]);
			}else{
				l.push_back(a[j]);
			}
		}
		cnt1[Ps(k,l)]++;
	}
	rep(i,1<<n){
		string k,l;
		rep(j,n){
			if(i & 1<<j){
				k.push_back(b[j]);
			}else{
				l.push_back(b[j]);
			}
		}
		cnt2[Ps(k,l)]++;
	}
	ll ans=0;
	for(auto itr:cnt1){
		ll num=cnt2[itr.fi];
		ans+=num*itr.se;
	}
	cout<<ans<<endl;
}


//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll kai(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y&1){
    return (x*kai(x,y-1))%MOD;
  }else{
    ll t = kai(x,y/2);
    return (t*t)%MOD;
  }
}

ll comb(ll a,ll b,vector<ll> &p){
  if(a == 0)return 1;
  if(b == 0)return 1;
  ll ans = p[a+b];
  ans = (ans*kai(p[a],MOD-2))%MOD;
  ans = (ans*kai(p[b],MOD-2))%MOD;
  return ans;
}

ll mind(int x,vector<int> &v){
  int ok = v.size()-1,ng = -1;
  while(ok - ng > 1){
    int next = (ok+ng)/2;
    if(v[next] > x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

ll maxd(int x,vector<int> &v){
  int ok = 0,ng = v.size();
  while(ng - ok > 1){
    int next = (ok+ng)/2;
    if(v[next] < x){
      ok = next;
    }else{
      ng = next;
    }
  }
  return ok;
}

int main(){
  int n,x,t;
  cin >> n >> x >> t;
  int ans = 0;
  ans += (n/x)*t;
  if(n%x != 0)ans += t;
  cout << ans << endl;

  return 0;
}

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

using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	/*int t;
	cin >> t;
	while (t--){
		int n;
		cin >> n;
		vector<int>v(n);
		for (int i = 0; i < n; i++){
			cin >> v[i];
		}
		if (n % 2){
			reverse(v.begin(), v.end());
			swap(v[n / 2], v[n / 2 - 1]);
		}
		else reverse(v.begin(), v.end());
		for (int i : v)cout << i << " ";
		cout << '\n';
	}*/
	double a, b, c;
	cin >> a >> b >> c;
	int count = ceil(a/b)*c;
	cout << count << '\n';
	//system("pause");
	return 0;
}


#include <cstdio>
using namespace std;
#define MAXN 100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAXN][MAXN];

int prim()
{
	int d[MAXN], p[MAXN], color[MAXN];
	int u, minv;
	for(int i = 0; i < n; i++)
	{
		d[i] = INFTY;
		p[i] = -1;
		color[i] = WHITE;
		//printf("===\n");
	}
	d[0] = 0;
	while(true)
	{
		u = -1;
		minv = INFTY;
		for(int i = 0; i < n; i++)
		{
			if(color[i] != BLACK && d[i] < minv)
			{
				u = i;
				minv = d[i];
				//printf("%d \n", u);
			}
		}
		if(u == -1)
		{
			break;
		}
		color[u] = BLACK;
		for(int v = 0; v < n; v++)
		{
			if(color[v] != BLACK && M[u][v] != INFTY)
			{
				if(d[v] > M[u][v])
				{
					d[v] = M[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	int sum = 0;
	for(int i = 0; i < n; i++)
	{
		if(p[i] != -1)
		{
			sum += M[i][p[i]];
		}
	}
	return sum;
}

int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			int e;
			scanf("%d", &e);
			M[i][j] = (e == -1) ? INFTY : e;
		}
	}
	printf("%d\n", prim());
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(auto i = 0 * n; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

class UnionFind {
	typedef size_t U;
	vector<int32_t> v;
public:
	UnionFind(U n) : v(n, -1) {}
	U find(U x) { return v[x] < 0 ? x : (v[x] = find((U)v[x])); }
	bool same(U x, U y) { return find(x) == find(y); }
	U size(U x) { return (U)-v[find(x)]; }
	void unite(U x, U y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (-v[x] < -v[y]) swap(x, y);
			v[x] += v[y];
			v[y] = x;
		}
	}
};

struct Edge{ uint32_t to, id; };
typedef vector<vector<Edge>> Graph;

template<class T> struct Kruskal{
	typedef uint32_t U;
	template<class V> Kruskal(U n, const V & u, const V & v, const vector<T> & w) : g(n) {
		vector<U> es(w.size());
		iota(es.begin(), es.end(), 0);
		sort(es.begin(), es.end(), [&](U i, U j) { return w[i] < w[j]; });
		UnionFind uf(n);
		for (U i : es) {
			if (!uf.same(u[i], v[i])) {
				uf.unite(u[i], v[i]); cost += w[i];
				g[u[i]].push_back({ (U)v[i], i }); g[v[i]].push_back({ (U)u[i], i });
			}
		}
	}
	Graph g; T cost = 0;
};

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

	ll n; cin >> n;
	vl u, v, w;
	REP(i, n) REP(j, n) {
		ll x; cin >> x;
		if (x != -1) {
			u.push_back(i);
			v.push_back(j);
			w.push_back(x);
		}
	}
	Kruskal<ll> mst(n, u, v, w);
	cout << mst.cost << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5+5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    2019;
int n;
ll ans=0;
multiset<ll> ms;
int main()
{  fast
cin>>n;

vector<ll> v(n);
for(auto&x:v)cin>>x;
for(auto x: v)ms.insert(x);
while(!ms.empty())
{
	ll val=*ms.rbegin();
	ms.erase(ms.find(val));ll y;
	for( y=1;y<=val;y*=2);
		auto it=ms.find(y-val);
		if(it!=ms.end())
		{
			ans++;
			ms.erase(it);

		}
}
cout<<ans;
}

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int msb(int x) { return 31 - __builtin_clz(x); }

int main() {
  int N; std::cin >> N;
  std::map<int,int> m;
  for(int i = 0; i < N; ++i) { int A; std::cin >> A; ++m[A]; }
  std::vector<std::pair<int,int>> v(m.begin(), m.end());
  int ans = 0;
  for(int j = v.size()-1; j >= 0; --j) {
    if(v[j].second < 1) continue;
    int val = v[j].first;
    int x = (1 << msb(val)+1) - val;
    if(val == x) { ans += v[j].second/2; continue; }
    int i = std::partition_point(v.begin(), v.end(),
              [&](auto const& p) { return p.first < x;}) - v.begin();
    if(i >= j) continue;
    if(v[i].first != x) continue;
    int n = std::min(v[j].second, v[i].second);
    ans += n;
    v[i].second -= n;
  }
  fin(ans);
  return 0;
}


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

int main() {
	int a, b, c, d;
  	cin >> a >> b >> c >> d;
  	int L = a+b, R = c+d;
    if (L>R) cout << "Left" <<endl;
    if (L==R) cout << "Balanced" << endl;
    if (L<R) cout << " Right" << endl;
}

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

using namespace std;

int main()
{
    int cs[5];
    while( scanf( "%d,%d,%d,%d,%d", &cs[0], &cs[1], &cs[2], &cs[3], &cs[4] ) != -1 ) {
        sort( cs, cs + 5 );

        vector<int> uc( 5 );
        unique_copy( cs, cs+5, uc.begin() );

        int p[5] = {};
        for( auto const& c : uc ) {
            ++p[count( cs, cs + 5, c )];
        }

        bool const is_straight = [&]{
            bool const b = [&](){
                for( int i=1; i<5; ++i ) {
                    if ( cs[i-1] + 1 != cs[i] )
                        return false;
                }
                return true;
            }();

            return b
                   || ( cs[0] == 10 && cs[1] == 11 && cs[2] == 12 && cs[3] == 13 && cs[4] == 1 )
                   || ( cs[0] == 1 && cs[1] == 10 && cs[2] == 11 && cs[3] == 12 && cs[4] == 13 );
        }();

        cout <<
            ( ( p[4] == 1 )
              ? "four card"
              : ( p[3] == 1 && p[2] == 1 )
              ? "full house"
              : ( is_straight )
              ? "straight"
              : ( p[3] == 1 )
              ? "three card"
              : ( p[2] == 2 )
              ? "two pair"
              : ( p[2] == 1 )
              ? "one pair"
              : "null" )
            << endl;
    }
}


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

int main(){
  long long int n, a, b;
  cin >> n >> a >> b;
  long long int x[n], diff[n]={};
  long long int ans=0;
  for(int i=0; i<n; i++){
    cin >> x[i];
    if(i==0) continue;
    if((x[i]-x[i-1])*a<b) ans += (x[i]-x[i-1])*a;
    else ans += b;
  }

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

#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  long long A, B;
  cin >> A >> B;
  long long ans = 0;
  long long x;
  cin >> x;
  for (int i = 0; i < N - 1; i ++) {
    long long k = 0;
    cin >> k;
    ans += min((k - x) * A, B);
    x = k;
  }
  cout << ans << endl;
}


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

#define ll double
#define mod 1e9+7

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL)

ll dp[301][301][301];

ll solve(int one, int two, int three, int& n)
{
	if(one < 0 || two < 0 || three < 0) return 0;
	if(one == 0 && two == 0 && three == 0) return 0;
	if(dp[one][two][three] > 0) return dp[one][two][three];
	int rem = one + two + three;
	ll exp_val = n + one*solve(one-1, two, three, n) + two*solve(one+1, two-1, three, n) + three*solve(one, two+1, three-1, n);

	return dp[one][two][three] = exp_val/rem;

}

int main()
{
	int i, j, n, m, p, k, x;
	cin>>n;
	int one = 0, two = 0, three = 0;
	for(i = 0; i < n; i++)
	{
		cin>>x;
		if(x == 1) one++;
		else if(x == 2) two++;
		else three++;
	}
	memset(dp, -1, sizeof(dp));
	cout<<fixed<<setprecision(9)<<solve(one, two, three, n);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

double dp[305][305][305];

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

	int n;
	cin >> n;
	int cnt[4] = {0};
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cnt[x]++;
	}
	for(int k = 0; k <= cnt[3]; k++) {
		for(int j = 0; j <= cnt[2] + cnt[3]; j++) {
			for(int i = 0; i <= n; i++) {
				if(i + j + k == 0) {
					dp[i][j][k] = 0;
				}
				else {
					dp[i][j][k] = 1;
					if(i >= 1) {
						dp[i][j][k] += (1.0 * i / n) * dp[i - 1][j][k];
					}
					if(j >= 1) {
						dp[i][j][k] += (1.0 * j / n) * dp[i + 1][j - 1][k];
					}
					if(k >= 1) {
						dp[i][j][k] += (1.0 * k / n) * dp[i][j + 1][k - 1];
					}
					dp[i][j][k] /= (1 - (1.0 * (n - i - j - k) / n));
				}
			}
		}
	}
	cout << fixed << setprecision(12) << dp[cnt[1]][cnt[2]][cnt[3]];

	return 0;
}


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

typedef long long ll;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<int> lk(q);
  vector<ll> memo(n, 0);
  for (int &k: lk) cin >> k;
  for (int k : lk) {
    ll ans = 0;
    vector<ll> ls(3, 0);
    for (int i = 0; i < n; ++i) {
      if (i >= k) {
        if (s[i-k] == 'D') {
          --ls[0];
          ls[2] -= ls[1];
        }
        if (s[i-k] == 'M') --ls[1];
      }
      if (s[i] == 'D') ++ls[0];
      if (s[i] == 'M') {
        ++ls[1];
        ls[2] += ls[0];
      }
      if (s[i] == 'C') {
        ans += ls[2];
      }
    }
    cout << ans << endl;
  }
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define gt getchar()
#define ll long long
#define File(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef std::pair<int,int> P;
#define mk std::make_pair
#define fr first
#define sc second
inline int in()
{
	int k=0;char ch=gt;bool p=1;
	while(ch<'-')ch=gt;if(ch=='-')ch=gt,p=0;
	while(ch>'-')k=k*10+ch-'0',ch=gt;
	return p?k:-k;
}
const int N=2e5+5;
const ll inf=1ll<<60;
ll sum[N],ans=inf;int pos[N],n,Q;
inline void cmin(ll &x,ll y){if(x>y)x=y;}
struct Segment_tree
{
#define lc k<<1
#define rc k<<1|1
	ll val[N];int mi[N<<2];
	inline int cmp(const int &x,const int &y){return val[x]<val[y]?x:y;}
	void build(int l,int r,int k)
		{
			if(l==r)return val[mi[k]=l]=inf,void();
			int mid=l+r>>1;
			build(l, mid ,lc),build(mid+1,r,rc);
			mi[k]=cmp(mi[lc],mi[rc]);
		}
	void upd(int l,int r,int k,int p,ll v)
		{
			if(l==r)return cmin(val[l],v);
			int mid=l+r>>1;
			if(p<=mid)upd(l,mid,lc,p,v);
			else upd(mid+1,r,rc,p,v);
			mi[k]=cmp(mi[lc],mi[rc]);
		}
	int query(int L,int R,int l,int r,int k)
		{
			if(L<=l&&r<=R)return mi[k];
			int mid=l+r>>1;
			if(L> mid)return query(L,R,mid+1,r,rc);
			if(R<=mid)return query(L,R,l, mid ,lc);
			return cmp(query(L,R,l,mid,lc),query(L,R,mid+1,r,rc));
		}
}A,B,C;
inline int abs(int x){return x<0?-x:x;}
inline void solve(int x)
{
	for(int i=2;i<=Q;++i)sum[i]=sum[i-1]+abs(pos[i]-pos[i-1]);
	A.build(1,n,1),B.build(1,n,1),C.build(1,n,1);
	A.upd(1,n,1,x,0-x),B.upd(1,n,1,x,0+x),C.upd(1,n,1,x,0);
	for(int i=2;i<=Q;++i)
	{
		int le=A.query(1,pos[i],1,n,1),ri=B.query(pos[i],n,1,n,1);
		int res=abs(pos[i]-pos[i-1]);
		if(A.val[le]+pos[i]>B.val[ri]-pos[i])
		{
			C.upd(1,n,1,pos[i-1],B.val[ri]-pos[i]-res);
			A.upd(1,n,1,pos[i-1],B.val[ri]-pos[i]-res-pos[i-1]);
			B.upd(1,n,1,pos[i-1],B.val[ri]-pos[i]-res+pos[i-1]);
		}
		else
		{
			C.upd(1,n,1,pos[i-1],A.val[le]+pos[i]-res);
			A.upd(1,n,1,pos[i-1],A.val[le]+pos[i]-res-pos[i-1]);
			B.upd(1,n,1,pos[i-1],A.val[le]+pos[i]-res+pos[i-1]);
		}
	}
	cmin(ans,C.val[C.mi[1]]+sum[Q]);
}
int main()
{
	n=in(),Q=in()+1;int a=in(),b=in();
	for(int i=2;i<=Q;++i)pos[i]=in();
	pos[1]=a;solve(b);pos[1]=b;solve(a);
	return printf("%lld\n",ans),0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#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(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int m;
int nmin,nmax;
int p[10000];

int main() {
	while (cin >> m >> nmin >> nmax&&m + nmax + nmin) {
		REP(i, m) {
			cin >> p[i];
		}
		int ans;
		int num = -1;
		for (int i = nmin; i <= nmax; i++) {
			if (num <= p[i - 1] - p[i]) {
				num = p[i - 1] - p[i];
				ans = i;
			}
		}
		cout << ans << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    unsigned long long a[5000]={0},c=0,p,o,u;
    rep(i,n){
      cin>>p>>o>>u;
      a[p]+=o*u;
      if(a[p]>=1000000){cout<<p<<endl;c++;}
    }
    if(!c)cout<<"NA"<<endl;
  }
}

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

int main()
{
	int n;
	int ans[4000];

	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		int i,j;
		for(i=0,j=0;i<n;i++)
		{
			int num[4000];
			int flag=1;
			double a[4000],b[4000];
			double ans_max[4000];

			cin >> num[i] >> a[i] >> b[i] ;
			ans_max[i]=a[i]/10000.0*b[i];
			for(int l=i-1;l>=0;l--)
			{
				if(num[l]==num[i])
				{
//					cout << "in" << endl;
					ans_max[i]+=ans_max[l];
					break;
				}
			}

//			cout << "ans_max[" << i << "]:" << ans_max[i] << " num:" << num[i] << endl;

			if(ans_max[i]>=100.0)
			{
				for(int k=0;k<j;k++)
				{
					if(ans[k]==num[i])
						flag=0;
				}
				if(flag==1)
				{
					ans[j]=num[i];
					j++;
				}
			}
		}

		if(j!=0)
		{
			for(int i=0;i<j;i++)
			{
				cout << ans[i] << endl;
			}
		}
		else
			cout << "NA" << endl;
	}
}


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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //

// - library ------------- //

// --------- library end - //

int main(){

  ll N = il();
  vector<vector<ll> > abs;
  rep(i,N){
    ll a = il();
    ll b = il();
    abs.p_b(vector<ll>{a+b, a, b});
  }
  sort(abs.begin(), abs.end());
  reverse(begin_end(abs));

  ll ans;
  rep(i, N){
    if (i % 2 == 0) ans += abs[i][1];
    else ans -= abs[i][2];
  }

  cout << ans << endl;

}

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  vector<bool> contains(26, false);
  for (char c : s) {
    contains[c - 'a'] = true;
  }

  if (s.size() < 26) {
    rep(i, 26) {
      if (!contains[i]) {
        cout << s << (char)(i + 'a') << endl;
        return 0;
      }
    }
  } else {
    set<char> t;
    rrep(i, s.size()) {
      char c = s[i];
      auto p = t.upper_bound(c);
      if (p != t.end()) {
        cout << s.substr(0, i) << *p << endl;
        return 0;
      }
      t.insert(c);
    }
  }
  cout << -1 << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

struct UnionFind {
  vector<int> c, s;
  UnionFind(size_t n) : c(n), s(n, 1) { iota(begin(c), end(c), 0); }
  int root(int i) { return c[i] == i ? i : (c[i] = root(c[i])); }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    i = root(i); j = root(j);
    if (i != j) {
      if (s[i] > s[j]) { c[j] = i; s[i] += s[j]; }
      else { c[i] = j; s[j] += s[i]; }
    }
  }
  int size(int i) { return s[root(i)]; }
};

lli n, k, l;
int main() {
  cin >> n >> k >> l;
  UnionFind ufp(n+1), ufr(n+1), ufm(n+1);
  for (lli i=0; i<k; ++i) {
    lli u, v; cin >> u >> v;
    ufp.unite(u, v);
  }
  for (lli i=0; i<l; ++i) {
    lli u, v; cin >> u >> v;
    ufr.unite(u, v);
  }
  map<pair<lli, lli>, lli> m;
  for (lli i=1; i<=n; ++i) {
    m[make_pair(ufp.root(i), ufr.root(i))]++;
  }
  for (lli i=1; i<=n; ++i) {
    cout << m[make_pair(ufp.root(i), ufr.root(i))] << '\n';
  }
  return 0;
}

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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int h, w;
  fscanf(stdin, "%d%d ", &h, &w);
  multiset<int> hd; // horizontal distance between from start to current position
  map<int, int> hdmap; // (current column, start column) to obtain the answer in log(n)
  REP(i,w) {
    hdmap[i] = i;
    hd.insert(0);
  }
  REP(i,h) {
    int l, r;
    fscanf(stdin, "%d%d ", &l, &r);
    --l; // semiopen interval [l-1, r) based on 0-index
    auto it = hdmap.lower_bound(l);
    int re = -1;
    while (it != hdmap.end() && it->first <= r) {
      re = max(re, it->second);
      hd.erase(hd.find(it->first - it->second));
      hdmap.erase(it++);
    }
    // the only optimal start point in [l-1, r) remains
    if (re != -1 && r < w) {
      hd.insert(r-re);
      hdmap[r] = re;
    }
    int res = -1;
    if (hd.size()) res = *hd.begin() + (i+1);
    fprintf(stdout, "%d\n", res);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

const int MAXX = 4007;
int fact[MAXX], ifact[MAXX];

int nCr(int n, int r) {
    if (r < 0 || n < r) return 0;
    return mul(fact[n], mul(ifact[r], ifact[n-r]));
}

int split(int elements, int buckets) {
    return nCr(elements+buckets-1, buckets-1);
}

int p2[MAXX];
int ans[MAXX];

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

    fact[0] = 1;
    for (int i = 1; i < MAXX; i++)      fact[i] = mul(i, fact[i-1]);
    ifact[MAXX-1] = pw(fact[MAXX-1], MOD-2);
    for (int i = MAXX-2; i >= 0; i--)   ifact[i] = mul(i+1, ifact[i+1]);
    p2[0] = 1;
    for (int i = 1; i < MAXX; i++) p2[i] = mul(p2[i-1], 2);

    int k, n;
    cin >> k >> n;

    for (int i = 3; i <= k+1; i += 2) {
        int have = i/2;
        for (int bam = 0; bam <= have && bam <= n; bam++) {
            int tmp = mul(nCr(have, bam), p2[bam]);
            tmp = mul(tmp, split(n-bam, k-have*2+bam));
            ans[i] = sum(ans[i], tmp);
//            cout << "bam: " << bam << " -> " << tmp << endl;
        }
//        cout << "ans[" << i << "] = " << ans[i] << endl;
    }

    for (int i = 2; i <= k+1; i += 2) {
        int have = i/2 - 1;
        for (int bam = 0; bam <= have && bam <= n; bam++) {
            int tmp = mul(nCr(have, bam), p2[bam]);
            int z = split(n-bam, k-have*2+bam-1);
            if (bam < n) {
                z = sum(z, split(n-bam-1, k-have*2+bam-1));
            }
            ans[i] = sum(ans[i], mul(tmp, z));
        }
//        cout << "ans[" << i << "] = " << ans[i] << endl;
    }

//    for (int i = 2; i <= k+k; i++) cout << ans[i] << "\n";

    for (int i = 2; i <= k+1; i++)    cout << ans[i] << "\n";
    for (int i = k; i >= 2; i--)  cout << ans[i] << "\n";

    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<int, int>;

const int INF = 1 << 30;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(H);
    rep(i, 0, H) {
        cin >> A[i] >> B[i];
        --A[i];
    }
    set<P> path;
    multiset<int> dist;
    rep(i, 0, W) {
        path.emplace(i, i);
        dist.insert(0);
    }
    rep(i, 0, H) {
        vector<P> buf;
        for (auto itr = path.lower_bound(P(A[i], 0)); itr != path.end() && (*itr).first < B[i]; ++itr) {
            buf.push_back(*itr);
        }
        int max_start = -INF;
        P max_path;
        for (auto& p : buf) {
            path.erase(p);
            dist.erase(dist.find(p.first - p.second));
            if (chmax(max_start, p.second)) {
                max_path = p;
            }
        }
        if (max_start > -INF) {
            path.emplace(B[i], max_path.second);
            dist.insert(B[i] == W ? INF : B[i] - max_path.second);
        }
        cout << (*dist.begin() == INF ? -1 : *dist.begin() + i + 1) << endl;
    }
    return 0;
}


#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
const int N = 1e5 + 5 ;
using namespace std ;
int cnt, n, a[4][N], d[5], b[N], bit[N], c[N], ind[N], outd[N] ; bool vis[N] ;
struct poi {
	int l, r ;
} p[N] ;
set <int> S ;
void put(int x) { for ( ; x <= n ; x += x & (- x)) ++ bit[x] ; }
int get(int x) { int res = 0 ; for ( ; x ; x -= x & (- x)) res += bit[x] ; return res ; }
bool cmp(poi a, poi b) {
	return a.r < b.r ;
}
int main() {
	scanf("%d", &n) ;
	rep(i, 1, 3) rep(j, 1, n) scanf("%d", &a[i][j]) ;
	rep(j, 1, n) {
		rep(i, 1, 3) d[i] = a[i][j] ;
		sort(d + 1, d + 4) ;
		if (d[1] % 3 != 1 || d[2] != d[1] + 1 || d[3] != d[2] + 1 || d[2] != a[2][j] || vis[d[1] / 3]) {
			printf("No\n") ;
			return 0 ;
		}
		vis[d[1] / 3] = true ;
		b[d[1] / 3 + 1] = j, c[j] = d[1] / 3 + 1 ;
		if ((c[j] - j) % 2) {
			printf("No\n") ;
			return 0 ;
		}
	}
/*	rep(i, 1, n) bit[i] = 0 ;
	for (int i = n; i; -- i) {
		if (i & 1) {
			put(c[i]) ;
			continue ;
		}
		if (((get(i) + abs(b[i] - i) / 2) & 1) ^ (a[1][b[i]] > a[3][b[i]])) {
			printf("No\n") ;
			return 0 ;
		}
	}
	rep(i, 1, n) bit[i] = 0 ;
	for (int i = n; i; -- i) {
		cout << i << endl ;
		if (i & 1) {
			if (((get(i) + abs(b[i] - i) / 2) & 1) ^ (a[1][b[i]] > a[3][b[i]])) {
				printf("No\n") ;
				return 0 ;
			}
		} else put(c[i]) ;
	}
*/
	rep(i, 1, n) {
		if (c[i] < i) ++ outd[i - 1], -- outd[c[i] - 1] ; else
		  ++ ind[i + 1], -- ind[c[i] + 1] ;
	}
	rep(i, 1, n) ind[i] += ind[i - 2] ;
	for (int i = n; i; -- i) outd[i] += outd[i + 2] ;
	rep(i, 1, n) if (ind[i] != outd[i]) {
		printf("No\n") ;
		return 0 ;
	}
	cnt = 0 ;
	rep(i, 1, n) if (i & 1) {
/*		if (ind[i] & 1) ++ cnt ;
//		if (ind[i] & 1) S.insert(i) ;
		if (((abs(c[i] - i) / 2) & 1) ^ (a[3][i] < a[1][i])) ; else continue ;
		++ cnt ; */
		cnt += a[3][i] < a[1][i] ;
//		p[cnt].l = min(c[i], i), p[cnt].r = max(c[i], i) ;
	} else {
		cnt += get(n - c[i] + 1) & 1 ;
		put(n - c[i] + 1) ;
	}
	if (cnt & 1) {
		printf("No\n") ;
		return 0 ;
	}
	rep(i, 1, n) bit[i] = 0 ;
//	sort(p + 1, p + cnt + 1, cmp) ;
//	rep(i, 1, n) cout << c[i] << " " ; cout << endl ;
/*	rep(i, 1, cnt) {
		std :: set <int> :: iterator it = S.lower_bound(p[i].l) ;
		if (it == S.end() || (*it) > p[i].r) {
			S.insert(p[i].r) ;
		} else {
			S.erase(it) ;
		}
	}
	if (!S.empty()) {
		printf("No\n") ;
		return 0 ;
	}*/
/*	if (cnt & 1) {
		printf("No\n") ;
		return 0 ;
	}
	cnt = 0 ;
*/
	cnt = 0 ;
	rep(i, 1, n) if (i & 1) cnt += get(n - c[i] + 1) & 1, put(n - c[i] + 1) ; else {
/*		if (ind[i] & 1) ++ cnt ;
//		if (ind[i] & 1) S.insert(i) ;
		if (((abs(c[i] - i) / 2) & 1) ^ (a[3][i] < a[1][i])) ; else continue ;
		++ cnt ;
*///		p[cnt].l = min(c[i], i), p[cnt].r = max(c[i], i) ;
		cnt += a[3][i] < a[1][i] ;
	}
	if (cnt & 1) {
		printf("No\n") ;
		return 0 ;
	}
//	sort(p + 1, p + cnt + 1, cmp) ;
//	rep(i, 1, cnt) cout << p[i].l << " " << p[i].r << endl ;
//	rep(i, 1, n) if (i & 1) ; else printf("%d ", ind[i]) ; cout << endl ;
/*	rep(i, 1, cnt) {
		std :: set <int> :: iterator it = S.lower_bound(p[i].l) ;
		if (it == S.end() || (*it) > p[i].r) {
			S.insert(p[i].r) ;
		} else {
			S.erase(it) ;
		}
	}
	if (!S.empty()) {
		printf("No\n") ;
		return 0 ;
	}
*/

	printf("Yes\n") ;
	return 0 ;
}

#include<bits/stdc++.h>

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double llf;
typedef std::pair<int,int> pii;

#define xx first
#define yy second

template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool repr(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool repl(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b){while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
#define mp(a,b) std::make_pair(a,b)
#define pb push_back
#define I inline
#define mset(a,b) memset(a,b,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

#define fo0(i,n) for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define fd0(i,n) for(int i=(n)-1;~i;i--)
#define fd1(i,n) for(int i=n;i;i--)
#define fd(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define foe(i,x)for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)

struct Cg{I char operator()(){return getchar();}};
struct Cp{I void operator()(char x){putchar(x);}};
#define OP operator
#define RT return *this;
#define RX x=0;char t=P();while((t<'0'||t>'9')&&t!='-')t=P();bool f=0;\
if(t=='-')t=P(),f=1;x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define RL if(t=='.'){lf u=0.1;for(t=P();t>='0'&&t<='9';t=P(),u*=0.1)x+=u*(t-'0');}if(f)x=-x
#define RU x=0;char t=P();while(t<'0'||t>'9')t=P();x=t-'0';for(t=P();t>='0'&&t<='9';t=P())x=x*10+t-'0'
#define TR *this,x;return x;
I bool IS(char x){return x==10||x==13||x==' ';}template<typename T>struct Fr{T P;I Fr&OP,(int&x)
{RX;if(f)x=-x;RT}I OP int(){int x;TR}I Fr&OP,(ll &x){RX;if(f)x=-x;RT}I OP ll(){ll x;TR}I Fr&OP,(char&x)
{for(x=P();IS(x);x=P());RT}I OP char(){char x;TR}I Fr&OP,(char*x){char t=P();for(;IS(t);t=P());if(~t){for(;!IS
(t)&&~t;t=P())*x++=t;}*x++=0;RT}I Fr&OP,(lf&x){RX;RL;RT}I OP lf(){lf x;TR}I Fr&OP,(llf&x){RX;RL;RT}I OP llf()
{llf x;TR}I Fr&OP,(uint&x){RU;RT}I OP uint(){uint x;TR}I Fr&OP,(ull&x){RU;RT}I OP ull(){ull x;TR}};Fr<Cg>in;
#define WI(S) if(x){if(x<0)P('-'),x=-x;char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
#define WL if(y){lf t=0.5;for(int i=y;i--;)t*=0.1;if(x>=0)x+=t;else x-=t,P('-');*this,(ll)(abs(x));P('.');if(x<0)\
x=-x;while(y--){x*=10;x-=floor(x*0.1)*10;P(((int)x)%10+'0');}}else if(x>=0)*this,(ll)(x+0.5);else *this,(ll)(x-0.5);
#define WU(S) if(x){char s[S],c=0;while(x)s[c++]=x%10+'0',x/=10;while(c--)P(s[c]);}else P('0')
template<typename T>struct Fw{T P;I Fw&OP,(int x){WI(10);RT}I Fw&OP()(int x){WI(10);RT}I Fw&OP,(uint x){WU(10);RT}
I Fw&OP()(uint x){WU(10);RT}I Fw&OP,(ll x){WI(19);RT}I Fw&OP()(ll x){WI(19);RT}I Fw&OP,(ull x){WU(20);RT}I Fw&OP()
(ull x){WU(20);RT}I Fw&OP,(char x){P(x);RT}I Fw&OP()(char x){P(x);RT}I Fw&OP,(const char*x){while(*x)P(*x++);RT}
I Fw&OP()(const char*x){while(*x)P(*x++);RT}I Fw&OP()(lf x,int y){WL;RT}I Fw&OP()(llf x,int y){WL;RT}};Fw<Cp>out;

const int N=100007;

int n,t[N][3],s[N];

int main()
{
	in,n;
	fo0(l,3)fo1(i,n)in,t[i][l];
	fo1(i,n)
	{
		int p=(t[i][0]-1)/3;
		//out,p,'\n';
		bool f1=1,f2=1;
		fo0(j,3)f1&=t[i][j]==p*3+j+1;
		fo0(j,3)f2&=t[i][j]==p*3+3-j;
		if((!f1&&!f2)||(~(i^p)&1))return puts("No"),0;
		s[i]=f1?p+1:-p-1;
	}
	//fo1(i,n)out,s[i],' ';out,'\n';
	int a[2]={0,0},b[2]={0,0};
	fo1(i,n)a[i&1]^=s[i]<0;
	fo1(i,n)while(abs(s[i])!=i)std::swap(s[i],s[abs(s[i])]),b[i&1]^=1;
	out,a[0]==b[1]&&a[1]==b[0]?"Yes":"No",'\n';
}


#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> a(m), b;
	vector<int> odds;
	for (int i = 0; i < m; ++i) {
		scanf("%d", &a[i]);
		if (a[i] & 1) odds.push_back(i);
	}
	if (odds.size() > 2) printf("Impossible\n");
	else {
		sort(odds.begin(), odds.end());
		if (odds.size() == 1) {
			swap(a[odds[0]], a[0]);
			b = a;
			--b[0];
			b.push_back(1);
		} else if (odds.size() == 2) {
			swap(a[odds[0]], a[0]);
			swap(a[odds[1]], a[m - 1]);
			b = a;
			--b[0];
			++b[m - 1];
		} else {
			b = a;
			--b[0];
			b.push_back(1);
		}
		for (int x : a) printf("%d ", x);
		printf("\n");
		if (b[0] == 0) b.erase(b.begin());
		printf("%d\n", b.size());
		for (int x : b) printf("%d ", x);
		printf("\n");
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    ll mod = 1e9+7;
    ll n,i,j,m;
    cin>>n>>m;
    vector<ll> x(n), y(m);
    for(i=0;i<n;i++) cin>>x[i];
    for(i=0;i<m;i++) cin>>y[i];
    ll xs = 0, ys = 0;
    for(i=0;i<n;i++)
    {
       xs = (xs + (i*x[i] - (n-i-1)*x[i]))%mod;
    }
    for(i=0;i<m;i++)
    {
        ys = (ys + (i*y[i] - (m-i-1)*y[i]))%mod;
    }
    ll ans = (xs*ys)%mod;
    cout<<ans;
}


#include<iostream>
#include<algorithm>
#define MAX 100
#define INFTY (1 << 21)
using namespace std;

int p[MAX + 1], mat[MAX + 1][MAX + 1];

void matrixChainMultiplication(int n) {
	for (int i = 1; i <= n; i++) {
		mat[i][i] = 0;
	}
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			mat[i][j] = INFTY;
			for (int k = i; k <= j - 1; k++) {
				mat[i][j] = min(mat[i][j], (mat[i][k] + mat[k + 1][j] + (p[i - 1] * p[k] * p[j])));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	matrixChainMultiplication(n);
	cout << mat[1][n] << endl;
	return 0;
}

#include <stdio.h>
const int N=110;
const int INF=1<<30;
int min(int a,int b){
    return a>b?b:a;
}
int main(){
    int n,dp[N][N],a[N];
    scanf("%d%d%d",&n,&a[0],&a[1]);
    for(int i=1;i<n;i++)scanf("%d%d",&a[i],&a[i+1]);
    for(int k=1;k<n;k++){
        for(int i=0;i<n-k;i++){
            dp[i][i+k]=INF;
            for(int j=i;j<i+k;j++)dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]+a[i]*a[j+1]*a[i+k+1]);
        }
    }
    printf("%d\n",dp[0][n-1]);
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	int N;string A,B,C;cin>>N>>A>>B>>C;
	int ans=0;int a=0;
	rep(i,N){
		if(A.at(i)==B.at(i)){
			a++;
		}
		if(B.at(i)==C.at(i)){
			a++;
		}
		if(C.at(i)==A.at(i)){
			a++;
		}
		if(a==0){
			ans++;
			ans++;
		}else if(a==1){
			ans++;
		}else if(a==3){

		}
		a=0;
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;int64 D;
int64 A[MAXN];
struct seg_tr {
    struct node {
        int L,R;
        int64 cov;
        pair<int64,int> val[2];
    }tr[MAXN * 4];
    void update(int u) {
        tr[u].val[1] = mp(1e16,0);
        if(tr[u].L != tr[u].R) {
            tr[u].val[0] = min(tr[u << 1].val[0],tr[u << 1 | 1].val[0]);
            tr[u].val[1] = min(tr[u << 1].val[1],tr[u << 1 | 1].val[1]);
        }
        tr[u].val[1] = min(tr[u].val[1],mp(tr[u].cov + tr[u].val[0].fi,tr[u].val[0].se));
    }
    void build(int u,int l,int r,int on) {
        tr[u].L = l;tr[u].R = r;tr[u].cov = 1e16;
        if(l == r) {
            tr[u].val[0] = mp(A[l] + on * l * D,l);
            update(u);
            return;
        }
        int mid = (l + r) >> 1;
        build(u << 1,l,mid,on);build(u << 1 | 1,mid + 1,r,on);
        update(u);
    }
    void Change(int u,int l,int r,int64 v) {
        if(l > r) return;
        if(tr[u].L == l && tr[u].R == r) {
            tr[u].cov = min(tr[u].cov,v);
            update(u);
            return;
        }
        int mid = (tr[u].L + tr[u].R) >> 1;
        if(r <= mid) Change(u << 1,l,r,v);
        else if(l > mid) Change(u << 1 | 1,l,r,v);
        else {Change(u << 1,l,mid,v);Change(u << 1 | 1,mid + 1,r,v);}
        update(u);
    }
    void Change_pos(int u,int p) {
        if(tr[u].L == tr[u].R) {
            tr[u].val[0] = mp(1e16,tr[u].L);
            update(u);return;
        }
        int mid = (tr[u].L + tr[u].R) >> 1;
        if(p <= mid) Change_pos(u << 1,p);
        else Change_pos(u << 1 | 1,p);
        update(u);
    }
}s[2];

void Solve() {
    read(N);read(D);
    for(int i = 1 ; i <= N ; ++i) read(A[i]);
    s[0].build(1,1,N,1);
    s[1].build(1,1,N,-1);
    s[0].Change_pos(1,1);s[1].Change_pos(1,1);
    s[0].Change(1,2,N,A[1] - D);
    int cnt = N - 1;
    int64 ans = 0;
    while(cnt--) {
        pair<int64,int> t[2];
        t[0] = s[0].tr[1].val[1],t[1] = s[1].tr[1].val[1];
        if(t[0] > t[1]) swap(t[0],t[1]);
        ans += t[0].fi;
        int u = t[0].se;
        s[0].Change_pos(1,u);s[1].Change_pos(1,u);
        s[1].Change(1,1,u - 1,1LL * u * D + A[u]);
        s[0].Change(1,u + 1,N,-1LL * u * D + A[u]);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  string s;
  cin >> s;
  reverse(ALL(s));
  s.push_back('0');
  vector<vector<int>> dp(s.size()+1, vector<int>(2, INF));
  dp.at(0).at(0) = 0;
  rep(i, s.size())rep(j, 2){
    int now = s.at(i) - '0';
    now += j;
    rep(a, 10){
      int ni = i+1, nj = 0;
      int b = a - now;
      if(b < 0){
        nj++;
        b += 10;
      }
      dp.at(ni).at(nj) = min(dp.at(ni).at(nj), dp.at(i).at(j)+a+b);
    }
  }
  cout << dp.at(s.size()).at(0) << endl;
  return 0;
}

/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

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

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

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

vector<vector<char>> ban(55,vector<char>(55));
vector<vector<int>> ans(55,vector<int>(55));

int main() {
    int N;cin >> N;
    vector<double> retu(N);
    double avg = 0;
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        avg += retu.at(i);
    }
    avg /= N;
    int ans = 0;
    double sa = 114514.0;
    for(int i = 0;i<N;i++){
        if(sa > abs(avg-retu.at(i))){
            sa = abs(avg-retu.at(i));
            ans = i;
        }
    }

    cout << ans << endl;
}


#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main(){
int n, dp[50];
while(cin>>n,n!=0){
fill(dp,dp+50,0);
dp[0]=0,dp[1]=1,dp[2]=1,dp[3]=2;
for(int i=3;i<=n+1;i++)dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
int ans=dp[n+1];
ans/=3650;
if(dp[n]%3650!=0)ans++;
cout<<ans<<endl;
}
return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
      int tmp;
      int dp[100];
      cin>> tmp;
      do{
            fill(dp,dp+100,0);
            dp[0] = 1;
            for (int i = 0; i<tmp;i++)
            {
                  for(int j = 1;j < 4;j++)
                        dp[i+j] += dp[i];
            }
            cout << dp[tmp]/3650 + 1<<endl;
            cin >> tmp;
      }while(tmp);

}


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

typedef long long Int;
typedef pair<Int,Int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair

#define MAX (6 << 10)

Int R[MAX][MAX + MAX];

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

	CLEAR(R, 0);
	R[0][MAX] = 1;
	int i, j;
	FOR(i, 0, 3*n)
	FOR(j, 0, MAX + MAX)
	if(R[i][j] != 0)
	{
		R[i + 1][j + 1] = (R[i + 1][j + 1] + R[i][j]) % m;
		if(i + 2 <= 3*n) R[i + 2][j - 1] = (R[i + 2][j - 1] + R[i][j]*(i + 1)) % m;
		if(i + 3 <= 3*n) R[i + 3][j] = (R[i + 3][j] + R[i][j]*(i + 1)*(i + 2)) % m;
	}

	Int res = 0;
	FOR(i, MAX, MAX + MAX) res += R[3*n][i];
	res %= m;
	cout << res << endl;
	return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);

#define l_ength size

ll MOD;

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[6060][13000];

int main(void){
	int n,i,j;
	ll ans = 0ll;
	std::cin >> n >> MOD;
	n *= 3;
	dp[0][6500] = 1ll;
	for(i=0; i<n; ++i){
		for(j=500; j<=12500; ++j){
			add_mod(dp[i+1][j-1],dp[i][j]);
			add_mod(dp[i+2][j+1],dp[i][j]*(i+1)%MOD);
			add_mod(dp[i+3][j],dp[i][j]*(i+1)*(i+2)%MOD);
		}
	}
	for(j=500; j<=6500; ++j){
		add_mod(ans,dp[n][j]);
	}
	std::cout << ans << std::endl;
	return 0;
}


#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll a,b;
    cin>>a>>b;
    cout<<max(max(a+b,2*a-1),2*b-1);}

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

int main() {
  int A, B;
  cin >> A >> B;

  if(A==B){
    cout << A+B << endl;
  }
  else if(A>B){
    cout << A+A-1 << endl;
  }
  else if(A<B){
    cout << B+B-1 << endl;
  }
}


#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	ll n;
	map<int, ll> field;
	vi jun;

	while(cin >> n, n) {
		field.clear();
		jun.clear();

		int ban;
		ll tan, suu;
		bool flag = true;

		REP(i, n) {
			cin >> ban >> tan >> suu;

			if(!field[ban]) {
				jun.push_back(ban);
			}

			if(field[ban] < 1000000) {
				field[ban] += tan*suu;
			}
		}

		if(jun.size() == 0) {
			cout << "NA" << endl;
		} else {
			REP(i, jun.size()) {
				if(field[jun[i]] >= 1000000) {
					cout << jun[i] << endl;
					flag = false;
				}
			}
			if(flag) {
				cout << "NA" << endl;
			}
		}
	}

	return 0;
}

#include<cstdio>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;

int flag[301] = {0};

int main(void){
    while(1){
        for(int i = 1;i <= 300;i++){
            flag[i] = 2;
        }
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        if(a == 0 && b == 0 && c == 0) break;
        vector < pair<pair<int,int> ,pair<int,int> > > v;
        pair<pair<int,int>,pair<int,int> > input;
        int n; scanf("%d",&n);
        for(int i = 0;i < n;i++){
            int x,y,z,w; scanf("%d%d%d%d",&x,&y,&z,&w);
            input.first.first = w;
            input.first.second = x;
            input.second.first = y;
            input.second.second = z;
            v.push_back(input);
        }
        sort(v.begin(),v.end(),greater <pair< pair<int,int>,pair<int,int> > >());
        for(int i = 0;i < n;i++){
            if(v[i].first.first == 1){
                flag[v[i].first.second] = 1;
                flag[v[i].second.first] = 1;
                flag[v[i].second.second] = 1;
            }
            else{
                if(flag[v[i].first.second] == 1 &&
                   flag[v[i].second.first] == 1 &&
                   flag[v[i].second.second] == 2){
                    flag[v[i].second.second] = 0;
                }

                if(flag[v[i].first.second] == 1 &&
                   flag[v[i].second.first] == 2 &&
                   flag[v[i].second.second] == 1){
                    flag[v[i].second.first] = 0;
                }

                if(flag[v[i].first.second] == 2 &&
                   flag[v[i].second.first] == 1 &&
                   flag[v[i].second.second] == 1){
                    flag[v[i].first.second] = 0;
                }
            }
        }
        for(int i = 1;i <= a+b+c;i++){
            printf("%d\n",flag[i]);
        }

    }
    return 0;
}


#include <iostream>
using namespace std;

int main () {
    int x, y;
    cin >> x >> y;
    cout << x*y;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

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

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int memo[64][64];

int main(void){
  while(1){
    int n,p;
    int pl[64] = {0};
    int ans = -1;
    int bowl;
    cin >> n >> p;
    bowl = n;
    if(n+p==0)break;
    if(memo[n][p] == 0){
      bowl = p;
      rep(i,1000000){
        if(bowl){
          bowl--;
          pl[(i%n)]++;
          if(pl[i%n] == p){ans = i%n;break;}
        }else{
          bowl = pl[i%n];
          pl[i%n] = 0;
        }
      }
      cout << ans << endl;
      memo[n][p] = ans;
    }else{
      cout << memo[n][p] << endl;
    }
  }
  return 0;
}