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

int main(){
  string S; cin >> S;
  int len = S.size();

  if(len == 1){
    int n = S.at(0) - '0';
    if(n % 8 == 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }
  if(len == 2){
    int a = S.at(0) - '0';
    int b = S.at(1) - '0';
    if((a * 10 + b) % 8 == 0 || (b * 10  + a) % 8 == 0){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }
  map<int,int> sum_i;
  for(int i = 1; i < 10; i++){
    sum_i[i] = 0;
  }
  for(int i = 0; i < len; i++){
    int num = S.at(i) - '0';
    sum_i[num]++;
  }

  bool flag = false;
  for(int i = 100; i < 1000; i++){
    if(i % 8 != 0) continue;
    string str = to_string(i);
    if(str.at(0) == '0' || str.at(1) == '0' || str.at(2) == '0'){
      continue;
    }
    map<int,int> m;
    for(int i = 1; i < 10; i++){
    m[i] = 0;
    }
    int c = i;
    while(c > 0){
      m[c%10]++;
      c /= 10;
    }
    int p = 0;
    for(int i = 1; i <= 9; i++){
      if(sum_i[i] >= m[i]){
        p++;
      }
    }
    if(p == 9) flag = true;
  }
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ll long long
#define ss second
#define ff first
#define mod 1000000007
#define w(x) ll x; cin>>x; while(x--)
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define re(i, j) fo(i, 0, j, 1)
#define pi acos(-1)
#define all(cont) cont.begin(), cont.end()
#define countbit(x) __builtin_popcount(x)
#define mod 1000000007
#define de(n) ll n;cin>>n;
#define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];}
#define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];}
#define deb(x) cout<<#x<<"="<<x<<endl;
#define tr(it,a) for(auto it=a.begin();it!=a.end();it++)
#define nl cout<<endl;
using namespace std;
void cp()
{
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
//18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix)
bool solve(string s)
{
   ll n=s.length();
   if(n==1)
   {
      if(s[0]=='8')
      return true;
   }
   if(n==2)
      {
         if(stoi(s)%8==0)
         return true;
         else
         {
            swap(s[0],s[1]);
            if(stoi(s)%8==0)
            return true;
         }
      }
      map<ll,ll>p;
      re(i,n)
      p[s[i]-'0']++;
      for(ll i=112;i<=1000;i+=8)
      {
         auto h=p;
         ll j=i;
         bool got=0;
         while(j!=0)
         {
            h[j%10]--;
            if(h[j%10]<0)
            {
               got=1;
               break;
            }
            j=j/10;
         }
         if(got==0)
         return true;
      }
      return false;
}
int main()
{
   //cp();
   //w(x)
   {
      string s;
      cin>>s;
      //ll n=s.length();
      if(solve(s))
      cout<<"Yes\n";
      else
      {
         cout<<"No\n";
      }
   }
}


#include <bits/stdc++.h>
using namespace std;
// Compile with "(g++) -std=c++11 -Wall -Wextra -Wconversion -Wshadow -Dcychien"
#ifdef cychien
#define debug(...) do {\
	fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
    _DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x) {cerr << x << '\n';}
template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
#define IOS
#else
#define debug(...)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#endif
#define FOR(i, n) for(int i = 0; i < n; i++)
#define FOR1(i, n) for(int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define SZ(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const int NF = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846264338327950288;

int main() {
    IOS;
    int t;
    cin >> t;
    while (t--){
    	int n;
    	cin >> n;
    	string a;
    	cin >> a;
    	cin >> a;
    	cin >> a;
    	FOR (i, n) cout << 0;
    	FOR (i, n) cout << 1;
    	cout << "0\n";
	}
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t, n, k;
    cin >> n;
    vector <ll> a, b;
    for (ll i = 1; i <= n; i++) {
      cin >> k;
      a.push_back(k);
    }
    for (ll i = 1; i <= n; i++) {
      cin >> k;
      b.push_back(k);
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
      ans += a[i] * b[i];
    }
  cout << (ans == 0 ? "Yes" : "No") << endl;
  return 0;
}


/**
 * Author : Ujjawal Pabreja [cuber_coder]
 * Email : ujjawalpabreja99@gmail.com
 */
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

void Solve() {
    int l, r;
    cin >> l >> r;
    int n = r - l + 1;
    cout << (2 * l <= r ? n * (n - l) - n * (n - 1) / 2 + l * (l - 1) / 2 : 0)
         << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int testcases = 1;
    cin >> testcases;

    for (int i = 1; i <= testcases; i++) {
        Solve();
    }
    return 0;
}

#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 = 998244353;
#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);
}
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;
}
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;
}
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;
}
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;
}
int t;
signed main() {
	cin >> t;
	rep(i, t) {
		int l, r;
		cin >> l >> r;
		if (l > r - l)cout << 0 << endl;
		else if (r > r - l) {
			int x = (r - l + 1) * (r - 2 * l + 1);
			int y = ((r - l + 1) * (r - l) - (l - 1) * l) / 2;
			cout << x - y << endl;
		}
		else {
			int x = (r - l + 1) * (r - l + 1);
			int y = ((r + 1) * r - (l - 1) * l) / 2;
			cout << x - y << endl;
		}
	}
	ggr
}


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

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);
    set<long long> dup;
    multiset<long long> dupnum;
    for (long long i = 0; i < n; i++) {
        cin >> a[i];
        dup.insert(a[i]);
        dupnum.insert(a[i]);
    }

    long long all = (n*(n-1))/2;
    //cout << all << endl;

    for (auto x : dup){
        long long count = dupnum.count(x);
        //cout << count << endl;
        if (count >= 2){
            long long minus = (count*(count-1))/2;
            all-=minus;
        }
    }

    cout << all << endl;

}

#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define rep(i,a,b) for(int i=a;i< b;i++)
#define endl "\n"
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define fr first
#define sc second
#define INF (int)(1e18)
#define pb push_back
#define ppb pop_back
#define sz(x) (int)((x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define PI 3.14159265358979323846
using namespace std;
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
const int N=2e5+5;

void test_case()
{
  int n;
  cin>>n;
  map<int,int> m;
  int ans=0;
  rep(i,0,n ){
    int x; cin>>x;
    ++m[x];
    ans+=i+1-m[x];
    // ++m[x];
  }
  cout<< ans;
}
signed main()
{
  fast_io;
  #ifdef SIEVE
    sieve();
  #endif
  #ifdef NCR
    init();
  #endif
  int t=1;
  // cin>>t;
  rep(i,0,t){
  //cout<< "Case #" << i+1 << ": ";
         test_case();
  }
  return 0;
}
//taskkill -im main.exe -f


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

int main() {
    ll n, slen = 10;
    rep(i, 9){
        slen *= 10;
    }
    cin >> n;
    string t;
    cin >> t;

    ll onecnt=0, res, firstone;
    bool appear = false, valid = true;
    rep(i, n){
        if(!appear&&t[i]=='1'){
            onecnt++;
        }else{
            if(!appear&&t[i]=='0'){
                appear = true;
                firstone = i;
                onecnt = 0;
            }else{
                if(t[i]=='1'){
                    onecnt++;
                }else{
                    if(onecnt!=2){
                        valid = false;
                        break;
                    }else{
                        onecnt = 0;
                    }
                }
            }
        }
        if(onecnt>2){
            valid = false;
            break;
        }
    }

    if(!valid){
        res = 0;
    }else{
        if(n==1){
            if(t[0]=='0'){
                res = slen;
            }else{
                res = 2LL * slen;
            }
        }else{
            if(t=="11"){
                res = slen;
            }else{
              res = (3LL * slen - n - 2LL + firstone) / 3LL + 1LL;
            }
        }
    }

    cout << res << endl;
    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll n;
    string t;
    cin >> n >> t;

    ll base = 1e10;

    if(n == 1){
        if(t == "0")cout << base << endl;
        else cout << 2 * base << endl;
        return 0;
    }
    else if(n == 2){
        if(t == "00")cout << 0;
        else {
            if(t[0] == '0')cout << (3*base - 2) / 3 << endl;
            else cout << base << endl;
        }

        return 0;
    }

    bool ok = true;
    rep(i, n-2){
        string subt = t.substr(i, 3);
        if(subt == "110" || subt == "101" || subt == "011")continue;

        ok = false;
    }

    ll ans = 0;
    if(ok){
        ans = 3 * base - max(0LL, n-3);
        if(t[0] == '0')ans -= 2;
        else if(t.substr(0, 2) == "10")ans -= 1;

        ans /= 3;
    }

    cout << ans << endl;
}


using namespace std;
#include<iostream>

int main(){
	float a, b;
	cin >> a >> b;
	cout << a * (b / 100) << endl;
	return 0;
}

#include "bits/stdc++.h"
#include<algorithm>
using namespace std;
#define int             long long
#define pb              push_back
#define ppb             pop_back
#define pf              push_front
#define ppf             pop_front
#define all(x)          (x).begin(),(x).end()
#define uniq(v)         (v).erase(unique(all(v)),(v).end())
#define sz(x)           (int)((x).size())
#define fr              first
#define sc              second
#define pli             pair<int,int>
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define mem1(a)         memset(a,-1,sizeof(a))
#define mem0(a)         memset(a,0,sizeof(a))
#define ppc             __builtin_popcount
#define ppcll           __builtin_popcountll

