#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
vector<ll> dijkstra(vector<vector<P>> graph, ll s) {
    vector<ll> ans(graph.size(), -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        ll cur1 = 0;
        ll cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (ll i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].first, graph[cur2][i].second});
            }
        }
    }
    return ans;
}
vector<string> maze;
ll h, w;
bool check(ll y, ll x) {
    if (x < 0 || x >= w || y < 0 || y >= h || maze[y][x] == '#') {
        return false;
    }
    return true;
}
double p;
long double f(long double x) { return x + p / (pow(2, x / 1.5)); }
ll gcd(ll a, ll b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> as(m);
    ll match[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    REP(i, m) { cin >> as[i]; }
    sort(as.rbegin(), as.rend());
    vector<ll> digit(10001, -INF);
    digit[0] = 0;
    rep(i, 1, n + 1) {
        REP(j, m) {
            if (i - match[as[j]] >= 0) {
                digit[i] = max(digit[i], 1 + digit[i - match[as[j]]]);
            }
        }
    }
    ll k = n;
    REP(i, digit[n]) {
        REP(j, as.size()) {
            if ((k - match[as[j]]) >= 0 && digit[k - match[as[j]]] == digit[k] - 1) {
                k -= match[as[j]];
                cout << as[j];
                break;
            }
        }
    }
}

#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, M; cin >> N >> M;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }
    vector<int> R(N+1);
    R[0] = 0;
    rep(i, N){
        int r = A[i] + R[i];
        r %= M;
        R[i+1] = r;
    }

    map<ll, ll> m;
    rep(i, N+1){
        m[R[i]]++;
    }

    ll ans = 0;
    for (auto p : m){
        ll value = p.second;
        value = value * (value-1) / 2;
        ans += value;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%3==0||i%5==0)
            continue;
        s+=i;
    }
    cout<<s<<endl;
}

// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

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

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

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

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

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

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

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

    ans = 0;

    while(cin >> n)
    {
		for(ll i = 1; i <= n; i++)
		{
			if(i % 3 && i % 5) ans += i;
		}

		cout << ans << "\n";
    }

}


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

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};

int main(){
  int n,m,q;
  cin >> n >> m >> q;
  vector<vector<int>> lr(m,vector<int>(2));
  for(int i=0;i<m;i++){
    cin >> lr.at(i).at(0) >> lr.at(i).at(1);
    lr.at(i).at(0)--;lr.at(i).at(1)--;
  }
  vector<vector<int>> pq(q,vector<int>(2));
  for(int i=0;i<q;i++){
    cin >> pq.at(i).at(0) >> pq.at(i).at(1);
    pq.at(i).at(0)--;pq.at(i).at(1)--;
  }
  vector<vector<int>> table(n,vector<int>(n,0));
  for(int i=0;i<m;i++){
    table.at(lr.at(i).at(0)).at(lr.at(i).at(1))++;
  }
  vector<vector<int>> s(n,vector<int>(n));
  s[0][0] = table[0][0];
  for(int i=1;i<n;i++){
    s[i][0] = s[i-1][0] + table[i][0];
    s[0][i] = s[0][i-1] + table[0][i];
  }
  for(int i=1;i<n;i++){
    for(int j=1;j<n;j++){
      s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + table[i][j];
    }
  }
  for(int i=0;i<q;i++){
    int pp = pq.at(i).at(0),qq = pq.at(i).at(1);
    if(pp == 0)cout << s[qq][qq] << endl;
    else{
      cout << s[qq][qq] - s[qq][pp-1] - s[pp-1][qq] + s[pp-1][pp-1] << endl;
    }
  }
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,x=0;string A,B,C;
  cin>>N>>A>>B>>C;
  for(int i=0;i<N;i++){
    char a=A.at(i),b=B.at(i),c=C.at(i);
    if(a==b){if(a!=c)x++;}
    else{
      if(a==c||b==c)x++;
      else x+=2;
    }
  }
  cout<<x<<endl;
}


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

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> S(N);
    for (auto& s : S) {
        cin >> s;
    }
    vector<P> pos, neg;
    for (auto& s : S) {
        string now;
        for (auto& c : s) {
            if (now.empty()) {
                now += c;
            } else {
                if (now.back() == '(' && c == ')') {
                    now.pop_back();
                } else {
                    now += c;
                }
            }
        }
        int A = 0, B = 0;
        for (auto& c : now) {
            if (c == ')') {
                ++A;
            } else {
                ++B;
            }
        }
        if (B - A >= 0) {
            pos.emplace_back(A, B);
        } else {
            neg.emplace_back(A, B);
        }
    }
    sort(all(pos), [](P a, P b) {
        return a.first < b.first;
    });
    int cumsum = 0;
    for (auto& p : pos) {
        cumsum -= p.first;
        if (cumsum < 0) {
            cout << "No" << endl;
            return 0;
        }
        cumsum += p.second;
    }
    sort(all(neg), [](P a, P b) {
        return a.second > b.second;
    });
    for (auto& p : neg) {
        cumsum -= p.first;
        if (cumsum < 0) {
            cout << "No" << endl;
            return 0;
        }
        cumsum += p.second;
    }
    if (cumsum) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1e6 + 5;
int n;
char s[mxn];
int bg[mxn], ln[mxn];
int a[mxn], b[mxn];
int id[mxn];

bool comp(int x, int y) {
	return min(-a[x], -a[x] + b[x] - a[y]) > min(-a[y], -a[y] + b[y] - a[x]);
}

void NO() {
	puts("No");
	exit(0);
}

int main() {
	scanf("%d", &n);
	rep(i, n) {
		scanf("%s", s + bg[i]);
		ln[i] = strlen(s + bg[i]);
		rep(j, ln[i]) {
			if (s[bg[i] + j] == '(') {
				++ b[i];
			} else {
				if (b[i]) -- b[i];
				else ++ a[i];
			}
		}
		bg[i + 1] = bg[i] + ln[i];
		id[i] = i;
	}
	sort(id, id + n, comp);
	int A = 0;
	rep(xx, n) {
		int i = id[xx];
		A -= a[i];
		if (A < 0) NO();
		A += b[i];
	}
	if (A != 0) NO();
	puts("Yes");
	return 0;
}


#include <iostream>
using namespace std;
int  partition(int A[],int n,int p,int r){

	int i=p-1;
	int x=A[r];
	for(int j=p;j<r;j++){
		if(A[j]<=x){
			++i;
			int t=A[j];
			A[j]=A[i];
			A[i]=t;
		}
	}
	A[r]=A[i+1];
	A[i+1]=x;

	return i+1;
}
int main(){
	int n;
	cin>>n;
	int *A=new int[n];
	for(int i=0;i<n;i++)cin>>A[i];

    int q=partition(A,n,0,n-1);

    for(int i=0;i<n;i++){
    	if(i>0)cout<<' ';
    	if(i==q)cout<<"[";
    	cout<<A[i];
        if(i==q)cout<<"]";
    }
    cout<<endl;

    return 0;
}

#include<iostream>
using namespace std;

int main(){
  int a[100001],n,count=0;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>a[i];

  for(int i=0;i<n;i++)
    if(a[i]>a[n-1])
      count++;
    else
      swap(a[i],a[i-count]);

  for(int i=0;i<n-count-1;i++)
    cout<<a[i]<<' ';
  cout<<'['<<a[n-count-1]<<']'<<' ';
  for(int i=n-count;i<n-1;i++)
    cout<<a[i]<<' ';
  cout<<a[n-1]<<endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}
bool bitcheck(ll x, ll y) { return (x >> y) & 1; }

