#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define MAX 100005

int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
  ll n;cin>>n;
  ll ar[n];
  ll count = 0;ll mi;
  for(ll i=0;i<n;i++)
  {
      ll x;cin>>x;
      if(i==0)mi = x;
      else if(x>mi)count++;
      else mi = x;
  }
  cout<<n-count<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e6;
int arr[maxn],n;
int main() {
  cin>>n;
  bool flag;
  int ans=1;
  int temp;
  cin>>arr[0];
  temp=arr[0];
  for(int i=1;i<n;i++)
  {
  	 cin>>arr[i];
	 if(arr[i]<temp)
  	 ans+=1;
  	 temp=min(arr[i],temp);
  }
 	cout<<ans;

}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    if(n == 0){
        cout << 0 << endl; return 0;
    }
    string bin = "";
    while(n != 0){
        ll foo = n%((ll)-2);
        n /= ((ll)-2);
        if(foo < 0){
            foo += abs((ll)-2);
            n++;
        }
        bin = to_string(foo)+bin;
    }
    cout << bin << endl;
    return 0;
}

#include <bits/stdc++.h>

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

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

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

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

    vector<int64_t> ans;
    while (n != 0) {
        if (n % 2 != 0) {
            ans.push_back(1);
            --n;
        } else {
            ans.push_back(0);
        }
        n /= -2;
    }

    for (auto a : ans | reversed) {
        cout << a;
    }
    cout << endl;
}


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

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

  int q;
  string s;
  set<int> ac;
  vector<int> wa(n+1, 0);
  for(int i=0; i<m; i++) {
    cin >> q >> s;
    if(ac.count(q)) continue;
    if(s=="AC") ac.insert(q);
    else wa[q]++;
  }

  for(int i=1; i<n+1; i++) if(!ac.count(i)) wa[i] = 0;
  cout << ac.size() << " " << accumulate(wa.begin(), wa.end(), 0) << endl;
  return 0;
}

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

int main(void){
   int N,M;
   cin >>N>>M;
   bool AC[N];
   int WA[N];

   int WAsum=0;
   int ACsum=0;

   rep(i,N){
       WA[i]=0;
       AC[i]=false;
   }
   while(M>0){
       int p;
       string s;
       cin >> p>>s;
       M--;
       if(AC[p-1]==true){
           continue;
       }
       if(s=="AC"){
           WAsum+=WA[p-1];
           ACsum++;
           AC[p-1]=true;

       }
       else if(s=="WA"){
           WA[p-1]++;
       }
   }
   cout << ACsum << " "<< WAsum << endl;

}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    string S = "";
    ll cur = 1;
    if(N==0){
        cout << 0 << endl;
        return 0;
    }
    while(N){
        if(N % -2){
            S = "1" + S;
            N--;
        }else{
            S = "0" + S;
        }
        N /= -2;
    }
    cout << S << endl;
}


#include<iostream>
#include<cstring>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAX 500000
#define INF 2e9
int L[MAX/2+2],R[MAX/2+2];
long long  cnt=0;
long long merge(int A[],int n,int left,int mid,int right)
{
	long long cnt=0;
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++)
    {
        L[i]=A[left+i];
    }
    for(int i=0;i<n2;i++)
    {
        R[i]=A[mid+i];
    }
    L[n1]=INF;
    R[n2]=INF;
    int i=0,j=0;
    for(int k=left;k<right;k++)//合并
    {
     if(L[i]<=R[j])
     A[k]=L[i++];
     else
     {
	 A[k]=R[j++];
	 cnt=cnt+(n1-i);
}
}
return cnt;
}
long long  mergeSort(int A[],int n,int left,int right)
{
	long long v1,v2,v3;
    if(left+1<right)
    {
        int mid=(left+right)/2;
        v1=mergeSort(A,n,left,mid);
        v2=mergeSort(A,n,mid,right);
        v3=merge(A,n,left,mid,right);
        return (v1+v2+v3);
    }
    else
    return 0;
}
int main()
{
int A[MAX],n;
cnt=0;
cin>>n;
for(int i=0;i<n;i++)
cin>>A[i];
cnt=mergeSort(A,n,0,n);
cout<<cnt<<endl;
return 0;
 }

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