template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2> &a) {in >> a.fr >> a.sc; return in;}
template<typename T1, typename T2>ostream& operator>>(ostream& out, pair<T1, T2> a) {out << a.fr << " " << a.sc; return out;}
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a - b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a - b; return a;}

const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;

const int N = 0;

void solve()
{
    int a, b;
    cin >> a >> b;

    double ans = a * b / 100.0;

    cout << ans;
    cout << endl;

}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#ifdef SIEVE
    sieve();
#endif
#ifdef NCR
    init();
#endif
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;

}


#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
#define pb push_back
#define ll long long int
#define pll pair<ll,ll>

    vector <int> g[102], gr[102];
    int comp_size[102];
    vector<bool> used;
	int num = 0;
    void dfs1 (int v) {
        used[v] = true;
        ++num;
        for (size_t i=0; i<gr[v].size(); ++i){
        	if (!used[ gr[v][i] ]){
        		dfs1 (gr[v][i]);
			}
		}

    }

    int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout << std::setprecision(12) ;
    std::cout << std::fixed;
    double ans = 0.0;

     int n;
     cin>>n;
     string s[n];
     for(int i=0;i<n;i++){
     cin>>s[i];
     for(int j=0;j<n;j++){
       		if(s[i][j]=='1'){
       			g[i].push_back (j);
            	gr[j].push_back (i);
			   }
		   }
	 }

        for (int i=0; i<n; ++i){
        	 used.assign (n, false);
        	 num =0;
        	 dfs1(i);
        	 ans = ans +(1.0/(double)(num));
		}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll;
template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));}

vvi g;
vi vdeg;
const int n=400000+8;
void solve(long long nume, std::vector<long long> a, std::vector<long long> b){
  g.resize(n+1);
  vdeg.resize(n+1);
  for (int i=0;i<nume;i++) {
    int x=a[i],y=b[i];
    g[x].PB(y); g[y].PB(x);
  }
  queue<int> q;
  for (int x=1;x<=n;x++) {
    int deg=g[x].size();
    vdeg[x]=(deg);
    if (deg==1) q.push(x);
  }
  int ones=0;
  while(!q.empty()) {
    int x=q.front(); q.pop();
    if (vdeg[x]==1) {
      ones++;
      vdeg[x]--;
      for (auto &y:g[x]) {
        --vdeg[y];
        if (vdeg[y]==1) q.push(y);
      }
    }
  }
  int final=ones;
  for (int x=1;x<=n;x++) if(vdeg[x]>0) final++;
  printf("%d\n",final);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(i) %= 200;
  }
  int64_t count, ans = 0;
  for (int i = 0; i < 200; i++) {
    count = 0;
    for (int j : A) {
      if (i == j)
        count++;
    }
    ans += count * (count - 1) / 2;
  }
  cout << ans << endl;
}

///*    ***Bismillahir Rahmanir Rahim***   */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dl;
typedef unsigned long long ull;
#define pb push_back
#define PB pop_back
#define nn "\n"
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define all(p) p.begin(), p.end()
#define zz(v) (ll) v.size()
#define ss ' '
#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(p) memset(p, 0, sizeof(p))
#define precision(a) fixed << setprecision(a)
#define rep(i, b) for (ll i = 0; i < (b); i++)
#define rep1(i, b) for (int i = 1; i <= (b); i++)
//#define rep(s,e)         for(i=s;i<e;i+=1)
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i, b, a) for (int i = (b); i >= (a); i--)
#define rep2(i, a, b, c) for (int i = (a); i != (b); i += (c))
#define arrsize(a) (sizeof(a) / sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define S(a) scanf("%lld", &a)
#define SS(a, b) scanf("%lld %lld", &a, &b)
#define SSS(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define pi acos(-1.0)
#define ff first
#define sc second
#define print(v)   \
    for (ll i : v) \
    cout << i << ss
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<ll> vll;
typedef map<string, ll> msl;
typedef map<ll, ll> mll;
#define yes cout << "YES\n"
#define no cout << "NO\n"
bool comp(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.first != b.first)
        return a.first > b.first;
    else
        return a.second > b.second;
}
//ll minelementindex = min_element(v.begin(),v.end()) - v.begin();
//ll minelement = *min_element(v.begin(), v.end());
//ll maxelementindex = max_element(v.begin(),v.end()) - v.begin();
//ll maxelement = *max_element(v.begin(), v.end());
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
//auto s =to_string(42);
//string s = "12345";
// object from the class stringstream
//stringstream geek(s);
// The object has the value 12345 and stream
// it to the integer x
//int x = 0;
//geek >> x;
#define MAX 1000005
#define precision(a) fixed << setprecision(a)
#define mod 1000000007
int main()
{
    //O_O ;
    ll n;
    cin >> n;
    map<ll, ll> mp;
    for (ll i = 0; i < n; i++)
    {
        ll x;
        cin >> x;
        x %= 200;
        mp[x]++;
    }
    ll ans = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it)
    {
        ll c = it->second;
        ans += ((c * (c - 1)) / 2);
    }
    cout << ans << nn;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){int a,b,x,y;cin>>a>>b>>x>>y;if(a>b)a--;
           int p=min(2*x,y);p*=abs(a-b);p+=x;cout<<p<<endl;}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
#pragma GCC target ("avx2,fma")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define rank fewfewf
#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1050;
const int K = 90;
const int mod = 1e9 + 7;
vector<pair<int,int>> g[N];
int d[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    int n = 100;
    for (int i = 0; i < n - 1; i++){
        g[i].pb({i + 1, y});
        g[i + 1].pb({i, y});
        g[i + n].pb({i + n + 1, y});
        g[i + n + 1].pb({i + n, y});
        g[i + 1].pb({i + n, x});
        g[i + n].pb({i + 1, x});
    }
    for (int i = 0; i < n; i++){
        g[i].pb({i + n, x});
        g[i + n].pb({i, x});
    }
    a--;
    b--;
    b += n;
    for (int i = 0; i < n + n; i++) d[i] = 1e9;
    set<pair<int,int>> s;
    s.insert({0, a});
    d[a] = 0;
    while(!s.empty()){
        int v = (*s.begin()).S;
        s.erase(s.begin());
        for (auto e: g[v]){
            if (d[e.F] > d[v] + e.S){
                s.erase({d[e.F], e.F});
                d[e.F] = d[v] + e.S;
                s.insert({d[e.F], e.F});
            }
        }
    }
    cout << d[b];
}


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

/* MACROS START */
#define input std::cin
#define for2(i,n) for(int i=0; i<n; i++)
#define for3(i,a,n) for(int i=a; i<n; i++)
#define for4(i,a,n,s) for(int i=a; i<n; i+=s)

using lint = long long int;
using namespace std;

template <typename T>
void printvec(T vec) {
  for (auto& a: vec)
	cout << a << " ";
  cout << endl;
}
/* MACROS END */

/* LIBRARY START */
/* LIBRARY END */

struct Expectation {
  double exact = 0, variable = 0;

  Expectation& operator+=(const Expectation& other) {
	this->exact += other.exact;
	this->variable += other.variable;
	return *this;
  }

  Expectation& operator-=(const Expectation& other) {
	this->exact -= other.exact;
	this->variable -= other.variable;
	return *this;
  }
};

Expectation operator/(const Expectation& e, double d) {
  return {e.exact/d, e.variable/d};
}

Expectation operator+(const Expectation& e, int d) {
  return {e.exact+d, e.variable};
}