template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}
map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    ll n, m;
    cin >> n >> m;
    primeFactors(m);
    ll ans = 1;
    for (auto x : cnt) {
        ans *= nCkmod(x.second + n - 1, n - 1, mod);
        ans %= mod;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

bool cmp(P a, P b)
{
    return a.first < b.first;
}

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

    int N;
    ll M;

    cin >> N >> M;

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

    ll ans=0;
    vector<P> div;

    for(ll i=2; i*i<=M; i++)
    {
        ll cnt = 0;
        if(M%i==0)
        {
            cnt=M/i;
            div.push_back(P(i, cnt));
            div.push_back(P(cnt, i));
        }
    }

    sort(div.begin(), div.end(), cmp);
    reverse(div.begin(), div.end());

    rep(i, div.size())
    {
        if(div[i].second>=N)
        {
            cout << div[i].first << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;

}


#include <cstdio>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int, int> P;
P po[100], res[100];
int main() {
    int n; scanf("%d",&n);
    for (int i=0; i<n; i++) {
        po[i].second=i;
        po[i].first=0;
    }
    for (int i=0; i<n*(n-1)/2; i++) {
        int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
        if (c>d) {
            po[a-1].first+=3;
        } else if (c<d) {
            po[b-1].first+=3;
        } else {
            po[a-1].first++;
            po[b-1].first++;
        }
    }
    sort(po, po+n);
    int pos=1, cnt=0, bef=0;
    for (int i=n-1; i>=0; i--) {
        if (bef!=po[i].first) {
            pos+=cnt;
            res[i].first=po[i].second;
            res[i].second=pos;
            cnt=1; bef=po[i].first;
        } else {
            res[i].first=po[i].second;
            res[i].second=pos;
            cnt++;
        }
    }
    sort(res,res+n);
    for (int i=0; i<n; i++) printf("%d\n",res[i].second);
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void pv(vector <int> &v) {
    for(int i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve() {

}

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

    ll n;
    cin >> n;
    vector <int> a(n, 0);
    vector <int> b(n, 0);

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

    reverse(b.begin(),b.end());
    // pv(b);
    int prob = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) prob++;
    }
    int c = -1;
    int l = INT_MAX;
    int r = INT_MIN;
    for(int i = 0; i < n; i++) {
        if(a[i] == b[i]) {
            c = a[i];
            l = i;
            break;
        }
    }
    for(int i = n-1; i >= 0; i--) {
        if(a[i] == b[i]) {
            r = i;
            break;
        }
    }

    int toSwap = (r-l+1);
    if(toSwap == 0 || prob == 0) {
        cout << "Yes" << endl;
        pv(b);
        return 0;
    }
    int l0 = l;
    int r0 = r;
    int avail = 0;
    for(int i = 0; i < l; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    for(int i = r+1; i < n; i++) {
        if(a[i] != c && b[i] != c) avail++;
    }
    if(avail < toSwap) {
        cout << "No" << endl;
        return 0;
    }
    else cout << "Yes" << endl;

    int i = 0;
    int j = r0+1;

    while(l <= r) {
        if(i < l0 && i < n) {
            if(a[i] != c && b[i] != c) {
                swap(b[i], b[l]);
                l++;
            }
        }
        i++;
        if(i == n) break;
    }
    // if(j < n) {
        while(l <= r) {
            if(j < n && a[j] != c && b[j] != c) {
                swap(b[j], b[l]);
                l++;
            }
            j++;
            // if(j == n) break;
        }
    // }

    // while(l <= r) {
    //     if(i < l0 && a[i] != c && b[i] != c) {
    //         swap(b[i], b[l]);
    //         l++;
    //         i++;
    //         continue;
    //     }
    //     else if(i == l0 && a[j] != c && b[j] != c && j < n) {
    //         swap(b[j], b[l]);
    //         l++;
    //         j++;
    //         continue;
    //     }
    //     i++;
    //     if(i == l0) j++;
    // }
    pv(b);

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        m[a]++;
    }
    vector<int> use;
    for(auto p:m){
        if(p.second>=4){
            use.push_back(p.first);
            use.push_back(p.first);
        }
        else if(p.second >=2){
            use.push_back(p.first);
        }
    }
    sort(use.begin(), use.end());
    reverse(use.begin(), use.end());
    if(use.size()<=1){
        cout << 0 << endl;
        return 0;
    }
    cout << (ll)use.at(0)*use.at(1) << endl;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    int A, B; cin >> A >> B;
    A--, B--;
    int h = 100, w = 100;
    vector<string> maze(h, string(w, '.'));
    rep(i, h/2) maze[i] = string(w, '#');

    bool flag = false;
    for (int i = 0; i < h / 2; i += 2) {
        for (int j = 0; j < w; j += 2) {
            if (A == 0) {
                break;
                flag = true;
            }
            maze[i][j] = '.';
            A--;
        }
        if (flag) break;
    }
    flag = false;
    for (int i = h / 2 + 1; i < h; i += 2) {
        for (int j = 0; j < w; j += 2) {
            if (B == 0) {
                break;
                flag = true;
            }
            maze[i][j] = '#';
            B--;
        }
        if (flag) break;
    }
    cout << h << ' ' << w << endl;
    rep(i, h) {
        cout << maze[i] << endl;
    }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
 int a, b, c;
 cin >> a >> b >> c;

 if (a <= b*c)
  cout << "Yes" << endl;
 else
  cout << "No" << endl;
}

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

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

  if(d % s == 0 && d / s <= t){
    cout << "Yes" << endl;
    return 0;
  }else if(d % s != 0 && d / s < t){
    cout << "Yes" << endl;
    return 0;
  }else{
    cout << "No" << 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 REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,ans=0;cin>>n;
    multiset<ll> v;
    rep(i,n){
        ll a;cin>>a;
        v.insert(a);
    }
    while(!v.empty()){
        auto it=v.end();
        it--;
        ll k=1;
        while(k<=*it)k*=2;
        k=k-*it;
        v.erase(it);
        auto w=v.lower_bound(k);
        if(*w==k){
            ans++;
            v.erase(w);
        }
    }
    out(ans);
}

#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";};
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n;
Vi a;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n;
	a.resize(n);
	map<ll,ll> ma;
	rep(i,n){
		cin>>a[i];
		ma[a[i]]++;
	}
	ll idt = 1;
	Vi tws;
	Sort(a);
	ll mx = a[0] + a[1];
	while(idt<=mx){
		idt *= 2;
		tws.pb(idt);
	}
	ll ans = 0;
	rep(i,n){
		if(ma[a[i]]<=0)continue;
		ll id = upper_bound(all(tws),a[i]) - tws.begin();
		for(ll j=tws.size();j>=id;j--){
			ll now = tws[j] - a[i];
			if(ma[now]<=0)continue;
			if(a[i]==now){
				if(ma[a[i]]>=2){
					ans++;
					ma[a[i]] -= 2;
					break;
				}
			}else{
				ans++;
				ma[a[i]]--;
				ma[now]--;
				break;
			}
		}
	}
	print(ans);
	return 0;
}


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

const int mod = 1e9 + 7;

int main() {
	int n, m; cin >> n >> m;
	vector<ll>x(n), y(m); for (auto&& xx : x)cin >> xx;for (auto&& yy : y)cin >> yy;
	sort(x.begin(), x.end());sort(y.begin(), y.end());
	ll a = 0, b = 0;
	for (int i = 0; i < n; i++)a -= x[i] * (n - 1 - i - i);
	for (int i = 0; i < m; i++)b -= y[i] * (m - 1 - i - i);
	cout << (a % mod) * (b % mod) % mod << endl;
	return 0;
}

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

long long n, m, x[100004], y[100004];
const int mod = 1000000007;
long long mul(long long a, long long b){
	long long ret = a * b;
	return ret% mod;
}
long long sum(long long a, long long b){
	return (a+b)%mod;
}
int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n>>m;
	for(int i = 0;i<n;i++)	cin>>x[i];
	for(int i = 0;i<m;i++)	cin>>y[i];
	int ver = 0, hor = 0;
	for(int i = 1;i<n;i++)	ver = sum(ver,mul(mul(x[i]-x[i-1],i),n-i));

	for(int i = 1;i<m;i++)	hor = sum(hor,mul(mul(y[i]-y[i-1],i),m-i));
	cout<<mul(ver,hor);
	return 0;
}


