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

int main(void){
    int N, x, ans=0;
    std::cin >> N >> x;
    std::vector<int> a(N);
    for (int i=0; i<N; ++i){
        std::cin >> a.at(i);
    }

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

    for (int i: a) {
        x -= i;
        if (x < 0){
            break;
        } else {
            ++ans;
        }
    }

    if (x > 0 && ans > 0) {
        --ans;
    }

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

    return 0;
}

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    long long N, x; cin >> N >> x;
    vector < long long > a(N);
    long long count = 0;
    rep(i, N) {
        cin >> a[i];
        count += a[i];
    }
    long long A = abs(x - count);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    rep(i, N) {
        if (A <= 0) {
            cout << N-i << endl;
            return 0;
        }
        A -= a[i];
    }
    cout << 0 << endl;
}


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

bool pal(int a)
{

    return true;
}

int main()
{
    int n,m,mn=0,mx;
    cin>>n>>m;
    mx=n+1;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a>=mn)
            mn=a;
        if(b<=mx)
            mx=b;
    }
    if(mn>mx)
        cout<<0;
    else
        cout<<mx-mn+1;
    return 0;
}

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

int N;
int L[100000], R[100000]; // [L,R)
pair<int, int> sec[100000];
vector<pair<int, int>> v;

signed main(){
    cin >> N;
    rep(i, N){
        cin >> L[i] >> R[i];
        L[i]--;
        sec[i] ={ L[i],-R[i] };
    }
    sort(sec, sec+N);

    rep(i, N){
        while(v.size() > 0 && v.back().second >= -sec[i].second){
            v.pop_back();
        }
        v.pb({ sec[i].first,-sec[i].second });
    }

    if(v.size() == 1){
        int ans = 0;
        rep(i, N-1){
            ans = max(ans, -sec[i].second - sec[i].first);
        }
        cout << ans + -sec[N-1].second - sec[N-1].first << endl;
        exit(0);
    }

    int ans = 0;
    for(int i=1; i<v.size(); i++){
        ans = max(ans, max(0, v[0].second-v[i-1].first) + max(0, v[i].second-v[v.size()-1].first));
    }
    set<pair<int,int>> l, r;
    rep(i, N){
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    rep(i, N){
        l.erase({ L[i],i });
        r.erase({ R[i],i });
        ans = max(ans, R[i]-L[i] + max(0, r.begin()->first-prev(l.end())->first));
        l.insert({ L[i],i });
        r.insert({ R[i],i });
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    double a, b, c, d;
    while(cin >> a >> b >> c >> d){
        double ans = sqrt( (c-a) * (c-a) + (d-b) * (d-b));
        printf("%.6lf",ans);
    }
}

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int MOD = 1000000007;

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	double dx = x2 - x1, dy = y2 - y1;
	printf("%f\n", sqrt(dx * dx + dy * dy));
}


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

int Roman_to_Arabia(char c){
	if (c == 'I')return 1;
	else if (c == 'V')return 5;
	else if (c == 'X')return 10;
	else if (c == 'L')return 50;
	else if (c == 'C')return 100;
	else if (c == 'D')return 500;
	else if (c == 'M')return 1000;
	else return 0;
}

int main(){
	string roman;
	int num;

	while (cin >> roman){
		num = 0;

		for (int i = 0; i < roman.size(); ++i){

			if (Roman_to_Arabia(roman[i]) < Roman_to_Arabia(roman[i + 1]))
				num -= Roman_to_Arabia(roman[i]);
			else
				num += Roman_to_Arabia(roman[i]);
		}
		cout << num << endl;
	}
	return 0;
}

#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;

int main(void){
	map <char, int> m;
	vi x;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	while (true){
		string roman;
		cin>>roman;
		if (cin.eof()) break;

		int tmp, tmp2= m[roman[0]];
		for (int i=0; i<(int)roman.size(); i++){
			tmp = m[roman[i]];
			if (i!=0 && tmp2<tmp)
				x[i-1] = -tmp2;
			x.push_back(tmp);
			tmp2 = tmp;
		}

		int s=0;
		for (int i=0; i<(int)x.size(); i++)
			s += x[i];
		cout<<s<<endl;
		x.clear();
	}
}


#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()

int get_int(){int x;scanf("%d",&x);return x;}

typedef long long ll;

const int mod = 998244353;
inline int mul(int x,int y){return 1ll*x*y%mod;}
int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y) {return x-y>=0?x-y:x-y+mod;}
int sq(int x){return 1ll*x*x%mod;}
int pows(int a,int b){return b == 0?1:(b&1?mul(a,sq(pows(a,b/2))):sq(pows(a,b/2)));}

const int maxn = 305;
int cnt[maxn*maxn];
int cnt2[maxn*maxn];

int sum;
int N;

void cal(int n,vector<int> &vi){
    cnt[0] = 1;
    cnt2[0] = 1;
    _for(i,0,N){
        int l = vi[i];
        for(int j = sum;j>=0;j--){
            cnt2[j] = add(cnt2[j],cnt2[j]);
            if(j-l >= 0) {
                cnt[j] = add(cnt[j],cnt[j-l]);
                cnt2[j] = add(cnt2[j],cnt2[j-l]);
            }
        }
    }
}

int main()
{
    vector<int> vi;
    N = get_int();
    _for(i,0,N){
        int num = get_int();
        sum += num;
        vi.push_back(num);
    }
    sort(ALL(vi));

    int ans = pows(3,N);
    //printf("all:%d\n",ans);

    cal(N,vi);
    //_rep(i,0,sum) printf("%d\n",cnt2[i]);

    _rep(i,(sum+1)/2,sum){
        ans = sub(ans,mul(3,cnt2[i]));
        //printf("%d\n",cnt2[i]);
    }

    if(!(sum&1)){
        ans = add(ans,mul(cnt[sum/2],3));
    }

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

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
    ll N; cin >> N;
    V<ll> a(N);
    for(int i = 0; i < N; ++i) cin >> a[i];
    ll sum = 0;
    for(int i = 0; i < N; ++i) sum += a[i];
    auto dp = make_v(N+1,sum + 1,0LL);
    dp[0][0] = 1;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= sum; ++j){
            if(j+a[i]<=sum) (dp[i+1][j+a[i]] += dp[i][j]) %=MOD2;
            (dp[i+1][j] += (2LL*dp[i][j]) % MOD2 ) %= MOD2;
        }
    }
    auto dp2 = make_v(N+1,sum+1,0LL);
    dp2[0][0] = 1;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= sum; ++j){
            if(j+a[i]<=sum) (dp2[i + 1][j + a[i]] += dp2[i][j]) %= MOD2;
            (dp2[i+1][j] += dp2[i][j]) %=MOD2;
        }
    }

    ll haf = sum/2 + (sum%2?1:0);
    ll ans = 1;
    for(int i = 0; i < N; ++i) (ans *= 3LL) %= MOD2;
    for(int j = haf; j <= sum; ++j){
        (ans += (MOD2 - (3LL*dp[N][j])%MOD2) ) %= MOD2;
    }
    if(!(sum%2)) (ans += (3LL*dp2[N][sum/2]) % MOD2 ) %= MOD2;
    // for(int i = 0; i < N; ++i) print(i,a[i],dp2[i]);
    // print(N,-N,dp2[N]);

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


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

int main() {
  int N, M;
  int x = 0;
  int y = 0;

  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    blue.at(i) = s;
  }
  sort(blue.begin(), blue.end());
  reverse(blue.begin(), blue.end());

  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    string t;
    cin >> t;
    red.at(i) = t;
  }
  sort(red.begin(), red.end());
  reverse(red.begin(), red.end());

  for (int j = 0; ; ) {
    if (N > 1 && M > 0) {
      if (blue.at(N - 1) != red.at(M - 1)) {
        if (blue.at(N - 1) > red.at(M - 1)) {
          red.pop_back();
          M--;
        }
        else {
          if (blue.at(N - 1) == blue.at(N - 2)) {
          blue.pop_back();
          N--;
          x++;
          }
          else {
            blue.pop_back();
            N--;
            x++;
            if (x > y) {
            y = x;
            }
            x = 0;
          }
        }
      }

      else if (blue.at(N - 1) == red.at(M - 1)) {
        if (blue.at(N - 1) == blue.at(N - 2)) {
          blue.pop_back();
          red.pop_back();
          N--;
          M--;
        }
        else {
          blue.pop_back();
          red.pop_back();
          N--;
          M--;
          if (x > y) {
            y = x;
          }
          x = 0;
        }
      }
    }

    else if (N > 1 && M == 0)
      if (blue.at(N - 1) == blue.at(N - 2)) {
        blue.pop_back();
        N--;
        x++;
      }
      else {
        blue.pop_back();
        N--;
        x++;
          if (x > y) {
            y = x;
          }
        x = 0;
      }

    else if (N == 1 && M == 0) {
      x++;
      if (x > y) {
        y = x;
      }
      x = 0;
      break;
    }

    else if (N == 1 && M > 0) {
      if (M > 1 && blue.at(N - 1) != red.at(M - 1)) {
        M--;
      }
      else if (M == 1 && blue.at(N - 1) != red.at(M - 1)) {
        x++;
        if (x > y) {
            y = x;
          }
        x = 0;
        break;
      }
      else if (blue.at(N - 1) == red.at(M - 1)) {
        if (x > y) {
          y = x;
          }
        x = 0;
        break;
      }
    }
  }
  cout << y << endl;
}

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