int main() {
  std::ios_base::sync_with_stdio(0);
  int n, m, k; input >> n >> m >> k;
  set<int> traps;
  for2(i, k) {
	int tr; input >> tr;
	traps.insert(tr);
  }
  queue<Expectation> runsum;
  for2(i, m) {
	runsum.push({0, 0});
  }
  Expectation sum = {0, 0};
  for(int i=n-1; i>0; i--) {
	if (traps.count(i)) {
	  runsum.push({0, 1});
	} else {
	  runsum.push((sum + m) / m);
	}
	sum -= runsum.front(); runsum.pop();
	sum += runsum.back();
  }
  Expectation exp = (sum + m) / m;
  if (exp.variable >= 1.0 - 1e-9)
	std::cout << -1 << std::endl;
  else {
	double ans = exp.exact / (1.0 - exp.variable);
	std::cout << std::fixed << ans << std::endl;
  }
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

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

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

ld pre[200005];
ld cnt[200005];
ld dp[200005];

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif

    int n,m,k;
    cin>>n>>m>>k;
    int a[n+m+2]={0};

    for(int i=0;i<k;i++)
    {
        int x;
        cin>>x;
        a[x]=1;
    }

    for(int i=n;i>=0;i--)
    {
        cnt[i]=cnt[i+1]+a[i];
    }

    ld l=1,r=1e12;
    ld eps=1e-8;

    while(r-l>eps)
    {
        ld mid=(l+r)/2;
        for(int i=n-1;i>=0;i--)
        {
            if(a[i]==1)
            {
                dp[i]=mid;
                pre[i]=pre[i+1]+dp[i];
            }
            else
            {
                dp[i]=(pre[i+1]-pre[i+m+1])/m+1;
                pre[i]=pre[i+1]+dp[i];
            }
        }

        if(dp[0]<mid)
        {
            r=mid;
        }
        else
        {
            l=mid;
        }
    }

    if(l>1e11)
    {
        cout<<-1;
        return 0;
    }
    cout<<fixed<<setprecision(5)<<l;

}


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

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

  long long Sa=0;
  vector<long long> V(N);
  for(int i=0;i<N;i++){
    long long a,b;
    cin >> a >> b;
    Sa += a;
    V[i] = a*2+b;
  }
  sort(V.rbegin(),V.rend());

  for(int i=0;i<=N;i++){
    if(Sa<0){
      cout << i << endl;
      return 0;
    }
    Sa -= V[i];
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

int main() {
	ll N;
	cin >> N;
	ll sum = 0;
	vll V(N);
	rep(i,N) {
		ll a;
		ll b;
		cin >> a >> b;
		sum += a;
		V[i] = 2*a + b;
	}
	sort(all(V));
	reverse(all(V));
	ll sum2 = 0;
	rep(i,N) {
		sum2 += V[i];
		if (sum2 > sum) {cout << i + 1 << endl;break;}
	}
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

	int N;
	cin >> N;

	ll A[200000];
	int K[3] = {};
	rep(i, N << 1) {
		ll a;
		char c;
		cin >> a >> c;
		ll C = (ll(c) >> 4 | ll(c) << 1) & 3;
		K[C]++;
		A[i] = a | C << 50;
	}
	sort(A, A + N * 2);
	if (K[0] % 2 == 0 && K[1] % 2 == 0 && K[2] % 2 == 0) {
		co(0);
		return 0;
	}

	auto P = A;
	auto Q = A + K[0];
	auto R = A + K[0] + K[1];
	const ll ma = (1ll << 50) - 1;
	rep(i, N << 1) A[i] &= ma;
	ll sai[3] = {};
	ll saiq = 1e18, sair = 1e18;
	int q = 0, r = 0;
	rep(p, K[0]) {
		if (q < K[1]) if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]);
		while (q < K[1] - 1 && Q[q] < P[p]) {
			q++;
			if (saiq > abs(Q[q] - P[p])) saiq = abs(Q[q] - P[p]);
		}
		if (r < K[2]) if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]);
		while (r < K[2] - 1 && R[r] < P[p]) {
			r++;
			if (sair > abs(R[r] - P[p])) sair = abs(R[r] - P[p]);
		}
	}
	sai[2] = saiq;
	sai[1] = sair;
	sair = 1e18;
	r = 0;
	q = 0;
	while (q < K[1]) {
		if (r < K[2]) if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]);
		while (r < K[2] - 1 && R[r] < Q[q]) {
			r++;
			if (sair > abs(R[r] - Q[q])) sair = abs(R[r] - Q[q]);
		}
		q++;
	}
	sai[0] = sair;
	ll kotae = 1e18;
	if (K[0] % 2 == 0) kotae = min(sai[0], sai[1] + sai[2]);
	else if (K[1] % 2 == 0) kotae = min(sai[1], sai[2] + sai[0]);
	else kotae = min(sai[2], sai[0] + sai[1]);
	co(kotae);

	Would you please return 0;
}