//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define ft first
#define sd second
#define mp(x,y) make_pair(x,y)
//#define int LL
using namespace std;
const int N   = 3e5+233;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,n) for (int i=1;i<=n;++i)
#define repp(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
int n,a[N],b[N],c[N],d[N];
signed main()
{
	read(n);
	rep(i,n)  read(a[i]),++c[a[i]];
	rep(i,n) read(b[i]),++d[b[i]];
	reverse(b+1,b+1+n);
	rep(i,n ) if (c[i]+d[i]>n)
	{
		printf("No");
		return 0;
	}
	int l=n,r=1;
	rep(i,n) if (a[i]==b[i])  l=min(l,i),r=max(r,i);
	int pos=l;
	for (int i=1;i<l&&pos<=r;++i) if (b[i]!=a[l]&&a[i]!=a[l]) swap(b[i],b[pos]),++pos;
	for (int i=r+1;i<=n&&pos<=r;++i) if (b[i]!=a[l]&&a[i]!=a[l]) swap(b[i],b[pos]),++pos;

	printf("Yes\n");
	rep(i,n) printf("%d ",b[i]);
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

// KMP
template <class T>
std::vector<int> KMP(T& S)
{
    std::vector<int> A(S.size()+1);
    A[0] = -1;
    int j = -1;

    for(int i=0; i<S.size(); i++){
        while(j > -1 && S[j] != S[i]) j = A[j];
        j++;
        A[i+1] = j;
    }

    return A;
}

// detect T from S
template <class Type>
std::vector<int> matchedIndex(Type& S, Type& T)
{
    std::vector<int> ret;
    std::vector<int> A = KMP(T);

    for(int m = 0, i = 0; m + T.size() <= S.size();){
        while(m+i < S.size() && i < T.size() && S[m+i] == T[i]) i++;
        if(i == T.size()) ret.push_back(m);
        m += std::max(i - A[i], 1);
        i = std::max(A[i], 0);
    }

    return ret;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for(auto& x: a) cin >> x;
    for(auto& x: b) cin >> x;
    a.push_back(a[0]);
    b.push_back(b[0]);

    vector<int> c(N), d(2*N);
    for(int i=0; i<N; i++){
        c[i] = a[i] ^ a[i+1];
        d[i] = b[i] ^ b[i+1];
        d[N+i] = d[i];
    }
    d.pop_back();

    vector<int> index = matchedIndex(d, c);
    for(auto& k: index){
        k = (N-k)%N;
    }
    sort(index.begin(), index.end());

    for(auto& k: index){
        cout << k << " " << (a[k] ^ b[0]) << endl;
    }
}


#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
#define Mod = 1e9 + 7;
#define mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
void spsp(vector<ll>&v) {
	for (int i = 0; i < v.size(); i++) {
		printf("%lld%s", v[i], (i == v.size() - 1 ? "\n" : " "));
	}
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int n;
	vector<H>a;
	cin >> n;
	int mx = -Inf, mn = Inf;
	for (int i = 0; i < n; i++) {
		int u, v;
		cin >> u >> v;
		a.push_back(H{ --u,v });
		chmax(mx, a[i].x);
		chmin(mn, a[i].y);
	}
	int ans = 0;
	for (auto z : a) {
		chmax(ans, max(0ll, mn - mx) + z.y - z.x);
	}
	vector<H>v;
	for(int i=0;i<n;i++){
		int c = max(0ll, mn - a[i].x);
		int d = max(0ll, a[i].y - mx);
		v.push_back(H{ d, -c });
	}
	sort(all(v));
	int w = inf;
	for(int i=0;i<n;i++){
		auto z = v[i];
		z.y = -z.y;
		if (i) chmax(ans, w + z.x);
		chmin(w, z.y);
	}
	cout << ans << endl;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int n,m,used[101010],cmp[101010];
vector<int> v[101010],rv[101010],vs;

void dfs(int x){
   used[x]=true;
   for(auto to:v[x])if(!used[to])dfs(to);
   vs.push_back(x);
}

void rdfs(int x,int k){
   used[x]=true;
   cmp[x]=k;
   for(auto to:rv[x])if(!used[to])rdfs(to,k);
}

int scc(){
   rep(i,n)if(!used[i])dfs(i);
   rep(i,n)used[i]=0;
   reverse(vs.begin(),vs.end());
   int k=0;
   for(auto x:vs)if(!used[x])rdfs(x,k++);
   return k;
}
int main(){
    cin>>n>>m;
    rep(i,m){
        int s,t;
        cin>>s>>t;
        v[s].push_back(t);
        rv[t].push_back(s);
    }
    scc();
    int q;
    cin>>q;
    rep(i,q){
        int s,t;
        cin>>s>>t;
        cout<<(cmp[s]==cmp[t])<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

const int N = 108;

int n;
int a[N], b[N];

int main() {
	int i, mid;
	scanf("%*d%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", a + i);
	if (n == 1) return *a == 1 ? puts("1\n1\n1") : printf("%d\n2\n1 %d\n", *a, *a - 1), 0;
	mid = std::partition(a, a + n, [] (const int x) -> bool {return x % 2;}) - a;
	if (mid > 2) return puts("Impossible"), 0;
	a[n] = *a;
	for (i = 1; i <= n; ++i) printf("%d%c", a[i], i == n ? 10 : 32);
	memcpy(b + 1, a + 1, n << 2), ++b[1], --b[n], n -= !b[n];
	printf("%d\n", n);
	for (i = 1; i <= n; ++i) printf("%d%c", b[i], i == n ? 10 : 32);
	return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105;
int n,m,a[maxn],b[maxn];
inline char nc(){
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=m;i++) a[i]=read();
	for (int i=2;i<=m;i++)
	if(a[i]&1) swap(a[i],a[1]);
	for (int i=m-1;i>1;i--)
	if(a[i]&1) swap(a[i],a[m]);
	for (int i=2;i<m;i++)
	if(a[i]&1) return puts("Impossible")&0;
	for (int i=1;i<=m;i++)
	printf("%d",a[i]),putchar(i==m?'\n':' ');
	if(a[1]>1) b[++b[0]]=a[1]-1;
	for (int i=2;i<m;i++) b[++b[0]]=a[i];
	if(m>1){
		b[++b[0]]=2;
		if(a[m]>1) b[++b[0]]=a[m]-1;
	}else b[++b[0]]=1;
	for (int i=0;i<=b[0];i++)
	printf("%d",b[i]),putchar(!i||i==b[0]?'\n':' ');
	return 0;
}


  /********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

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

#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos

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

#define vpi                         <vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
int32_t main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i<n;i++)
		cin >> a[i];
	int mn = MX,cnt = 0;
	for(int i = 0;i<n;i++)
	{
		mn = min(mn,a[i]);
		if(a[i] <= mn)
		{
			cnt++;
		}
	}
	cout <<cnt<<endl;
}

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

int main() {
  ll n; cin >> n;
  vll A(5);
  rep(i,5) cin >> A[i];
  rep(i,4) {
    if (A[i] < A[i+1]) A[i+1] = A[i];
  }
  ll ans = 4 + (n-1)/A[4] + 1;
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
	vector<int> card(5);
	vector<int> count(13);
	string handName[7] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
	int hand;
	int max, pair;
	int i;

	while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF) {
		fill(count.begin(), count.end(), 0);
		max = 0;
		pair = 0;
		for (i = 0; i < 5; i++) {
			if ( ++count[card[i]-1] > max )
				max = count[card[i]-1];
			if ( count[card[i]-1] == 2 )
				pair++;
		}

		if (max == 4) hand = 6;
		else if (max==3 && pair==2) hand = 5;
		else if (max == 3) hand = 3;
		else if (pair == 2) hand = 2;
		else if (pair == 1) hand = 1;
		else hand = 0;
		if (hand < 4) {
			for (i = 0; i < 13-3; i++) {
				if (count[i]==1 && count[i+1]==1 && count[i+2]==1 && count[i+3]==1 && count[(i+4)%13]==1)
					hand = 4;
			}
		}

		cout<<handName[hand]<<endl;
	}
	return 0;
}


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

int N, M;
int score[1002001];
int point[1001];
int bin_search(int n){
    int h=0, t=(N+1)*(N+1);
    int temp;
    int status;
    while(h<=t){
        temp = (t+h)/2;
        if(n == score[temp]) return -1;
        else if(n > score[temp]){
            h = temp + 1;
            status = 1;
        }else{
            t = temp - 1;
            status = 0;
        }
    }
    if(status){
        return score[temp];
    }else{
        return score[temp-1];
    }
}
int main(){
    int a;
    int size;
    int b;
    int m;
    cin >> N >> M;
    while(N || M){
        m = 0;
        point[0] = 0;
        for(int i=1;i<=N;i++){
            cin >> point[i];
        }
        size = -1;
        for(int i=0;i<=N;i++){
            for(int j=0;j<=N;j++){
                score[size++] = point[i]+point[j];
            }
        }
        sort(score,score+size);
        for(int i=0;i<size && score[i] < M;i++){
            b = bin_search(M-score[i]);
            if(b == -1){
                break;
            }else{
                m = max(m, b+score[i]);
            }
        }
        cout << m << endl;
        cin >> N >> M;
    }
}

#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int in()
{
	int x;cin>>x;
	return x;
}
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

int main ()
{
	int n,m;
	while(cin>>n>>m&&n&&m)
	{
		vector<long long > a,b;
		b.push_back(0);
		rep(i,n)
		{
			b.push_back(in());
		}
		rep(i,n+1)
		{
			rep(l,n+1)
			{
				a.push_back(b[i]+b[l]);
			}
		}
		long long ans = 0;
		sort(a.begin(),a.end());
		rep(i,a.size())
		{
			vector<long long>::iterator t=upper_bound(a.begin(),a.end(),m-a[i]);
			if(t==a.begin())continue;
			t--;
			ans=max(ans,*t+a[i]);
		}
		cout<<ans<<endl;

	}

}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int t = 753;
	int d = 1000;
	string res;
	for (int i = 0; i + 2 < n; i++) {
				string ss = string(1, s[i]) + string(1, s[i + 1]) + string(1, s[i + 2]);
				if (abs(stoi(ss) - t) < d) {
					res = ss;
					d = abs(stoi(ss) - t);
				}

	}
	cout << d << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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 (a>b) { a=b; return 1; } return 0; }

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

  int n = s.length();
  rep(i, n - 1) {
    if (s.substr(i, 2) == "AC") {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	ll n;
	cin>>n;
	ll a[n],ans=0,mins=n+1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<mins){
			ans+=mins-a[i]-1;
			mins=a[i];
		}
	}
	cout<<n-ans;
}

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


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

int main() {
  int A, B, i, a, b, x, y, z = 0;
  cin >> A >> B;
  for (int i = A; i < B + 1; i++){
    a = i / 10000;
    b = (i / 1000) % 10;
    x = i % 10;
    y = (i % 100) / 10;
    if (a == x && b == y){
      z += 1;
    }
    else
      continue;
  }
  cout << z << endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  cout << n - k + 1 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 1e6;
const int MOD = 1e9+7;

int ans;
int n;
ll v[MAX], sum[MAX];

void solve() {
	cin >> n;
	for(int i=0; i<n; i++) cin >> v[i];
	ans = 0;
	for(int i=0; i<61; i++) {
		ll c1 = 0;
		for(int j=0; j<n; j++) c1 += (v[j] >> i)&1;
		ll sum = c1*(n-c1);
		for(int j=0; j<i; j++) sum = 2*sum % MOD;
		ans = (ans + sum) % MOD;
	}
	cout << ans%MOD << "\n";
}

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

 	solve();

  	return 0;
}

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

int lengths[105];
bool allDifferent(int len1, int len2, int len3)
{
	return (len1 != len2) && (len2 != len3) && (len3 != len1);
}

bool canFormTriangle(int len1, int len2, int len3)
{
	int maxLen = max(max(len1, len2), len3);
	return len1 + len2 + len3 - maxLen > maxLen;
}

int main()
{
	int N;
	scanf("%d", &N);

	for(int i = 1; i <= N; i++)
		scanf("%d", &lengths[i]);

	int ans = 0;
	for(int i = 1; i <= N; i++)
	{
		for(int j = i + 1; j <= N; j++)
		{
			for(int k = j + 1; k <= N; k++)
			{
				if(allDifferent(lengths[i], lengths[j], lengths[k]) && canFormTriangle(lengths[i], lengths[j], lengths[k]))
					ans++;
			}
		}
	}

	printf("%d", ans);
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int64_t i=1;i<n;++i){
    if(i*i>n){
      cout<<(i-1)*(i-1)<<endl;
      return 0;
    }
  }
  cout<<1<<endl;
}

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

typedef long long ll;

ll e, m, x, min_;

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

    while (cin >> e, e) {
        min_ = m = (int)(1e9 + 7);

        for (int y = 0; y <= sqrt((double)e); y++) {
            for (int z = 0; z <= sqrt((double)e); z++) {
                x = e - y * y - z * z * z;
                if (x < 0) break;
                else {
                    m = x + y + z;
                    //cout << "x, m = " << x << " " << m << endl;
                    if (min_ > m) min_ = m;
                }
            }
        }

        cout << min_ << endl;
    }

    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, M, A[1005], B[1005];
ll ans = 1;

int main(){
	getint(N), getint(M);
	for(register int i = 1; i <= N; i++) getint(A[i]);
	for(register int i = 1; i <= M; i++) getint(B[i]);
	sort(A + 1, A + N + 1), sort(B + 1, B + M + 1), A[N + 1] = B[M + 1] = inf;
	for(register int i = 1; i < N; i++) if(A[i] == A[i + 1]) return puts("0"), 0;
	for(register int i = 1; i < M; i++) if(B[i] == B[i + 1]) return puts("0"), 0;
	for(register int i = 1, j = 1, k = 1; i <= N * M; i++){
		while(j <= N && A[j] < i) j++;
		while(k <= M && B[k] < i) k++;
		if(A[j] == i && B[k] != i) ans = ans * (M - k + 1) % MOD;
		else if(A[j] != i && B[k] == i) ans = ans * (N - j + 1) % MOD;
		else if(A[j] != i && B[k] != i) ans = ans * ((M - k + 1) * (N - j + 1) - (N * M - i)) % MOD;
	}
	return printf("%lld\n", ans), 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

ll ca[1111111]={};
ll cb[1111111]={};

int main(){
  ll n,m,p=1e9+7;
  cin>>n>>m;

  ll f=0;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    ca[a]++;
    if(ca[a]==2)f=1;
  }
  for(int i=0;i<m;i++){
    ll b;
    cin>>b;
    cb[b]++;
    if(cb[b]==2)f=1;
  }

  ll nm=n*m;
  if(ca[nm]==0||ca[nm]==0||f){
    cout<<0<<endl;
    return 0;
  }

  ll cr=0,cc=0;
  ll ans=1;
  ll c0=0;
  for(int i=nm;i>0;i--){
    //    cout<<ans<<" "<<cr<<" "<<cc<<endl;
    if(ca[i]&&cb[i]){
	 cc++;
	 cr++;
	 c0++;
	 continue;
    }
    if(ca[i]){
	 ans*=cc;
	 ans%=p;
	 cr++;
	 c0++;
	 continue;
    }
    if(cb[i]){
	 ans*=cr;
	 ans%=p;
	 cc++;
	 c0++;
	 continue;
    }
    ans*=(cr*cc-c0);
    ans%=p;
    c0++;
    continue;
  }

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


#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define eb emplace_back
using namespace std;
string s;
ll ans=1,cnt=0,n;
const int mod=1e9+7;
int main(){
    cin>>n>>s;
    for(auto x:s){
        if(x=='W'&&(cnt&1)){
            cnt++;
        }else if(x=='B'&&!(cnt&1)){
            cnt++;
        }else{
            (ans*=cnt)%=mod;
            cnt--;
        }
    }
    for(ll i=1;i<=n;i++){
        (ans*=i)%=mod;
    }
    if(cnt){
        ans=0;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=2e5+2,M=1e9+7;

int32_t main(){

    int n;
    string s;
    cin>>n>>s;
    int ans=1,fac=1,bal=0;
    for(int i=1;i<=n;++i)(fac*=i)%=M;
    for(char c:s){
        if(c=='B'){
            if(bal&1){
                (ans*=bal)%=M;
                bal--;
            }else{
                bal++;
            }
        }else{
            if(bal&1){
                bal++;
            }else{
                (ans*=bal)%=M;
                bal--;
            }
        }
    }
    if(bal!=0)ans=0;
    cout<<(ans*fac)%M<<'\n';

    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n - 8; ++i) {
    cout << s[i];
  }
  puts("");
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

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

int main(){

  string s;cin>>s;
  out(s.substr(0,s.size()-8));

  return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n;
    int a;
    int count = 1e9;
    cin >> n;
    for(int i = 0;i<n;i++){
        cin >> a;
        int key = 0;
        while(a%2 == 0){
            a /= 2;
            key++;
        }
        if(key<count){
            count = key;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	ll n, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  string x;
  cin >> x;
  for(int i=x.length()-1;i>=0;i--)
    cout << x[i];
  cout << endl;
  return 0;
}

#include<iostream>
#include<string>
#include<iterator>

std::string reverse_str(std::string str);

int main()
{
	std::string str;
	while (std::cin >> str)
	{
		str = reverse_str(str);
		std::cout << str << std::endl;
	}
	return 0;
}

std::string reverse_str(std::string str)
{
	std::string str_ans;
	for (unsigned long i = 1; i <= str.size(); ++i)
	{
		std::string::iterator it = std::prev(end(str), i);
		str_ans += *it;
	}
	return str_ans;
}


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

#define Int register int
#define mod 1000000007

template <typename T> inline void read (T &t){t = 0;char c = getchar();int f = 1;while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}while (c >= '0' && c <= '9'){t = (t << 3) + (t << 1) + c - '0';c = getchar();} t *= f;}
template <typename T,typename ... Args> inline void read (T &t,Args&... args){read (t);read (args...);}
template <typename T> inline void write (T x){if (x < 0){x = -x;putchar ('-');}if (x > 9) write (x / 10);putchar (x % 10 + '0');}

int N,X,Y,Z,dp[41][1 << 17];

int mul (int a,int b){return 1ll * a * b % mod;}
int dec (int a,int b){return a >= b ? a - b : a + mod - b;}
int add (int a,int b){return a + b >= mod ? a + b - mod : a + b;}
void Add (int &a,int b){a = add (a,b);}
int qkpow (int a,int b){
	int res = 1;for (;b;b >>= 1,a = mul (a,a)) if (b & 1) res = mul (res,a);
	return res;
}

signed main(){
	read (N,X,Y,Z),dp[0][0] = 1;
	int ans = 1,up = (1 << X + Y + Z) - 1,st = (1 << X + Y + Z - 1) | (1 << Y + Z - 1) | (1 << Z - 1);
	for (Int i = 1;i <= N;++ i){
		ans = 1ll * ans * 10 % mod;
		for (Int S = 0;S <= up;++ S)
			if (dp[i - 1][S] && (S & st) != st)//(S&st)!=st：如果前面还没有出现过合法解
				for (Int c = 1;c <= 10;++ c)
					Add (dp[i][((S << c) | (1 << c - 1)) & up],dp[i - 1][S]);
	}
	for (Int S = 0;S < (1 << X + Y + Z);++ S) if ((S & st) != st) ans = dec (ans,dp[N][S]);
	write (ans),putchar ('\n');
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 45,mx = 1 << 17 + 5;
int n,x,y,z;
int lim,chk,ans = 0;
int dp[N][mx] = {0};
int fa[N][mx] = {0};
int main(){
	scanf("%d%d%d%d",&n,&x,&y,&z);
	lim = 1 << (x+y+z);
	chk = (1 << (x+y+z-1)) + (1 << (y+z-1)) + (1 << (z-1));
	fa[0][0] = 1;
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<lim;j++){
			for(int k = 1;k<=10;k++){
				int res = ((j << k) + (1 << (k-1))) % lim;
				if((res & chk) == chk) dp[i][res] += fa[i-1][j];
				else dp[i][res] += dp[i-1][j];
				dp[i][res] %= mod;
				fa[i][res] = (fa[i][res] + fa[i-1][j]) % mod;
			}
		}
	}
	for(int i = 0;i<lim;i++) ans = (ans + dp[n][i]) % mod;
	printf("%d",ans);
	return 0;
}


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

int main(){

  int i;
  double x,sum,v1,v2,a[100];

  while(cin >> a[0]){

    sum = 0;

    for(i=1;i<9;i++) scanf(",%lf",&a[i]);
    scanf(",%lf,%lf,%lf",&a[9],&v1,&v2);

    for(i=0;i<10;i++) sum += a[i];

    x = sum/(v1+v2);

    sum = v1 * x;

    for(i=0;i<10;i++){
      if(sum - a[i] > 0) sum -= a[i];
      else{
	cout << i+1 << endl;
	break;
      }
    }

  }
}

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

int main()
{

  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int dx=abs(sx-tx);
  int dy=abs(sy-ty);
  cout<<string(dx,'R')<<string(dy,'U');
  cout<<string(dx,'L')<<string(dy,'D');
  cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
  cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
  cout<<endl;
  return 0;

}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  int x = tx - sx; int y = ty - sy;
  vector<string> ans;
  REP(i, y) ans.push_back("U");
  REP(i, x) ans.push_back("R");
  REP(i, y) ans.push_back("D");
  REP(i, x) ans.push_back("L");
  ans.push_back("L");
  REP(i, y + 1) ans.push_back("U");
  REP(i, x + 1) ans.push_back("R");
  ans.push_back("D");
  ans.push_back("R");
  REP(i, y + 1) ans.push_back("D");
  REP(i, x + 1) ans.push_back("L");
  ans.push_back("U");
  REP(i, ans.size()) cout << ans[i];
  cout << endl;
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long LL;

const int MOD = 1000000007;
const int MAXN = 2 * 100005;

LL H, W;
LL A, B;
LL fact[MAXN];

// Exponentiation by squaring
LL expsq(LL x, LL p) {
	LL res = 1;
	while (p > 0) {
		if (p & 1) {
			res = (res * x) % MOD;
		}
		x = (x * x) % MOD;
		p /= 2;
	}
	return res;
}

// Extended Euler's algorithm
LL modinv(LL x) {
	return expsq(x, MOD - 2);
}

LL C(LL n, LL k) {
	return (fact[n] * modinv(fact[n - k] * fact[k] % MOD)) % MOD;
}

int main() {
	cin >> H >> W >> A >> B;
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= MOD;
	}

	LL ans = 0;
	for (LL i = B; i <= W - 1; i++) {
		LL res = C(H - A - 1 + i, i);
		LL end = C(W - i - 1 + A - 1, A - 1);
		res *= end;
		res %= MOD;

		ans += res;
		ans %= MOD;
	}

	cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  int M = N;
  int i = 0;
  int sum = 0;

  while (M >= 1) {
    sum += (M - (M / 10) * 10);
    M = M / 10;
  }

  if (N % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

#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 N;
  cin>>N;
  string tmp = to_string(N);
  int X = 0;
  for(int i=0;i<tmp.size();++i) {
    X += tmp[i]-'0';
  }
  if(N%X==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int lmax = 0, rmin = n;
    rep(i,m) {
      int l, r;
      cin >> l >> r;
      lmax = max(lmax, l);
      rmin = min(rmin, r);
    }
    int ans = rmin - lmax + 1;
    if (ans <= 0) ans = 0;
    cout << ans << endl;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int n,ord[N];
ll val[N],l[N],u[N],b[N],s[N],x;

bool cmp(int x,int y) {return val[x]>val[y];}

ll chk_mx(ll k) {
	ll mx=0;
	ll p=k/x,q=k%x;
	if (p==n) return s[n];
	fo(i,1,n) {
		int z=ord[i];
		ll tmp=(q<=b[z])?q*l[z]:b[z]*l[z]+(q-b[z])*u[z];
		tmp+=(i<=p)?s[p+1]-val[z]:s[p];
		mx=max(mx,tmp);
	}
	return mx;
}

int main() {
	n=read();x=read();
	fo(i,1,n) b[i]=read(),l[i]=read(),u[i]=read();
	fo(i,1,n) val[i]=l[i]*b[i]+(x-b[i])*u[i];
	fo(i,1,n) ord[i]=i;sort(ord+1,ord+n+1,cmp);
	fo(i,1,n) s[i]=s[i-1]+val[ord[i]];
	ll d=0;fo(i,1,n) d+=l[i]*b[i];
	ll L=0,R=0,ans=0;fo(i,1,n) R+=b[i];
	while (L<=R) {
		ll mid=L+R>>1;
		if (chk_mx(mid)>=d) ans=mid,R=mid-1;
		else L=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}


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

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

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

  bool ok = true;
  REP(i,n){
    if(i != n-1){
      if(a[i] == a[i+1]){
        ok = false;
      }
    }
  }

  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;

}

//\\//\\ * * * //\\// ||
#include <bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;

const int N = 110;

int a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) {
          if (a[i] + a[j] > a[k]) {
            ++ans;
//            debug(i);
//            debug(j);
//            debug(k);
//            debug(a[i]);
//            debug(a[j]);
//            debug(a[k]);
          }
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


#ifndef TEMPLATE_HPP
#define TEMPLATE_HPP
#include <bits/stdc++.h>
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())
using namespace std;
using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void chmax(T &x, T y) { x = max(x, y); }
template <typename T> void chmin(T &x, T y) { x = min(x, y); }
template <typename T> T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename U> vector<U> make_vector(T&& n, U&& val) { return vector<U>(forward<T>(n), forward<U>(val)); }
template <typename T, typename... Args> decltype(auto) make_vector(T&& n, Args&&... args) { return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...)); }
const int INF = 1001001001;
const i64 LINF = 1001001001001001001ll;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
#endif

void solve() {
  int n;
  cin >> n;
  vi32 a(n);
  cin >> a;
  sort(a.rbegin(), a.rend());
  map<int, int> cnt;
  rep(i, n) cnt[a[i]]++;
  int ans = 0;
  rep(i, n) {
    if (cnt[a[i]] == 0) continue;
    cnt[a[i]]--;
    int m = 1;
    while (a[i] >= m) m <<= 1;
    int b = m - a[i];
    if (cnt[b] == 0) continue;
    cnt[b]--;
    ans += 1;
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  solve();
  return 0;
}

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

int main()
{
    int n;
    while(1)
    {
        int sell_num[10] = {};
        cin >> n;
        if(n == 0)
        {
            break;
        }
        for(int i=0; i<n; i++)
        {
            int id;
            cin >> id;
            sell_num[id]++;
        }
        for(int i=0; i<10; i++)
        {
            if(sell_num[i] == 0)
            {
                cout << "-" << endl;
            }
            else
            {
                string str;
                for(int j=0; j<sell_num[i]; j++)
                {
                    str += "*";
                }
                cout << str << endl;
            }
        }
    }
    return 0;
}


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

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

using ld=long double;

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    ld n,m,d;
    cin>>n>>m>>d;
    ld ans=(m-1.0)*(n-d);
    if(d!=0.0) ans *=2.0;
    ans /=n;
    ans /=n;
    cout<<ans<<'\n';
}/*
./problem.exe
*/


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

int main(){
    string root;
    int sx, sy, tx, ty;
    int dx, dy;
    int i, j;

    cin >> sx >> sy >> tx >> ty;

    dx = tx - sx;
    dy = ty - sy;

    //root = NULL;
    //root = '\0';

    root = 'R';

    for (i=1; i<dx; i++){
        root = root + 'R';
    }
    for (i=0; i<dy; i++) {
        root = root + 'U';
    }
    for (i=0; i<dx; i++){
        root = root + 'L';
    }
    for (i=0; i<dy; i++) {
        root = root + 'D';
    }

    root = root +'L';
    for (i=0; i<dy+1; i++) {
        root = root + 'U';
    }
    for (i=0; i<dx+1; i++){
        root = root + 'R';
    }
    root = root +'D';

    root = root +'R';
    for (i=0; i<dy+1; i++) {
        root = root + 'D';
    }
    for (i=0; i<dx+1; i++){
        root = root + 'L';
    }
    root = root +'U';

    cout << root << endl;

}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 100000100LL

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    ll ans = INF, MINa = INF, MINb = INF;
    vector<ll> a(A), b(B);
    rep(i, A){
        cin >> a[i];
        MINa = min(MINa, a[i]);
    }
    rep(i, B){
        cin >> b[i];
        MINb = min(MINb, b[i]);
    }
    ans = min(ans, MINa + MINb);
    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        ll tmp = a[x] + b[y] - c;
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


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

int main() {
    string s,t; cin >> s >> t;
    cout << t+s << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    int k;
    string ss;
    cin>>k>>s;
    if(s.length()>k){
        for(int i=0; i<k; i++){
            ss += s[i];
        }
        ss+="...";
    }
    else {
        ss =s;
    }
    cout<<ss;
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int p;
    string s;
    vector<int>v(n, 0);
    int c = 0, w = 0;
    rep(i, m) {
        cin >> p >> s;
        p--;
        if (v[p] != -1) {
            if (s == "AC") {
                w += v[p];
                c++;
                v[p] = -1;
            }else{
                v[p]++;
            }
        }
    }

    cout << c << ' ';
    cout << w << endl;
    return 0;
}

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

#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0)
{
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

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

const int maxn = 1005;

vector<int>graph[maxn];

vector<int>ans;
int n,m;
int vis[maxn];
void dfs(int u, int target)
{
  vis[u] = 1;
  for(const auto &v: graph[u])
  {
    if(vis[v] == 1)
    {
      if(v == target)
      {
        vector<int>cycle;
        for(int i = 1; i <= n ; i++)
          if(vis[i] == 1)
            cycle.push_back(i);
        if(ans.size() == 0 || cycle.size() < ans.size())
          ans = cycle;
      }
    }
    else if(vis[v] == 0)
    {
      dfs(v, target);
    }
  }
  vis[u] = 2;
}

int main()
{
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for(int i = 0 ; i < m ; i++)
  {
    int u,v;
    cin >> u >> v;
    graph[u].push_back(v);
  }
  for(int i = 1 ; i <= n ; i++)
  {
    MSET(vis, 0);
    dfs(i, i);
  }

  if(ans.size() == 0)
    cout << "-1\n";
  else
  {
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++)
    {
      cout << ans[i] << endl;
    }
  }
  return 0;
}


/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */

#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

int main()
{
    int n;
    scf(n);

    if(n==1)
    cout<<"Hello World";

    else
    {
        int a,b;
        scf(a),scf(b);

        prin(a+b);

    }

}

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

int main() {
	string str;
	int q;
	int a,b;
	string p;
	string query;

	cin>>str;
	cin>>q;
	for(int i=0;i<q;++i){
		cin>>query;
		cin>>a>>b;

		if(query=="print"){
			cout<<str.substr(a,b-a+1)<<endl;
		}else if(query=="reverse"){
			reverse(&(str[a]), &(str[b+1]));
		}else if(query=="replace"){
			cin>>p;
			for(int j=0;j<b-a+1;++j){
				str[a+j] = p[j];
			}
		}
	}
}


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

const int N = 303;
const int MOD = 998244353;

int n, k;
char s[N];

vector<int> ones;

int dp[N][N][N];
int f(int x, int use, int sum) {
  if (use > k) return 0;
  if (x < 0) return sum == 0;
  if (~dp[x][use][sum]) return dp[x][use][sum];

  int ret = f(x-1, use, sum);
  for (int i = 1; i <= ones[x]; ++i) {
    ret = (ret + f(x-1, use + i, sum + i)) % MOD;
  }
  for (int i = 1; i <= sum; ++i) {
    ret = (ret + f(x-1, use, sum - i)) % MOD;
  }

  return dp[x][use][sum] = ret;
}

int solve() {
  scanf("%s %d", s, &k);

  int n = strlen(s);
  ones.push_back(0);
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') {
      ones.push_back(0);
    } else {
      ++ones.back();
    }
  }

  // for (int o: ones) cerr << o << " "; cerr << endl;

  memset(dp, -1, sizeof dp);
  printf("%d\n", f((int) ones.size() - 1, 0, 0));
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}

#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>

#include <istream>
#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace asl
{

    template <typename T>
    std::vector<std::vector<T>> board(int n = 0, int m = 0)
    {
        return std::vector<std::vector<T>>(n, std::vector<T>(m));
    }

}

namespace asl
{

    const int m1000000007 = 1000000007;

    const int m998244353 = 998244353;

    int MOD = m1000000007;

    void set_mod(int mod)
    {
        MOD = mod;
    }

    class Mint
    {
    public:
        int val;

        Mint(long long v = 0)
        {
            if (v >= 0)
            {
                if (v < MOD)
                    val = v;
                else
                    val = v % MOD;
            }
            else
            {
                if (v >= -MOD)
                {
                    val = v + MOD;
                }
                else
                {
                    v %= MOD;
                    if (v < 0)
                        v += MOD;
                    val = v;
                }
            }
        }

        Mint &operator+=(const Mint &other)
        {
            val += other.val;
            if (val >= MOD)
                val -= MOD;
            return *this;
        }

        Mint &operator-=(const Mint &other)
        {
            val -= other.val;
            if (val < 0)
                val += MOD;
            return *this;
        }

        friend std::ostream &operator<<(std::ostream &stream, const Mint &m)
        {
            return stream << m.val;
        }

    };
}

#include <random>

#define endl '\n'

using namespace std;
using namespace asl;

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

    set_mod(m998244353);

    string s;
    int k;

    cin >> s >> k;

    s += "0";

    vector<int> g;
    int total = 0;
    int ones = 0;

    for (auto x : s)
    {
        if (x == '1')
        {
            ++total;
            ++ones;
        }
        else
        {
            g.push_back(total);
            total = 0;
        }
    }

    reverse(g.begin(), g.end());

    auto dp = board<Mint>(ones + 1, ones + 1);

    dp[0][0] = 1;

    for (int i = 0; i < g.size(); ++i)
    {
        auto ndp = board<Mint>(ones + 1, ones + 1);

        for (int k = 0; k <= ones; ++k)
        {
            for (int l = 0; l <= ones; ++l)
            {
                if (l > 0 && k > 0)
                    ndp[l][k] = ndp[l - 1][k - 1];

                int rmin = l - g[i] - 1;
                if (rmin >= 0 && k - l + rmin >= 0)
                    ndp[l][k] -= dp[rmin][k - l + rmin];

                int rmax = l - 1;
                if (rmax >= 0 && k - l + rmax >= 0)
                    ndp[l][k] += dp[rmax][k - l + rmax];
            }
        }

        for (int k = 0; k <= ones; ++k)
        {
            Mint A(0);
            for (int l = ones; l >= 0; --l)
            {
                A += dp[l][k];

                ndp[l][k] += A;
            }
        }

        dp.swap(ndp);

    }

    Mint ans;

    for (int d = 0; d <= min(ones, k); ++d)
    {
        ans += dp[0][d];
    }

    cout << ans << endl;

    return 0;
}


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

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

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

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

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
//最大公約数
template<typename T>
constexpr T gcd(T a, T b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

//最小公倍数
template<typename T>
constexpr T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		PRI("Yay!");
	}
	else PRI(":(");
	return 0;
}

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

    }

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