int main() {
    int n, m;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);
    cin >> m;
    vector<string> t(m);
    rep(i, m) cin >> t.at(i);

    int ans = 0;
    string say;
    rep(i, n) {
        int rwd = 0;
        say = s.at(i);
        rep(i, n) {
            if(say == s.at(i)) rwd++;
        }
        rep(i, m) {
            if(say == t.at(i)) rwd--;
        }
        if(rwd > ans) ans = rwd;
    }
    cout << ans << endl;
}


#include <iostream>
#include <fstream>

using namespace std;

int main() {

	int n, x, t;

	cin >> n >> x >> t;

	int time = 0;
	while (n > 0) {
		time = time + t;
		n = n - x;
	}
	cout << time;

	return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int N, X, T;
    cin >> N >> X >> T;

    cout << (int)(ceil(1.0*N / X) * T) << endl;

    return 0;
}


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

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, Q;
  cin >> N >> Q;

  fenwick_tree<ll> ft(N);

  for(ll i = 0; i < N; ++i) {
    ll ai;
    cin >> ai;
    ft.add(i, ai);
  }

  for(;Q-->0;) {
    ll op;
    cin >> op;
    if (op) {
      ll l, r;
      cin >> l >> r;
      cout << ft.sum(l, r) << endl;
    } else {
      ll p, x;
      cin >> p >> x;
      ft.add(p, x);
    }
  }
  return 0;
}

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;

template<class T>
class SegmentTree2 {
    public:

      SegmentTree2(const vector<T>& data, function<T(T,T)> f_, T zero_value = 0) : zv(zero_value), f(f_) {
          Initialize(data);
      }

      SegmentTree2(int n, function<T(T,T)> f_, T zero_value = 0) : zv(zero_value), f(f_) {
          vector<T> temp(n, zv);
          Initialize(temp);
      }

      T operator[](int i) {
          return tree[B+i];
      }

      T GetEvaluation(int L, int R) {   // "min/max" on interval [L,R); 0-based indexing, as usual
        if (R<=L) {  return zv;  }
        return GetEvaluationHelper(L, R, 0, B, 1);
      }

      void SetVal(int i, T val) {
			tree[B+i] = val;
			for(int j = (B + i) / 2; j >= 1; j /= 2) {
				tree[j] = f(tree[2*j], tree[2*j+1]);
			}
      }

      private:
        vector<T> tree;
        int B;  // power of two greater than size of input data
        T zv;
        function<T(T,T)> f;

        void Initialize(const vector<T>& data) {
    	  B = 1;
          while(B < data.size()) {B *= 2;  }
          tree = std::move(vector<T>(2*B, zv));
          copy(data.begin(), data.end(), next(tree.begin(), B));
          for(int i = B - 1; i >= 1; --i) {
  	  	     tree[i] = f(tree[2*i], tree[2*i+1]);
          }
        }

      T GetEvaluationHelper(int L, int R, int start, int length, int tree_index) {
          if (L==R) {  return zv; }
          if ((L==start) && (R==start+length)) {   return tree[tree_index];  }
          int midpoint = start + length/2;

          T left_ = zv, right_ = zv;
          if (L<=min(midpoint,R)) {
            left_ = GetEvaluationHelper(L, min(midpoint,R), start, length/2, 2*tree_index);
          }
          if (max(midpoint,L)<=R) {
            right_ = GetEvaluationHelper(max(midpoint,L), R, midpoint, length/2, 2*tree_index+1);
          }
          return f(left_, right_);
      }

};