#include<algorithm>
#include<cstdio>
#define ll long long
#define MaxN 200500
using namespace std;
const ll INF=1ll<<60;
struct Data{ll x;char c;}a[MaxN];
bool cmp(const Data &A,const Data &B)
{return A.x<B.x;}
int n,o[255];ll sav[255];
int main()
{
  scanf("%d",&n);n*=2;
  for (int i=1;i<=n;i++){
    scanf("%lld%s",&a[i].x,&a[i].c);
    o[a[i].c]++;
  }
  bool fl=0;
  for (int i='A';i<='Z';i++)if (o[i]&1)fl=1;
  if (!fl){puts("0");return 0;}
  sort(a+1,a+n+1,cmp);
  for (int i='A';i<='Z';i++)sav[i]=INF;
  ll ans1=INF,ans2=0;
  for (int i=1;i<=n;i++)if (o[a[i].c]&1){
    if (i>1&&a[i-1].c!=a[i].c){
      sav[a[i].c]=min(sav[a[i].c],a[i].x-a[i-1].x);
      int p=i-1;while(p>1&&!(o[a[p].c]&1))p--;
      if (o[a[p].c]&1&&a[p].c!=a[i].c)ans1=min(ans1,a[i].x-a[p].x);
    }
    if (i<n&&a[i+1].c!=a[i].c){
      sav[a[i].c]=min(sav[a[i].c],a[i+1].x-a[i].x);
      int p=i+1;while(p<n&&!(o[a[p].c]&1))p++;
      if (o[a[p].c]&1&&a[p].c!=a[i].c)ans1=min(ans1,a[p].x-a[i].x);
    }
  }
  for (int i='A';i<='Z';i++)
    if (o[i]&1)ans2+=sav[i];
  printf("%lld",min(ans1,ans2));
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define set(x, i) (x | (1 << i))
#define check(x, i) (x & (1 << i))
#define printcase printf("Case %d: ",test++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
ll mpow(ll base, ll exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

int test = 1;
vi g[N];
int a[N];

void solve() {
  int i, j, n, m;
	// printcase;
	cin >> n;
	set <int> nums;
	fo(i,n) {
		int a;
		cin >> a;
		nums.insert(a);
	}
	ll ans = 1;
	int itr = 0;
	for(int i: nums) {
		ans = (ans * (i  + 1- itr))%mod;
		itr = i;
	}
	ans%= mod;
	pl(ans%mod);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}

ll mpow(ll base, ll exp) {
  base %= mod;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
    u--, v--;
		g[u].pb(v);
		g[v].pb(u);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979;
#define setup\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
    cout << setprecision(20) << fixed;
#define int long long int
#define db double
#define P pair<int,int>
#define F first
#define S second
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define rtod(rad) (((rad)/2/pi)*360)
#define all(a) a.begin(),a.end()
#define Srep(n) for(int i = 0; i < n; i++)
#define Lrep(i,a,n) for(int i = a; i < n; i++)
#define Brep1st(n) for(int bit = 0; bit < (1 << n); bit++)
#define Brep2nd(n) Srep(n) if(bit >> i & 1)
#define rep2d(n,m) Srep(n) Lrep(j,0,m)
#define vi vector<int>
#define vvi vector<vi>
#define vdb vector<db>
#define vb vector<bool>

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main(){
    setup;
    int n, ans = 1;
    cin >> n;
    Lrep(i,2,n+1) ans = lcm(ans, i);
    cout << ans + 1 << endl;
}


#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
//#define MOD 998244353
//#define MAX 200100
//#define NIL -1
#define INF 1000000000000000000
//const LL SEG_VAL = 1 << 19;

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

    LL N;
    LL M;
    cin >> N >> M;
    vector<LL> a(N);
    vector<vector<LL>> edge_f(N);
    vector<vector<LL>> edge_b(N);
    vector<LL> dp_min(N, INF);
    vector<LL> dp_max(N, 0);
    LL x;
    LL y;
    for(LL i=0; i<N; i++){
        cin >> a[i];
    }
    for(LL i=0; i<M; i++){
        cin >> x >> y;
        x--;
        y--;
        edge_f[x].push_back(y);
        edge_b[y].push_back(x);
    }

    for(LL i=0; i<N; i++){
        dp_min[i]=min(dp_min[i], a[i]);
        for(LL j=0; j<edge_f[i].size(); j++){
            dp_min[edge_f[i][j]]=min(dp_min[edge_f[i][j]], dp_min[i]);
        }
    }
    for(LL i=N-1; i>=0; i--){
        dp_max[i]=max(dp_max[i], a[i]);
        for(LL j=0; j<edge_b[i].size(); j++){
            dp_max[edge_b[i][j]]=max(dp_max[edge_b[i][j]], dp_max[i]);
        }
    }

    /*
    for(LL i=0; i<N; i++){
        cout << i << " " << dp_min[i] << " " << dp_max[i] << endl;
    }
    */

    LL ans=(-1)*INF;
    for(LL i=0; i<N; i++){
        for(LL j=0; j<edge_f[i].size(); j++){
            ans=max(ans, dp_max[edge_f[i][j]]-dp_min[i]);
        }
    }

    cout << ans << endl;

    return 0;
}

// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define int long long
#define endl "\n"
#define mod 1000000007
#define inf (int)1e18

const int mxn = 2e5+10;
vector<int> g[mxn];
bool vis[mxn];
int a[mxn];
vector<int> maxes(mxn,-1e14);

void dfs(int v){
    vis[v] = 1;

    for(int u : g[v]){
        if(!vis[u])
            dfs(u);
        maxes[v] = max(maxes[v],a[u]);
        maxes[v] = max(maxes[v],maxes[u]);
    }
}

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

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

    for(int i=1;i<=m;i++){
        int u,v; cin >> u >> v;
        g[u].push_back(v);
    }

    int ans = -inf;

    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }

    for(int i=1;i<=n;i++){
        if(maxes[i]!=-1e14){
            ans = max(ans,maxes[i]-a[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 100010;

signed main() {
    IOS;

    int x;
    cin >> x;

    if(x < 0) { x = 0; }
    print(x);

    return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2> &a) {in >> a.fr >> a.sc; return in;}
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) {out << a.fr << " " << a.sc; return out;}
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}

const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		cout << c;
	else if (a == c)
		cout << b;
	else if (b == c)
		cout << a;
	else
		cout << 0;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}


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

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define REP(inc, bgn, end) for(int inc=bgn; inc<end; inc++)
typedef long long ll;

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

    cout << 100-(n%100) << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,n;
	cin>>x;
	for(int i=1;i<=100000;i++)
	{
		if((x+i)%100==0)
		{
			cout<<i;
			return 0;
		}
		if(x%100==0)
		{
			break;
		}
	}
	cout<<"100";
	return 0;
}


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

int main(){
  int a,b,c,x[3];
  cin>>a>>b>>c;

  x[0]=a;
  x[1]=b;
  x[2]=c;

  sort(x,x+3);

  cout<<x[1]+x[2]<<endl;
  return 0;
}

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

// ModIntR::set_mod()
struct ModIntR {
  int x;
  ModIntR() : x(0) {}
  ModIntR(int64_t y) : x(y >= 0 ? y % mod() : (mod() - (-y) % mod()) % mod()) {}
  static int &mod() {
    static int mod = 0;
    return mod;
  }
  static void set_mod(int md) { mod() = md; }
  ModIntR &operator+=(const ModIntR &p) {
    if ((x += p.x) >= mod()) x -= mod();
    return *this;
  }
  ModIntR &operator-=(const ModIntR &p) {
    if ((x += mod() - p.x) >= mod()) x -= mod();
    return *this;
  }

  ModIntR &operator*=(const ModIntR &p) {
    long long m = mod();
    x = (int)(1LL * x * p.x % m);
    return *this;
  }

  ModIntR &operator/=(const ModIntR &p) {
    *this *= p.inverse();
    return *this;
  }

  ModIntR operator-() const { return ModIntR(-x); }

  ModIntR operator+(const ModIntR &p) const { return ModIntR(*this) += p; }

  ModIntR operator-(const ModIntR &p) const { return ModIntR(*this) -= p; }

  ModIntR operator*(const ModIntR &p) const { return ModIntR(*this) *= p; }

  ModIntR operator/(const ModIntR &p) const { return ModIntR(*this) /= p; }

  bool operator==(const ModIntR &p) const { return x == p.x; }

  bool operator!=(const ModIntR &p) const { return x != p.x; }

  ModIntR inverse() const {
    int a = x, b = mod(), u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModIntR(u);
  }

  ModIntR pow(int64_t n) const {
    ModIntR res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }

  friend ostream &operator<<(ostream &os, const ModIntR &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModIntR &a) {
    int64_t t;
    is >> t;
    a = ModIntR(t);
    return (is);
  }
};

int n, k, m, ofst = 2e6, len;
vector<ModIntR> cnt, memo;

void add(int x);
void sub(int x);
bool isvalid(int x) { return -len + ofst <= x && x <= len + ofst; }

int main() {
  cin >> n >> k >> m;
  len = n * (n + 1) / 2 * k;
  ModIntR::set_mod(m);
  cnt.assign((int)4e6, 0);
  memo.assign((int)4e6, 0);
  cnt[ofst] = 1;
  for (int i = 1; i <= n; ++i) add(i);
  for (int i = 1; i <= n; ++i) {
    // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " ";
    // cout << endl;
    if (n + 1 - i != 0) sub(n + 1 - i);
    // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " ";
    // cout << endl;
    cout << (cnt[ofst] * (k + 1)) - 1 << endl;
    add(-i);
    // for (int j = -6; j <= 6; ++j) cout << cnt[j + ofst] << " ";
    // cout << endl;
  }
  return 0;
}

void add(int x) {
  vector<ModIntR> sum(abs(x), 0);
  int sign = x / abs(x);
  x = abs(x);
  for (int i = -len * sign + ofst; isvalid(i); i += sign) {
    sum[i % x] -= memo[i];
    memo[i] = 0;
    ModIntR tmp = sum[i % x];
    sum[i % x] += cnt[i];
    if (isvalid(i + sign * x * (k + 1))) memo[i + sign * x * (k + 1)] = cnt[i];
    cnt[i] += tmp;
  }
}
void sub(int x) {
  vector<ModIntR> sum(abs(x), 0);
  int sign = x / abs(x);
  x = abs(x);
  for (int i = -len * sign + ofst; isvalid(i); i += sign) {
    sum[i % x] -= memo[i];
    memo[i] = 0;
    ModIntR tmp = sum[i % x];
    cnt[i] -= tmp;
    sum[i % x] += cnt[i];
    if (isvalid(i + sign * x * (k + 1))) memo[i + sign * x * (k + 1)] = cnt[i];
  }
}


#include <bits/stdc++.h>

const int MAXN = 200;

int A[MAXN + 5], B[MAXN + 5];
int P[MAXN + 5], D[MAXN + 5];
bool Dp[MAXN + 5][MAXN + 5];

bool Check(int l, int r) {
	int mid = (l + r) >> 1, len = mid - l + 1;
	for (int i = l; i <= r; i++) {
		if (P[i]) {
			if (P[i] != -1) {
				if (P[i] < l || P[i] > r)
					return false;
				if (P[i] > i && P[i] - i != len)
					return false;
			}
			else {
				if (D[i] == 1 && (i > mid || P[i + len]))
					return false;
				if (D[i] == -1 && (i <= mid || P[i - len]))
					return false;
			}
		}
	}
	return true;
}

bool Read(int N) {
	for (int i = 1; i <= N; i++) {
		int l, r; scanf("%d%d", &l, &r);
		if (l == -1 && r == -1)
			continue;
		if (l == r) return false;
		if (l != -1) {
			if (P[l]) return false;
			P[l] = r, D[l] = 1;
		}
		if (r != -1) {
			if (P[r]) return false;
			P[r] = l, D[r] = -1;
		}
	}
	return true;
}

int main() {
	int N;
	scanf("%d", &N);
	if (!Read(N))
		return puts("No"), 0;
	N <<= 1;
	for (int len = 2; len <= N; len += 2) {
		for (int i = 1; i + len - 1 <= N; i++) {
			int j = i + len - 1;
			for (int k = i + 1; k < j; k += 2) {
				if (Dp[i][k] && Dp[k + 1][j]) {
					Dp[i][j] = true;
					break;
				}
			}
			if (!Dp[i][j]) Dp[i][j] = Check(i, j);
		}
	}
	puts(Dp[1][N] ? "Yes" : "No");
	return 0;
}

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=char(n%10+48);n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

#ifndef ONLINE_JUDGE
template<typename T>
void pr(T a){std::cerr<<a<<std::endl;}
template<typename T,typename... Args>
void pr(T a, Args... args) {std::cerr<<a<<' ',pr(args...);}
#else
template<typename... Args>
void pr(Args... args){}
#endif

using namespace std;
const int MM = 205;

int n, cnt[MM], l[MM], r[MM], at[MM], no, dp[MM][MM], aa;

int main(){
	scan(n);
	for(int i = 1; i <= n; i++){
		scan(l[i], r[i]);
		if(l[i] == -1)
			l[i] = 0;
		else{
			cnt[l[i]]++;
			at[l[i]] = i;
		}
		if(r[i] == -1)
			r[i] = 0;
		else{
			cnt[r[i]]++;
			at[r[i]] = i;
		}

		if(l[i] and r[i] and l[i] > r[i])
			no = 1;

		// assert(l[i] or r[i]);
		if(!l[i] and !r[i]){
			aa++;
		}
	}
	dp[0][0] = 1;
	for(int i = 1; i <= 2*n; i++){
		if(!cnt[i]){
			for(int t = 0; t <= 2*n; t++)
				dp[i][t] |= dp[i-1][t];
		}
		if(!cnt[i] and !cnt[i-1] and i > 2){
			for(int t = 1; t <= 2*n; t++)
				dp[i][t] |= dp[i-2][t-1];
		}
		// pr("i", i);
		for(int j = 1; j < i; j++){
			if((i-j+1)%2 || !dp[j-1]) continue;
			int len = (i-j+1)/2;
			// pr("j", j, len);
			int ok = 1, add = 0;
			for(int k = j; k < j+len; k++){
				// pr("k", k, ok);
				if(at[k] and at[k+len]){
					if(at[k] != at[k+len])
						ok = 0;
				}
				else if(at[k]){
					int id = at[k];
					if(r[id])
						ok = 0;
					// r[id] = k+len;
					// cnt[k+len]++;
				}
				else if(at[k+len]){
					int id = at[k+len];
					if(l[id])
						ok = 0;
					// l[id] = k;
					// cnt[k]++;
				}
				else{
					//add an extra "free" one into here
					add++;
				}
			}
			if(ok){
				for(int t = add; t <= 2*n; t++)
					dp[i][t] |= dp[j-1][t-add];
			}
		}
	}
	int ans = dp[2*n][aa];

	for(int i = 0; i <= 2*n; i++){
		// print(cnt[i], dp[i]);
		if(cnt[i] > 1)
			no = 1;
	}
	if(no)
		ans = 0;

	puts(ans ? "Yes" : "No");
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ll arr[4];
    for(ll i=0;i<4;i++)cin>>arr[i];
    for(ll i=0;i<(1<<4);i++){
        ll suma=0,sumb=0;
        for(ll j=0;j<4;j++){
            if((1<<j)&i)
            suma+=arr[j];
            else
            sumb+=arr[j];
        }
        if(suma==sumb){
        cout<<"Yes";return 0;}
    }
    cout<<"No";
}

#include <bits/stdc++.h>

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

bool solve(vi& a, int n, int s) {
  if (a[n - 1] > s or (n < 0 and s)) return false;
  if (a[n - 1] == s) return true;
  return solve(a, n - 1, s - a[n - 1]) | solve(a, n - 1, s);
}

int main() {
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

  int sum = 0;
  vi a(4);
  loop(4) {
    cin >> a[i];
    sum += a[i];
  }
  bool ans = false;
  if (~sum & 1) {
    sum /= 2;
    ans = solve(a, 4, sum);
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
void printb(ll N,ll d){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;

}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
ll N,M;
map<pair<ll,ll>,bool>m;
vl dp,dp2;
ll rec(ll s){
    //cout<<s<<endl;
    //cout<<dp[s]<<endl;
    if(dp[s]!=-1){
        return dp[s];
    }

    rep(i,N){
        if(((s>>i)&1)==1){
            if(rec(s-(1<<i))==0)continue;
            ll flag=0;
            rep(j,N){
                if(i==j)continue;
                if(((s>>j)&1)==0)continue;

                if(rec((1<<i)|(1<<j))==0){
                    flag=1;
                    break;
                }
            }
            if(flag==0){
                dp[s]=1;
                return 1;
            }
        }
    }
    dp[s]=0;
    return 0;
}

ll rec2(ll s){
    //cout<<s<<endl;
    if(dp2[s]!=-1){
        return dp2[s];
    }
    if(dp[s]==1){
        return dp2[s]=1;
    }
    ll ret=INF;
    for(ll t=(s-1)&s;t>=1;t=(t-1)&s){
        //cout<<s<<" "<<t<<endl;
        //cout<<(s&(~t))<<endl;
        chmin(ret,rec2(s&(~t))+rec2(t));

    }

    return dp2[s]=ret;
}
int main() {

    cin>>N>>M;
    vl A(N),B(N);
    dp=vl((1<<N),-1);
    dp2=vl((1<<N),-1);
    dp[0]=1;
    //dp2[0]=0;
    rep(i,N){
        dp[(1<<i)]=1;
        dp2[(1<<i)]=1;
    }
    rep(i,M){
        ll a,b;
        cin>>a>>b;
        a--,b--;
        m[{a,b}]=1;
        dp[(1<<a)|(1<<b)]=1;
    }

    rep(i,N){
        rep3(j,i+1,N){
            if(dp[(1<<i)|(1<<j)]==-1){
                dp[(1<<i)|(1<<j)]=0;
            }
        }
    }

    rep(i,(1<<N)){
        if(dp[i]!=-1)continue;
        rec(i);
    }

    //cout<<"ok"<<endl;
    /*rep(i,(1<<N)){
        printb(i,N);
        cout<<dp[i]<<endl;
    }*/

    /*rep(i,(1<<N)){

    }*/

    cout<<rec2((1<<N)-1)<<endl;

    return 0;

}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define setp(x) fixed << setprecision(x)
#define endl "\n"
#define mod 1000000007
#define mod1 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 100005
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0)
        return 0;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}
bool edge[18][18];
ll dp[(1ll << 18)];
void solve()
{
    ll n, m;
    cin >> n >> m;
    bool good[(1ll << n)];
    mem0(good);
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            edge[i][j] = false;
        }
    }
    for (ll i = 0; i < m; i++)
    {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        edge[x][y] = true;
        edge[y][x] = true;
    }
    for (ll i = 0; i < (1ll << n); i++)
    {
        dp[i] = 1e18;
        vector<ll> v;
        for (ll j = 0; j < n; j++)
        {
            if (i & (1 << j))
            {
                v.pb(j);
            }
        }

        good[i] = true;
        ll sz = v.size();
        for (ll j = 0; j < sz; j++)
        {
            for (ll k = j + 1; k < sz; k++)
            {
                if (!edge[v[j]][v[k]])
                {
                    good[i] = false;
                    break;
                }
            }
        }
    }
    for (ll i = 0; i < (1ll << n); i++)
    {
        if (good[i] == true)
        {
            dp[i] = 1;
        }
        for (ll j = i; j; j = (j - 1) & i)//iterating over all submasks in total 3^n
        {
            dp[i] = min(dp[i], dp[j] + dp[j ^ i]);
        }
    }
    cout << dp[(1ll << n) - 1] << endl;
    return;
}
int main()
{

    speed;
    ll kk;
    kk = 1;
    // cin >> kk;
    while (kk--)
    {
        solve();
    }
}


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