#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<random>
#include<iomanip>
#include<queue>
#include<stack>
#include<assert.h>
#include<time.h>
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 1000000007;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 2330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
int COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
int dight_min(int n) {
	int ans = 9;
	while (n >= 10) {
		ans = min(ans, n % 10);
		n /= 10;
	}
	ans = min(ans, n);
	return ans;
}
int dight_max(int n) {
	int ans = 0;
	while (n >= 10) {
		ans = max(ans, n % 10);
		n /= 10;
	}
	ans = max(ans, n);
	return ans;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
signed main() {
	int n, m, k;
	cin >> n >> m >> k;
	int xx = 0, yy = 0, memo = comb(n * m - 2, k - 2);
	for (int i = 1; i <= n - 1; i++) {
		int p = ((n - i) * m * m * i) % mod * memo % mod;
		xx += p;
		xx %= mod;
	}
	for (int j = 1; j <= m - 1; j++) {
		int p = ((m - j) * n * n * j) % mod * memo % mod;
		yy += p;
		yy %= mod;
	}
	cout << (xx + yy) % mod << endl;
	ggr
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(ll i=0;i<n;i++)
#define repn(i,n) for(ll i=1;i<=n;i++)
using namespace std;
typedef long long ll;

const ll MOD=1'000'000'007;
const ll c[7]={1,2,3,5,8,13,21};
ll H,W,K;
ll dp[101][8];

int main(){
    rep(i,101) fill(dp[i],dp[i]+8,0);
    dp[0][0]=1;
    cin>>H>>W>>K;

    repn(i,H){
        rep(j,W){
            if(j==0)
                dp[i][j]=dp[i-1][j]*c[max((ll)0,W-2)]
                        +dp[i-1][j+1]*c[max((ll)0,W-3)];
            else if(j==W-1)
                dp[i][j]=dp[i-1][j]*c[max((ll)0,W-2)]
                        +dp[i-1][j-1]*c[max((ll)0,W-3)];
            else
                dp[i][j]=dp[i-1][j-1]*c[max((ll)0,j-2)]*c[max((ll)0,W-j-2)]
                        +dp[i-1][j]*c[max((ll)0,j-1)]*c[max((ll)0,W-j-2)]
                        +dp[i-1][j+1]*c[max((ll)0,j-1)]*c[max((ll)0,W-j-3)];
            dp[i][j]%=MOD;
        }
    }

    ll ans=dp[H][K-1]>=0?dp[H][K-1]:dp[H][K-1]+MOD;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b

signed main(){
	int a,b,c; cin>>a>>b>>c;
	int k; cin>>k;
	int d=max({a,b,c});
	//d*=2;
	rep(i,0,k) d*=2;
	cout<<(a+b+c-max({a,b,c})+d);

	return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  vi d(3);
  rep(i, 3) cin >> d[i];

  int k; cin >> k;
  sort(all(d));

  rep(i, k) d[2] *= 2;

  cout << accumulate(all(d),0) << endl;

  return (0);
}


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

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

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

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

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

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

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

int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll>> z(n+1,vector<ll>(n+1));
    for (int i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        z[a][b]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            z[i][j + 1] += z[i][j];
        }
    }
    for (int i = 0; i < q; i++) {
        ll a, b;
        cin >> a >> b;
        ll ans = 0;
        for (int j = a; j < b+1; j++) {
            ans += z[j][b];
        }
        cout << ans << endl;
    }
}

//-- In The Name of God --
#include<bits/stdc++.h>
using namespace std;

#define      mod     1e9+7
#define      pai     acos(-1)
#define      ff      first
#define      ss      second
#define      ll      long long
#define      pb      push_back
#define      mp      make_pair
#define      endl    "\n"
#define      fii     freopen("input.txt","r",stdin);
#define      foo     freopen("output.txt","w",stdout);
#define      fast    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const   ll   mx=1e5+100;
ll arr[600][600];
map<pair<ll,ll>,bool>visit;
int main()
{
    fast;
    ll i,j,a,b,c,d,n,m,t;
    cin>>n>>m;
    memset(arr,-1,sizeof(arr));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>arr[i][j];
        }
    }
    vector<pair<pair<ll,ll>,pair<ll,ll> > >vec;
    ll flag=1;
    for(i=1;i<=n;i++)
    {
        if(flag==1)
        {
            for(j=1;j<m;j++)
            {
                if(arr[i][j]&1)
                {
                    if(arr[i][j+1]!=-1)
                    {
                        arr[i][j+1]+=1;
                        vec.pb(mp(mp(i,j),mp(i,j+1)));
                    }
                }
            }
            if(arr[i+1][m]!=-1 && arr[i][m]&1)
            {
                arr[i+1][m]+=1;
                vec.pb(mp(mp(i,j),mp(i+1,j)));
            }
            flag=2;
        }
        else if(flag==2)
        {
            for(j=m;j>1;j--)
            {
                if(arr[i][j]&1)
                {
                    arr[i][j-1]+=1;
                    vec.pb(mp(mp(i,j),mp(i,j-1)));
                }
            }
            if(arr[i+1][1]!=-1 && arr[i][1]&1)
            {
                arr[i+1][1]+=1;
                vec.pb(mp(mp(i,j),mp(i+1,j)));
            }
            flag=1;
        }
    }

    ll cnt=vec.size();
    cout<<cnt<<endl;
    for(auto it:vec)
    {
        a=it.first.first;
        b=it.first.second;
        c=it.second.first;
        d=it.second.second;
        cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
    }
    return 0;

}