int main() {
    int M = 1 << 18 + 1;
    int N;
    cin >> N;
    vector<int> A(N), a(N), ord(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
        a[i] = A[i];
    }

    sort(a.begin(), a.end());
    for ( int i = 0; i < N; i++ ) {
        ord[i] = lower_bound(a.begin(), a.end(), A[i]) - a.begin();
    }

    ll ans = 0;
    vector<int> bit(M);
    int k,sum;
    for ( int i = 0; i < N; i++ ) {
        // add
        k = ord[i] + 1;
        while ( k <= M ) {
            bit[k]++;
            k += k & -k;
        }
        // sum
        sum = 0;
        k = ord[i] + 1;
        while ( k > 0 ) {
            sum += bit[k];
            k -= k & -k;
        }

        ans += i + 1 - sum;
    }

    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (1e+9)+7;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  ll sm = 0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    sm = (sm + a[i]) % MOD;
  }
  ll ans = 0;
  for(int i=0; i<n; i++){
    sm -= a[i];
    if(sm < 0) sm += MOD;
    ans = (ans + (a[i] * (sm)) % MOD) % MOD;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
int64_t mod = 1e9+7;
int main() {
    int n;
    cin >> n;
    vector<int64_t>arr(n);
    for(auto & i : arr)
        cin >> i;
    vector<int64_t>sufsum;
    sufsum.push_back(0);
    for(int i = n-1; i > 0; --i){
        auto a = sufsum.back();
        a+=arr[i];
        sufsum.push_back(a);
    }
    reverse(sufsum.begin(),sufsum.end());
    int64_t ans = 0;
    for(int i = 0 ; i < n; ++i){
        ans+=(arr[i]*(sufsum[i]%mod));
        ans%=mod;
    }
    cout << ans << "\n";
    return 0;
}


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

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

ll N,M;
vector<ll> A;

int main(){
    cin>>N>>M;
    A.resize(N);
    rep(i,N)cin>>A[i];
    vector<ll> V(N);
    V[0] = A[0]%M;
    rep1(i,N-1)V[i] = (V[i-1] + A[i])%M;
    sort(V.begin(),V.end());
    map<ll,ll> r;;;;
    rep(i,N) r[V[i]]++;
    ll res = 0;
    for(auto p:r){
        ll amari = p.first;
        ll cnt = p.second;
        if(amari==0){
            res += cnt;
            res += cnt*(cnt-1)/2;
        }else{
            res += cnt*(cnt-1)/2;
        }
    }
    cout<<res<<endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n, m;
ll k;
int x[100000];
int d[100000];
int D[100000];
int to[100000];
int a[100000];
int tmp[100000];
bool saw[100000];

int main() {
    cin >> n;
    rep(i,n) cin >> x[i];
    rep(i,n-1) d[i] = x[i+1]-x[i];
    rep(i,n-1) to[i] = i;
    cin >> m >> k;
    rep(i,m) cin >> a[i];
    rep(i,m) a[i]--;
    rep(j,m) {
        swap(to[a[j]-1], to[a[j]]);
    }
    rep(i,n-1) {
        if (saw[i]) continue;
        int p = i;
        int si = 0;
        saw[p] = true;
        tmp[si++] = p;
        while (!saw[to[p]]) {
            saw[to[p]] = true;
            p = to[p];
            tmp[si++] = p;
        }
        rep(j,si) {
            D[tmp[j]] = d[tmp[(j+k)%si]];
        }
    }

    ll pos = x[0];
    cout << pos << endl;
    rep(i,n-1) {
        pos += D[i];
        cout << pos << endl;
    }
}


#include<iostream>
#include<string>
#include<algorithm>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

int main() {
	string str, cmd, p, tmp;
	int q, i, j, a, b;
	cin >> str >> q;
	rep(i,q) {
		cin >> cmd;
		if (cmd == "print") {
			cin >> a >> b;
			cout << str.substr(a,b-a+1) << endl;
		} else if (cmd == "reverse") {
			cin >> a >> b;
			tmp = str.substr(a,b-a+1);
			reverse(tmp.begin(),tmp.end());
			rep(j,b-a+1) str[a+j] = tmp[j];
		} else if (cmd == "replace") {
			cin >> a >> b >> p;
			rep(j,p.length()) str[a+j] = p[j];
		} else cout << "Input Error";
	}
	return 0;
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000

int main(){
  int n;
  while(scanf("%d", &n), n){
    vector<int> k(n);
    rep(i,n){
      scanf("%d", &k[i]);
    }
    char s[103];
    scanf("%s", s);

    int len=strlen(s);
    rep(i,len){
      if(s[i]>='a' && s[i]<='z'){
	s[i]=s[i]-k[i%n];
	if(s[i]<'a'){
	  s[i]+='Z'-'a'+1;
	  if(s[i]<'A') s[i]+='z'-'A'+1;
	}
      } else {
	s[i]=s[i]-k[i%n];
	if(s[i]<'A'){
	  s[i]+='z'-'A'+1;
	  if(s[i]<'a') s[i]+='Z'-'a'+1;
	}
      }
    }

    cout<<s<<endl;

  }
  return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
signed main()
{
  int a,b,c=1,d;
  cin>>a>>b;
  d=a;
  for(int i=1;i<=d;i++){
    if(a>b){
    a-=b;
    a+=b-1;
    c++;
    }
  }
  cout<<c<<"\n";
}


#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
#define mod 998244353
#define N 1000010
using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    int l=1,r=m+1;
    while(l<r)
    {
        cout<<l++<<" "<<r--<<endl;
    }
    l=m+2,r=2*m+1;
    while(l<r)
    {
        cout<<l++<<" "<<r--<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
char gap = 32;
template < typename T >
ostream& operator<<(ostream &os, const vector < T > &v) {
  os << '{';
  for (const auto &x: v) os << gap << x;
  return os << '}';
}
template < typename A, typename B >
ostream& operator<<(ostream &os, const pair < A, B > &p) {
  return os << '(' << p.first << gap << p.second << ')';
}

template < class T >
void read(T &x) {
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar());
  for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int, int > ii;
typedef vector < ii > vii;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef tree <
int,
null_type,
less < int >,
rb_tree_tag,
tree_order_statistics_node_update >
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
ll dp[1001][1001];
ll mod=1000000007;
vector<string>Data;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll i,j,k,l,n,m;
  cin>>n>>m;
  vector<pair<ll,ll>>res;
  ll ini=1;
  ll fina=n;
  vector<ll>used(n+1,0);
  ll kola1=(m+1)/2;
  while(kola1--){
    used[ini]=1;used[fina]=1;
    res.pb({ini++,fina--});
  }
  m=m/2;
  ll cnt=2*m;
  while(m--){
    while(used[ini]==1) ini++;
    res.pb(make_pair(ini,ini+cnt));
    used[ini]=1;
    used[ini+cnt]=1;
    cnt-=2;
  }
  for(auto x:res) cout<<x.first<<" "<<x.second<<'\n';
}


#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdio>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii;
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int main(void){
	string num;
	getline(cin,num);
	int n = atoi(&num[0]);
	while(n--){
		string s;
		getline(cin,s);
		rep(i,s.size()){
			if(s[i]=='H'&&s[i+1]=='o'&&s[i+2]=='s'&&s[i+3]=='h'&&s[i+4]=='i'&&s[i+5]=='n'&&s[i+6]=='o'){
				s[i+6]='a';
			}
			if(s[i]=='\n'){cout<<endl;n--;break;cout<<"test"<<n<<endl;}
			}
		cout<<s<<endl;
	}
}

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  string s;
  string::size_type t;
  cin >> n;
  getchar();
  while (n--) {
    getline(cin, s);
    t = 0;
    while ((t = s.find("Hoshino", t)) != string::npos) {
      s[t + 6] = 'a';
      t += 1;
    }
    cout << s << endl;
  }
  return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;
ll h, w;

int main(){
    cin >> n;
    vector<ull> a(n);
    for (ll i=0; i<n; ++i){
        cin >> a[i];
    }
    ull asu=0, asq=0;
    for (ll i=0; i<n; ++i){
        asu += a[i];
        asu %= DENOM;
        asq += a[i] *a[i];
        asq %= DENOM;
    }
    ll ret = ((asu * asu) - asq) % DENOM;
    if (ret %2 ==0){
        ret /= 2;
    }else{
        ret = (ret + DENOM) / 2;
    }
    cout << ret << endl;
    return 0;
}

/*  Perseverance can make miracle happens  */
/* If u identify me then u r my frnd */

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

#define int long long int
#define vi vector<int>
#define pq priority_queue<int>
#define mpi map<int,int>
#define pb push_back
#define ff first
#define ss second
#define forn(i,n) for(int i=0;i<n;i++)
#define M 1000000007
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

int mod(long long x) {
	return ((x % M + M) % M);
}
int add(int a, int b) {
	return mod(mod(a) + mod(b));
}
int diff(int a, int b) {
	return mod(mod(a) - mod(b));
}

int mul(int a, int b) {
	return mod(mod(a) * mod(b));
}

void solve() {

	int n; cin >> n;
	int a[n];
	int s = 0;
	forn(i, n) {
		cin >> a[i];
		s += a[i];
	}

	int ps[n];
	ps[0] = a[0];
	for (int i = 1; i < n; i++) {
		ps[i] = add(ps[i - 1] , a[i]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = add(mod(ans) , mul(a[i] , (s - ps[i])));
	}

	cout << ans << endl;

}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t; cin >> t;
	int t = 1;

	while (t--) {
		solve();
	}

	return 0;
}


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

int main(){

int get_rate=0;
int get_goal=0;

cin >> get_rate >> get_goal;

cout << 2*get_goal-get_rate;
}

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

const int MaxN = 1000000;

int n;
char s[MaxN + 2], t[MaxN + 2];

int q_l, q_r;
int q[MaxN + 1];

inline int solve()
{
	if (!strcmp(s + 1, t + 1))
		return 0;

	q_l = 1, q_r = 0;

	int l = 0, last = n + 1;
	int res = 0;
	for (int i = n, j = n; i; --i)
	{
		if (i > 1 && t[i] == t[i - 1])
			continue;

		while (j > i || (j && s[j] != t[i]))
			--j;
		if (j == 0)
			return -1;

		q[++q_r] = j + ++l;
		while (q_l <= q_r && q[q_l] - l >= last)
			++q_l;

		res = max(res, q_r - q_l + 1);

		last = i - 1;
	}

	return res;
}

int main()
{
	scanf("%d", &n);
	scanf("%s%s", s + 1, t + 1);

	cout << solve() << endl;

	return 0;
}


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

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

#define _INF -2000000001

int main()
{
    int n;
    cin >> n;
    int *a = inputint(n);

    long long f0[2][3];
    long long f1[2][3];

    int wmax = (n % 2 == 0) ? 1 : 2;
    int index = 0;
    f0[0][0] = a[0];
    f0[0][1] = _INF;
    f0[0][2] = _INF;
    f1[0][0] = _INF;
    f1[0][1] = 0;
    f1[0][2] = _INF;
    index = 0;
    for( int i = 1; i < n; i++ )
    {
        int next = (index + 1) % 2;
        for( int w = 0; w <= wmax; w++ )
        {
            f0[next][w] = f1[index][w];
            if( f0[next][w] != _INF ) f0[next][w] += (long long)a[i];

            if( w > 0)
            {
                f1[next][w] = max(f1[index][w - 1], f0[index][w]);
            }
            else
            {
                f1[next][w] = f0[index][w];
            }
        }
        index = next;
    }

    long long ans = max(f0[index][wmax], f1[index][wmax - 1]);
    cout << ans;
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    string date;
    cin>> date;
    date[3]='8';
    cout<<date;
    return 0;
}


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

int main()
{
    cout << fixed << setprecision(30);
    ll N, M;
    cin >> N >> M;
    vector<bool> available(M + 1, true); //実施されるかどうか
    vector<vector<ll>> A(N, vector<ll>(M));
    loop(i, N) loop(j, M) cin >> A[i][j];
    ll ans = 1e9;
    loop(i, M)
    {
        vector<ll> count(M + 1); //各競技の参加者の数
        loop(j, N)
        {
            loop(k, M)
            {
                ll now = A[j][k];
                if (available[now])
                {
                    count[now]++;
                    break;
                }
            }
        }
        ll maxx = 0;
        Loop(j, 1, M + 1) if (available[j]) maxx = max(maxx, count[j]);
        Loop(j, 1, M + 1) if (available[j]) if (count[j] == maxx)
        {
            available[j] = false;
            break;
        }
        ans = min(ans, maxx);
    }
    putout(ans);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
const int mod=1e9+7;
const int N=1e6+5;

int main()
    {
        Nitroboost;
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif

        int n,m;
        cin>>n>>m;
        map<int,int>mp;
        for(int i=1;i<=m;i++)
            mp[i]=i;

        multiset<int>v;
        for(int i=1;i<=m;i++)
            v.insert(0);

        for(int i=1;i<=n;i++)
        {
            int l,r;
            cin>>l>>r;
            r++;
            auto it=mp.lower_bound(l);
            int t=-1;
            while(it!=mp.end() && it->first<=r)
            {
                t=max(t,it->second);
                v.erase(v.find(it->first-it->second));
                mp.erase(it++);
            }
            if(t!=-1 && r<=m)
            {
                v.insert(r-t);
                mp[r]=t;
            }

            if(v.size()>0)
            cout<<i+(*v.begin())<<"\n";
            else
                cout<<"-1\n";
        }
    }


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

#define vt vector
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define ar array
#define inf() ifstream cin("d.txt")
#define onf() ofstream cout("test.txt")
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define in(a) cin>>a
#define inn(a,b) cin>>a>>b
#define innn(a,b,c) cin>>a>>b>>c
#define rep(i,st,end) for(int i=st;i<end;i++)
#define repv(i,st,end) for( i=st;i>=end;i--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define TEST ll tc;cin>>tc;while(tc--)
#define EACH(x, a) for (auto& x: a)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"\n";
    err(++it, args...);
}

void solve()
{
  ll d,t,s;
  read(d,t,s);
  ll di = s*t ;
  if(di>=d)
    cout<<"Yes";
  else
    cout<<"No";
}

 int main()
 {
    fio;
    ll k = 1;
    ll tc = 1;
    // cin>>tc;
    while(tc--){
       // cout<<"Case #"<<k<<": ";k++;
        solve();
        endl;
    }

 }

#include <bits/stdc++.h>
using namespace std;
int const MX = 2e5 + 2;

int main()
{
    int d, s, t;
    cin>>d>>t>>s;
    int time = (d + s - 1)/s;
    if(time <= t) cout<<"Yes\n";
    else cout<<"No\n";
}


#include <stdio.h>

void grade(int students)
{
    while(students != 0) {
        for(int i = 0; i < students; ++i) {
            int math, english, japanese;
            scanf("%d %d %d", &math, &english, &japanese);
            int mean = (math + english + japanese) / 3;
            if ((math == 100) || (english == 100) || (japanese == 100)) {
                printf("A\n");
            } else {
                if (((math + english) / 2 >= 90) || mean >= 80) {
                    printf("A\n");
                } else if ((mean >= 70) || ((mean >= 50) && ((math >= 80) || (english >= 80)))) {
                    printf("B\n");
                } else {
                    printf("C\n");
                }
            }
        }
        scanf("%d", &students);
    }
}

int main(void)
{
    int students;
    scanf("%d", &students);
    grade(students);
    return 0;
}

#include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int point[3];
	int n;
	int ave;
	int me_ave;
	bool has100point;

	while( true )
	{
		n = in();
		if( n == 0 )break;
		for(int i = 0; i < n; i++)
		{
			ave = me_ave = 0;
			has100point = false;
			for(int j = 0; j < 3; j++)
			{
				point[j] = in();
				if( point[j] == 100 )has100point = true;
			}
			ave = (point[0] + point[1] + point[2]) / 3;
			me_ave = (point[0] + point[1]) / 2;
			if( has100point || me_ave >= 90 || ave >= 80 )
			{
				puts("A");
			}
			else if( ave >= 70 || (ave >= 50 && (point[0] >= 80 || point[1] >= 80)) )
			{
				puts("B");
			}
			else
			{
				puts("C");
			}
		}
	}
	return (0);
}


#include<bits/stdc++.h>
using namespace std;
const int N=1050;
int a[N],b[N],col,n,m,com,tot;
const long long mod=1e9+7;
long long ans=0;
bool vis[2][N*N];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		vis[0][a[i]]=true;
	}
	for(int j=1;j<=m;j++) {
		scanf("%d",&b[j]);
		vis[1][b[j]]=true;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	ans=1;
	for(int i=1;i<n;i++) if(a[i]==a[i+1]) ans=0;
	for(int j=1;j<m;j++) if(b[j]==b[j+1]) ans=0;
	col=n;com=m;
	for(int i=m*n;i>=1;i--){
		while(col>=1&&a[col]>=i) col--;
		while(com>=1&&b[com]>=i) com--;
		tot=(n-col)*(m-com)-(n*m-i);
		if(tot<=0) ans=0;
		if(vis[0][i]&&vis[1][i]) tot=1;
		else if(vis[0][i]) tot=m-com;
		else if(vis[1][i]) tot=n-col;
		ans=ans*tot%mod;
	}
	printf("%lld\n",ans);

}

#include<bits/stdc++.h>

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

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

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m;cin>>n>>m;
  vector<int>a(n), b(m);
  rep(i, n)cin>>a[i];
  rep(i, m)cin>>b[i];

  map<int, int>ma, mb;
  for(auto c:a)ma[c]++;
  for(auto p: ma)if(p.second>1) { cout<<0<<endl; return 0; }
  for(auto c:b)mb[c]++;
  for(auto p: mb)if(p.second>1) { cout<<0<<endl; return 0; }

  vector<int> counter_a(n*m+1);
  vector<int> counter_b(n*m+1);
  for(auto c: a)counter_a[c]++;
  for(auto c: b)counter_b[c]++;
  rrep1(i, n*m)counter_a[i-1] += counter_a[i];
  rrep1(i, n*m)counter_b[i-1] += counter_b[i];

  ll result=1;
  rrep1(c, n*m){
    ll cca = counter_a[c];
    ll ccb = counter_b[c];
    ll reduce = (n*m-c);

    if(ma[c]>0 && mb[c]>0);
    else if(ma[c]>0){
      result = result*ccb%MOD;
    }else if(mb[c]>0){
      result = result*cca%MOD;
    }else{
      result = result*(cca*ccb-reduce)%MOD;
    }
  }

  cout<<result<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

const ll MODULO = 998244353L;

void print() { cout << endl; }
template <typename Head, typename... Tail>
void print(Head head, Tail... tail) {
    int size = sizeof...(Tail);
    cout << head;
    if (size > 0) {
        cout << " ";
    }
    print(tail...);
}

void print0() {}
template <typename Head, typename... Tail>
void print0(Head head, Tail... tail) {
    cout << head;
    print0(tail...);
}

ll mod_pow(ll x, ll n, ll modval) {
    if (n == 0) {
        return 1;
    }
    ll res = mod_pow(x * x % modval, n / 2, modval);
    if (n & 1) {
        res = res * x % modval;
    }
    return res;
}
ll pow(ll x, ll n) {
    return mod_pow(x, n, MODULO);
}
ll mod(ll n) {
    return n % MODULO;
}

const ll COMBMAX = 200000;
ll factorial[COMBMAX+1], invfactor[COMBMAX+1];
void combination_init() {
    factorial[0] = 1;
    factorial[1] = 1;
    invfactor[0] = 1;
    invfactor[1] = 1;
    for (ll i = 2; i <= 1 + COMBMAX; i++) {
      factorial[i] = (i * factorial[i-1]) % MODULO;
      invfactor[i] = pow(factorial[i], MODULO-2);
    }
}
ll combination(ll n, ll k) {
    return mod(mod(factorial[n]*invfactor[k])*invfactor[n-k]);
}

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

    combination_init();
    ll result = 0;
    for (ll j = 0; j <= K; j++) {
        result = mod(result + mod(combination(N - 1, j) * mod(M * pow(M - 1, N - j - 1))));
    }
    print(result);
}

// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s, t;
  cin >> n >> s >> t;
  REP(int, i, n)
  {
    string a = "", b = "";
    REP2(int, j, i, n) a += s[j];
    REP(int, j, n-i) b += t[j];
    if (a == b)
    {
      cout << n + i << endl;
      return 0;
    }
  }
  cout << 2*n << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll a[105];

int main()
{
	while (1) {
		cin >> n >> k;
		if (n == 0 && k == 0) {
			return 0;
		} else {
			fill(a, a + 105, 0);
			ll ma = 0;
			REP(i, n)
			{
				cin >> m;
				REP(j, m)
				{
					ll b;
					cin >> b;
					a[b]++;
				}
			}
			ll p;
			REP(i, 105)
			{
				if (ma < a[i]) {
					ma = a[i];
					p = i;
				}
			}
			if (ma < k) {
				cout << 0 << endl;
			} else {
				cout << p << endl;
			}
		}
	}
}

#include <iostream>
#include <vector>
#include <algorithm>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit
//	freopen ("testcase.thanksgiving", "r", stdin );
	int n, m;

	while (cin >> n >> m && n && m){
		vector <int> bp(n + 1);
		int i;

		bp[0] = 10001;
		for (i = 1; i <= n; ++i){
			cin >> bp[i];
		} // end while

		sort (bp.begin(), bp.end(), greater<int>() );

		int res = 0;

		for (i = 1; i <= n; ++i){
			if (i % m == 0){
				continue;
			} // end if
			res += bp[i];
		} // end for
		cout << res << endl;

	} // end loop

	return 0;
}