int main(){
  ll n;
  int m;
  cin>>n>>m;
  if(m==0){
    cout<<1<<endl;
    return 0;
  }
  vector<ll> a(m);
  for(int i=0;i<m;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  ll b=a.at(0)-1;
  ll v=-1;
  if(b==0){
    for(int i=0;i<m-1;i++){
      b=a.at(i+1)-a.at(i)-1;
      if(b!=0){
        v=i;
        break;
      }
    }
  }
  if(b==0){
    if(n==m){
      cout<<0<<endl;
      return 0;
    }
    cout<<1<<endl;
    return 0;
  }
  for(int i=0;i<m-1;i++){
    if(a.at(i+1)-a.at(i)-1==0)continue;
    b=min(b,a.at(i+1)-a.at(i)-1);
  }
  if(n-a.at(m-1)>0)b=min(b,n-a.at(m-1));
  ll count=0;
  if((a.at(0)-1)%b==0)count+=(a.at(0)-1)/b;
  else count+=(a.at(0)-1)/b+1;
  for(int i=0;i<m-1;i++){
    if((a.at(i+1)-a.at(i)-1)%b==0)count+=(a.at(i+1)-a.at(i)-1)/b;
    else count+=((a.at(i+1)-a.at(i)-1)/b)+1;
  }
  if((n-a.at(m-1))%b==0)count+=(n-a.at(m-1))/b;
  else count+=((n-a.at(m-1))/b)+1;
  cout<<count<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
const int MOD=998244353;
const ll MODD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    ll t,p;
    cin>>t>>p;
    ll cnt=0;
    ll idt=0;
    vector<ll>ans;
    while(idt<=100){
        if(((cnt+t)/100)%10!=(cnt/100)%10){
            ans.push_back((idt+(ll)((idt)*((double)t/100.0)))+1);
        }
        cnt+=t;
        idt++;
    }
    ll num=ans.size();
    ll row=(p-1)/num;
    ll shun=0;
    shun=row*(100+t)+ans[(p-1)%num];
    cout<<shun<<endl;
}


/*
Author : Aditya Gupta
Team : TechTurtle
Date : 29-08-2020
Time : 20:05:54
*/

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vpll vector< pll >
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define endl "\n"
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define fst first
#define scd second
#define mk(arr,n,type)  type *arr=new type[n];

#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))

using namespace std;

///////////////////////////////////////////////////////////////////////// Maths //////////////////////////////////////////////////////////////////////////////

//vll sieve;
//void Sieve(int N){  //smallest prime factor
//	const ll maxn = N;
//	sieve.resize(maxn);
//	forn(i,maxn) sieve[i] = i;
//	sieve[1] = -1;
//	sieve[0] = -1;
//	forab(i,2,maxn,1) if(i == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) if(sieve[j] == j) sieve[j] = i;
//
////	for(auto i:sieve){
////		cout<<i<<" ";
////	}
//
//}
vll sieve;
vll* Sieve(int N) {
	const ll maxn = N;
	sieve.resize(maxn);
	forn(i,maxn) sieve[i] = 1;
	sieve[1] = 0;
	sieve[0] = 0;
	forab(i,2,maxn,1) if(1 == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) sieve[j] = 0;

	vll* primes=new vll();
	primes->pb(2);
	for(int i=3; i<maxn; i+=2)
		if(sieve[i]) {
			primes->pb(i);
		}
	return primes;

}

ll extended_GCD(ll a , ll b , ll &x , ll &y) {
	if(a == 0) {
		x = 0;
		y = 1;
		return b;
	}
	ll x1 , y1;
	ll gcd = extended_GCD(b%a , a , x1 , y1);
	x = y1 - (b/a)*x1;
	y = x1;
	return gcd;
}

ll ncr(ll n,ll k) {
	ll r=1;
	if(k>n-k)
		k=n-k;
	for(ll i=0; i<k; i++) {
		r*=(n-i);
		r/=(i+1);
	}
	return r;
}

ll power(ll a, ll b,ll m = MOD) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}

	return res;
}