int main()   {

      ios_base::sync_with_stdio(false);

      cout.precision(17);
      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(q);
        vector<ll> data;
        forr(i,0,n) {
            readint(dd); data.push_back(dd);
        }
        SegmentTree2<ll> seg(data, [](ll x, ll y){return x+y;}, 0);
        forr(i,0,q) {
            readint(a); readint(b); readint(c);
            if (a==0) {
                seg.SetVal(b, seg[b] + c);
            }
            if (a==1) {
                cout << seg.GetEvaluation(b,c) << endl;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
    string ans = "Yes";
    int h, w;
    cin >> h >> w;
    vector<string> S(h);
    for (int i = 0; i < h; ++i)
    {
        cin >> S[i];
    }
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (S[i][j] == '#')
            {
                bool can = false;
                for (int k = 0; k < 4; ++k)
                {
                    int ni = i + dx[k];
                    int nj = j + dy[k];
                    if (ni < 0 || ni > h - 1)
                    {
                        continue;
                    }
                    if (nj < 0 || nj > w - 1)
                    {
                        continue;
                    }
                    if (S[ni][nj] == '#')
                    {
                        can = true;
                    }
                }
                if (can == false)
                {
                    ans = "No";
                }
            }
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    rep(i,k){
        vector<int>sum(n);
        rep(j,n){
            int l=max(0,j-a[j]);
            int r=min(n,j+a[j]+1);
            sum[l]++;
            if(r!=n)sum[r]--;
        }
        rep(j,n-1)sum[j+1]+=sum[j];
        bool same=true;
        rep(j,n){
            if(a[j]!=sum[j])same=false;
            a[j]=sum[j];
        }
        if(same)break;
    }
    rep(i,n)cout<<a[i]<<" ";
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define all(v) v.begin(), v.end()
#define rip return;
#define fo(i,a,b) for(int i = a ; a < b ? i <= b : i >= b ; i += (a < b ? 1 : -1))

#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;

const int mod = 1e9 + 7;
// const int mod = 998244353;
const ll inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e6 + 55;

int dp[N], dp2[N];

int solve (string s) {
	s = "0" + s;
	int n = s.size();
	fo (i, 0, n + 1) {
		dp[i] = 0, dp2[i] = 0;
	}
	dp2[0] = 1;
	fo (i, 1, n) {
		int u = s[i - 1] - '0';
		dp[i] = min (dp[i - 1] + u, dp2[i - 1] + 10 - u);
		dp2[i] = min (dp2[i - 1] + 9 - u, dp[i - 1] + 1 + u);
	}
	return dp[n];
}

int to_int (string s) {
	int res = 0;
	for (char c : s) {
		res = res * 10 + c - '0';
	}
	return res;
}

int dig (int x) {
	int res = 0;
	while (x) res += x % 10, x /= 10;
	return res;
}

pair <int, int> brute (string s) {
	int u = to_int (s);
	int best = dig (u), sec = u;
	for (int v = u ; v <= 1e7 ; ++ v) {
		int cur = dig (v) + dig (v - u);
		if (cur < best) {
			sec = v;
			best = cur;
		}
		// best = min (best, dig (v) + dig (v - u));
	}
	return {best, sec};
}

int main () {
	// ios;
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt-- || 0) {
		string s;
		cin >> s;
		// cout << brute (s).F << " " << brute (s).S << "\n";
		// if (solve (s) != brute (s).F) {
			// cout << "ERROR " << solve (s) << " " << brute (s).F << "\n\t" << brute (s).S << "\nERROR " << s << "\n";
			// return 0;
		// }
		cout <<
		solve(s);
		// cout << "\n";
	}
}

#include<bits/stdc++.h>
using namespace std;
int st[1000003][5];
string q;
int dmc(int g,int k)
{
    if(g==q.length())return k;
    if(st[g][k]!=1e9)return st[g][k];
    int z=1e8;
    if(!k)z=min((dmc(g+1,0)+(q[g]-'0')),(dmc(g+1,1)+10-(q[g]-'0')));
    else{
        z=min(z,dmc(g+1,0)+1+(q[g]-'0'));
        z=min(z,dmc(g+1,1)+10-((q[g]-'0')+1));
    }
    return st[g][k]=z;
}
int main()
{
    int g;
    cin>>q;
    reverse(q.begin(),q.end());
    for(g=0;q[g];g++)st[g][0]=st[g][1]=1e9;
    printf("%d\n",dmc(0,0));
    return 0;
}


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

int main(){
	int n, h[11][11];
	while(scanf("%d", &n)){
		if(!n)break;
		for(int i = 0;i < n;i++){
			int num = 0;
			for(int j = 0;j < n;j++){
				scanf("%d", &h[i][j]);
				num += h[i][j];
				printf("%5d", h[i][j]);
			}
			h[i][n] = num;
			printf("%5d\n", num);
		}

		for(int i = 0;i <= n;i++){
			int num = 0;
			for(int j = 0;j < n;j++)num += h[j][i];
			printf("%5d", num);
		}
		printf("\n");
	}
}

#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 3e5 + 10;
const int Mod = 1e9 + 7;

void Chkadd(int &x, const int &y) { if ((x += y) >= Mod) x -= Mod; }

char s[maxn];
int F[7], G[7];

int main()
{
	int n = fread(s, 1, maxn, stdin);
	while (s[n - 1] != '0' && s[n - 1] != '1' && s[n - 1] != '?') -- n;
	int *f = F, *g = G;
	f[0] = 1;
	for (int i = 0; i < n; ++ i)
	{
		swap(f, g);
		fill(f, f + 7, 0);
		if (s[i] != '1')
		{
			Chkadd(f[1], g[0]);
			Chkadd(f[2], g[1]);
			Chkadd(f[1], g[2]);
			Chkadd(f[4], g[3]);
			Chkadd(f[6], g[4]);
			Chkadd(f[5], g[5]);
			Chkadd(f[4], g[6]);
		}
		if (s[i] != '0')
		{
			Chkadd(f[3], g[0]);
			Chkadd(f[0], g[1]);
			Chkadd(f[1], g[2]);
			Chkadd(f[5], g[3]);
			Chkadd(f[3], g[4]);
			Chkadd(f[5], g[5]);
			Chkadd(f[4], g[6]);
		}
	}
	Chkadd(f[5], f[3]);
	printf("%d\n", f[5]);
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

// 約数の列挙 O(√n)
vector<ll> divisor(ll n) {
    vector<ll> res;

    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }

    return res;
}

int main() {
    INIT;

    ll N;
    cin >> N;
    vector<ll> a(N + 1, 0);
    reps(i, 1, N + 1) cin >> a[i];

    vector<ll> b;
    vector<ll> sum(N + 1, 0);
    ll ans = 0;

    for (ll i = N; i > 0; i--) {
        if (sum[i] % 2 != a[i]) {
            b.pb(i);
            vector<ll> divs = divisor(i);
            rep(j, SZ(divs)) { sum[divs[j]]++; }
        }

        // cout << i << ": ";
        // repv(sum) cout << *it << " ";
        // cout << endl;
    }

    sort(ALL(b));
    cout << SZ(b) << endl;
    if (SZ(b) > 0) {
        repv(b) { cout << *it << " "; }
        cout << 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;
    cin >>n;
	vector<int> a(n);
	cin >> a;
	for (int i = n - 1; i >= 0;i--){
		for (int j = i * 2+1; j < n;j+=i+1){
			a[i] = (a[i] + a[j]) % 2;
		} }
	//clog << a << endl;
	Vi ans;
    rep(i,n){
        if(a[i]){
			ans.pb(i);
		}
    }
	cout << ans.size()<<endl;
	rep(i, ans.size()) { cout << ans[i]+1;
    if(i!=ans.size()-1){
		cout << " ";
	} }
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,L;
  cin >> N >> L;
  long long wa=0,sa=10000000000;
  for(int i=0; i<N; i++){
    long long kaage = L+i;
    wa += kaage;
    if(abs(sa) > abs(kaage)){
      sa = kaage;
    }
  }
    cout << wa-sa << endl;
}

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

int main() {

    int n, l;
    cin >> n >> l;

    int r = n + l - 1;

    int eat;

    if (r <= 0) eat = r;
    else if (l >= 0) eat = l;
    else eat = 0;

    cout << (r + l) * (r- l + 1) / 2 - eat << endl;

    return 0;
}


#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

struct edge{int to,cost;};
vector<vector<edge>> G(100100);
int dist[100100];
void dijkstra(int s) {
    fill(dist,dist+100100,INF);
    priority_queue<P,vector<P>,greater<P>> pri;
    dist[s]=0;
    pri.push({0,s});
    while(!pri.empty()) {
        P p = pri.top();pri.pop();
        int v = p.second;
        if(dist[v]<p.first) continue;
        for(auto e:G[v]) if(chmin(dist[e.to],dist[v]+e.cost)) pri.push({dist[e.to],e.to});
    }
}
signed main() {
    int n;cin >> n;
    rep(i, n-1) {
        int a,b,c;cin >> a >> b >> c;
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }
    int q,k;cin >> q >> k;
    dijkstra(--k);
    rep(i, q) {
        int a,b;cin >> a >> b;
        cout << dist[--a]+dist[--b] << char(10);
    }
    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
vector<pair<int,int>> g[MAX_N];

ll dist[MAX_N];

void dfs(int u, int prev, ll cur_dist) {
  dist[u] = cur_dist;
  for (auto e : g[u]) if (e.first != prev) {
    dfs(e.first, u, cur_dist + e.second);
  }
}
int main2() {
  REP(i, MAX_N) g[i].clear();
  int N = nextLong();

  REP(i, N-1) {
    int a = nextLong() - 1;
    int b = nextLong() - 1;
    ll c = nextLong();
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }

  int Q = nextLong();
  int K = nextLong() - 1;
  dfs(K, -1, 0);
  REP(_, Q) {
    int x = nextLong() - 1;
    int y = nextLong() - 1;
    ll ans = dist[x] + dist[y];
    cout << ans << '\n';
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

using namespace std;

int main(void)
{
	int n;
	while(cin >> n && n != 0)
	{
		vector<int> a(n+1);
		a[0] = 1;a[1] = 1;a[2] = 2;

		for (int i = 3; i <= n; i++)
			a[i] = a[i-1] + a[i-2] + a[i-3];

		double year;
		year = ceil((double)a[n] / 3650);
		cout << year << endl;
	}

	return 0;
}

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

using namespace std;

int main(){
  int n;
  vector<int> K(100);
  string s;
  string c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

  while(1){
    int l=0;
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++) cin>>K[i];
    for(int j=n;j<100;j++){
      int count=0;
      if(count==n)l=count=0;
      K[j]=K[l];
      l++;
      count++;
    }
    cin>>s;
    for(int i=0;i<s.size();i++){
      for(int j=0;j<c.size();j++){
	if(s[i]==c[j]){
	  if(j-K[i]<0){
	    s[i]=c[c.size()+j-K[i]];
	    break;
	  }else{
	    s[i]=c[j-K[i]];
	    break;
	  }
	}
      }
    }
    cout<<s<<endl;
    s.clear();
    K.clear();
  }

  return 0;
}


#include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

struct Edge{
    int from, to; ll cost;
    Edge(int from, int to, ll cost){
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
    bool operator<(const Edge &e) const{
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const{
        return cost > e.cost;
    }
};

struct Graph{
    int V,E;
    vector<vector< pair<int, ll> > > edges;

    Graph(){
        cin >> V >> E;
        edges.resize(V);
        int s,t; ll w;
        rep(E){
            cin >> s >> t >> w;
            edges[s].emplace_back(t, w);
            edges[t].emplace_back(s, w);
        }
    }

    ll kruskal(){
        ll ret = 0LL;
        priority_queue<Edge, vector<Edge>, greater<Edge> > que;
        vector<bool> used(V, false);

        used[0] = true;
        for(pair<int, ll> e: edges[0])
            que.push(Edge(0, e.first, e.second));

        while(!que.empty()){
            Edge e = que.top(); que.pop();
            while(!que.empty() && used[e.to]){
                e = que.top(); que.pop();
            }
            if(used[e.to]) break;
            ret += e.cost;
            used[e.to] = true;
            for(pair<int, ll> next: edges[e.to])
                if(!used[next.first]) que.push(Edge(e.to, next.first, next.second));
        }
        return ret;
    }
};

int main(){
    Graph g = Graph();
    cout << g.kruskal() << endl;
}

#include <bits/stdc++.h>

const int MAXN = 100010;
int xs[MAXN], D, n, Q;
int R[MAXN][20];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> xs[i];
	std::cin >> D >> Q;
	for (int i = 1; i <= n; ++i)
		R[i][0] = std::upper_bound(xs + 1, xs + 1 + n, xs[i] + D) - xs - 1;
	for (int i = 1; i < 20; ++i)
		for (int j = 1; j <= n; ++j)
			R[j][i] = R[R[j][i - 1]][i - 1];
	while (Q --> 0) {
		int x, y, t = 0; std::cin >> x >> y; if (x > y) std::swap(x, y);
		for (int i = 19; ~i; --i) if (R[x][i] < y) t += 1 << i, x = R[x][i];
		std::cout << t + 1 << '\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define All(a) a.rbegin(), a.rend()
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed
//double Time=clock();
int main() {
    ios;
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a + (a - 1), b + (b - 1)});
    //cout <<endl<< clock() - Time << endl;
    return 0;
}

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

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

struct edge {int to; ll cost; };

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

int main(){
  int n, k;
  cin >> n >> k;
  double ans = 0.0, ex = 0.0;
  vector<double> p(n);
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  for(int i=0; i<k; i++){
    ex += 1+p[i];
  }
  if(n==k){
    ex /= 2.0;
    cout << ex << endl;
    return 0;
  }
  ans = ex;
  for(int i=k; i<n; i++){
    ex = ex-p[i-k]+p[i];
    ans = max(ans, ex);
  }
  ans /= 2.0;
  printf("%.6lf", ans);
  return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    auto N = next<int>();
    vector<int> point(N, 0);
    times(N * (N - 1) / 2, i) {
        auto A = next<int>() - 1, B = next<int>() - 1, C = next<int>(), D = next<int>();
        if(C > D) {
            point[A] += 3;
        } else if(C < D) {
            point[B] += 3;
        } else {
            point[A]++;
            point[B]++;
        }
    }
    vector<int> point_(N, 0), rank(N);
    times(N, i) point_[i] = point[i];
    sort(all(point_), greater<int>());
    int p_ = 0;
    #ifdef debug
        times(N, i) cout << point[i] ln;
        cout ln;
        times(N, i) cout << point_[i] ln;
        cout ln;
    #endif
    times(N, i) {
        int p = point_[i];
        if(p == p_) continue;
        p_ = p;
        times(N, j) {
            if(p == point[j]) {
                rank[j] = i + 1;
            }
        }
    }
    times(N, i) cout << rank[i] ln;

    return 0;
}

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

typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;
	int table[101][101] = {0};
	for(int i=0 ; i < n*(n-1)/2 ; i++ ){
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--;
		int s1, s2;
		if( c > d ){
			s1 = 3;
			s2 = 0;
		}else if( c == d ){
			s1 = s2 = 1;
		}else{
			s1 = 0;
			s2 = 3;
		}
		table[a][b] = s1;
		table[b][a] = s2;
	}
	vector<P> v;
	int score[101] = {0};
	for(int i=0 ; i < n ; i++ ){
		for(int j=0 ; j < n ; j++ ){
			if( i == j ) continue;
			score[i] += table[i][j];
		}
		v.push_back( P(-score[i],i) );
	}
	sort( v.begin() , v.end() );
	int rank[101] = {0};
	rank[ v[0].second ] = 1;
	for(int i=1 ; i < v.size() ; i++ ){
		rank[ v[i].second ] = ( v[i].first == v[i-1].first )? rank[ v[i-1].second ] : i+1;
	}
	for(int i=0 ; i < n ; i++ ){
		cout << rank[i] << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
ll N;
vector<vector<ll>> A(16, vector<ll>(16, 0));
//dp[i]は集合の状態がiのときの最大値
vector<ll> dp((1<<16),0);

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

    for(ll S=0;S<(1<<N);S++){
        for(ll i=0;i<N;i++)
            for(ll j=0;j<i;j++){
                if(S>>i&S>>j&1)dp[S]+=A[i][j];
            }
        for(ll T=S;T>0;T=(T-1)&S)chmax(dp[S],dp[T]+dp[S-T]);
    }

    print(dp[(1<<N)-1])

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int INF = -1e18;
const int N = 16;
ll cost[1<<N];
ll dp[1<<N];
int n;

ll f(int mask) {
    if (mask == 0) return 0;
    ll &r = dp[mask];
    if (r != -1) return r;

    r = -INF;
    for (int sub = mask; sub; sub = (sub-1)&mask) {
        int next = mask&~sub;
        r = max(r, f(next) + cost[sub]);
    }
    return r;
}

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

    cin >> n;
    int g[n][n];
    forn(i, 0, n) {
        forn(j, 0, n) {
            cin >> g[i][j];
        }
    }

    forn(mask, 1, 1<<n) {
        forn(i, 0, n) if ((mask>>i)&1) {
            forn(j, i, n) if ((mask>>j)&1) {
                cost[mask] += g[i][j];
            }
        }
    }

    int mask = (1<<n)-1;
    memset(dp, -1, sizeof dp);
    ll ans = f(mask);

    cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  bool vanmo = false;
  while(n > 0){
    if(n % 10 == 7){
      vanmo = true;
    }
    n = n / 10;
  }
  if(vanmo){
    cout << "Yes";
  }else{
    cout << "No";
  }
	return 0;
}

#include<iostream>
using namespace std;

int main() {
    int N; cin >> N;
    string s = to_string(N);
    int sum = 0;
    for (int i = 0; i < s.size(); i++) {
        sum += s[i] - '0';
    }
    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

int main() {
	int n, m;
	while(cin >> n >> m, n || m) {
		vector<int> v;
		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp; v.push_back(tmp);
		}
		sort(v.rbegin(), v.rend());
		int res = 0;

		for(int i = 0; i < v.size(); i++) {
			if((i+1) % m)
				res += v[i];
		}
		cout << res << endl;
	}
}

#include<iostream>

using namespace std;

int main(){
  int n, i;
  while(cin >> n && n != 0) {
    int dp[n+1] = {};
    dp[1] = 1;
    dp[2] = 2;
    dp[3] = 4;

    for(i = 4; i <= n; i++) {
      dp[i] = dp[i-3] + dp[i-2] + dp[i-1];
    }

    i = 0;

    while(dp[n] > 0) {
      dp[n]-=3650;
      i++;
    }

    cout <<  i  << endl;
  }

  return 0;
}


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

using namespace std;

int main(){
	int H, W;
	cin >> H >> W;
	int a[510][510];
	rep(i,H){
		rep(j,W) cin >> a[i][j];
	}
	int ans=0;
	vector<int> ys, xs, yg, xg;
	rep(i,H){
		rep(j,W){
			if(i==H-1 && j==W-1) break;
			if(a[i][j]%2==1){
				ans++;
				if(j!=W-1){
					a[i][j]--;
					a[i][j+1]++;
					ys.emplace_back(i+1);
					xs.emplace_back(j+1);
					yg.emplace_back(i+1);
					xg.emplace_back(j+2);
				}
				else{
					a[i][j]--;
					a[i+1][j]++;
					ys.emplace_back(i+1);
					xs.emplace_back(j+1);
					yg.emplace_back(i+2);
					xg.emplace_back(j+1);
				}
			}
		}
	}
	cout << ans << endl;
	rep(i,ans) cout << ys[i] << " " << xs[i] << " "
	<< yg[i] << " " << xg[i] << endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 1e5+5;
unsigned long long sum = 0;
LL ans = 0;
LL one = 1;

unsigned long long A[maxn];
int used[maxn];
int cnt[maxn];

char M[62][maxn];

int N;

int Gauss(int H,int W)
{
    int i,j,col;

    for(col = 0;col < W;col++){

        int pivot = -1;
        for(int row = 0;row < H;row++){
            int bit = 61 - row;
            if(used[bit]) continue;
            if(M[row][col] == 1){
                pivot = row;
                break;
            }
        }

        used[61 - pivot] = 1;
        for(int row = 0;row < H;row++){
            int bit = 61 - row;
            if(used[bit]) continue;
            if(M[row][col] == 1){
                for(j = col;j <= W;j++){
                    M[row][j] ^= M[pivot][j];
                }
            }
        }
    }

    return 0;
}

int bit_n(LL t){
    int ret = 0;
    _for(i,0,N){
        if(t & A[i]) ret++;
    }
    return ret;
}

int main()
{
    cin >> N;
    _for(i,0,N) {
        cin >> A[i];
    }
    MEM(used,0);

    for(int bit = 61;bit >= 0;bit--){
        LL t = one<<bit;
        cnt[bit] = bit_n(t);
    }
    MEM(M,0);

    LL ans = 0;

    for(int bit = 0;bit <= 61;bit++){
        LL t = one<<bit;

        if(cnt[bit] == 0) {
            used[bit] = 1;
            continue;
        }
        else if(cnt[bit] & 1) {
            ans += t;
            used[bit] = 1;
            continue;
        }
        else M[61 - bit][N] = 1;

        _for(i,0,N){
            if(t & A[i]){
                if(!used[bit])
                    M[61-bit][i] = 1;
            }
        }
    }

    /*
    _for(i,54,62){
        if(cnt[61-i] == 0 || (cnt[61-i]&1)) continue;
        _rep(j,0,N){
            printf("%d ",M[i][j]);
        }
        printf("\n");
    }
    */

    Gauss(62,N);

    _rep(i,0,61){
        int bit = 61 - i;
        if(cnt[bit] == 0 || (cnt[bit]) & 1) continue;
        int ok = 0;

        _for(j,0,N) if(M[i][j]) ok = 1;
        if(!M[i][N]) ok = 1;
        if(ok) ans += (one << (bit+1));

    }

    /*
   _for(i,54,62){
        if(cnt[61-i] == 0 || (cnt[61-i]&1)) continue;
        _rep(j,0,N){
            printf("%d ",M[i][j]);
        }
        printf("\n");
    }
    */
    cout << ans << endl;

    return 0;
}


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

void solve()
{
    int n;cin>>n;
    int a[n],b[n];
    REP(i,n)cin>>a[i];
    REP(i,n)cin>>b[i];
    int j=0,now=-1;
    REP(i,n){
        if(now!=a[i])j=0;
        if(a[i]==b[i]){
            for(;j<n;j++){
                if(a[i]!=a[j]&&a[i]!=b[j]){
                    swap(b[i],b[j]);
                    break;
                }
            }
            if(j==n){cout<<"No"<<endl;return;}
        }
        now=a[i];
    }
    cout<<"Yes"<<endl;
    REP(i,n)cout<<(i?" ":"")<<b[i];cout<<endl;
}

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

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 200010
int n,a[N],b[N],c[N],d[N];
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n+1)c[i]=d[i]=0;
    rep(i,n)c[a[i]]++,d[b[i]]++;
    rep(i,n+1){
	if(c[i]+d[i]>n){
	    cout<<"No\n";
	    return 0;
	}
    }
    for(int i=1;i<=n;i++){
	c[i]+=c[i-1];
	d[i]+=d[i-1];
    }
    int x=0;
    for(int i=1;i<=n;i++)x=max(x,c[i]-d[i-1]);
    cout<<"Yes\n";
    rep(i,n){
	if(i)cout<<" ";
	cout<<b[(i+n-x)%n];
    }
    cout<<"\n";
}


#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	int n;
	LLI a, b, x, diff, sum = 0 ;
	cin >> n >> x;
	cin >> a >> b;
	if( a + b > x )
	{
		diff = a + b - x;
		if( diff <= b )
	    	b -= diff;
	    else
	    	b = 0;
		sum += diff;
	}
	a = b;
	for(int i = 2; i < n; i++)
	{
	    cin >> b;
	    if( a + b > x )
		{
			diff = a + b - x;
			if( diff <= b )
		    	b -= diff;
		    else
		    	b = 0;
			sum += diff;
		}
		a = b;
	}
	cout << sum;
}

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

int main()
{
    int n, x;
    std::cin >> n >> x;

    std::vector<int> arr;
    arr.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        arr.push_back(tmp);
    }

    int64_t count = 0;
    if (arr[0] + arr[1] > x)
    {
        const int d = arr[0] + arr[1] - x;
        count += d;
        arr[1] = std::max(arr[1] - d, 0);
        // arr[0]はもう参照しないので編集しない
    }
    for (int i = 2; i < n; ++i)
    {
        const int d = arr[i - 1] + arr[i] - x;
        if (d > 0)
        {
            arr[i] -= d;
            count += d;
        }
    }

    std::cout << count << std::endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <set>

std::set <int> s;

int main()
{
    int n;
    std::cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int x;
        std::cin >> x;
        if(s.find(x) != s.end())
        {
            s.erase(x);
        }
        else
        {
            s.insert(x);
        }
    }
    std::cout << s.size();
    // system("pause");
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

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

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

int main(){
    map<long long, int> mp;
    int n;
    cin >> n;
    for (int i = 0;i < n;i++){
        int a;
        cin >> a;
        mp[a]++;
    }

    int cnt = 0;
    for (auto v : mp){
        if (v.second % 2 != 0){
            cnt++;
        }
    }

    cout << cnt << endl;
}


#include <bits/stdc++.h>
#define inf 1e9
using namespace std;
int w,h,ans = inf,gx,gy;
int grid[21][21];
int syoki[21][21];
int x[4] = {-1,0,1,0};
int y[4] = {0,1,0,-1};

bool in(int a,int b){
  if(a< 0 || b<0 || w<=a || h<=b)return false;
  return true;
}

void dfs(int w1,int h1,int count){
  //  cout<<h1<<" "<<w1<<" "<<count<<endl;
  if(count == 10)return;
  for(int i = 0;i < 4;i++){
    int a = w1,b = h1;
    if(in(a+y[i],b+x[i]) && grid[b+x[i]][a+y[i]]==0){
      while(1){
	if(!in(a+y[i],b+x[i]))break;
	if((b+x[i])==gy && (a+y[i]) == gx){
	  ans = min(ans,count+1);
	  return;
	}
	else if(grid[b+x[i]][a+y[i]] == 1){
	  grid[b+x[i]][a+y[i]] = 0;
	  dfs(a,b,count+1);
	  grid[b+x[i]][a+y[i]] = 1;
	  break;
	}
	a += y[i];
	b += x[i];
      }
    }
  }
}

int main(){
  int sx,sy;
  while(1){
    cin >> w >> h;
    if(w == 0)break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	cin >> grid[i][j];
	if(grid[i][j] == 2){
	  sx = j;
	  sy = i;
	  grid[i][j]=0;
	}
	if(grid[i][j] == 3){
	  gx = j;
	  gy = i;
	  grid[i][j]=0;
	}

      }
    }
    ans = inf;
    dfs(sx,sy,0);
    if(ans == inf)cout << -1 <<endl;
    else cout << ans <<endl;
  }
  return 0;
}

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

typedef long long LL;

const int MAXN=400;

LL n, m, ans, cntW, cntB;
bool visited[MAXN][MAXN];
string s[MAXN];

bool avail(int i, int j, char c){
	if(i < 0 || i >= n || j < 0 || j >= m) return false;
	if(s[i][j] == c) return false;
	return true;
}

void dfs(int i, int j){
	if(i < 0 || i >= n || j < 0 || j >= m) return;
	if(visited[i][j]) return;

	visited[i][j] = true;
	if(s[i][j] == '.') cntW++;
	else cntB++;
	if(avail(i, j - 1, s[i][j])) dfs(i, j - 1);
	if(avail(i, j + 1, s[i][j])) dfs(i, j + 1);
	if(avail(i + 1, j, s[i][j])) dfs(i + 1, j);
	if(avail(i - 1, j, s[i][j])) dfs(i - 1, j);
}

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> s[i];

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			visited[i][j] = false;

	ans = 0;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			if(!visited[i][j]){
				cntB = 0; cntW = 0;

				dfs(i, j);
				ans += cntB * cntW;
			}
	cout << ans << "\n";
}


#define _USE_MATH_DEFINES

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

using namespace std;

int main(){
	int l[10];
	int v1, v2;
	char c;
	int d;

	while(cin >> l[0]){
		d=l[0];
		for(int i=1;i<10;i++){
			cin >> c >> l[i];
			d+=l[i];
		}
		cin >> c >> v1 >> c >> v2;

		double t = (double)d/(v1+v2);
		d=0;
		//cout << t<<endl;
		for(int i=0;i<10;i++){
			d+=l[i];
			//cout << v1*t <<" "<<d<<endl;
			if(v1*t <= d){
				cout << i+1 <<endl;
				break;
			}
		}
	}
	return 0;
}

#include<iostream>
#include<numeric>
#include<cstdio>

int l[10],v,v2;

int main(){
	while(true){
		for(int i=0;i<10;i++){
			if(scanf("%d,",&l[i])==EOF)return 0;
		}
		if(scanf("%d,%d",&v,&v2)==EOF)return 0;

		double k=(double)std::accumulate(l,l+10,0)/(v+v2)*v;

		int sum=0;
		for(int i=0;i<10;i++){
			sum+=l[i];
			if(sum>=k){
				std::cout<<i+1<<std::endl;
				break;
			}
		}
	}

	return 0;
}


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

int main(){
  int x, y;
  cin >> x >> y;

  long long ans = 0;
  ans += abs(abs(x) - abs(y));
  if(x > 0){
    if(y > 0 && x > y) ans += 2;
    if(y < 0) ans++;
  }
  if(x < 0){
    if(y < 0 && x > y) ans += 2;
    if(y > 0) ans++;
  }
  if(x == 0 && y < 0) ans++;
  if(y == 0 && x > 0) ans++;

  cout << ans << endl;
}

// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// class
// ------------------------------------------------
class Combi
{
  public:
    Combi();
    long long Combination(long long n, long long k);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

  ll x,y;
  cin >> x >> y;

  ll ans = 0;

  if(x * y > 0)
  {
    ans = abs(y-x) + ( x < y ? 0 : 2);
  }
  else if(x == 0)
  {
    ans = abs(y) + ( y < 0 ? 1 : 0);
  }
  else if(y == 0)
  {
    ans = abs(x) + ( x < 0 ? 0 : 1);
  }
  else
  {
    ans = abs( y + x ) + 1;
  }

  cout << ans << endl;
  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}

Combi::Combi(){
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0)
  {
    ret = memo[n][k];
  }
  else if(n == k || k == 0)
  {
    memo[n][k] = 1;
    ret = 1;
  }
  else
  {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k)
{
  if(n_num <= n || k_num <= k)
  {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr)
    {
      itr->resize(k_num);
    }
  }
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};