#define _USE_MATH_DEFINES

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

using namespace std;

int main(){

	int card[4];
	char c;

	while(cin >> card[0] ){
		for(int i=1;i<5;i++){
			cin >> c >> card[i];
		}
		sort(card, card+5);

		int two = 0;
		bool three = 0;
		bool four = 0;

		for(int i=0;i<5;i++){
			int count = 1;
			for(int j=i+1;j<5;j++){
				if(card[i]==card[j]){
					count++;
				}
				else{
					break;
				}
			}
			if(count==2){
				two+=1;
				i+=1;
			}
			else if(count==3){
				three=1;
				i+=2;
			}
			else if(count==4){
				four=1;
				i+=3;
			}
		}

		if(two && three){
			cout << "full house" << endl;
		}else if(two==2){
			cout << "two pair" <<endl;
		}else if(two==1){
			cout << "one pair" <<endl;
		}else if(three){
			cout << "three card" <<endl;
		}else if(four){
			cout << "four card" <<endl;
		}else{
			bool straight_flag = 1;
			bool ace_flag = 1;
			bool has_13 = 0;
			if(card[4]==13){
				has_13=1;
			}

			for(int i=3;i>=0;i--){
				if(ace_flag && card[i+1]-1==card[i]){
					//cout<<1;
				}else if(ace_flag && has_13 && card[i]==i+1){
					//cout<<0;
					ace_flag=0;
				}else{
					straight_flag=0;
					break;
				}
			}

			if(straight_flag){
				cout << "straight" << endl;
			}else{
				cout << "null" << endl;
			}
		}
	}
	return 0;
}