ll modinv(ll a , ll mod = MOD) {
	ll x , y;
	extended_GCD(a , mod , x , y);
	if(x < 0) x += mod;
	return x;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bool prime(int n) {
	int c=0;
	for(int i=2; (i*i)<=n; i++) {
		if(n%i==0) {
			c++;
			return false;
		}
	}
	if(c==0)
		return true;
}
// bool compareInterval(char i1, char i2)
//{
//    return (i1 < i2);
//}
// int countoperation(int n,m){
// 	vector<int> d<m+1,-1>;
// }
vector<int> v[200006];
int vis[200006];
int c;
int in[200006];
vector<int> res;

bool khan(int n){
	priority_queue<int,vector<int>,greater<int>> q;
	for(int i=1;i<=n;i++){
		if(in[i]==0)
		q.push(i);
	}

	while(!q.empty()){
		int curr=q.top();
		res.pb(curr);
		q.pop();

		for(int node:v[curr]){
			in[node]--;
			if(in[node]==0)
			q.push(node);
		}
	}

	return n==res.size();

}

void dfs(int n){
	vis[n]=1;
	cout<<n<<" ";
	for(int i:v[n]){
		if(!vis[i])
		dfs(i);
	}

}

void solve() {

ll n;
cin>>n;

ll s=0,i=1;

ll N=(n+1)*2;
ll x=((int)sqrt(1+4*N)-1)/2;

while((x+2)*(x+1)/2<=n+1)
x++;

cout<<n-x+1<<"\n";

}

int main() {
	flash
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

//	test
	solve();
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define erep(i,j) for(int i=hd[j];i;i=nxt[i])
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}

using namespace std;
const int M=1e6+5;
int mob[M],vis[M],cnt[M];
int E[M*20],hd[M*20],nxt[M*20];
int tot;
void add(int a,int b){
	E[++tot]=b,nxt[tot]=hd[a];
	hd[a]=tot;
}
long long que(int l,int r){
	long long ans=0;
	rep(i,1,r)cnt[i]=0;
	rep(i,l,r){
		erep(j,i){
			int t=E[j];
			ans+=cnt[t];
			cnt[t]+=mob[t];
		}
	}
	return ans;
}
int main() {
	int L=read(),R=read();
	rep(i,1,M-1)mob[i]=1;
	rep(i,2,M-1){
		if(vis[i])continue;
		mob[i]=-1;
		for(int j=i+i;j<M;j+=i){
			vis[j]=1;
			if(j/i%i==0)mob[j]=0;
			else mob[j]=-mob[j];
		}
	}
	rep(i,1,M-1)for(int j=i;j<M;j+=i)add(j,i);
	long long ans=0;
	rep(i,2,M-1){
		int mi=2e9,mx=-2e9;
		for(int j=i+i;j<M;j+=i)if(j>=L&&j<=R)mi=min(mi,j/i),mx=max(mx,j/i);
		if(mi<=mx)ans+=que(mi,mx);
	}
	printf("%lld\n",ans*2);
	return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#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 mydeb(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
//#define mydeb(fmt, ...)

int main()
{
    int64_t t,n;
    cin >> t >> n;
    cout << (n*100+(t-1))/t*(100+t)/100 -1 << endl;
}

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

//一次元配列に入力する関数 vin(n);
vector<string> vin(int n) {
	vector<string> vec(n);
	for (int i = 0; i < n; i++)
	  cin >> vec.at(i);
	return vec;
}

//一次元配列から順番に出力する関数 cout<<"a:";vout(a,n);cout<<endl;
void vout(vector<long long> vec, int n) {
	for (int i = 0; i < n; i++)
	cout << vec.at(i) << ",";
	return;
}

//debug用出力関数 dout("n",n);
void dout(string s, int n) {
	cout << s << ":" << n << endl;
	return;
}

int main() {

  	long long n,ans = 0;
	cin >> n;
	unordered_set<long long> a;
	//cout<<"a:";vout(a,n);cout<<endl;

	long long i = 2,j = 2,m = 0;
	while(i * i <= n){//dout("i",i);
		j = 2;
		m = 0;
		while(m <= n){
			m = pow(i,j);//dout("j",j);
          	//m = i * i;
          	//dout("m",m);
			if(m <= n){
				a.insert(m);//dout("m",m);
			}
			j++;
		}
		i++;
	}
	//cout<<"a:";vout(a,n);cout<<endl;

	ans = n - a.size();
	cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

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

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}

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

    ll x,y,a,b;
    cin>>x>>y>>a>>b;

 	ll mn=min(y-1,x+b),ans=0;

    while((__int128)x*a <= (__int128)mn)
    {
    	x*=a;
    	ans++;
    }

    ans+=(y-1-x)/b;
    cout<<ans<<endl;
    return 0;
}

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

const int mod2 = 998244353;
const int mod = 1e9+7;
const int maxi = 4e3 + 2;
int power(int a,int b){
    int res = 1;
    while(b){
        if(b&1LL)res = (res*a)%mod;
        a = (a*a)%mod;
        b/=2LL;
    }
    return res;
}

int fermat(int a){
    return power(a,mod-2);
}

struct seg_tree{
    int n;
    vector<int> tree;

    seg_tree(int _n){
        n = _n;
        n *= 4;
        n ++;
        tree = vector<int>(n,-1);
    }

    void build(int v,int tl,int tr,vector<int> &a){
        if(tl == tr){
            tree[v] = a[tl];
            return;
        }
        int mid = (tl+tr)/2;
        build(v*2,tl,mid,a);
        build(v*2+1,mid+1,tr,a);
        tree[v] = max(tree[v*2],tree[v*2+1]);
    }

    int query(int v,int tl,int tr,int l,int r){
        // cout<<l<<" "<<r<<" "<<tl<<" "<<tr<<" "<<v<<" "<<tree[v]<<endl;
        if(l>r)return -1;
        if((l == tl) && (r == tr))return tree[v];
        int mid = (tl+tr)/2;
        int ans1 = query(v*2,tl,mid,l,min(r,mid));
        int ans2 = query(v*2+1,mid+1,tr,max(l,mid+1),r);
        return max(ans1,ans2);
    }
};

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int T = 1;
    // cin >> T;

    while(T --){
       int a,b,c;
       cin >> a >> b >> c;
       int s = 21 - (a+b+c);
       cout<<s;
    }

    return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=2e6+5;
double d[maxm];
int n;
void solve(){
    cin>>n;
    d[n]=0;
    for(int i=n-1;i>=1;i--){
        d[i]=d[i+1]+n*1.0/(n-i);
    }
    printf("%.10f\n",d[1]);
}
signed main(){
    solve();
    return 0;
}

/**
  *  author:    Apiram
  *  created:   06.03.2021 18:23:08
**/
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double n;
cin>>n;
cout<<setprecision(15)<<fixed;
double a=0;
for (int i =1;i<n;++i){
a+=n/i;
}
cout<<a;
return 0;}


#include <bits/stdc++.h>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T>
bool chmin(T a, T &b) {
    return a < b ? b = a, true : false;
}

template<typename T>
bool chmax(T a, T &b) {
    return a > b ? b = a, true : false;
}

/*----------------------------------------------------------------*/

void solve() {
    ll n;
    std::cin >> n;

    vll x(n), y(n);
    for (ll i = 0; i < n; i++)
        std::cin >> x[i] >> y[i];

    ll ans = 0;
    for (ll i = 0; i < n; i++) for (ll j = i + 1; j < n; j++)
        if (std::llabs(x[i] - x[j]) >= std::llabs(y[i] - y[j]))
            ans++;

    std::cout << ans << '\n';
}

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

    solve();
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=(a); i<(n); i++)
#define rrep(i,a,n) for(int i=(a); i>=(n); i--)
#define all(n) begin(n),end(n)
#define rall(n) rbegin(n),rend(n)
//#define yn(bool) if(bool){cout<<Yes<<endl;}else{cout<<No<<endl;}
#define fore(i,a) for(auto &i:a)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }

void _main() {
    int n;
    cin>>n;
    vi x(n),y(n);
    rep(i,0,n) cin>>x[i]>>y[i];
    int ans = 0;

    rep(i,0,n) {
        rep(j,i+1,n){
            if(abs(y[i]-y[j]) <= abs(x[i]-x[j])) ans++;
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, po[8];
vector<string> s[8];

int main() {
    ci(n);
    po[0] = 1;
    rep(i, n - 1) po[i + 1] = 2 * po[i] + 1;
    s[0].epb("AB");
    rep(i, n - 1) {
        rep(j, po[i]) {
            string tmp1, tmp2;
            for (auto &c: s[i][j]) {
                tmp1.append(2, c);
                tmp2.append(1, c);
                tmp2.append(1, 'A' + (c - 'A' + 1) % 2);
            }
            s[i + 1].epb(tmp1);
            s[i + 1].epb(tmp2);
        }
        string tmp;
        rep(j, po[i] + 1) tmp.append("AB");
        s[i + 1].epb(tmp);
    }
    co(po[n - 1]);
    rep(i, po[n - 1]) co(s[n - 1][i]);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
using Graph=vector<vector<int>>;

void dfs(int v,vector<bool> &flag,Graph &g){
  if(!flag[v]){return;}
  flag[v]=false;
  for(auto &nx : g[v]){dfs(nx,flag,g);}
}

int main(){
  int n,res=0;
  cin >> n;
  vector<int> a(n);
  vector<bool> flag(200005,false);
  Graph g(200005);
  for(auto &nx : a){
    cin >> nx;
    if(!flag[nx]){flag[nx]=true;res++;}
  }
  int p=0,q=n-1;
  while(p<q){
    g[a[p]].push_back(a[q]);
    g[a[q]].push_back(a[p]);
    p++;q--;
  }
  for(int i=1;i<=200000;i++){
    if(flag[i]){
      res--;
      dfs(i,flag,g);
    }
  }
  cout << res;
}


#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#include<random>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (int)(Y);++(X))
#define reps(X,S,Y) for (int (X) = (int)(S);(X) < (int)(Y);++(X))
#define rrep(X,Y) for (int (X) = (int)(Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (int)(Y)-1;(X) >= (int)(S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"
#define cauto const auto

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
void ouT(ll x,int d=3){auto re=to_string(x);if((int)re.size()>d) re=x>0?"oo":"-oo";cout<<string(d-re.size(),' ')<<re<<",";}
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
template<class A,class B> pair<A,B> operator+(const pair<A,B> &p,const pair<A,B> &q){ return {p.X+q.X,p.Y+q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator+=(pair<A,B> &p,const pair<C,D> &q){ p.X+=q.X; p.Y+=q.Y; return p;}
template<class A,class B> pair<A,B> operator-(const pair<A,B> &p,const pair<A,B> &q){ return {p.X-q.X,p.Y-q.Y};}
template<class A,class B,class C,class D> pair<A,B>& operator-=(pair<A,B> &p,const pair<C,D> &q){ p.X-=q.X; p.Y-=q.Y; return p;}
template<class A,class B> istream& operator>>(istream &is, pair<A,B> &p){ is>>p.X>>p.Y; return is;}
template<class T=ll> T read(){ T re; cin>>re; return move(re);}
template<class T=ll> T read(const T &dec){ T re; cin>>re; return re-dec;}
template<class T=ll> vector<T> readV(const int sz){ vector<T> re(sz); for(auto &x:re) x=read<T>(); return move(re);}
template<class T=ll> vector<T> readV(const int sz, const T &dec){ vector<T> re(sz); for(auto &x:re) x=read<T>(dec); return move(re);}
vv<int> readG(const int &n,const int &m){ vv<int> g(n); rep(_,m){ cauto a=read<int>(1),b=read<int>(1); g[a].pb(b); g[b].pb(a);} return move(g);}
vv<int> readG(const int &n){ return readG(n,n-1);}
#define TT cauto TTT=read();rep(_,TTT)
const ll MOD=1e9+7; //998244353;

vector<int> primes,prime;
class PRPRPR{
public:
  PRPRPR(int PRIME_MAX){
    prime.resize(PRIME_MAX);
    for(int i=2;i<PRIME_MAX;i++)if(!prime[i]){
	primes.pb(i);
	for(int j=i*2;j<PRIME_MAX;j+=i)
	  prime[j]=1;
      }
  }
} prprprpr(1123456);

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	cauto n=read();
	vector<int> cnt(n+1);
	for(cauto p:primes)for(ll i=p;i<=n;i*=p)for(ll j=i;j<=n;j+=i) ++cnt[j];
	rep(i,n) cout<<cnt[i+1]+1<<" ";
	cout NL;
  return 0;
}

#define MOD_TYPE 2

#pragma region Macros

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

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-7;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

map<ll, ll> memo;

ll x, y;

ll f(ll i)
{
  if (i <= 1)
    return abs(i - x);
  if (i == x)
    return 0;
  if (memo.count(i))
    return memo[i];
  ll res = abs(i - x);
  if (i % 2 == 0)
    chmin(res, f(i / 2) + 1);
  else
  {
    chmin(res, f((i - 1) / 2) + 2);
    chmin(res, f((i + 1) / 2) + 2);
  }
  return memo[i] = res;
}

void solve()
{
  cin >> x >> y;
  cout << f(y) << "\n";
}

int main()
{
  solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b)
const int maxn = 2e5 + 10;
pii a[maxn];
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; ++i) scanf("%d%d", &a[i].first, &a[i].second);
	sort(a + 1, a + k + 1);
	unordered_set<int> s;
	s.insert(n);
	int j = 1;
	for(int i = 1; i <= k; i = j)
	{
		vector<int> toInsert;
		vector<int> toErase;
		while(a[j].first == a[i].first)
		{
			if(s.count(a[j].second - 1) || s.count(a[j].second + 1))
				toInsert.push_back(a[j].second);
			else toErase.push_back(a[j].second);
			++j;
		}
		for(auto v : toInsert) s.insert(v);
		for(auto v : toErase) s.erase(v);
	}
	printf("%d\n", s.size());
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = Root(x); y = Root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool IsSameRoot(int x, int y) {
    return Root(x) == Root(y);
  }
  int Root(int x) {
    return data[x] < 0 ? x : data[x] = Root(data[x]);
  }
  int Size(int x) { return -data[Root(x)]; }
};

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> a(N), b(N); cin >> a >> b;

  UnionFindTree tree(N);
  for (int i = 0; i < M; ++i) {
    int c, d; cin >> c >> d;
    --c; --d;
    tree.Unite(c, d);
  }

  map<int, vector<int>> sets;
  for (int i = 0; i < N; ++i) sets[tree.Root(i)].push_back(i);

  for (auto [index, v] : sets) {
    LL as = 0, bs = 0;
    for (LL x : v) {
      as += a[x];
      bs += b[x];
    }

    if (as != bs) {
      cout << "No" << endl;
      return 0;
    } else {
      continue;
    }
  }
  cout << "Yes" << endl;
}


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

using namespace std;

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

    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<int> X(m), Y(m), Z(m);
    for (int i = 0; i < m; ++i) {
        cin >> X[i] >> Y[i] >> Z[i];
        --Y[i];
    }

    vector<vector<int>> events(n + 1);
    for (int i = 0; i < m; ++i) {
        events[X[i]].push_back(i);
    }

    int N = 1 << n;

    vector<vector<int>> cnts(n, vector<int>(N, 0));

    for (int i = 0; i < N; ++i) {
        for (int j = 0, c = 0; j < n; ++j) {
            if ((i >> j) & 1) {
                ++c;
            }
            cnts[j][i] = c;
        }
    }

    vector<int> bits(N, 0);
    for (int i = 0; i < N; ++i) {
        bits[i] = bits[i >> 1] + (i & 1);
    }

    vector<long long> dp(N, 0);
    dp[0] = 1;

    for (int i = 0; i < N; ++i) {
        int b = bits[i];
        bool ok = true;
        for (auto& j : events[b]) {
            int y = Y[j];
            int z = Z[j];
            if (cnts[y][i] > z) {
                ok = false;
                break;
            }
        }
        if (!ok) {
            dp[i] = 0;
            continue;
        }
        for (int j = 0; j < n; ++j) {
            if ((i >> j) & 1) {
                continue;
            }
            int ni = i | 1 << j;
            dp[ni] += dp[i];
        }
    }

    cout << dp[N - 1] << '\n';

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define    lcm(a,b)                ((a*b)/(__gcd(a,b)))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
using namespace __gnu_pbds;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const ll N=100+5,mod=1000000007,sh=201,inf=2000000000;
typedef tree<
pair<ll,ll> ,
null_type,
less<pair<ll,ll> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
string s[N];
bool check(int r1,int c1,int r2,int c2){

  if(s[r1][c1]=='#'||s[r2][c2]=='#') return 0;

  if(r1==r2&&c1==c2){

    return 1;
  }

  if(r1!=r2&&c1!=c2) return 0;

  if(r1==r2){

    if(c2<c1) swap(c1,c2);

    for(int i=c1;i<=c2;i++){
        if(s[r1][i]=='#') return 0;
    }
    return 1;
  }
  else{
    if(r2<r1) swap(r1,r2);

    for(int i=r1;i<=r2;i++){
        if(s[i][c1]=='#') return 0;
    }
    return 1;
  }

}
int main(){
     GO();

     int T=1;
    // cin>>T;
     while(T--){

        int n,m,r,c;
        cin>>n>>m>>r>>c;
        r--;
        c--;

        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        int ans=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                ans+= check(r,c,i,j);
            }
        }

        cout<<ans<<"\n";

     }

}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vi accA(n+1),accT(n+1),accC(n+1),accG(n+1);
  rep(i,n) {
    accA[i+1] = accA[i];
    accT[i+1] = accT[i];
    accC[i+1] = accC[i];
    accG[i+1] = accG[i];
    if(s[i]=='A') {
      accA[i+1]++;
    } else if(s[i]=='T'){
      accT[i+1]++;
    } else if(s[i]=='C') {
      accC[i+1]++;
    } else {
      accG[i+1]++;
    }
  }
  // [l,r]
  auto getA = [&](int l,int r) {
    return accA[r+1]-accA[l];
  };
  auto getT = [&](int l,int r) {
    return accT[r+1]-accT[l];
  };
  auto getC = [&](int l,int r) {
    return accC[r+1]-accC[l];
  };
  auto getG = [&](int l,int r) {
    return accG[r+1]-accG[l];
  };
  int ans = 0;
  rep(i,n) {
    rep(j,n) {
      int a = getA(i,j);
      int t = getT(i,j);
      int c = getC(i,j);
      int g = getG(i,j);
      if(a!=t) continue;
      if(c!=g) continue;
      if(a+c>0) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <cstdio>
#include <algorithm>
const int N = 3e5 + 5;
long long n, k, ans, d[N];
int x;
int main(){
    scanf("%lld%lld", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        d[x] ++;
    }
    long long last = k;
    for(long long i = 0; i <= n; i++){
        long long nl = std::min(last, d[i]);
        ans += i  * (last - nl);
        last = nl;
    }
    printf("%lld", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    int T[N][N];
    for(int i=0;i<N;i++)for(int j=0;j<N;j++){
        cin >> T[i][j];
    }

    vector<int> p;
    for(int i=0;i<N;i++){
        p.push_back(i);
    }
    p.push_back(0);

    int ans = 0;
    do{
        int sum = 0;
        for(int i=0;i<N;i++){
            sum += T[p[i]][p[i+1]];
        }
        if(sum == K){
            ans++;
        }
    }while(next_permutation(p.begin()+1,p.end()-1));

    cout << ans;
}

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
typedef long long LL;
int n,k;
int S(int t) {
	int l=max(1,t-n),r=min(n,t-1);
	return max(r-l+1,0);
}
int main() {
	cin>>n>>k;
	LL s=0;
	For(i,1,n+n) {
		s+=1LL*S(i)*S(i+k);
	}
	cout<<s;
	return 0;
}


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

int64_t synthesis(int num,int64_t x,vector<int> &a);
const int64_t _infinity=(int64_t)1000000000000000000+1;

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

	vector<int> a(n);
	for (int i=0;i<n;++i)
	{
		cin >> a[i];
	}
	sort(a.begin(),a.end());

	int64_t fastest=_infinity;
	for (int i=1;i<=n;++i)
	{
		fastest=min(fastest,synthesis(i,x,a));
	}
	cout << fastest << endl;
}

int64_t synthesis(int num,int64_t x,vector<int> &a)
{
	vector<vector<int>> dp(num+1,vector<int>(num,-1));
	for (int i=0;i<a.size();++i)
	{
		int modulo=a[i]%num;
		for (int j=num-1;j>=1;--j)
		{
			for (int k=0;k<num;++k)
			{
				if (dp[j][k]<0)
				{
					continue;
				}
				int k2=k+modulo;
				if (k2>=num)
				{
					k2-=num;
				}
				dp[j+1][k2]=max(dp[j+1][k2],dp[j][k]+a[i]);
			}
		}
		dp[1][modulo]=a[i];

#ifdef NEVER_DEFINED
		fprintf(stderr,"%d %d\n",i,a[i]);
		for (int j=1;j<=num;++j)
		{
			fprintf(stderr,"%d: ",j);
			for (int k=0;k<num;++k)
			{
				fprintf(stderr,"%d ",dp[j][k]);
			}
			fprintf(stderr,"\n");
		}
		fprintf(stderr,"\n");
#endif // NEVER_DEFINED
	}
	return (dp[num][x%num]>0) ? (x-dp[num][x%num])/num : _infinity;
}

#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e18 + 10;

ll N, X;
ll A[105];
ll S[105][105][105][105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    REP(i, N) {
        cin >> A[i];
    }
    memset(S, -1, sizeof(S));
    sort(A, A + N, greater<ll>());

    FOR(i, N + 1, 1) {
        S[0][0][i][X % i] = 0;
    }
    REP(i, N) {
        REP(j, i + 1) {
            FOR(a, N + 1, 1) {
                REP(b, N + 1) {
                    S[i + 1][j][a][b] = std::max(S[i + 1][j][a][b], S[i][j][a][b]);
                    if (S[i][j][a][b] < 0)
                        continue;
                    ll s = S[i][j][a][b] + A[i];
                    ll p = (X - s) % a;
                    S[i + 1][j + 1][a][p] = std::max(S[i + 1][j + 1][a][p], s);
                }
            }
        }
    }

    ll ans = INF;
    FOR(i, N + 1, 1) {
        if (S[N][i][i][0] < 0)
            continue;
        ans = std::min(ans, (X - S[N][i][i][0]) / i);
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

void solve() {
    ll n;
    cin >> n;
    vector<ll> p(n);
    for (ll &i : p)cin >> i;
    vector<ll> ans;
    ll oper = 1;
    ll cur = 1;
    bool ok = true;
    while (cur <= n) {
        ll i;
        for (i = 0; i < n; ++i) {
            if (p[i] == cur)break;
        }
        if (i + 1 == cur) {
            cur++;
            continue;
        }
        if (i % 2 == oper % 2) {
            ans.push_back(i);
            swap(p[i], p[i - 1]);
            oper++;
        } else {
            if (cur % 2 == oper % 2) {
                oper++;
                swap(p[cur], p[cur - 1]);
                ans.push_back(cur);
            } else {
                if (cur == n - 1) {
                    swap(p[cur - 2], p[cur - 1]);
                    ans.push_back(cur - 1);
                    swap(p[cur], p[cur - 1]);
                    ans.push_back(cur);
                    swap(p[cur - 2], p[cur - 1]);
                    ans.push_back(cur - 1);
                    oper += 3;
                    cur--;
                }
                oper++;
                swap(p[cur], p[cur + 1]);
                ans.push_back(cur + 1);
            }
        }
    }
    if (ans.size() > n * n || !is_sorted(p.begin(), p.end())) {
        cout << 1 / 0;
        return;
    }
    cout << ans.size() << "\n";
    for (auto x : ans)cout << x << " ";
    cout << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin >> t;
    while (t--)solve();
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 2e5 + 10;

int a[N], res[N], pos[N];

void Swap(int p, int &idx) {
	swap(pos[a[p]], pos[a[p + 1]]);
	swap(a[p], a[p + 1]);
	res[idx++] = p;
}

void solve() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		pos[a[i]] = i;
	}
	int idx = 1;
	for(int i = n; i >= 1; i--) {
		if(a[i] == i) continue;
		while(idx % 2 != pos[i] % 2) {
			if(idx & 1) Swap(1, idx);
			else Swap(2, idx);
		}
		while(pos[i] != i) {
			Swap(pos[i], idx);
		}
	}
	printf("%d\n", idx - 1);
	for(int i = 1; i < idx; i++) {
		printf("%d ", res[i]);
	}
	puts("");
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE

    int t; cin >> t; while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

int main() {
    int N;
    std::cin >> N;
    std::vector<long long int> a(N), b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        std::cin >> b[i];
    }

    long long int max_a = 1, max_b = 1;
    long long int max = 1;
    // long long int max = 1;
    for (int i = 0; i < N; i++) {
        max_a = std::max(max_a, a[i]);
        if (b[i] >= max_b) {
            max_b = b[i];
            max = max_a * max_b;
        } else if (max_a * b[i] >= max) {
            max_b = b[i];
            max = max_a * max_b;
        }
        std::cout << max << std::endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}void __print(long x) {cout << x;}void __print(long long x) {cout << x;}void __print(unsigned x) {cout << x;}void __print(unsigned long x) {cout << x;}void __print(unsigned long long x) {cout << x;}void __print(float x) {cout << x;}void __print(double x) {cout << x;}void __print(long double x) {cout << x;}void __print(char x) {cout << '\'' << x << '\'';}void __print(const char *x) {cout << '\"' << x << '\"';}void __print(const string &x) {cout << '\"' << x << '\"';}void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define loop(i,a,b)     for (ll i=a;i<=(ll)b;i++)
#define rloop(i,a,b)    for (ll i=a;i>=(ll)b;i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           ((a)*(a))
#define sz(a)           a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
      ll n;
      cin>>n;
      ll a[n],b[n];
      ll mx=0;
      loop(i,0,n-1)
      {
        cin>>a[i];
        mx=max(mx,a[i]);
        a[i]=mx;
      }
      mx=0;
      loop(i,0,n-1)
      {
        cin>>b[i];
        mx=max(mx,b[i]*a[i]);
        cout<<mx;
        nl;
      }
    }
    return 0;
}


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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

void Solve()
{
	ll N;
	cin >> N;
	VL a(N), t(N);
	REP(i, N) cin >> a[i] >> t[i];
	ll Q;
	cin >> Q;
	VL x(Q);
	REP(i, Q) cin >> x[i];

	ll sum = 0;
	ll maxVal = -INF;
	ll minVal = INF;
	REP(i, N) {
		if (t[i] == 1) {
			sum += a[i];
			maxVal += a[i];
			minVal += a[i];
		}
		if (t[i] == 2) {
			maxVal = max(maxVal, a[i]);
			minVal = max(minVal, a[i]);
		}
		if (t[i] == 3) {
			maxVal = min(maxVal, a[i]);
			minVal = min(minVal, a[i]);
		}
	}

	for (auto q : x) {
		ll ans = q + sum;
		ans = max(ans, maxVal);
		ans = min(ans, minVal);
		cout << ans << endl;
	}
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}

#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define ini(x, y) memset(x, y, sizeof(x));
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e9;
const double PI = acos(-1);
ll a[200001], t[200001], x[200001];

int main(void) {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	// freopen("input.txt", "r", stdin);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> t[i];
	}
	int q; cin >> q;
	for (int i = 1; i <= q; i++) cin >> x[i];
	vector<pll> v;
	for (int i = 1; i <= q; i++) {
		v.push_back({ x[i], i });
	}
	sort(all(v));
	ll tmp = 0;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 1) tmp += a[i];
		else {
			a[i] -= tmp;
		}
	}
	ll mx = -1e18;
	ll mi = 1e18;
	bool chk = false;
	ll val;
	for (int i = 1; i <= n; i++) {
		if (t[i] == 1) continue;
		else if (t[i] == 2) {
			if (chk) {
				val = max(val, a[i]);
			}
			else {
				mx = max(mx, a[i]);
				if (mx >= mi) {
					chk = true;
					val = mx;
				}
			}
		}
		else {
			if (chk) {
				val = min(val, a[i]);
			}
			else {
				mi = min(mi, a[i]);
				if (mi <= mx) {
					chk = true;
					val = mi;
				}
			}
		}
	}
	if (chk) {
		for (int i = 1; i <= q; i++) {
			cout << val + tmp<<'\n';
		}
	}
	else {
		for (int i = 1; i <= q; i++) {
			if (mx > x[i]) cout << mx + tmp << '\n';
			else if (mi < x[i]) cout << mi + tmp << '\n';
			else cout << x[i] + tmp << '\n';
		}
	}

}