int main() {
  int H,W; cin >>H >>W;
  int A,B; cin >>A >>B;
  for (int i=0; i<H; i++){
    int ai = i < B ? 0 : 1;
    for (int j=0; j<W; j++){
      int aj = j < A ? 0 : 1;
      int res = (ai+aj)%2;
      cout <<res;
    }
    cout <<endl;
  }
}

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

void solve(long long H, long long W, long long A, long long B){
  rep(i,H-B) {
    rep(j,W-A) {
      std::cout << 1;
    }
    rep(j,A) {
      std::cout << 0;
    }
    std::cout << std::endl;
  }
  rep(i,B) {
    rep(j,W-A) std::cout << 0;
    rep(j,A) std::cout << 1;
    std::cout << std::endl;
  }
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(H, W, A, B);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n,d,k=1;
    long long minx=10000;
    cin>>n;
    while(1){
        d=n/k%1000;
        if(d<100){
            break;
        }
        else if(abs(753-d)<minx){
            minx=abs(753-d);
        }
        k*=10;

    }
    cout<<minx<<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){
   string S;
   cin>>S;
   int len=S.size();
   int num;
   int ans=1000;
   rep(i,len-2){
       num=(S[i]-'0')*100+(S[i+1]-'0')*10+S[i+2]-'0';
       ans=min(ans,abs(753-num));
   }
   cout<<ans<<endl;

}