#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	string s;
	for (; cin >> s;)
	{
		vector<int> a(14);

		stringstream ss;
		ss << s;

		for (int i = 0; i < 5; i++)
		{
			int x;
			ss >> x;

			a.at(x - 1)++;
			if (x == 1)
			{
				a.at(13)++;
			}

			ss.ignore();
		}

		int maxn = 0;
		int cnt = 0;
		int len = 0;
		bool str = false;
		for (int i = 0; i < 14; i++)
		{
			if (a.at(i) > 0)
			{
				maxn = max(maxn, a.at(i));
				if (i < 13)
				{
					cnt++;
				}
				len++;
				if (len >= 5)
				{
					str = true;
				}
			}
			else
			{
				len = 0;
			}

		}

		if (maxn == 4)
		{
			cout << "four card" << endl;
		}
		else if (maxn == 3)
		{
			if (cnt == 2)
			{
				cout << "full house" << endl;
			}
			else
			{
				cout << "three card" << endl;
			}
		}
		else if (maxn == 2)
		{
			if (cnt == 3)
			{
				cout << "two pair" << endl;
			}
			else
			{
				cout << "one pair" << endl;
			}
		}
		else
		{
			if (str)
			{
				cout << "straight" << endl;
			}
			else
			{
				cout << "null" << endl;
			}
		}
	}
}


#include <iostream>

using namespace std;

int main() {
    class Dice {
        public:
            int men[6];
            void setMen(int i, int value) {men[i] = value;}
            void getMen() {cout << men[0] << endl;}
            void SwitchMen (char Alpha) {
                switch (Alpha) {
                    case 'S':
                        ChangeMen(men[4], men[0], men[2], men[3], men[5], men[1]);
                        break;
                    case 'N':
                        ChangeMen(men[1], men[5], men[2], men[3], men[0], men[4]);
                        break;
                    case 'E':
                        ChangeMen(men[3], men[1], men[0], men[5], men[4], men[2]);
                        break;
                    case 'W':
                        ChangeMen(men[2], men[1], men[5], men[0], men[4], men[3]);
                        break;
                }
            }
            void ChangeMen (int tmp1, int tmp2, int tmp3, int tmp4, int tmp5, int tmp6) {
                men[0] = tmp1;
                men[1] = tmp2;
                men[2] = tmp3;
                men[3] = tmp4;
                men[4] = tmp5;
                men[5] = tmp6;
            }
    };
    Dice dice;
    for(int i = 0; i < 6; i++) {
        int tmp;
        cin >> tmp;
        dice.setMen(i, tmp);
    }
    char Alpha;
    while(cin >> Alpha) {
        dice.SwitchMen(Alpha);
    }

    dice.getMen();

    // for(int i = 0; i < 6; i++) {
    //     cout << dice.men[i] << endl;
    // }

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n,a,b,c;
	while(1){
		cin>>a>>b>>c;
		n=a+b+c;
		if(n==0) break;
		int m;
		cin>>m;
		vi d(n+1,2),x(m),y(m),z(m),f(m);
		rep(i,0,m){
			cin>>x[i]>>y[i]>>z[i]>>f[i];
			if(f[i]==1){
				d[x[i]]=1;
				d[y[i]]=1;
				d[z[i]]=1;
			}
		}
		rep(i,0,m){
			if(f[i]==0){
				if(d[x[i]]==1 && d[y[i]]==1) d[z[i]]=0;
				else if(d[z[i]]==1 && d[y[i]]==1) d[x[i]]=0;
				else if(d[x[i]]==1 && d[z[i]]==1) d[y[i]]=0;
			}
		}
		rep(i,1,n+1){
			o(d[i]);
		}
	}
}


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

int32_t main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(((double)d/(double)s) <= t)
      cout << "Yes";
    else
      cout << "No";
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int mod=1e9+7;
const int N=1e6+10;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int S,T,V;
    read(S),read(T),read(V);
    if(T*V>=S) puts("Yes");
    else puts("No");
    return 0;
}


#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
bool solve(int n, vector<int> a) {
	int parity = 0, odds = 0, minelem = a[0];
	for (int i = 0; i < n; ++i) {
		parity = (parity + a[i] - 1) % 2;
		if (a[i] & 1) ++odds;
		minelem = min(minelem, a[i]);
	}
	if (parity == 1) return true;
	if (minelem == 1 || odds >= 2) return false;
	int g = -1;
	for (int i = 0; i < n; ++i) {
		if (a[i] & 1) --a[i];
		if (i == 0) g = a[i];
		else g = gcd(g, a[i]);
	}
	for (int i = 0; i < n; ++i) {
		a[i] /= g;
	}
	bool res = solve(n, a);
	return !res;
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	bool res = solve(n, a);
	cout << (res ? "First" : "Second") << endl;
	return 0;
}

#include<bits/stdc++.h>

/*zzzzdfadfadfad*/
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long LL;
const int N=100500;
int read(int &n)
{
    char ch=' ';int q=0,w=1;
    for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
    if(ch=='-')w=-1,ch=getchar();
    for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,ans;
int a[N];
int g[N];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main()
{
    int w;
/*zzzzdfadfadfad*/
    LL q;
    read(n);
    fo(i,1,n)q+=(LL)read(a[i]);
    if(n==1&&a[1]==1)return printf("Second\n"),0;
    if(n==1)return printf("First\n"),0;
    if(!(n&1))
    {
        if(q&1)printf("First\n");
        else printf("Second\n");
        return 0;
    }
    if(!(q&1))return printf("First\n"),0;
    for(bool I=0;1;I=!I)
    {
        g[n]=a[n];
        LL t=a[n]-1;
/*zzzzdfadfadfad*/
        fod(i,n-1,1)g[i]=gcd(g[i+1],a[i]),t+=(LL)a[i];
        bool OK=0;
        q=a[1];
        if(a[1]-1&&(1&(t/(ans=gcd(g[2],a[1]-1)))))OK=1,--a[1];
        else fo(i,2,n)if(a[i]-1)
        {
            w=gcd(q,a[i]-1);
            if(i<n)w=gcd(w,g[i+1]);
            if((1&(t/(ans=w))))
            {
                OK=1,--a[i];
                break;
            }
/*zzzzdfadfadfad*/
            q=gcd(q,a[i]);
        }else break;
        if(!OK)
/*zzzzdfadfadfad*/
        {
            if(I)printf("First\n");
            else printf("Second\n");
            return 0;
        }
        fo(i,1,n)a[i]/=ans;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    vector<long long >v;
    vector<long long >t;
    vector<long long >f;
    set<long long>s;
    set<long long>::iterator it;
    map<long long,long long>m;
    for(int i=0;i<n;i++)
    {
        long long x;
        cin>>x;
        m[x]+=1;
       s.insert(x);
    }
    long long mx=0;
    for(it=s.begin();it!=s.end();it++)
    {
        if(m[*it]>=2)
        {
            t.push_back(*it);
        }
        if(m[*it]>=4)
        {
            f.push_back(*it);
        }
    }
    if(f.size()!=0)
    {
       mx=max(mx,f[f.size()-1]*f[f.size()-1]);
    }
     if(t.size()>=2)
    {
         mx=max(mx,t[t.size()-1]*t[t.size()-2]);
    }

cout<<mx<<endl;

}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	FOR(i,n) cin >>a[i];
	sort(a,a+n);
	int j=n-1;
	while(j>=1 && a[j]!=a[j-1]) j--;
	if(j==0) {
		cout <<0;
		return 0;
	}
	else {
		int k=j-2;
		while(k>=1 && a[k]!=a[k-1]) k--;
		if(k==0) {
			cout << 0;
			return 0;
		}
		else cout << a[j]*a[k];
	}

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;
#define PI acos(-1)

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

  cout<<2*N*PI<<endl;
  return 0;
}

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

int main() {
  int A,B; cin >> A >>B;
  int ans = 0;
  if (A==B) ans = A+B;
  else ans = max(A,B) * 2 -1;
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<int> x = {1,-1,0,0};
vector<int> y = {0,0,-1,1};
int main(){
    set<ll> data;
    ll n;
    cin >> n;
    rep(i,0,n){
        ll a;
        cin >> a;
        if(data.count(a)){
            data.erase(a);
        }else{
            data.insert(a);
        }
    }
    cout<<data.size()<<endl;

  return 0;
}

#include <iostream>

using namespace std;

int main(){
	int n, m;
	cin >> n;
	cin >> m;
	int a[1000] = {};
	int b[1000] = {};
	int point[1000] = {};
	int selected;

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

	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			if(a[j] <= b[i]){
				point[j]++;
				break;
			}
		}
	}

	selected = 0;
	for(int i = 1; i < n; i++){

		if(point[selected] < point[i]){
			selected = i;
		}
	}

	cout << selected + 1 << endl;
	return 0;
}