#include <iostream>

int main () {
	std::string a, b, c;

  std::cin >> a >> b >> c;

  if(a.substr(a.size()-1, 1) == b.substr(0, 1) && b.substr(b.size()-1, 1) == c.substr(0, 1)) {
  	std::cout << "YES" << std::endl;
  }else {
  	std::cout << "NO" << std::endl;
  }
}

#include <stdio.h>

int main() {
  char str[31], ctr = 0;
  scanf("%[^\n]", str);

  for(int i = 0; str[i] != '\0'; i++) {
    if(str[i] == ' ' && str[i-1] == str[i+1]) {
      ctr++;
    }
  }
  if(ctr == 2) {
    puts("YES");
  }
  else {
    puts("NO");
  }
  return 0;
}


#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> poly;
#define pb push_back
const int rlen=1<<18|1,inf=0x3f3f3f3f;
const ll Inf=1e18;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline ll readl() {
  ll ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
inline int Read(char*s) {
  int tp=0;
  char ch=gc();
  while(!isdigit(ch)&&!isalpha(ch)) ch=gc();
  while(isdigit(ch)||isalpha(ch)) s[++tp]=ch,ch=gc();
  return tp;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
  inline int sqr(int a) { return mul(a,a); }
  inline int cub(int a) { return (ll)a*a%mod*a%mod; }
}
using namespace modular;
template<typename T> inline void ckmax(T&a,T b) { a<b?a=b:0; }
template<typename T> inline void ckmin(T&a,T b) { a>b?a=b:0; }
template<typename T> inline T gcd(T a,T b) { T t;while(b)t=a,a=b,b=t-t/a*a;return a; }
template<typename T> inline T Abs(T x) { return x<0?-x:x; }
inline int rd() { return rand()|(rand()<<15); }
const int N=5e5+5;
int n,pre[N],suf[N];
pii a[N];
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read();
  for(ri i=1;i<=n;++i) a[i].fi=read(),a[i].se=read();
  sort(a+1,a+n+1);
  pre[0]=0x3f3f3f3f,suf[n]=0x3f3f3f3f;
  for(ri i=1;i<n;++i) pre[i]=min(pre[i-1],a[i].se);
  for(ri i=n-1;i;--i) suf[i]=min(suf[i+1],a[i].se);
  int res=0;
  for(ri mn,r1,r2,t,i=1;i<n;++i) {
    r1=a[i].se,r2=min(max(suf[i+1],a[n].fi-1),a[n].se);
    t=(r1-a[i].fi+1)+(r2-a[n].fi+1);
    mn=pre[i-1];
    ckmax(res,t-max(0,min(r1-max(a[i].fi-1,mn),r2-max(a[n].fi-1,mn))));
  }
  cout<<res;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 100010;
const int INF = INT_MAX/2;

int n;
vector <pi> v;
int pre[maxn],suf[maxn];

int dist(int x, int y) {
	return max(y - x + 1,0ll);
}

int32_t main() {
	FAST
	cin >> n;
	v.push_back(pi(0,0));
	for (int i =1;i<=n;i++) {
		int a,b; cin >> a >> b;
		v.push_back(pi(a,b));
	}
	sort(all(v));

	//CASE 1: All .f of group 1 < All .f of group 2
	//prefix[i] from 1 to i
	int maxl=0, minr=INF;

	for (int i = 1;i<=n;i++) {
		maxl = max(maxl,v[i].f);
		minr = min(minr,v[i].s);

		pre[i] = dist(maxl,minr);
	}
	int whack = pre[n];

	//Suffix[i] from n to i+1
	maxl = 0; minr = INF;
	for (int i =n-1;i>=1;i--) {
		maxl = max(maxl,v[i+1].f);
		minr = min(minr,v[i+1].s);

		suf[i] = dist(maxl,minr);
	}
	int ans = 0;
	for (int i =1;i<n;i++) {
		ans = max(ans, pre[i] + suf[i]);
	}

	//CASE 2: Just take largest guy for group 1 and throw the rest into group 2.

	for (int i =1;i<=n;i++) {
		ans = max(ans, whack + dist(v[i].f,v[i].s));
	}
	cout << ans;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, q, inf=2e9, cnt;
vector<int> par ;
vector<pair<int,pair<int,int> > > v;
map<int,int> id ;
int tree[3000006];
void update(int node, int s, int e, int l, int r, int val)
{
    if(s>r||e<l)
        return ;
    if(s>=l && e<=r)
    {
        tree[node]=min(tree[node],val);
        return ;
    }
    int m=(s+e)/2;
    update(2*node,s,m,l,r,val);
    update(2*node+1,m+1,e,l,r,val);
}
int solve(int node, int s,int e, int pos)
{
    if(s==e)
        return tree[node];
    int m=(s+e)/2;
    tree[2*node]=min(tree[node],tree[2*node]);
    tree[2*node+1]=min(tree[node],tree[2*node+1]);
    return pos<=m ? solve(2*node,s,m,pos) : solve(2*node+1,m+1,e,pos);
}
int main()
{
    IO
    cin>>n>>q;
    for(int i=1; i<=3e6; i++)
        tree[i]=inf;
    for(int i=1; i<=n; i++)
    {
        int s, t, x;
        cin>>s>>t>>x;
        v.push_back({x,{s-x,t-x-1}});
        id[s-x]++;
        id[t-x-1]++;
    }
    for(int i=1; i<=q; i++)
    {
        int d;
        cin>>d;
        id[d]++;
        par.push_back(d);
    }
    for(auto i : id)
        id[i.first]=++cnt;
    for(int i=0; i<n; i++)
    {
        int l=id[v[i].second.first], r=id[v[i].second.second];
        update(1,1,cnt,l,r,v[i].first);
    }
    for(int i=0; i<q; i++)
    {
        int ans=solve(1,1,cnt,id[par[i]]);
        if(ans==inf)
            ans=-1;
        cout<<ans<<"\n";
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,q;cin>>n>>q;
    int S,T,X;
    vector<tuple<int,int,int>> ban(n);
    rep(i,n){
        cin>>S>>T>>X;
        ban[i]=make_tuple(X,S-X,T-X);
    }
    sort(all(ban));
    int d;
    map<int,int> num;
    set<int> time;
    rep(i,q){
        cin>>d;
        num[d]=i;
        time.insert(d);
    }
    time.insert(inf);
    vin ans(q,-1);
    //s<=d<tなるdをxが小さい順に見つけていく
    queue<int> que;
    int x,s,t;
    rep(i,n){
        if(time.size()==1)break;
        x=get<0>(ban[i]);
        s=get<1>(ban[i]);
        t=get<2>(ban[i]);
        auto l=time.lower_bound(s);
        auto r=time.lower_bound(t);
        for(auto itr=l;itr!=r;itr++){
            ans[num[*itr]]=x;
            que.push(*itr);
        }
        while(que.size()){
            time.erase(que.front());
            que.pop();
        }
    }
    rep(i,q)cout<<ans[i]<<endl;
}