#include <iostream>
using namespace std;
class Dice {
    private:
        int num[6];
        void go2N() {
            int tmp = num[0];
            num[0] = num[1];
            num[1] = num[5];
            num[5] = num[4];
            num[4] = tmp;
        }
        void go2S() {
            int tmp = num[0];
            num[0] = num[4];
            num[4] = num[5];
            num[5] = num[1];
            num[1] = tmp;
        }
        void go2E() {
            int tmp = num[0];
            num[0] = num[3];
            num[3] = num[5];
            num[5] = num[2];
            num[2] = tmp;
        }
        void go2W() {
            int tmp = num[0];
            num[0] = num[2];
            num[2] = num[5];
            num[5] = num[3];
            num[3] = tmp;
        }

    public:
        Dice(int *_num) {
            for (int i=0;i<6;i++) {
                num[i] = _num[i];
            }
        }

        void go(char op) {
            switch (op) {
                case 'N':
                    go2N();
                    break;
                case 'S':
                    go2S();
                    break;
                case 'E':
                    go2E();
                    break;
                case 'W':
                    go2W();
                    break;
                default:
                    break;
            }
        }

        int getNum(int id) {
            int ret = 0;
            if (0 <= id && id < 6) ret = num[id];
            return ret;
        }
};

int main() {
    int num[6];
    string op;
    cin >> num[0] >> num[1] >> num[2] >> num[3] >> num[4] >> num[5];
    Dice D(num);
    cin >> op;
    for (int i=0;i<op.size();i++) {
        D.go(op[i]);
    }
    cout << D.getNum(0) << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,neg=0,mn=INT_MAX;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        if(arr[i]<0)
            neg++;
        int cur=abs(arr[i]);
        mn=min(mn,cur);
    }
    ll sum=0,sub=0;
    if(neg%2)
    {

        sub=mn;
    }
    for(int i=0; i<n; i++)
        sum+=abs(arr[i]);
    sum-=sub*2;
    cout<<sum<<endl;

    return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t);

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}