/* 十 聖イシドールスよ、迷えるプログラマを導き給え！ 十 */
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <deque>

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

//const long long INF = 1LL << 60;
const int INF = 1e9;
using ll = long long;

int main()
{
	int N, Q;
	std::cin >> N >> Q;
	std::vector<int> ACGT(N, 0);	// AGCT[i]文字目までに何個現れたか
	std::string S;
	std::cin >> S;

	// 前処理...ACの数を数えておく
	char pre = S[0];
	for( int i = 1; i < N; i++ )
	{
		char now = S[i];
		//printf( "%c:%c", pre, now );
		ACGT[i] = ACGT[i-1];
		if( pre == 'A' )
		{
			if( now == 'C')
			{
				//printf("now!");
				ACGT[i] = ACGT[i-1] + 1;
			}
		}
		//printf("\n");
		pre = now;
	}

//	printf("===\n");
//	rep( i, N )
//	{
//		printf( "%d\n", ACGT[i]);
//	}
//	printf("===\n");

	// 問題をとく
	for( int i = 0; i < Q; i++ )
	{
		int l, r;
		std::cin >> l >> r;
		l--; r--;

		int ans = ACGT[r] - ACGT[l];

		if( ( S[l] == 'A' ) && ( S[r] == 'C' ) )
		{
			//ans++;
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

struct StQuery
{
  StQuery() : m_nLeft(0), m_nRigt(0) { }

  int m_nLeft;
  int m_nRigt;
};

void input(string& rsStr, vector<StQuery>& rvoQuery)
{
  int nStrSiz, nQuerySiz;
  cin >> nStrSiz >> nQuerySiz;
  rvoQuery.resize(nQuerySiz);

  cin >> rsStr;

  for (StQuery& roQuery : rvoQuery)
    cin >> roQuery.m_nLeft >> roQuery.m_nRigt;
}

void calcSubStrACCnt(string sStr, const vector<StQuery>& cnrvoQuery)
{
  vector<int> vnCumlSum(sStr.size() + 1);      // 累積和

  //vnCumlSum_ix 0 1 2 3 4 5 6 7 8
  //sStr_pos      1 2 3 4 5 6 7 8
  //sStr          A C A C T A C G
  //sStr_ix       0 1 2 3 4 5 6 7
  for (int nBgn = 0; nBgn < vnCumlSum.size() - 1; nBgn++)
  {
    vnCumlSum[ nBgn + 2 ] = vnCumlSum[ nBgn + 1 ];
    if (sStr[nBgn] == 'A' && sStr[nBgn + 1] == 'C')
      vnCumlSum[ nBgn + 2 ]++;
  }

 for (int i = 0; i < cnrvoQuery.size(); i++)
  {
    cout << vnCumlSum[ cnrvoQuery[i].m_nRigt ] - vnCumlSum[ cnrvoQuery[i].m_nLeft ];
    cout << endl;
  }
}

int main()
{
  string sStr;
  vector<StQuery> voQuery;

  input(sStr, voQuery);
  calcSubStrACCnt(sStr, voQuery);

  return 0;
}


#include <stdio.h>

int main() {
  char s1[101], s2[101];
  scanf("%s %s", s1, s2);
  printf("%s%s\n", s2, s1);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=1;

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


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

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

int main(){
    int h,w;cin >> h >> w;
    queue<int> q;
    rep(i,h)rep(j,w){
        char ch;cin >> ch;
        if(ch == '#'){
            dist[i][j]=0;
            q.push(w*i+j);
        }else dist[i][j] = -1;
    }

    while(q.size()){
        int ind = q.front();
        q.pop();
        int y = ind/w;
        int x = ind%w;
        for(int i = 0;i < 4;i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
            if(dist[ny][nx]!=-1) continue;
            dist[ny][nx] = dist[y][x] + 1;
            q.push(w*ny+nx);
        }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            ans = max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
long long M=1000000007;
vector<int> num;
int isprime[105];
int n,m,d;
string a,b;
long long dp[10005][2][2][105];
long long solve(int idx,int flag,int flag2,int rem)
{
    //cout<<rem<<endl;
    if(idx==b.size())
        {
            if(rem==0)
                return 1;
            else
                return 0;
        }
    if(dp[idx][flag][flag2][rem]!=-1)
        return dp[idx][flag][flag2][rem];

    int lim=flag?9:(b[idx]-'0');
    int lim1=flag2?0:(a[idx]-'0');
    long long ans=0;
    for(int i=lim1;i<=lim;i++)
    {
        ans=(ans+solve(idx+1,flag||(i<lim),flag2||(i>lim1),(rem+i)%m)%M)%M;

    }
    return dp[idx][flag][flag2][rem]=ans%M;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
{
    memset(dp,-1,sizeof(dp));
    a="1";
    cin>>b;
    cin>>m;
    n=b.size();
    for(int i=0;i<n-1;i++)
        a="0"+a;
    cout<<solve(0,0,0,0)<<endl;

}

return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int fac[2000005], ifac[2000005];

void gen_fac()
{
	fac[0] = 1;
	rep1(i, 2000000) fac[i] = 1LL * fac[i - 1] * i % MOD;
	ifac[1] = 1;
	for(int i = 2; i <= 2000000; i ++) ifac[i] = MOD - 1LL * ifac[MOD % i] * (MOD / i) % MOD;
	ifac[0] = 1;
	rep1(i, 2000000) ifac[i] = 1LL * ifac[i - 1] * ifac[i] % MOD;
}

int comb(int n, int m)
{
	if(n < m) return 0;
	return 1LL * fac[n] * ifac[n - m] % MOD * ifac[m] % MOD;
}

int solve(int n, int m, int k)
{
	int tot = comb((3 * m - k) / 2 + n - 1, n - 1);
	tot = (tot - 1LL * k * comb((m - k) / 2 + n - 1, n - 1) % MOD + MOD) % MOD;
	tot = (tot - 1LL * (n - k) * comb((m - k - 2) / 2 + n - 1, n - 1) % MOD + MOD) % MOD;
	return tot;
}

int main()
{
	gen_fac();
	int n, m;
	scanf("%d%d", &n, &m);
	int ans = 0;
	for(int i = 0; i <= m; i ++)
	if(!(m - i & 1)) ans = (ans + 1LL * comb(n, i) * solve(n, m, i)) % MOD;
	printf("%d\n", ans);
	return 0;
}

//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}

#define N 6000004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}

int main(){fastio
    calc();
    ll n,m;cin>>n>>m;
    ll a1,a2=0,a3=0;
    a1=comb(3*m+n-1,n-1);
    rep(ma,2*m+1,3*m){
        ll res=3*m-ma;
        Add(a2,comb(res+n-2,n-2));
    }
    a2=mod(a2*n);
    rep(i,m+1,3*m){
        if((3*m-i)%2==1)continue;
        if(n<i)continue;
        ll res=(3*m-i)/2;
        Add(a3,comb(n,i)*comb(res+n-1,n-1));
    }
    cout<<mod(a1-a2-a3)<<endl;
    return 0;
}


#include<cstdio>

int main()
{
while(true) {

int a, b, c, n;
int test[3000], r[1000];
int ans[1000];
scanf("%d%d%d", &a, &b, &c);
if(a == 0)
break;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2, r + i);
test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
}

for(int i = 0; i < a + b + c; ++i)
ans[i] = 2;
for(int i = 0; i < n; ++i) {
if(r[i] != 1)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j)
ans[test[j]] = 1;
}
for(int i = 0; i < n; ++i) {
if(r[i] != 0)
continue;
int correct = 0;
for(int j = i * 3; j < i * 3 + 3; ++j)
correct += (ans[test[j]] == 1);
if(correct != 2)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j) {
if(ans[test[j]] != 1)
ans[test[j]] = 0;
}
}
for(int i = 0; i < a + b + c; ++i)
printf("%d\n", ans[i]);
}
return 0;
}

#include<iostream>
using namespace std;

struct Test{
  int A[3];
  bool R;
};

Test tests[1000];
int info[301], M[3], N;

int main()
{
  while(true)
  {
    for(int i = 0; i <= 300; i++)
      info[i] = 2;

    cin >> M[0] >> M[1] >> M[2];
    if(!(M[0] || M[1] || M[2]))
      break;
    cin >> N;
    for(int i = 1; i <= N; i++)
     cin >> tests[i].A[0] >> tests[i].A[1] >> tests[i].A[2] >> tests[i].R;

    bool b = true;
    while(b)
    {
      b = false;
      for(int i = 1; i <= N; i++)
      {
        if(tests[i].R)
        {
          for(int j = 0; j < 3; j++)
          {
            if(info[tests[i].A[j]] != 1)
            {
              info[tests[i].A[j]] = 1;
              b = true;
            }
          }
        }
        else
        {
          int tmp = 0;
          bool f = false;
          for(int j = 0; j < 3; j++)
          {
            tmp += info[tests[i].A[j]] == 1;
          }
          if(tmp == 2)
          {
            for(int j = 0; j < 3; j++)
            {
              if(info[tests[i].A[j]] == 2)
              {
                info[tests[i].A[j]] = 0;
                b = true;
              }
            }
          }
        }
      }
    }
    for(int i = 1; i <= M[0] + M[1] + M[2]; i++)
    {
       cout << info[i] << endl;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    double n;
    cin >> n;
    vector<double>a(n);
    double sum =0;
    for(int i=0;i<n;i++){
        cin >>a.at(i);
        sum+=a.at(i);
    }
    sum/=n;
    vector<pair<double,int>>d(n);
    for(int i=0;i<n;i++){
        if(sum==a.at(i)){
            cout <<i<<endl;
            return 0;
        }
        d.at(i)=make_pair(abs(sum-a.at(i)),i);
    }
    sort(d.begin(),d.end());
    cout << d.at(0).second<<endl;
}

#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
int main(void){
    int n;cin>>n;

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

    for (int i =0;i<n;i++){
        a[i]*=n;
    }
    int mn = 1000000;
    int ans =-1;
    for (int i =0;i<n;i++){
        if (mn>abs(sm-a[i])){
            ans = i;
            mn=abs(sm-a[i]);
        }
    }
    cout<<ans;

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll INF =  1LL << 60;
const int inf = 1 << 30;
int n, m, x, y,q;ll z, w=0, sum = 0, ans = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int dp[10010][2][110];
int main(void) {
	string s; int d; cin >> s >> d;
	Fill(dp, 0);
	dp[0][1][0] = 1;
	rep(i, s.size()) {
		rep(j, d) {
			rep(k, 10) {
				dp[i + 1][0][(j + k) % d] += dp[i][0][j];
				dp[i + 1][0][(j + k) % d] %= MOD;
			}
			int Si = s[i] - '0';
			rep(k, Si) {
				dp[i + 1][0][(j + k) % d] += dp[i][1][j];
				dp[i + 1][0][(j + k) % d] %= MOD;
			}
			dp[i + 1][1][(j + Si) % d] = dp[i][1][j];
		}
	}cout << (dp[s.size()][0][0] + dp[s.size()][1][0] - 1 + MOD) %MOD << endl;
}

#include<bits/stdc++.h>

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

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

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

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

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

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

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

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


#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
int d[30],len,dp[30][30][30];
int DP(int n){
	int ret=0;
	memset(dp,0,sizeof(dp));
	dp[0][0][0]=1;
	for(int i=0;i<(n>>1);i++)
		for(int j=0;j<10;j++)
			for(int k=0;k<10;k++)
				if(dp[i][j][k])
					for(int x=0;x<10;x++){
						int l1=x+d[i+1]+k,y=l1%10,l2=10*j+x-y-d[n-i];
						l1/=10;
 						if(l2<0||l2>9||(!i&&(!x||!y)))
							continue;
						dp[i+1][l2][l1]+=dp[i][j][k];
					}
	if(n&1){
		int mid=(n+1)>>1;
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				if(dp[n>>1][i][j])
					for(int x=0;x<10;x++){
						int y=x+d[mid]+j;
						if(x==y%10&&y/10==i)
							ret+=dp[n>>1][i][j];
					}
	}
	else
		for(int i=0;i<10;i++)
			ret+=dp[n>>1][i][i];
	return ret;
}
int getans(){
	int ret=0;
	for(int i=max(2,len);i<=20;i++)
		ret+=DP(i);
	return ret;
}
void Input(){
	char c;
	do c=getchar();
	while(!isdigit(c));
	do{
		d[++len]=c^48;
		c=getchar();
	}while(isdigit(c));
	reverse(d+1,d+len+1);
	return;
}
int main(){
	Input();
	printf("%d",getans());
	return 0;
}

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

typedef long long ll;
ll D,ans;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>D;
	if(D%9){
		cout<<0<<'\n';
		return 0;
	}
	D/=9;ll pw=1;
	for(int i=1;i<=17;++i){
		ll tmp=1,d=D,lp=pw,rp=1;pw*=10;
		ll b=(pw-1)/9;
		for(int j=0;j+j<=i;++j){
			tmp*=10-abs(d%(rp*10)/rp)-!j;
			d-=b*(d%(rp*10)/rp);
			b-=lp+rp;lp/=10;rp*=10;
		}
		if(!d)ans+=tmp;
	}
	cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	int sum = 0;
	for(int i=0; i<N; i++) sum += A[i];

	int diff = abs(sum-N*A[0]);
	int idx = 0;
	for(int i=1; i<N; i++) {
		int d = abs(sum-N*A[i]);
		debug(i, d);
		if(d < diff){
			diff = d;
			idx = i;
		}
	}

	cout << idx << endl;

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


#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
    int c;
    while((c=a%b)!=0){
        a=b;
        b=c;
    }
    return b;
}
vector<int> divisor(int n){
    vector<int> div;
    for(int i=1;i<=n;i++){
        if(n%i==0){
            div.push_back(n/i);
        }
    }
    sort(div.begin(),div.end());
    return div;
}
int main(void){
    int n,A[3],gcdA;
    vector<int> div;
    cin>>n;
    if(n==2){
        cin>>A[0]>>A[1];
        gcdA=gcd(A[0],A[1]);
        vector<int> div=divisor(gcdA);
        for(int i=0;i<div.size();i++){
            cout<<div[i]<<endl;
        }
    }else{
        cin>>A[0]>>A[1]>>A[2];
        gcdA=gcd(A[0],gcd(A[1],A[2]));
        vector<int> div=divisor(gcdA);
        for(int i=0;i<div.size();i++){
            cout<<div[i]<<endl;
        }
    }
    return 0;
}

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

int main(){
    int n,memo;
    priority_queue<int,vector<int>,greater<int> > que;
    cin >> n;
    int a[n];

    rep(i,0,n){
        cin >> a[i];
    }

    sort(a,a+n);

    rep(i,1,sqrt(a[n-1])+1){
        rep(j,0,n){
            if(a[j] % i)break;
            else if(j == n-1)que.push(i);
        }

        if(a[n-1]/i == i)continue;

        rep(j,0,n){
            if(a[j] % (a[n-1]/i))break;
            else if(j == n-1)que.push(a[n-1]/i);
        }
    }

    while(!que.empty()){
        if(que.top() == memo){
            que.pop();
            continue;
        }
        memo = que.top(); que.pop();

        cout << memo << endl;
    }
}


#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

lint N;
lint arr_A[100000], arr_B[100000];
plint arr[100000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	lint sum = 0;
	REP(i, N) {
		cin >> arr_A[i] >> arr_B[i];
		arr[i] = plint(arr_A[i] + arr_B[i], i);
		sum -= arr_B[i];
	}
	sort(arr, arr + N);
	reverse(arr, arr + N);
	REP(i, (N + 1) / 2) {
		sum += arr[2 * i].first;
	}
	cout << sum;
}

#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 <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
int main(){
	string str;
  	cin >> str;
  	vector<int> num;
  	for(int i=0;i<str.size();i++){
      num.push_back(str.at(i)-'0');
    }

  	reverse(num.begin(),num.end());
  	num.push_back(0);
  	int n=num.size();

  	// 下からi桁目までに使用する紙幣の最小
  	// j=0のときは繰り下がりなし、j=1のときは繰り下がりあり
  	vector<vector<int>> dp(n+1,vector<int>(2));
  	for(int i=0;i<n+1;i++){
      for(int j=0;j<2;j++){
        dp.at(i).at(j) = inf;
      }
    }
  	dp.at(0).at(0) = 0;

  	//状態(i,j)が確定しているときに状態(ni,nj)を計算する
  	for(int i=0;i<n;i++){
      for(int j=0;j<2;j++){
        int x = num.at(i);
        x += j;
        for(int a=0;a<10;a++){
          int ni = i+1;
          int nj = 0;
          int b = a-x;
          if(b<0){
            b += 10;
            nj = 1;
          }
          dp.at(ni).at(nj) = min( dp.at(ni).at(nj), dp.at(i).at(j)+a+b );
        }
      }
    }

  	//n桁全て確定したときに繰り下がりはあってはいけない
  	cout << dp.at(n).at(0) << endl;

  	return(0);
}

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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    S = "00" + S;
    int N = S.length();
    int ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(S[i] > '9') {
            S[i - 1]++;
            S[i] -= 10;
        }
        if(S[i] <= '4' || (S[i] == '5' && S[i - 1] < '5')) {
            ans += S[i] - '0';
        } else {
            ans += 10 - (S[i] - '0');
            S[i - 1]++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
  int n,y;
  cin >> n >> y;
  int tth=n,fth=0,th=0;
  bool ok=false;
  for(int i=0;i<=n;i++){
    tth=i;
    for(int j=0;j<=n-i;j++){
      fth=j;
      th=n-i-j;
      if(tth*10000+fth*5000+th*1000==y){
        ok=true;
        break;
      }
    }
    if(ok)
      break;
  }
  if(ok)
    cout << tth << " " << fth << " " << th << endl;
  else
    cout << "-1 -1 -1\n";
  return 0;
}

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

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


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;

ll n,x[100010]={0},y[100010]={0};
vector<pll>vx,vy;
vector<pll>edge[100010];
priority_queue<pll,vector<pll>,greater<pll>>q;
//priority_queue<pll>q;
bool used[100010];
ll res=0;

signed main(){

    cin>>n;
    for(int i=0;i<n;++i){
        cin>>x[i]>>y[i];
        vx.push_back(pll(x[i],i));
        vy.push_back(pll(y[i],i));
    }

    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    for(int i=0;i<n-1;++i){
        ll j=vx[i].second,k=vx[i+1].second;
        ll wj=vx[i].first,wk=vx[i+1].first;
        edge[j].push_back(pll(wk-wj,k));
        edge[k].push_back(pll(wk-wj,j));
        j=vy[i].second,k=vy[i+1].second;
        wj=vy[i].first,wk=vy[i+1].first;
        edge[j].push_back(pll(wk-wj,k));
        edge[k].push_back(pll(wk-wj,j));
    }

    for(int i=0;i<n;++i){
        used[i]=false;
    }
    int c=1;
    for(int i=0;i<edge[0].size();++i)q.push(edge[0][i]);
    used[0]=true;
    while(c<n){
        pll t=q.top();
        q.pop();
        if(!used[t.second]){
            res+=t.first;
            for(int i=0;i<edge[t.second].size();++i){
                q.push(edge[t.second][i]);
            }
            used[t.second]=true;
            c++;
            //cout<<t.first<<" "<<t.second<<endl;
        }
    }

    cout<<res<<endl;

    return 0;
}

#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

const int N = 100005;

bool cmp1(pair<int,pair<int,int>>a, pair<int,pair<int,int>>b){
    return a.S.F<b.S.F;
}

bool cmp2(pair<int,pair<int,int>>a, pair<int,pair<int,int>>b){
    return a.S.S<b.S.S;
}

pair<int,pair<int,int>>c[N];
int par[N],siz[N];

int find(int x){
    while(par[x]!=x){
        x=par[x];
    }
    return x;
}

void un(int a,int b){
    a=find(a);
    b=find(b);
    if(siz[a]<siz[b]){
        par[a]=par[b];
        siz[b]+=siz[a];
    }
    else{
        par[b]=par[a];
        siz[a]+=siz[b];
    }
}

int main(){
    IOS

    int n;
    cin>>n;
    FOR(i,1,n+1){
        par[i]=i;
        siz[i]=1;
        c[i].F=i;
        cin>>c[i].S.F>>c[i].S.S;
    }

    vector<pair<int,pair<int,int>>>v;

    sort(c+1,c+n+1,cmp1);

    FOR(i,1,n){
        v.pb(mp(c[i+1].S.F-c[i].S.F,mp(c[i].F,c[i+1].F)));
    }
    sort(c+1,c+n+1,cmp2);
    FOR(i,1,n){
        v.pb(mp(c[i+1].S.S-c[i].S.S,mp(c[i].F,c[i+1].F)));
    }
    sort(all(v));

    int cnt=0;
    int i=0;
    ll ans=0;
    while(cnt<n-1){
        int x=find(v[i].S.F),y=find(v[i].S.S);
        if(x==y){
            i++;
            continue;
        }
        un(x,y);
        ans+=v[i].F;
        i++;
        cnt++;
    }
    cout<<ans;

    cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n;

    //cin>>t;
    t = 1;
    while (t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        set<ll> s;
        s.insert(a);s.insert(b);s.insert(c);

        if(s.sz==2)cout<<"Yes";
        else cout<<"No";
    }

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
//setprecision(15)

int main() {
	int a, b, c; cin >> a >> b >> c;
	if ( a == b || b == c || c == a ) {
		if (a == b && b == c) {
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
	} else {
		cout << "No" << endl;
	}
}


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

const int MAX_N = 410;
const int MAX_X = 3e5+10;
const int MOD = 1e9+7;

int dp[MAX_N][MAX_X];
// i番目までで先頭の値がjの時の総和をdp[i][j]をおく

void modadd(int &a, int b ){
  a = (a+b)%MOD;
}

signed main(void){

  int N,X; cin >> N >> X;
  vector<int> s(N);
  map<int,int> mp;
  for(int i = 0; i < N; i++){ cin >> s[i]; }

  sort(s.begin(),s.end());

  for(int i = 0; i < MAX_X; i++){ dp[0][i] = i;}

  for(int i = 0; i < N; i++){
    // 次にi+1コメを見る
    for(int x = 0; x < MAX_X; x++){ //先頭の文字全体を探索する
      //未更新から飛ばさない方がいい？
      modadd(dp[i+1][x],dp[i][x%s[i]]);
      modadd(dp[i+1][x],dp[i][x]*i);
    }
  }

  cout << dp[N][X] << endl;

  return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

int x[100001], y[100001];
ll sumx[100001], sumy[100001]; // sum[i] ; 1～iまでの和

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

	int n, m; cin >> n >> m;
	sumx[0] = sumy[0] = 0LL;

	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		sumx[i] = sumx[i - 1] + x[i];
	}

	for (int i = 1; i <= m; i++) {
		cin >> y[i];
		sumy[i] = sumy[i - 1] + y[i];
	}

	ll L = 0LL;
	for (int i = 1; i <= m; i++) {
		L += sumy[m] - sumy[i] - (m - i)*ll(y[i]);
		L %= MOD;
	}

	ll K = 0LL;
	for (int i = 1; i <= n; i++) {
		K += sumx[n] - sumx[i] - (n - i)*ll(x[i]);
		K %= MOD;
	}

	cout << K * L % MOD << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll h,w,a,b;cin >> h >> w >> a >> b;
    string s;
    rep(i,a)s+='1';
    rep(i,w-a)s+='0';
    rep(i,b){
        cout << s << endl;
    }
    rep(i,w)s[i]^='0'^'1';
    rep(i,h-b){
        cout << s <<endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, A, B;
bool ans[1005][1005];

int main(){
  cin >> H >> W >> A >> B;

  for (int i = 0; i < B; i++){
    for (int j = 0; j < W; j++){
      if (j < A) cout << 0;
      else cout << 1;
    }
    cout << endl;
  }

  for (int i = B; i < H; i++){
    for (int j = 0; j < W; j++){
      if (j < A) cout << 1;
      else cout << 0;
    }
    cout << endl;
  }

  return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=1e5+5;
int n,m,p,a[N],b[N],ans=1e9;

signed main(){
	read(n,m,p);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=m;i++) read(b[i]);
	ans=*min_element(a+1,a+1+n)+*min_element(b+1,b+1+n);
	while(p--){
		int x,y,z;
		read(x,y,z);
		ans=min(ans,a[x]+b[y]-z);
	}
	write(ans);
}

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

static const int N = 100;

int main() {

	int n, p[N + 1], m[N + 1][N + 1];

	scanf("%d", &n);

	for ( int i = 1; i <= n; i++ ) {
		cin >> p[i - 1] >> p[i];
	}

	for ( int i = 1; i <= n; i++ ) m[i][i] = 0;

		for ( int l = 2; l <= n; l++ ) {
			for ( int i = 1; i <= n - l + 1; i++ ) {

				int j = i + l - 1;
				m[i][j] = (1 << 21);

				for ( int k = i; k <= j - 1; k++ ) {
					m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
				}
			}
		}

		printf("%d\n", m[1][n]);

		return 0;
	}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll k;
	cin>>k;
	vector<ll> vl;
	string s = "~abcdefghijklmnopqrstuvwxyz";
	if(k<=26)
	{
		cout<<s[k]<<endl;
		return 0;
	}
	while(k>=26)
	{
		ll yu = k%26;
		k/=26;
		if(yu == 0)
		{
			yu = 26;
			k--;
		}
		vl.pb(yu);
	}
	if(k>0)
		vl.pb(k);
	reverse(all(vl));
	FOR(i,0,vl.size())
	{
		if(vl[i]>0)cout<<s[vl[i]];
		else cout<<"z";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

void insertionSort(vector<int> &a, int g, long &cnt)
{
	int j;
	int v;
	for (int i = g; i < a.size(); i++)
	{
		v = a[i];
		j = i - g;
		while (j >= 0 && a[j] > v)
		{
			a[j + g] = a[j];
			j = j - g;
			cnt++;
			if (cnt > (int)pow(a.size(), 1.5))
			{
				return;
			}
		}
		a[j + g] = v;
	}
}

int shellSort(vector<int> &a, vector<int> &g)
{
	long cnt = 0;
	for (int i = 0; i < g.size(); i++)
	{
		insertionSort(a, g[i], cnt);
		if (cnt > (int)pow(a.size(), 1.5))
		{
			break;
		}
	}
	return cnt;
}

int main()
{
	int n;
	long cnt = 0;
	cin >> n;
	vector<int> a(n, 0);
	vector<int> org(a);
	vector<int> g;
	for (int i = 0; i < n; i++)
	{
		cin >> org[i];
	}
	for (int m = 100; m >= 1; m--)
	{
		a = org;
		g.resize(m);
		g[m - 1] = 1;
		for (int i = 1; i < m; i++)
		{
			g[m - 1 - i] = 3 * g[m - i] + 1;
			if ((g[m - 1 - i] <= 0) || (n <= g[m - 1 - i]))
			{
				g[0] = -1;
				break;
			}
		}
		if (g[0] < 0)
		{
			continue;
		}
		else
		{
			cnt = shellSort(a, g);
			if (cnt <= pow(n, 1.5))
			{
				break;
			}
		}
	}
	cout << setprecision(10) << g.size() << endl;
	for (int i = 0; i < g.size(); i++)
	{
		cout << g[i];
		if (i == g.size() - 1)
		{
			cout << endl;
		}
		else
		{
			cout << " ";
		}
	}
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << endl;
	}
}


#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

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

int main(){
  int n,m,q;cin >> n >> m >> q;
  vector<P> sche(m);
  vector<pair<P,int>> query(q);
  rep(i,m){
    int l,r;cin >> l >> r;
    sche[i] = make_pair(l,r);
  }
  sort(sche.rbegin(),sche.rend());
  vector<int> ans(q);
  rep(i,q){
    int p,q;cin >> p >> q;
    P temp = make_pair(p,q);
    query[i] = make_pair(temp,i);
  }
  sort(query.rbegin(),query.rend());
  int inds = 0;
  int indq = 0;
  BIT<int> tree(505);
  for(int x = n;x >= 0;x--){
    while(inds < m && sche[inds].first >= x) {
      tree.add(sche[inds].second,1);
      inds++;
    }

    while(indq < q && query[indq].first.first >= x){
      ans[query[indq].second] += tree.sum(query[indq].first.second);
      indq++;
    }
  }

  rep(i,q) cout << ans[i] << endl;
}

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

int main(){
    int n,m,q; cin>>n>>m>>q;
   vector<vector<int>> a(n,vector<int> (n,0));
    for(int i=0;i<m;i++){
        int l,r; cin>>l>>r;
        l--; r--;
       a[l][r]++;
    }

    vector<vector<int>> s(n+1,vector<int> (n+1,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            s[i+1][j+1]=s[i][j+1]+s[i+1][j]-s[i][j]+a[i][j];
        }
    }

    for(int i=0;i<q;i++){
        int x,y; cin>>x>>y;
        x--;
        cout<<s[y][y]-s[x][y]-s[y][x]+s[x][x]<<endl;
    }
}


#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int e, m; (e = m = in());) {
		for (int z = cbrt(e) + 0.00001; z >= 0; z--) {
			int te = e - z * z * z;
			int y = (int)sqrt(te);
			int tm = z + y + te - y * y;
			if (y > m)
				break;
			m = min(m, tm);
		}
		out(m, '\n');
	}
}

#include <iostream>
using namespace std;

static const int INF = 1000001;

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

		int i;
		for (i = 0; i * i * i <= e; i++)
			;
		int t = i - 1;

		int m = INF;
		for (int j = t; j >= 0; j--) {
			int tz = j * j * j;
			for (int k = 0; tz + k * k <= e; k++) {
				int ty = k * k;
				int tx = e - tz - ty;
				if (tx + k + j < m)
					m = tx + k + j;
			}
		}

		cout << m << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main(){

 int n;
 long a, min = 1000000, max = -1000000, sum = 0;

 cin >> n;

 for (n; n > 0; n--) {
  cin >> a;
  if ( a > max) max = a;
  if ( a < min) min = a;
  sum += a;
 }

 cout << min << " " << max << " " << sum << "\n";

 return 0;
}

#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define ll long long
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug cout<<"Debugging.."<<endl
using namespace std;
int main()
{
	faster;

	ll int tc=1;
	while(tc--)
	{
		ll int n;
		cin>>n;
		 string s;
        while(n)
        {
            s+='a'+(n-1)%26;
            n=(n-1)/26;
        }
        reverse(s.begin(),s.end());
        cout<<s<<endl;

	}
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

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

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

    int ansI = -1, ansJ = -1, ansK = -1;
    rep(i, n+1) rep(j, n+1) {
        int k = n-i-j;
        if(k < 0) continue;
        if(10000*i+5000*j+1000*k == y) {
            ansI = i, ansJ = j, ansK = k;
        }
    }

    cout << ansI << " " << ansJ << " " << ansK << endl;

    return 0;
}


#include <iostream>
using namespace std;
long long d, t, s;
int main()
{
    cin >> d >> t >> s;
    if(t * s >= d)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

signed main(){
  int A,B;
  string S,ans="No";
  cin>>A>>B>>S;
  int SS=S.size();
  if((A+B+1)!=SS){
    cout<<ans<<endl;
    return 0;
  }
  rep(i,SS){
    if(i!=A&&S[i]=='-'){
      cout<<ans<<endl;
      return 0;
    }
  }
  if(S[A]=='-')ans="Yes";
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
int  main(){
double n,sum=0;
  cin >>n;
  vector<double>a(n),b(n);
  for(int i =0;i<n;i++){
    double z;
    cin >>z;
    sum+=z;
    a.at(i)=z;
    b.at(i)=z;
    }
  sum/=n;
  for(int i=0;i<n;i++){
    a.at(i)=abs(a.at(i)-sum);
    b.at(i)=a.at(i);
    }
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
     if(a.at(0)==b.at(i)){
       cout << i <<endl;
       break;
       }
    }
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    vector<double> b(n);
    int sum=0;
    rep(i,n){
        cin >> a[i];
     sum+=a[i];
    }
    double ave=(double)sum/n;
    int ans=0;
    rep(j,n){
     b[j]=abs(ave-a[j]);
    }
    sort(b.begin(),b.end());
    rep(i,n){
        if(abs(ave-a[i])==b[0]){
            ans=i;
            break;
        }
    }
  cout << ans << endl;
  return 0;
}


#include<cstdio>
using ull = unsigned long long;
const static int MOD = 1000000007;
const static int MAX_H = 100;
const static int MAX_W = 8;
ull dp[MAX_H+1][MAX_W], fibonacci[8] = {1, 1, 2, 3, 5, 8, 13, 21};

int main(){
    unsigned H, W, K;
    scanf("%u %u %u", &H, &W, &K);
    if(W == 1){
        printf("1\n");
        return 0;
    }
    K--;
    dp[0][0] = 1;
    for (size_t i = 1; i <= H; i++){
        dp[i][0] = (dp[i-1][0]*fibonacci[W-1] + dp[i-1][1]*fibonacci[W-2]) %MOD;
        for (size_t j = 1; j < W-1; j++){
            dp[i][j] = (dp[i-1][j-1]*fibonacci[j-1]*fibonacci[W - j - 1] + dp[i-1][j]*fibonacci[j]*fibonacci[W - j - 1] + dp[i-1][j+1]*fibonacci[j]*fibonacci[W - j - 2]) %MOD;
        }
        dp[i][W-1] = (dp[i-1][W-1]*fibonacci[W-1] + dp[i-1][W-2]*fibonacci[W-2]) %MOD;
    }
    printf("%llu\n", dp[H][K]);
	return 0;
}

//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    int h, w, k;
    cin >> h >> w >> k;

    vector<ll> dp(w + 2);
    dp[1] = 1;

    for(int i = 1; i <= h; i++){

        vector<ll> dp2(w + 2);
        for(int j = 1; j <= w; j++){

            for(int t = 0; t < (1 << (w - 1)); t++){
//                cerr << "test " << t << "\n";
                t <<= 1;
                bool tmp = true;
                for(int l = 1; l < w; l++){
                    if((t & (1 << l)) && (t & (1 << (l + 1)))) tmp = false;
                }
//                cerr << "test " << t << " " << tmp << "\n";
                if(tmp){
//                cerr << t << "\n";
                    if(!(t & (1 << j)) && !(t & (1 << (j - 1)))) dp2[j] += dp[j];
                    if(t & (1 << (j - 1))) dp2[j] += dp[j - 1];
                    if(t & (1 << j)) dp2[j] += dp[j + 1];
                    dp2[j] %= MOD;
                }
                t >>= 1;
            }
        }
        dp = dp2;
//        printv(dp, cerr);
    }

    cout << dp[k] << "\n";

    return 0;
}