int main(){

    ll n; cin >> n;
    ll absmin = INF;
    ll ans = 0;
    ll minuscnt = 0;
    rep(i, n){
        ll in; cin >> in;
        chmin(absmin, abs(in));
        if(in<0) minuscnt++;
        ans += abs(in);
    }

    cout << (minuscnt%2==0?ans:ans-2*absmin) << endl;

    return 0;
}


#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll X;
  cin>>X;
  ll ans = 0;
  ans += X/500*1000;
  X %= 500;
  ans += X/5*5;
  X %= 5;
  cout<<ans<<endl;
}

#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }

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

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    ll n; cin >> n;
    string a;
    ll left = 0ll, right = n-1ll;
    cout << 0 << endl;
    cin >> a;
    if(a=="Vacant"){
        return 0;
    }
    string b;
    while(b!="Vacant"){
        ll mid = (left+right)/2ll;
        cout << mid << endl;
        cin >> b;
        if(b=="Vacant") return 0;
        if(mid%2==0){
            if(a==b){
                left = mid+1;
            }
            else{
                right = mid-1;
            }
        }
        else{
            if(a!=b){
                left = mid+1;
            }
            else{
                right = mid-1;
            }
        }
    }
}


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

int main(){
  double n, m, d;
  cin >> n >> m >> d;
  double ans;
  if(d == 0){
    ans = 1/n;
  }else{
    ans = 2*(n-d)/(n*n);
  }
  ans *= (m-1);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

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

using namespace std;
// using namespace __gnu_pbds;

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

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    ll tc = 0;
    while(tc++ < t){
    	ll n, m, d;
        cin>>n>>m>>d;
        ld ans = 1.0*(m-1)*(n-d)/(n*1.0*n);
        if(d > 0)	ans *= 2.0;
        cout<<fixed<<setprecision(10)<<ans;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

bool dfs(int now, int pre, vector<int> &d, vector<vector<int>> &g) {
    if (now) d[now] = d[pre] + 1;

    bool ret = false;
    for (int nxt : g[now]) {
        if (d[nxt] != -1) {
            if (d[nxt] % 2 != d[now] % 2)
                continue;
            else
                return true;
        }
        ret |= dfs(nxt, now, d, g);
    }
    return ret;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> d(n, -1);
    d[0] = 0;
    if (dfs(0, -1, d, g)) {
        cout << (ll)n * (n - 1) / 2 - (ll)m << endl;
        return 0;
    }

    ll odd = 0, even = 0;
    rep(i, n) {
        (d[i] % 2 == 0 ? even : odd)++;
    }
    cout << odd * even - (ll)m << endl;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int V, E;
vector<int>G[10010];//グラフの隣接リスト表現
vector<int>rG[10010];//辺の向きを逆にしたグラフ
vector<int>vs;//帰りがけ順の並び
bool used[10010];//すでに調べたか
int cmp[10010];//属する強連結成分のトポロジカル順序
void add_edge(int from, int to) {
	G[from].push_back(to);
	rG[to].push_back(from);
}
void dfs(int v) {
	used[v] = true;
	for (int i = 0; i < G[v].size(); ++i) {
		if (!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
}
void rdfs(int v, int k) {
	used[v] = true;
	cmp[v] = k;
	for (int i = 0; i < rG[v].size(); ++i) {
		if (!used[rG[v][i]])rdfs(rG[v][i], k);
	}
}
int main() {
	cin >> V >> E;
	REP(i, E) {
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		rG[t].push_back(s);
	}
	int Q;
	cin >> Q;
	int num = 0;
	memset(used, 0, sizeof(used));
	vs.clear();
	for (int v = 0; v < V; ++v) {
		if (!used[v])dfs(v);
	}
	memset(used, 0, sizeof(used));
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]])rdfs(vs[i], num++);
	}
	REP(i, Q) {
		int u, v;
		cin >> u >> v;
		if (cmp[u] == cmp[v]) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	if (R < 1200) cout << "ABC" << endl;
	else if (R < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}

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

int main(){

string A;
cin >> A;
if(A.at(0)-'0'==7||A.at(1)-'0'==7||A.at(2)-'0'==7) cout << "Yes" << endl;
else cout << "No" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    ll A[N];
    rep(i, N) cin >> A[i];
    int ans = 0;
    sort(A, A+N, greater<ll>());
    ll sum = 0;
    rep(i, N){
        if(i < P-1) {ans++; continue;}
        if(A[i]+M < A[P-1]) break;
        ll S = (N-i-1)*M;
        S += (i-P+1)*(A[i]+M) - sum;
        if(S >= M*(V-P)) ans++;
        sum += A[i];
    }
    cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define pf push_front
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rsz resize()
#define lb lower_bound
#define ub upper_bound

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

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bit(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

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

#ifndef LOCAL
string to_string(__int128 x) {
	string s = "";
	bool neg = 0;
	if(x < 0) { s += "-"; neg = 1; }
	if(!x) s += '0';
	while(x) {
		int rem = x % 10;
		s += to_string(rem);
		x /= 10;
	}
	reverse(s.begin() + neg, s.end());
	return s;
}
#endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
*/

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

int good(int idx) {
	vector<int> bad;
	fr(i, 1, n) {
		if(a[i] > a[idx]) bad.pb(a[i] - a[idx]);
	}
	sort(all(bad));
	int tot = max(0, (int)bad.size() - p + 1);
	int maxi = 0;
	ll s = 0;
	fr(i, 0, tot - 1) {
		s += bad[i];
		maxi = max(maxi, bad[i]);
	}
	debug(a[idx], bad);
	return (maxi <= m) && (s <= m * 1LL * v);
}

void solve() {
	cin >> n >> m >> v >> p;
	v = n - v;
	fr(i, 1, n) {
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	reverse(a + 1, a + n + 1);
	int l = 0, r = n + 1;
	while(r - l > 1) {
		int m = (l + r) >> 1;
		if(good(m))
			l = m;
		else
			r = m;
	}
	cout << l;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


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

int main(void) {
  int n;
  cin >> n;
  map<ll, int> a;
  rep(i, n) {
    ll temp;
    cin >> temp;
    a[temp]++;
  }

  ll ans = 0;
  for (auto x : a) {
    if (x.second % 2 != 0) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

// input
int N;
vector<int> A;

void input() {
    cin >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}

int main() {
    input();
    set<int> s;
    for (int a : A) {
        if (s.count(a)) s.erase(a);
        else s.insert(a);
    }
    int ans = s.size();
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  ll N; cin >> N;
  ll x[N]; rep(i,N) cin >> x[i];
  ll M, K; cin >> M >> K;
  ll a[M]; rep(i,M) { cin >> a[i]; a[i]--; }
  ll diff[N-1]; rep(i,N-1) diff[i] = x[i+1] - x[i];

  ll pos[N-1]; rep(i,N-1) pos[i] = i;
  ll p_bit[N-1]; rep(i,N-1) p_bit[i] = i;
  for (int i=0; (1ull<<i)<=K; i++) {
    if (i==0) rep(i,M) swap(p_bit[a[i]-1], p_bit[a[i]]);
    else {
      ll p_tmp[N-1]; rep(i,N-1) p_tmp[i] = p_bit[i];
      rep(i,N-1) p_bit[i] = p_tmp[p_tmp[i]];
    }
    if (K&(1ull<<i)) rep(i,N-1) pos[i] = p_bit[pos[i]];
    // cout << i << ":"; rep(i,N-1) cout << p_bit[i] << " "; cout << endl;
    // rep(i,N-1) cout << pos[i] << " "; cout << endl;
  }
  ll result[M]; result[0] = x[0];
  rep(i,N-1) result[i+1] = result[i] + diff[pos[i]];
  rep(i,N) cout << result[i] << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
const int N=1e5+5;
int a[N],b[N],d[N],p[N],ans[N],vis[N],st[N],tt=0,n,m;ll k;
void dfs(int u){if(!vis[u])vis[u]=1,st[++tt]=u,dfs(p[u]);}
main()
{
    scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]),d[i]=a[i]-a[i-1];
    scanf("%lld%lld",&m,&k);
    for(int i=1;i<=n;i++)p[i]=i;
    for(int i=1;i<=m;i++)scanf("%lld",&b[i]),swap(p[b[i]],p[b[i]+1]);
    for(int i=1;i<=n;i++)
    {
        if(vis[i])continue;
        tt=0;dfs(i);
        for(int j=1;j<=tt;j++)ans[st[j]]=d[st[(j+k-1)%tt+1]];
    }
    for(int i=1;i<=n;i++)printf("%lld.0\n",ans[i]+=ans[i-1]);
}


#include <iostream>
using namespace std;
int main() {
	int n, m;
	while (cin >> n >> m) {
		int i, a[10001] = { 0 }, b[10001] = { 0 };
		bool list[2][1001] = { false };
		if (n == 0 && m == 0) goto END;
		for (i = 0; i < m; i++) {
			cin >> a[i] >> b[i];
			if (a[i] == 1) {
				list[0][b[i]] = true;
				list[1][b[i]] = true;
			}
			if (b[i] == 1) {
				list[0][a[i]] = true;
				list[1][a[i]] = true;
			}
		}
		for (i = 0; i < m; i++) {
			if (list[0][a[i]] == true) {
				list[1][b[i]] = true;
			}
			if (list[0][b[i]] == true) {
				list[1][a[i]] = true;
			}
		}
		int ans = 0;
		for (i = 2; i <= n; i++) {
			if (list[1][i]) ans++;
		}
		cout << ans << endl;
	}
END:;
	return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

/*
*    coder :: ATUL_PANDEY_2608
*        >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define mod 1000000007
//#define maxx 200006
#define ll long long
#define quick    ios_base::sync_with_stdio(NULL),cin.tie(0);
#define listll vector< long long >
#define listi vector< int>
#define pii   pair<int , int>
#define pll pair<long long , long long >
#define minheap priority_queue<long long , vector< long long >, greater<long long > >
#define rep(i,a,b) for(int i=a;i<b;i++)
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

template < class T > using oset = tree< T , null_type, less  < T  > , rb_tree_tag , tree_order_statistics_node_update > ;

// end of #define

// define globals ...
const int maxx = 2e6+26;

//write function from here ...

vector <  int > arr;

void prime () {

	bool vis[maxx];
	memset ( vis, 0 , sizeof (vis) );

	for (  ll i = 2; i*i <=maxx; i++){

		if( vis[i] == 0 ){

			for( ll j = i*i; j<maxx ; j+= i){

				vis[j] =1 ;

			}

		}

	}

	for ( int i= 2; i < maxx; i++){

		if( vis[i]== 0){
			arr.pb( i);
		}

	}

}

int Main(){

prime();
ll  a,b;
cin>>a>>b;

int nn = arr.size();

ll temp  =a;
int  i = 0 ;
set < ll > st ;
map< ll , int   > mp1 ,mp2;

//int j = 0 ;
 //for(auto it : arr ) {
	 //if( j > 100)
	 //break;
     //else
     //{cout<<it<<" ";j++;
	 //}
	//}
while(i < nn  && temp > 1){
	if( temp%arr[i]==0)
	{
		mp1[arr[i]]= 1;
		st.insert( arr[i]);
	}
	while(temp%arr[i] == 0 )
	{

		temp/=arr[i];

	}

	i++;

}
if(temp > 1)
{
	mp1[temp ] = 1;
	st.insert(temp);
}

temp = b;
i =0 ;

while(i < nn && temp > 1){
	if( temp%arr[i]==0){
	mp2[arr[i]]= 1;
	st.insert(arr[i]);
}

	while(temp%arr[i] == 0 )
	{

		temp/=arr[i];

	}

	i++;

}
if(temp > 1)
{
	mp2[temp ] = 1;
	st.insert(temp);
}

int cnt =1;

for( auto it : st ) {

	if(mp1 [it]  && mp2[it] ){
	cnt++;
	}

}

cout<<cnt<<endl;

return 0;

}

int main(){
 quick;
int t =1;
//cin>>t;
while(t-- )
 Main();

 return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll d, g; cin >> d >> g;
    vector<ll> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    ll ans = INF;
    rep(i, (1<<d)) {
        ll sum = 0;
        ll cnt = 0;
        rep(j, d) {
            if(i&(1<<j)) {
                sum += 100 * (j + 1) * p[j] + c[j];
                cnt += p[j];
            }
        }
        //cout << d << ' ' << g << ' ' << ans << ' ' << sum << endl;
        if(sum >= g) {chmin(ans, cnt); continue;}
        for(ll j=d-1; j>=0; j--) {
            if(!(i&(1<<j))) {
                Rep(k, 1, p[j]) {
                    sum += 100 * (j + 1);
                    cnt++;
                    if(sum >= g) chmin(ans, cnt);
                }
            }
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 1e5 + 2;
int n, k, p[11], c[11];
ll dp[11][A];
ll solve(int ind, int rem) {
    if (rem <= 0) return 0;
    if (ind == n) return 1e9;
    if (~dp[ind][rem])
        return dp[ind][rem];
    ll val = solve(ind + 1, rem - (p[ind] * (ind + 1)) - c[ind]) + p[ind];
    for (int i = 0; i < p[ind]; i++)
        val = min(val, solve(ind + 1, rem - (i * (ind + 1))) + i);
    return dp[ind][rem] = val;
}
int main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n >> k;
    k /= 100;
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> c[i];
        c[i] /= 100;
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, k);
    return 0;
}


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

int main(){
    ll n; cin >> n;
    ll ans=0;
    ll s=n/3;
    ll a=n/5;
    ll d=n/15;
    ans=(1+n)*n/2;
    ans=ans-(3+s*3)*s/2-(5+a*5)*a/2+(15+d*15)*d/2;
    cout << ans << "\n";
}

#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    long long int ans=0;
    for(int i=1;i<=n;i++){
       if(i%3==0 ||i%5==0){
           continue;
       }
       ans +=i;
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int a, b;
   string s;
   cin >> a >> b >> s;
   if(a+b+1 != s.size() || s[a] != '-')
   {
      cout << "No" << nl;
      return 0;
   }
   for(int i = 0; i < s.size(); i++)
   {
      if(i == a) continue;
      if(s[i] < '0' || s[i] > '9')
      {
         cout << "No" << nl;
         return 0;
      }
   }
   cout << "Yes" << nl;
   return 0;
   return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    bool ans=true;
    rep(0,i,a)if(!(s[i]>='0'&&s[i]<='9'))ans=false;
    if(s[a]!='-')ans=false;
    rep(0,i,b)if(!(s[a+1+i]>='0'&&s[a+1+i]<='9'))ans=false;
    if(ans)cout<<"Yes";
    else cout<<"No";
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll ng = 0, m = INF, sum = 0;
    REP(i,0,N) {
        if(A[i] < 0) ++ng;
        m = MIN(m,abs(A[i]));
        sum += abs(A[i]);
    }

    if(ng % 2 == 0) PR(sum);
    else PR(sum-m*2);

    return 0;
}

/*

*/

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

int main(){
  int N, mcount=0;
  cin >> N;
  long long A[N];
  for (int i = 0; i < N; i++){
    cin >> A[i];
    if (A[i]<0){
      mcount++;
      A[i] *= -1;
    }
  }

  long long ans = 0;
  if (mcount%2==0){
    for (int i = 0; i < N; i++){
      ans += A[i];
    }
    printf("%llu\n", ans);
  }else{
    sort(A, A+N);
    for (int i = 1; i < N; i++){
      ans += A[i];
    }
    printf("%llu\n", ans - A[0]);
  }

}


#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;
int main()
{
    stat();
    ll n, t;
    cin >> n >> t;
    ull ans = 0,curtime=0;
    vec<ll> v(n);
    rep(i, n) { cin >> v[i]; }
    rep(i,n-1){
	    curtime+=v[i];
	    ans+=min(t,abs(v[i+1]-v[i]));
    }
    cout<<ans+t<<endl;
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}

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

int dp[1005][1005];

void ExtendedEditDistance(vector<string> s1, vector<string> s2){

  const int INF = 1e9;

  for(int i=0;i<1005;i++)
    for(int j=0;j<1005;j++) dp[i][j] = INF;

  dp[0][0] = 0;

  int sum1 = 0, sum2;

  for(int i=0;i<(int)s1.size();i++){

    for(int j=0;j<(int)s1[i].size();j++){

      int idx1 = sum1 + j;

      sum2 = 0;

      for(int k=0;k<(int)s2.size();k++){

	for(int l=0;l<(int)s2[k].size();l++){

	  int idx2 = sum2 + l;

	  if( s1[i][j] == s2[k][l] ) dp[idx1+1][idx2+1] = min( dp[idx1+1][idx2+1], dp[idx1][idx2] );
	  else{

	    dp[idx1+1][idx2] = min( dp[idx1+1][idx2], dp[idx1][idx2] + 1 );

	    dp[idx1][idx2+1] = min( dp[idx1][idx2+1], dp[idx1][idx2] + 1 );

	    dp[idx1+1][idx2+1] = min( dp[idx1+1][idx2+1], dp[idx1][idx2] + 1 );

	  }
	  /*
	  if( j == 0 ) dp[idx1+s1[i].size()][idx2] = min( dp[idx1+s1[i].size()][idx2], dp[idx1][idx2] + 1 );

	  if( l == 0 ) dp[idx1][idx2+s2[k].size()] = min( dp[idx1][idx2+s2[k].size()], dp[idx1][idx2] + 1 );
	  */
	  if( i == (int)s1.size() - 1 ){

	    int idx1 = sum1 + s1[i].size();

	    dp[idx1][idx2+1] = min( dp[idx1][idx2+1], dp[idx1][idx2] + 1 );

	    //if( l == 0 ) dp[idx1][idx2+s2[k].size()] = min( dp[idx1][idx2+s2[k].size()], dp[idx1][idx2] + 1 );

	  }

	}

	if( k == (int)s2.size() - 1 ){

	  int idx2 = sum2 + s2[k].size();

	  dp[idx1+1][idx2] = min( dp[idx1+1][idx2], dp[idx1][idx2] + 1 );

	  //	  if( j == 0 ) dp[idx1+s1[i].size()][idx2] = min( dp[idx1+s1[i].size()][idx2], dp[idx1][idx2] + 1 );

	}

	sum2 += s2[k].size();

      }

    }

    sum1 += s1[i].size();

  }

  cout<<dp[sum1][sum2]<<endl;

  /*
    int ans = dp[sum1][sum2];

  for(int i=0;i<1005;i++) ans = min( ans, dp[sum1][i] + sum2 - i );

  for(int i=0;i<1005;i++) ans = min( ans, dp[i][sum2] + sum1 - i );

  cout<<ans<<endl;
  */

}

signed main(){

  vector<string> s1, s2;

  string A, B;
  cin>>A>>B;

  s1.push_back( A );

  s2.push_back( B );

  ExtendedEditDistance(s1,s2);

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

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

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

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

    cout << t + s << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

using namespace std;

class cLSearch
{
	int mn, mq;
	string mS, mT;
	vector<int> vs, vt;
	int ans;

	void decode();
public:
	cLSearch(const int &n, const int &q, const string &s, const string &t)
	{
		mn = n;
		mq = q;
		mS = s;
		mT = t;

		decode();
	}

	void search();
	void output();
};

void cLSearch::search()
{
	sort(vs.begin(), vs.end());
	sort(vt.begin(), vt.end());
	int count = 0;
	vector<int>::iterator vis = vs.begin();
	vector<int>::iterator vit = vt.begin();

	int ts, tt;
	while (vis != vs.end() && vit != vt.end())
	{
		if (*vis == *vit)
		{
			++count;
			ts = *vis;
			tt = *vit;
			while (vis != vs.end() && ts == *vis)
				++vis;
			while (vit != vt.end() && tt == *vit)
				++vit;
		}
		else
		{
			if (vis != vs.end() && vit != vt.end() && *vis > *vit)
				++vit;
			else
				++vis;
		}
	}

	ans = count;
}

void cLSearch::output()
{
	cout << ans << endl;
}
void cLSearch::decode()
{
	istringstream iss;
	iss.str(mS);
	int ts;
	for (int i = 0; i < mn; ++i)
	{
		iss >> ts;
		vs.push_back(ts);
	}
	iss.str(mT);
	iss.seekg(0, iss.beg);
	for (int i = 0; i < mq; ++i)
	{
		iss >> ts;
		vt.push_back(ts);
	}
}

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

	int n, q;
	string s, t;
	cin >> n;
	cin.ignore();
	getline(cin, s);
	cin >> q;
	cin.ignore();
	getline(cin, t);

	cLSearch cls(n, q, s, t);
	cls.search();
	cls.output();

	return 0;
}

#include <cstdio>
#include <vector>

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

using namespace std;

bool linerSearch(vector<int> vec, int key) {
    rep(i, vec.size()) if (vec[i] == key) return true;
    return false;
}

int main() {
    int n, q, key;
    scanf("%d", &n);
    vector<int> S(n);
    rep(i, n) scanf("%d", &S[i]);

    int ans = 0;
    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        scanf("%d", &key);
        if (linerSearch(S, key)) ++ans;
    }

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