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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll invMod(ll num){
  return fast_expo(num, MOD - 2)%MOD;
}

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

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n; cin >> n;
    vector<ll> AdjL[n + 1];
    ll a[n], b[n];
    for(ll i = 1; i < n; ++i){
      cin >> a[i] >> b[i];
      AdjL[a[i]].pb(b[i]);
      AdjL[b[i]].pb(a[i]);
    }

    ll lev[n + 1], vis[n + 1]{};
    queue<ll> Q;
    Q.push(1);
    vis[1] = lev[1] = 1;
    while(!Q.empty()){
      ll node = Q.front();
      Q.pop();
      for(auto i: AdjL[node]){
        if(!vis[i]){
          vis[i] = 1;
          Q.push(i);
          lev[i] = lev[node] + 1;
        }
      }
    }

    ll c[n + 1]{};
    ll q; cin >> q;
    for(ll i = 1; i <= q; ++i){
      ll t, e, x; cin >> t >> e >> x;
      ll ini = a[e], fin = b[e];
      if(t == 2) swap(ini, fin);

      if(lev[ini] < lev[fin]){
        c[1] += x;
        c[fin] -= x;
      } else {
        c[ini] += x;
      }
    }

    ll ans[n + 1]{};
    fill_n(vis, n + 1, 0);
    Q.push(1);
    vis[1] = 1; ans[1] = c[1];

    while(!Q.empty()){
      ll node = Q.front();
      Q.pop();
      for(auto i: AdjL[node]){
        if(!vis[i]){
          vis[i] = 1;
          Q.push(i);
          ans[i] = ans[node] + c[i];
        }
      }
    }

    for(ll i = 1; i <= n; ++i)
      cout << ans[i] << endl;
  }
  return 0;
}

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P = pair<ll,ll>;
    const int mod=998244353;
    const int INF=1001001001;

    int main() {
      int N;
      cin>>N;
      vector<ll>x(N),y(N);
      rep(i,N){cin>>x[i]>>y[i];}
      int M;
      cin>>M;
      vector<P>b1(M+1),b2(M+1),b3(M+1);
      b3[0]=P(1,0);
      b2[0]=P(0,1);
      rep(i,M){
        int s;
        cin>>s;
        if(s==1){
          b1[i+1]=P(b1[i].second,-b1[i].first);
          b2[i+1]=P(b2[i].second,-b2[i].first);
          b3[i+1]=P(b3[i].second,-b3[i].first);
        }
        else if(s==2){
          b1[i+1]=P(-b1[i].second,b1[i].first);
          b2[i+1]=P(-b2[i].second,b2[i].first);
          b3[i+1]=P(-b3[i].second,b3[i].first);
        }
        else{
          int p;
          cin>>p;
          if(s==3){
            b1[i+1]=P(2*p-b1[i].first,b1[i].second);
            b2[i+1]=P(2*p-b2[i].first,b2[i].second);
            b3[i+1]=P(2*p-b3[i].first,b3[i].second);
          }
          if(s==4){
            b1[i+1]=P(b1[i].first,2*p-b1[i].second);
            b2[i+1]=P(b2[i].first,2*p-b2[i].second);
            b3[i+1]=P(b3[i].first,2*p-b3[i].second);
          }
        }
      }
      int Q;
      cin>>Q;
      rep(i,Q){
        int a,b;
        cin>>a>>b;
        b--;
        ll X=(b3[a].first-b1[a].first)*x[b]+(b2[a].first-b1[a].first)*y[b]+b1[a].first;
        ll Y=(b3[a].second-b1[a].second)*x[b]+(b2[a].second-b1[a].second)*y[b]+b1[a].second;
        cout<<X<<" "<<Y<<endl;
      }
      return 0;
    }


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

#define all(v) v.begin(), v.end()
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, b) for (ll i = a; i < b; ++i)
#define rep_down(i, a, b) for (ll i = a; i > b; --i)

#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second

#define vvvvll vector<vector<vector<vector<ll>>>>
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>

#define vvvvdo vector<vector<vector<vector<double>>>>
#define vvvdo vector<vector<vector<double>>>
#define vvdo vector<vector<double>>
#define vdo vector<double>

#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 998244353;
// constexpr ll mod = 67280421310721;
// constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];
        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
template <typename T>
void pt_vvll(vector<vector<T>> &v) {
    ll vs = v.size();
    rep(i, vs) pt_vll(v[i]);
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}

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

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll x, ll n) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1)
            ret = ret * x % mod;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % mod;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
ll minv(ll a, ll m) { return modpow(a, m - 2); }
void pre_process(vector<ll> &a, vector<ll> &s) {  //累積和のvector
    ll n = (ll)a.size();
    s.assign(n + 1, 0);
    for (ll i = 0; i < n; i++) {
        s[i + 1] = s[i] + a[i];
        s[i + 1] %= mod;
    }
}
#define MAX 1000100
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
// 二項係数計算
ll combi(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
// mainに   COMinit();   を入れる
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();

    ll N, K;
    cin >> N >> K;
    vll A(N);
    rep(i, N) cin >> A[i];

    vvll mp(K + 1, vll(N)), sp(K + 1);

    rep(i, K + 1) {
        rep(j, N) { mp[i][j] = modpow(A[j], i); }
    }

    rep(i, K + 1) { pre_process(mp[i], sp[i]); }

    rep_up(X, 1, K + 1) {
        ll ans = 0;
        rep(k, X + 1) {
            ll m1 = (sp[k][N] * sp[X - k][N]) % mod;
            ll m2 = combi(X, k);

            (ans += (m1 * m2) % mod) %= mod;
        }

        ((ans -= (modpow(2, X) * sp[X][N]) % mod) += 100 * mod) %= mod;

        ans *= minv(2, mod);
        ans %= mod;
        (ans += 100 * mod) %= mod;

        pt(ans);
    }
    return 0;
}

/* include */
#include <bits/stdc++.h>
using namespace std;
/* definition */
#define _GLIBCXX_DEBUG
#define rep(i, N) for (ll i = 0; i < (ll)(N); i++)
#define repp(i, N) for (ll i = 1; i <= (ll)(N); i++)
#define pb(n) push_back(n)
#define all(v) (v).begin(), (v).end()
#define co(ans) cout << (ans)
#define fin << endl
#define enter cout << endl
#define ll long long
#define spr(i) cout << fixed << setprecision((ll)(i))
#define lmax 9223372036854775807
#define lmin -9223372036854775807
#define pi 3.1415926535897932384626433832795028
/* own maid function */
ll ctol(char c){
  if(c == '0')return 0;
  else if(c == '1')return 1;
  else if(c == '2')return 2;
  else if(c == '3')return 3;
  else if(c == '4')return 4;
  else if(c == '5')return 5;
  else if(c == '6')return 6;
  else if(c == '7')return 7;
  else if(c == '8')return 8;
  else if(c == '9')return 9;
  else return -1;
}
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;
}
bool isPrime(ll x){
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}
ll digsum(ll n){
  ll res = 0;
  while (n > 0)
  {
    res += n % 10;
    n /= 10;
  }
  return res;
}
ll dignum(ll n){
  ll res = 0;
  while (n > 0)
  {
    res += n % 10;
    n++;
  }
  return res;
}
vector<ll> enum_div(ll n){
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i != 1 && i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  return ret;
}
ll stringcount(string s, char c){
  return count(s.cbegin(), s.cend(), c);
}
/*
vector<> ();
vector<vector<>> (, vector<>(, ));
vector<vector<vector<>>> (, vector<vector<>>(, vector<>(, )));
*/
/* cins */
ll cinl(){ll l; cin >> l; return l;}
double cind(){double d; cin >> d; return d;}
char cinc(){char c; cin >> c; return c;}
string cins(){string s; cin >> s; return s;}
/* function */

/* main */
int main(void){
  ll A = cinl(), B = cinl(), C = cinl();
  ll a, b, c;
  a = A * (A+1) / 2;
  b = B * (B+1) / 2;
  c = C * (C+1) / 2;
  a %= 998244353;
  b %= 998244353;
  c %= 998244353;
  co((a*b%998244353)*c%998244353) fin;
}
/* fin */


#include<iostream>
#include<cstdio>
using namespace std;
struct Edge{
	int to,nxt;
}e[400005];
int n,k,h[200005],num,f[200005],g[200005],cnt;
void add(int u,int v){
	e[++num].to=v;
	e[num].nxt=h[u];
	h[u]=num;
}
void dfs(int u,int fa,int lim){
	int i,v;
	f[u]=1e9;
	g[u]=0;
	for(i=h[u];i;i=e[i].nxt){
		v=e[i].to;
		if(v!=fa){
			dfs(v,u,lim);
			f[u]=min(f[u],f[v]+1);
			g[u]=max(g[u],g[v]+1);
		}
	}
	if(f[u]+g[u]<=lim)
		g[u]=-1e9;
	if(g[u]>=lim)
		++cnt,f[u]=0,g[u]=-1e9;
}
bool judge(int lim){
	cnt=0;
	dfs(1,0,lim);
	return (cnt+(g[1]>=0))<=k;
}
int solve(){
	int l=1,r=n,mid,res;
	while(l<=r){
		mid=(l+r)>>1;
		if(judge(mid))
			r=mid-1,res=mid;
		else
			l=mid+1;
	}
	return res;
}
int main(){
	ios::sync_with_stdio(false);
	int i,u,v;
	cin>>n>>k;
	for(i=1;i<n;i++){
		cin>>u>>v;
		add(u,v);add(v,u);
	}
	cout<<solve()<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
P dfs(int u, int p, vector<vector<int>>&G, int t){
	int ac = 0;
	int mu = -1e9, ma = t;
	for(int v: G[u]) if(v != p){
		auto [fs, sd] = dfs(v,u,G,t); fs--;
		ac += sd;
		if(fs < 0) mu = max(mu,fs);
		else ma = min(ma,fs);
	}
	if(mu+ma >= 0) return {mu,ac};
	else if(ma == 0) ac++;
	return {ma, ac};
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vector<vector<int>> G(n);
	rep(i,n-1){
		int u, v; cin >> u >> v; v--; u--;
		G[v].push_back(u);
		G[u].push_back(v);
	}
	int l=-1, r=n-1;
	while(l+1<r){
		int mid = (l+r) / 2;
		auto [m, kk] = dfs(0,0,G,mid); if(m > 0) kk++;
		(kk <= k ? r : l) = mid;
	}
	cout << r << "\n";
}


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

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

	ll am = 0;
	double ae = 0;
	int ac = 0;
	rep(i, n)
	{
		ll x;
		cin >> x;
		x = abs(x);
		am += x;
		ae += x * x;
		ac = max(ac, (int)x);
	}
	ae = sqrt(ae);

	cout << setprecision(9) << fixed;
	cout << am << endl;
	cout << ae << endl;
	cout << ac << endl;
	return 0;
}

/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

template<class T>void sort(vector<T> &v){
  sort(v.begin(), v.end());
  return;
}
template<class T>void rsort(vector<T> &v){
  sort(v.begin(), v.end(), std::greater<int>());
  return;
}

const int MOD = 1000000007;

ll Manhattan_Distance(vec<int> v){
  ll D = 0;
  for(int i = 0; i < v.size(); i++){
    D += abs(v[i]);
  }
  return D;
}

double Euclidean_Distance(vec<int> v){
  ll D = 0;
  for(int i = 0; i < v.size(); i++){
    D += (ll)v[i] * (ll)v[i];
  }
  return sqrt(D);
}

int Chebyshev_Distance(vec<int> v){
  int D = 0;
  for(int i = 0; i < v.size(); i++){
    if(D < abs(v[i])){
      D = abs(v[i]);;
    }
  }
  return D;
}

int main(int argc, char* argv[]){
  int N;
  cin >> N;
  vec<int> x(N);
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }

  cout << Manhattan_Distance(x) << endl;
  printf("%.10lf\n", Euclidean_Distance(x));
  cout << Chebyshev_Distance(x) << endl;

  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;

const int N=0;

void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    cout << 21 - a - b - c;
}
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>
using namespace std;
typedef long long ll;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	ll sum=a+b+c;
	ll p=21-sum;
	cout<<p<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
long long dp[61][2];
string S[60];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }

  dp[0][0] = 1;
  dp[0][1] = 1;
  for(int i = 1; i <= N; i++){
    if(S[i - 1] == "OR"){
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][0] + (long long) 2 * dp[i - 1][1];
    } else {
      dp[i][0] = (long long) 2 * dp[i - 1][0] + dp[i - 1][1];
      dp[i][1] = dp[i - 1][1];
    }
  }
  cout << dp[N][1] << endl;
  return 0;
}

//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//絶対値はソートで取れる
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m × q^n ×...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N; i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define MOD pow(10, 9) + 7
#define PI 3.14159265358979323846264338327950L
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	int N; cin >> N;
	vector<string> S(N); rep(i, N) cin >> S[i];

	ll T=1, F=1;

	for(int i = 0; i < N; i++){
		if(S[i] == "AND") {
			F = 2*F + T;
		}
		else{
			T = 2*T + F;
		}
	}

	cout << T << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define endl "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sz(a) (int)a.size()
#define Q(x) for(int i=0;i<x;i++)
#define show(x) cout<<#x<<" ";for(auto i:x)cout<<i<<" ";cout<<endl;
// ctrl + shift + q -- stop execution
// use brackets after modulo operation
//if ((i & (1 << j) ) == 0) and if(i & (i << j) == 0) are different
const ll mod = 1e9 + 7;
using namespace std;

/*void solve() {

}*/
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	/*int t;
	cin >> t;
	while (t--) {
		solve();
	}*/
	ll n, x;
	cin >> n >> x;
	vll a(n);
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n) {
		if (a[i] != x)cout << a[i] << " ";
	}

	return 0;
}

#include <bits/stdc++.h>
#define int long long

using namespace std;

void fastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}

void test_case() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a * 2 == b + c || b * 2 == a + c || c * 2 == a + b)
    cout << "Yes\n";
  else cout << "No\n";
}

void solve() {
  int T = 1;
  for (int tc = 0; tc < T; ++tc)
    test_case();
}

int32_t main() {
  fastIO();
  solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout << #x << "=" << x << ", ";}
#define in(x); { for (auto &to : x) cin >> to;}
#define out(x); { for (auto &to : x) cout << to << " "; cout << '\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const int mod1 = 1e9+7;
const int mod2 = 1e9+21;

void solve()
{
    int n;
    cin>>n;
    ll need;
    cin>>need;
    vector <int>a(n);
    in(a);
    // sum==X (mod%k)
    vector <vector <vi> > dp(n+1,vvi(n+1,vi(n+1,-INF)));
    for (int i=1;i<=n;i++)
    {
        dp[i][0][0]=0;
    }
    for (auto to:a)
    {
        for (int total=1;total<=n;total++)
        {
            for (int got=total-1;got>=0;got--)
            {
                for (int rem=0;rem<total;rem++)
                {
                    if (dp[total][got][rem]==-INF)
                        continue;
                    dp[total][got+1][(rem+to)%total]=max(dp[total][got+1][(rem+to)%total],dp[total][got][rem]+to);
                }
            }
        }
    }
    ll ans=INFLL;
    for (int total=1;total<=n;total++)
    {
        if (dp[total][total][need%total]==-INF)
            continue;
//        cout<<need%total<<" "<<(need-dp[total][total][need%total])/total<<" "<<dp[total][total][need%total]<<" "<<total<<'\n';
        ans=min(ans,(need-dp[total][total][need%total])/total);
    }
    cout<<ans<<'\n';
}

int main() {
    #ifdef Mip182
    freopen("a.in", "r", stdin);
    #else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
    int _t;
    _t=1;
//    cin>>_t;
    while (_t--)
        solve();
    #ifdef Mip182
    cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n';
    #endif
}

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

int main() {
    int n;
    int ans = 1 << 30;
    cin >> n;

    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A.at(i);
    }

    for(int bit = 0; bit < (1 << (n-1)); bit++){
        int index = 0;
        int tmp = 0;
        vector<int> B(n, 0);

        for(int i = 0; i < n; i++){
            if(((bit >> (i-1)) & 1) && (i > 0)){
                index++;
            }
            B[index] |= A[i];
        }

        for(int i = 0; i <= index; i++){
            tmp ^= B[i];
        }

        ans = min(tmp, ans);
    }

    cout << ans << endl;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;

// GCC __gcd(long long A, long long B)

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

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

template<typename T>
vector<T> divisor(T n) {
  vector<T> res, res2;
  for (T i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i < n) res2.push_back(n / i);
    }
  }

  reverse(res2.begin(), res2.end());
  res.insert(res.end(), res2.begin(), res2.end());

  return res;
}

int main() {
  int N, A[SIZE];

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    scanf("%d", A + i);
  }

  sort(A, A + N);

  map<int, int> mm;

  for (int i = 0; i < N; i++) {
    auto divs = divisor(A[i]);

    for (int d : divs) {
      auto it = mm.find(d);
      if (it != mm.end()) {
        mm[d] = gcd(A[i], it->second);
      } else {
        mm[d] = A[i];
      }
    }
  }

  int ans = 0;

  for (auto v : mm) {
    ans += v.first == v.second && v.first <= A[0];
  }

  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

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

using namespace std;

using ll = long long;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

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

    int N;
    cin >> N;
    ll x = 0;
    ll S = 0;
    ll M = 0;
    ll result = 0;
    REP(i, N) {
        int A;
        cin >> A;
        S += A;
        amax(M, S);
        amax(result, x + M);
        x += S;
    }

    cout << result << endl;

    return 0;
}


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

int main()
{

    unsigned int oi[4];
    bool flag = false;
    int sum = 0;
    cin >> oi[0] >> oi[1] >> oi[2] >> oi[3];

    sum = oi[0] + oi[1] + oi[2] + oi[3];
    for(int i=0; i<4; i++){
        if(oi[i] == (sum - oi[i])){
            flag = true;
            break;
        }
    }

    for(int i=0; i<4-1; i++){
        for(int j=1; j<4; j++){
            if((oi[i] + oi[j]) == (sum - oi[i] - oi[j]))
                flag = true;
        }
    }

    if(flag == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

#include <iostream>

int main(){
    int A,B,C,D;
    std::cin >> A >> B >> C >> D;

    if (A==B+C+D || B==A+C+D || C==A+B+D || D==A+B+C || A+B==C+D || A+C==B+D || A+D==B+C){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }

    return 0;

}


#include <bits/stdc++.h>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

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

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
template<class T> bool chmax(T& a, const T& b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T> bool chmin(T& a, const T& b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

struct Edge {
public:
	int from, to;
	ll C, D;
	Edge() {}
	Edge(int _from, int _to, ll _C, ll _D) {
		from = _from;
		to = _to;
		C = _C;
		D = _D;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<ll, int> P;

ll getTime(ll time, Edge e) {
	return time + e.C + (e.D / (time + 1ll));
}

ll fastestTime(ll time, Edge e) {
	ll mid = sqrt(e.D);
	ll best = mid;
	for (ll i = max(mid - 100, 0ll);i <= mid + 100;i++) {
		if (getTime(best, e) > getTime(i, e)) {
			best = i;
		}
	}
	if (best >= time)return getTime(best, e);
	else return getTime(time, e);
}

vll dijkstra(int s, Graph G) {//s=>始点
	priority_queue<P, vector<P>, greater<P> > que;
	vll D(SZ(G), LINF);
	D[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (D[v] < p.first)continue;
		for (Edge e : G[v]) {
			ll fastest = fastestTime(D[v], e);
			if (D[e.to] > fastest) {
				D[e.to] = fastest;
				que.push(P(D[e.to], e.to));
			}
		}
	}
	return D;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	Graph G(N);
	REP(i, M) {
		int A, B;
		cin >> A >> B;
		ll C, D;
		cin >> C >> D;
		A--;B--;
		G[A].push_back(Edge(A, B, C, D));
		G[B].push_back(Edge(B, A, C, D));
	}
	vll ans = dijkstra(0, G);
	if (ans[N - 1] == LINF) {
		cout << -1 << endl;
	}
	else {
		cout << ans[N - 1] << endl;
	}
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const double PI = 3.141592653589793238;
int main() {
  auto start = chrono::system_clock::now();
  ll si, sj;
  cin >> si >> sj;
  ll nowi = si, nowj = sj;
  vector<ll> t(2500);
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> t[50 * i + j];
    }
  }

  vector<ll> p(2500);
  for (ll i = 0; i < 50; ++i) for (ll j = 0; j < 50; ++j) cin >> p[50 * i + j];

  string lastans = "";
  ll lastpnt = 0;
  map<ll, bool> used;
  string ans = "";
  while (true) {
    ll id = 50 * nowi + nowj;
    ll maxi = -1;
    used[t[id]] = true;
    char togo = ' ';
    if (nowj != 0 && !used[t[id - 1]] && maxi < p[id - 1]) {
      togo = 'L';
      maxi = p[id - 1];
    }
    if (nowj != 49 && !used[t[id + 1]] && maxi < p[id + 1]) {
      togo = 'R';
      maxi = p[id + 1];
    }
    if (nowi != 0 && !used[t[id - 50]] && maxi < p[id - 50]) {
      togo = 'U';
      maxi = p[id - 50];
    }
    if (nowi != 49 && !used[t[id + 50]] && maxi < p[id + 50]) {
      togo = 'D';
      maxi = p[id + 50];
    }
    if (togo != ' ')ans += togo;
    switch (togo)
    {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    default:
      goto exit;
    }
  }
exit:;
  nowi = si, nowj = sj;
  lastans = ans;
  ll now = 50 * nowi + nowj;
  lastpnt += p[now];
  for (ll i = 0; i < ans.size(); ++i) {
    switch (ans[i]) {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    }
    lastpnt += p[now];
  }

  string sample = "LRUD";
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> cha(0, 3), rand(1, 1000);
  auto dur = chrono::system_clock::now() - start;

  while (chrono::duration_cast<std::chrono::milliseconds>(dur).count() < 1990) {
    ans = lastans;

    uniform_int_distribution<> change(0, ans.size());
    ll ch = change(mt), at = cha(mt), r = rand(mt);
    if (ch == ans.size()) ans.push_back(sample[at]);
    else ans[ch] = sample[at];

    nowi = si, nowj = sj;
    now = 50 * nowi + nowj;
    map<ll, bool> used;
    used[t[now]] = true;
    ll pnt = p[now];
    for (ll i = 0; i < ans.size(); ++i) {
      switch (ans[i]) {
      case 'L': --nowj;
        break;
      case 'R': ++nowj;
        break;
      case 'U': --nowi;
        break;
      case 'D': ++nowi;
        break;
      }
      if (nowi < 0 || 49 < nowi || nowj < 0 || 49 < nowj) {
        pnt = -1;
        break;
      }
      now = 50 * nowi + nowj;
      if (used[t[now]]) {
        pnt = -1;
        break;
      }
      used[t[now]] = true;
      pnt += p[now];
    }
    if (pnt >= lastpnt) {
      lastpnt = pnt;
      lastans = ans;
    }
    else if (pnt != -1 && r <= 125) {
      lastpnt = pnt;
      lastans = ans;
    }
    dur = chrono::system_clock::now() - start;
  }
  cout << lastans << "\n";
}


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

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
vector<ll> cnt(10 , 0) , cnt1(10 , 0);
ll p(ll a , ll n){
    if(n == 0){
        return 1;
    }
    ll res = p(a*a , n / 2);
    if(n % 2){
        res *= a;
    }
    return res;
}
ll calc(string b){
    ll res = 0;
    for(ll i = 1; i <= 9; i++){
        res += (i * p(10LL , cnt1[i]));
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k;
    cin>>k;
    string s , t;
    cin>>s>>t;
    for(int i = 0; i < 4; i++){
        cnt[s[i] - '0']++;
        cnt[t[i] - '0']++;
    }
    ld m = 9*k - 8;
    ld total = m*(m - 1);
    ld ans = 0;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            for(int l = 0; l < 10; l++){
                cnt1[l] = 0;
            }
            cnt1[i]++;
            for(int l = 0; l < 4; l++){
                cnt1[s[l] - '0']++;
            }
            ll tak = calc(s);
            for(int l = 0; l < 10; l++){
                cnt1[l] = 0;
            }
            cnt1[j]++;
            for(int l = 0; l < 4; l++){
                cnt1[t[l] - '0']++;
            }
            ll aoki = calc(t);
            if(tak > aoki){
                if(i == j){
                    ans += ((k - cnt[i]) * (k - cnt[j] - 1));
                }else{
                    ans += ((k - cnt[i]) * (k - cnt[j]));
                }
            }
        }
    }
    ans /= total;
    cout<<fixed<<setprecision(16)<<ans<<"\n";
    return 0;
}

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = int64_t;

ll score(string S){
    vector<ll> cnt(10);
    iota(cnt.begin(), cnt.end(), 0);
    for(char c : S) cnt[c - '0'] *= 10;
    return accumulate(cnt.begin(), cnt.end(), 0);
}
int main(){
    ll K;
    string S, T;
    cin >> K >> S >> T;
    vector<ll> cnt(10, K);
    for(auto c : S + T) cnt[c - '0']--;
    ll win = 0;
    for(ll x = 1; x <= 9; x++) for(ll y = 1; y <= 9; y++){
        S.back() = '0' + x;
        T.back() = '0' + y;
        if(score(S) <= score(T)) continue;
        win += cnt[x] * (cnt[y] - (x == y));
    }
    const ll rem = 9 * K - 8;
    cout << double(win) / rem / (rem - 1) << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

int main(void){

    ll N;
    vector<ll> A;

    cin >> N;
    REP(i,N){
        ll a;
        cin >> a;
        A.push_back(a);
    }

    ll Ans=0;
    for(ll i=0;i<N;i++){
        ll mn = INF;
        for(ll j=i;j<N;j++){
            mn = min(mn,A[j]);
            Ans = max(Ans,mn*(j-i+1));
        }
    }
    cout << Ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return false;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return false;}
template<class T> void print(const T &t) { cout << t << "\n"; }
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

int n;
double d,h,x,y;

int main() {
    fio(); cin>>n>>d>>h;
    double cln=99999;
    rep(i,n){cin>>x>>y; chmin(cln,(h-y)/(d-x));}
    double ans = max(0.0,h-cln*d);
    cout << fixed << setprecision(12) << ans << "\n";
}
//9min


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

int main(){
  int n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  ll ans=1;
  for(int i=0;i<n-1;i++){
    ans*=(a[i+1]-a[i]+1);
    ans%=mod;
  }
  ans*=(a[0]+1);
  ans%=mod;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 998244353;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

class binomial_coefficients {
	long long MAX_VAL;
	vector<long long> fac, mmi;

public:

	binomial_coefficients(){
	}

	binomial_coefficients(long long num){
		init(num);
	}

	~binomial_coefficients(){

	}

	void init(long long num){
		MAX_VAL = num+1;
		fac.resize(MAX_VAL);
		mmi.resize(MAX_VAL);

		factorial_mod();
		modular_multiplicatibe_inverse();
	}

	void factorial_mod(){
		 fac[0] = 1;
		for(long long i = 1; i < MAX_VAL; fac[i] %= MOD, i++)
			fac[i] = fac[i - 1] * (i % MOD);
	}

	long long power(long long x, long long n){
		long long ans = 1;
		for(;n;n >>= 1, x *= x, ans %= MOD, x %= MOD) if(n&1)ans*=x;
		return ans % MOD;
	}

	void exgcd(long long a, long long b, long long &x, long long &y){
		if(b == 0){
			x = 1;
			y = 0;
			return ;
		}
		exgcd(b, a % b, y, x);
		y -= a / b * x;
	}

	void modular_multiplicatibe_inverse(){
		long long x, y;
		exgcd(fac[MAX_VAL - 1], MOD, x, y);
		mmi[MAX_VAL-1] = (x%MOD + MOD) % MOD;
		// mmi[MAX_VAL-1] = power(fac[MAX_VAL-1], MOD-2);
		for(long long i = MAX_VAL - 2; i >= 0; mmi[i]%=MOD, i--)
			mmi[i] = mmi[i + 1] * ((i + 1) % MOD);
	}

	long long combination(long long n, long long r){
		return n < r ? 0 :fac[n] * (mmi[r] * mmi[n-r] % MOD) % MOD;
	}
};

signed main(){
	cout<<fixed<<setprecision(10);

	binomial_coefficients BC;
	int N, M;
	static int dp[5100][20];
	int ans = 0;

	cin>>N>>M;

	BC.init(N + M);

	dp[0][0] = 1;

	for(int i = 0; i < 16; i++){
		int X = 1, Y = (1<<(i+1));
		for(int j = 0; j <= M; j += X){
			for(int k = 0, l = 0; j+k <= M; k += Y, l += 2){
				dp[j+k][i+1] += dp[j][i] * BC.combination(N, l) % MOD;
				dp[j+k][i+1] %= MOD;
			}
		}
	}

	cout<<dp[M][16]<<endl;

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define trace(x) cerr << #x << " = " << x << endl;

// memset(a,0xc0,sizeof(a)); // initializing with negative infinity
// memset(a,0x3f,sizeof(a)); // initializing with positive infinity

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

///////////////////////////////////////////////////////////////////////
#define int long long

const int N = 1010;
int dp[N][N];

void solve(){

	int n , m;
	cin>>n>>m;
	vector<int> a(n) , b(m);
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];
	for(int i = 0 ; i < m ; ++i)
		cin>>b[i];
	memset(dp , 0x3f , sizeof dp);

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

		for(int j = 0 ; j <= m ; ++j){

			if(i==0 && j==0)
				dp[i][j] = 0;
			else if(i==0)
				dp[i][j] = j;
			else if(j==0)
				dp[i][j] = i;
			else{

				dp[i][j] = dp[i - 1][j - 1] + (a[i - 1]!=b[j - 1]);
				int val = 1 + min(dp[i - 1][j] , dp[i][j - 1]);
				dp[i][j] = min(dp[i][j] , val);
			}
		}
	}
	cout<<dp[n][m]<<endl;

}

signed main(){

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int H,W; cin >> H >> W;
	V<string> s(H); rep(i,H) cin >> s[i];
	int ans = 0;
	V<int> dx={0,1},dy={1,0};
	rep(i,H) rep(j,W) if(s[i][j]=='.'){
		rep(d,2){
			int x=i+dx[d],y=j+dy[d];
			if(0<=x&&x<H&&0<=y&&y<W&&s[x][y]=='.') ans++;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <utility>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;
const ll MOD = 1e9+7;

ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b%a, a); }
ll mod(ll a) { return a % MOD < 0 ? (a % MOD) + MOD : a % MOD; }
ll mod_add(ll a, ll b) { return (a%MOD + b%MOD) % MOD; }
ll mod_sub(ll a, ll b) { return mod((a%MOD - b%MOD) % MOD); }
ll mod_mul(ll a, ll b) { return (a%MOD * b%MOD) % MOD; }
ll mod_pow(ll a, ll b)
{
    if(b == 0) return 1;
    ll p = mod_pow(a, b/2) % MOD;
    p = mod_mul(p, p);
    return (b%2 == 0) ? p : mod_mul(a, p);
}
ll mod_inv(ll a) { return mod_pow(a, MOD-2); }
ll mod_div(ll a, ll b) { return a%MOD * mod_inv(b) % MOD; }
ll mod_summation(ll N) { return mod_div(mod_mul(N, mod_add(N, 1)), 2); }

int main()
{
    char a, b, c;
    std::cin >> a >> b >> c;

    print((a == b && b == c ? "Won" : "Lost"))
    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int a, b, c; cin >> a >> b >> c;
	cout << max({ a + b,b + c,c + a }) << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
using namespace std;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#define endl "\n"
#define mini -10000000000000000
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<int>
#define si              set<int>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define deb(x)          cout << #x << " = " << x << endl
#define set_bit(x, idx) x = x|1LL<<idx
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define toggle_bit(x, idx) x = x^(1LL<<idx)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using    namespace __gnu_pbds;
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> rordered_set;
int main()
{
    ios;
    #ifdef DEBUG
    freopen("input.txt", "r", stdin);
    #endif
    ll t;
    cin>>t;
    while(t--){
    ll n,i,j,k,m;
    cin>>n;
    ll a[n];
    ll o=0;
    f(i,0,n)
    {
        cin>>a[i];
        if(a[i]>1)
        o++;
    }
        if(n%2)
        cout<<"Second"<<endl;
        else
        {
            bool f=0;
            sort(a,a+n);
           for(i=0;i<n-1;i+=2)
            {
            if(a[i]!=a[i+1])
            {
                f=1;
            }
            }
            if(f)
            cout<<"First"<<endl;
            else cout<<"Second"<<endl;
        }
    }
   rr;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n; cin >> n; vector<int> a(n), b(n);
	rep(i, n) {
		a[i] = (2 * i)%n;
		b[i] = (2 * i + 1) % n;
	}
	rep(i, n)cout << a[i] + 1 << " " << b[i] + 1 << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}


#include <cstdio>
#include <map>
#include <vector>
using namespace std;

int Max(int x, int y) {return x > y ? x : y;}

const int MAXN = 2 * 1e5 + 5;
int c[MAXN], fa[MAXN], dep[MAXN];
map<int, int> ans[MAXN];
vector<int> num[MAXN];
bool flag[MAXN];

void Make_Set(int n) {
	for(int i = 1; i <= n; i++) {
		fa[i] = i;
		dep[i] = 0;
		ans[i][c[i]] = 1;
		num[i].push_back(c[i]);
	}
}

int Find_Set(int x) {
	if(fa[x] != x)
		return fa[x] = Find_Set(fa[x]);
	return x;
}

int main() {
	int n, q, ma = 0;
	scanf ("%d %d", &n, &q);
	for(int i = 1; i <= n; i++)
		scanf ("%d", &c[i]);
	Make_Set(n);
	for(int i = 1; i <= q; i++) {
		int opt, x, y;
		scanf ("%d %d %d", &opt, &x, &y);
		if(opt == 1) {
			int u = Find_Set(x), v = Find_Set(y);
			if(u != v) {
				if(dep[u] > dep[v]) {
					for(int j = 0; j < num[v].size(); j++) {
						bool flag = false;
						if(ans[u][num[v][j]] == 0)
							flag = true;
						ans[u][num[v][j]] += ans[v][num[v][j]];
						if(ans[u][num[v][j]] > 0 && flag)
							num[u].push_back(num[v][j]);
					}
					fa[v] = u;
				}
				else if(dep[u] < dep[v]) {
					for(int j = 0; j < num[u].size(); j++) {
						bool flag = false;
						if(ans[v][num[u][j]] == 0)
							flag = true;
						ans[v][num[u][j]] += ans[u][num[u][j]];
						if(ans[v][num[u][j]] > 0 && flag)
							num[v].push_back(num[u][j]);
					}
					fa[u] = v;
				}
				else {
					for(int j = 0; j < num[v].size(); j++) {
						bool flag = false;
						if(ans[u][num[v][j]] == 0)
							flag = true;
						ans[u][num[v][j]] += ans[v][num[v][j]];
						if(ans[u][num[v][j]] > 0 && flag)
							num[u].push_back(num[v][j]);
					}
			        fa[v] = u;
			        if(dep[u] == dep[v])
						dep[u]++;
				}
			}
		}
		else
			printf("%d\n", ans[Find_Set(x)][y]);
	}
	return 0;
}

//dp d[i][j]表示是i到j的最短回文串长度
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define pii pair<int,int>
#define inf 0x3f3f3f3f
typedef long long ll;
const int maxn=1005;
vector<int> g[maxn][26];
int d[maxn][maxn];
int n,m;
void solve()
{
	memset(d,-1,sizeof(d));
	cin>>n>>m;
	queue<pii> q;
	rep(i,1,n+1){
		d[i][i]=0;
		q.emplace(i,i);
	}
	while(m--){
		int x,y,z;
		char ch;
		cin>>x>>y>>ch;
		z=ch-'a';
		g[x][z].emplace_back(y);
		g[y][z].emplace_back(x);
		if(x!=y){
			d[x][y]=d[y][x]=1;
			q.emplace(x,y);
		}
	}
	while(!q.empty()){
		auto [u,v]=q.front();
		q.pop();
		for(int i=0;i<26;i++){
			if(!g[u][i].empty()&&!g[v][i].empty()){
				int len1=g[u][i].size(),len2=g[v][i].size();
				for(int j=0;j<len1;j++){
					for(int k=0;k<len2;k++){
						int u1=g[u][i][j],v1=g[v][i][k];
						if(d[u1][v1]==-1){
							d[u1][v1]=d[v1][u1]=d[u][v]+2;
							q.emplace(u1,v1);
						}
					}
				}
			}
		}
	}
	cout<<d[1][n]<<endl;
}
int main()
{
    solve();
    return 0;
}


#include<iostream>
#include<numeric>
using namespace std;
const int VAL = 105;
const int BUF = 5005;
const int MOD = 998244353;

int fact[VAL];

void makeTable() {
    fact[0] = 1;
    for (int i = 1; i < VAL; ++i) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
    }
}

int nVal;
int val[VAL];

void read() {
    cin >> nVal;
    for (int i = 0; i < nVal; ++i) {
        cin >> val[i];
    }
}

void work() {
    int total = accumulate(val, val + nVal, 0);
    if (total % 2 != 0) {
        cout << 0 << endl;
        return;
    }

    int dp[VAL][BUF] = {};
    dp[0][0] = 1;

    for (int loop = 0; loop < nVal; ++loop) {
        for (int nPick = loop; nPick >= 0; --nPick) {
            for (int sum = 0; sum + val[loop] <= total / 2; ++sum) {
                if (!dp[nPick][sum]) continue;
                dp[nPick + 1][sum + val[loop]] = (dp[nPick + 1][sum + val[loop]] + dp[nPick][sum]) % MOD;
            }
        }
    }

    int ans = 0;
    for (int nPick = 0; nPick <= nVal; ++nPick) {
        ans = (ans + 1LL * dp[nPick][total / 2] * fact[nPick] % MOD * fact[nVal - nPick]) % MOD;
    }
    cout << ans << endl;
}

int main() {
    makeTable();
    read();
    work();
    return 0;
}

//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define re register int
#define ll long long
#define I inline int
#define V inline void
#define LL inline ll
#define FOR(i,a,b) for(re i=(a),i##i=(b);i<=i##i;++i)
#define ROF(i,a,b) for(re i=(a),i##i=(b);i>=i##i;--i)
#define gc (_ft==_fs&&(_ft=(_fs=buf)+fread(buf,1,1<<20,stdin),_ft==_fs))?0:*_fs++
//#define gc getchar()
using namespace std;
const int N=2e4+10,M=110,mo=998244353;
char buf[1<<20],*_fs,*_ft;
LL read(){
	ll w=0,p=0; char ch=gc;
	while(!isdigit(ch)) w=ch=='-',ch=gc;
	while(isdigit(ch))  p=p*10+ch-'0',ch=gc;
	return w?-p:p;
}
int n,a[M],tot,fl;
ll ans,dp[M][N],f[M],fc[M],fv[M];
LL Pow(ll x,ll y){ ll as=1; for(;y;y>>=1,x=x*x%mo) if(y&1) as=as*x%mo; return as;}
LL ck(ll x){ return x-=mo,x+=x>>63&mo; }
V ipt(){ n=read();  FOR(i,1,n) a[i]=read(),tot+=a[i];}
V ycl(){
	fc[0]=1;
	FOR(i,1,n) fc[i]=fc[i-1]*i%mo;
	return ;
}
V sol(){
	if(tot&1) return ;
	dp[0][0]=1,tot>>=1;
	FOR(i,1,n) ROF(j,i-1,0) ROF(k,tot,0){
		dp[j+1][k+a[i]]=ck(dp[j+1][k+a[i]]+dp[j][k]);
	}
	FOR(i,0,n) f[i]=dp[i][tot];
	FOR(i,0,n){
		if(2*i==n) ans=(ans+f[i]*fc[i]%mo*fc[i]%mo)%mo;
		else ans=(ans+f[i]%mo*fc[i]%mo*fc[n-i]%mo)%mo;
	}
	return ;
}
V opt(){ cout<<ans; }
int main(){
	ipt();
	ycl();
	sol();
	opt();
	return 0;
}


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

int main()
{
	string a;
	cin>>a;
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='6') a[i]='9';
		else if(a[i]=='9') a[i]='6';
	}
	for(int i=a.size()-1;i>=0;i--) cout<<a[i];
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<ll>

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

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}

int main(){
    vi n(4);
    rep(i,4) cin >> n[i];
    sort(all(n));
    cout << n[0] <<endl;
    return 0;
}


#include <bits/stdc++.h>

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,N,...) N
#define macro_dispatcher(macro,...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro,nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro,nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro,nargs) macro ## nargs
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DBN1(a)            cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)        cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)        cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)    cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)    cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"

#define endl '\n'
#define DBN1D(x) cerr<<#x<<endl;for(auto _:x){cerr<<_<<" ";}cerr<<endl
#define DBN2D(x) cerr<<#x<<endl;for(auto _:x){for(auto __:_){cerr<<__<<" ";}cerr<<endl;}cerr<<"------"<<endl
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp(x,y) make_pair(x,y)
#define mpp(w,x,y,z) mp(mp(w,x),mp(y,z))
using namespace std;
typedef long long loli;
typedef vector<loli> vl;
typedef vector<vl> vvl;
typedef pair<loli,loli> pll;
typedef pair<pll,pll> pllll;

void solve(){
	loli n,k;
	cin>>n>>k;
	map<loli,loli> mp;
	for(loli i=0;i<n;++i){
		loli x,y;
		cin>>x>>y;
		mp[x]+=y;
	}
	vector<pll> f(1);
	f[0]=mp(0,k);
	for(auto&x:mp){
		f.push_back(x);
	}
	// // for(int i=1;i<=n;++i){
	// // 	int x,y;
	// // 	cin>>x>>y;
	// // 	f[i]={x,y};
	// // }
	// // sort(f.begin(),f.end());

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

	// }

	loli tmp=0;

	for(loli i=0;i<=f.size();++i){
		f[i].second+=tmp;
		tmp=f[i].second;
	}

	// for(auto x:f){
	// 	cout<<x.first<<" "<<x.second<<endl;
	// }
	for(loli i=0;i<f.size();++i){
		if(f[i].second<f[i+1].first){
			cout<<f[i].second<<endl;
			return;
		}
	}
	cout<<f.back().second<<endl;
}

int main(){
    sync;
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=int(b)-1;i>=int(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
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; }

void Main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<pair<ll, ll>> v(n);
    rep(i, n){
        ll a, b;
        cin >> a >> b;
        v[i] = {a, b};
    }
    sort(v.begin(), v.end());
    rep(i, n){
        auto [a, b] = v[i];
        if (a > k) {
            cout << k << endl;
            return;
        } else{
            k += b;
        }
    }
    cout << k << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // int t; cin >> t; rep(i, t)
    Main();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecI = vector<int>;
using vec2I = vector<vecI>;
using vec3I = vector<vec2I>;
ll mod{(ll)1e9 + 7};
double pi = 2 * acos(0.0);
//Check for long

void solve()
{
	ll n;
	cin >> n;
	ll ct{}, minus{1LL}, i{1000LL};
	int mul{};
	for(; i <= n; i *= 1000)
	{
		ct += (i - minus) * mul;
		minus *= 1000;
		mul++;
	}
	ct += (n - minus + 1) * mul;
	cout << ct;

}

int main()
{
//Ignore from
	//Godspeed cin to cout
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
	//for getting input from input text
	freopen("input.txt", "r", stdin);
	//for writing output to output.txt
	freopen("output.txt", "w", stdout);
	#endif
// Ignore to
	// int t;
	// cin >> t;
	// while(t--)
		solve();
	return 0;
}

//Clock
// auto start = chrono::steady_clock::now();
// auto end = chrono::steady_clock::now();
// auto diff = end - start;
// cerr << chrono::duration <double, milli> (diff).count() << " ms" << endl;

//Napolean Cake
// void solve()
// {
// 	int n;
// 	cin >> n;
// 	vecI vec(n);
// 	for(int &x : vec)
// 		cin >> x;
// 	vecI diffArr(n + 1);
// 	for(int i{}; i < n; i++)
// 	{
// 		if(vec[i] == 0)
// 			continue;

// 		diffArr[max(i - vec[i] + 1, 0)]++;
// 		diffArr[min(i + 1, n)]--;
// 	}
// 	int sum{};
// 	for(int i{}; i < n; i++)
// 	{
// 		sum += diffArr[i];
// 		diffArr[i] = sum;
// 		if(diffArr[i] == 0)
// 			cout << 0;
// 		else
// 			cout << 1;
// 		cout << ' ';
// 	}
// 	cout << '\n';
// }

//Alexey & Train
// void solve()
// {
// 	int n;
// 	cin >> n;
// 	vector<pair<int, int>> vec(n);
// 	for(auto &it : vec)
// 		cin >> it.first >> it.second;

// 	vector<int> delay(n);
// 	for(auto &it : delay)
// 		cin >> it;

// 	int cur{};
// 	int prev{};
// 	for(int i{}; i < n; i++)
// 	{
// 		cur += vec[i].first - prev + delay[i];
// 		//cerr << cur << ' ';
// 		if(i == n - 1)
// 			break;
// 		int min_time{(int)ceil((vec[i].second - vec[i].first) / 2.0)};
// 		cur = max(cur + min_time, vec[i].second);
// 		prev = vec[i].second;
// 	}
// 	cout << cur << '\n';
// }

#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <ctime>
#include <chrono>
#include <random>
#define int long long int
using namespace std;

const int MAX = 1e4;
void solve()
{
	int n;
	cin >> n;
	int cnt = 3;
	cout << 6 << ' ' << 10 << ' ' << 15 << ' ';
	for (int j = 16; j <= MAX; j++)
	{
		if (cnt == n) break;
		if (j % 6 == 0 || j % 10 == 0 || j % 15 == 0)
		{
			cnt++;
			cout << j << ' ';
		}
	}
	cout << '\n';
	return;
}

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


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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min({a,b,c,d});
}

#include <iostream>
using namespace std;

int main() {
  int arr[4];
  for(int i=0; i<4; i++) cin >> arr[i];
  int sum=arr[0];
  for(int i=0; i<4; i++) sum = arr[i]<sum? arr[i]: sum;

  cout << endl << sum;
}


#include <bits/stdc++.h>

using namespace std;

#define f0r(a, b) for (long long a = 0; a < b; a++)
#define f1r(a, b, c) for (long long a = b; a < c; a++)
#define f0rd(a, b) for (long long a = b; a >= 0; a--)
#define f1rd(a, b, c) for (long long a = b; a >= c; a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define f first
#define s second

#define ao(a, n) {for (int ele = 0; ele < n; ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const ll inf = 1e16;

const int MOD = 1e9 + 7;
typedef decay<decltype(MOD)>::type T;
struct mi {
    T val;
    explicit operator T() const { return val; }
    mi() { val = 0; }
    mi(const long long& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD; }
    friend ostream& operator<<(ostream& os, const mi& a) { return os << a.val; }
    friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; }
    friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }
    friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; }
    mi operator-() const { return mi(-val); }
    mi& operator+=(const mi& m) {
        if ((val += m.val) >= MOD) val -= MOD;
        return *this; }
    mi& operator-=(const mi& m) {
        if ((val -= m.val) < 0) val += MOD;
        return *this; }
    mi& operator*=(const mi& m) { val = (long long) val * m.val % MOD;
        return *this; }
    friend mi pow(mi a, long long p) {
        mi ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans; }
    friend mi inv(const mi& a) { assert(a != 0); return pow(a, MOD - 2); }
    mi& operator/=(const mi& m) { return (*this) *= inv(m); }
    friend mi operator+(mi a, const mi& b) { return a += b; }
    friend mi operator-(mi a, const mi& b) { return a -= b; }
    friend mi operator*(mi a, const mi& b) { return a *= b; }
    friend mi operator/(mi a, const mi& b) { return a /= b; }
};

ll trade[200005];
vl graph[200005];

ll mx[200005];
ll vis[200005];

ll rec(ll v) {
    if (vis[v]) {
        return max(trade[v], mx[v]);
    }

    vis[v] = 1;

    ll m = -inf;

    for (ll u: graph[v]) {
        m = max(m, rec(u));
    }

    //cout << v << " " << m << " " << trade[v] << endl;
    mx[v] = m;

    return max(mx[v], trade[v]);
}

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

    ll n, m; cin >> n >> m;

    f0r(i, n) {
        cin >> trade[i];
    }

    f0r(i, m) {
        ll x, y; cin >> x >> y;
        x--; y--;
        graph[x].pb(y);
    }

    f0r(i, n) {
        sort(graph[i].begin(), graph[i].end());
        reverse(graph[i].begin(), graph[i].end());

    }

    ms(vis, 0);

    f0r(i, n) {
        if (!vis[i]) {
            rec(i);
        }
    }

    ll ret = -inf;

    f0r(i, n) {
        ret = max(ret, mx[i] - trade[i]);

    }

    cout << ret << endl;

}

#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()
#define re          return
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;

ll A[MAXN+5],dp[MAXN+5];
vi dske[MAXN+5];

ll Solves(){

	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE

	sc2(n,m);
	f1(i,n)sc(A[i]);

	while(m--){
		sc2(x,y);
		dske[x].pb(y);
	}

	ms(dp,1);
	x=oo;
	y=-oo;
	ans=-oo;
	f1(i,n){
		if(dp[i]>1e9);
		else mxz(ans,A[i]-dp[i]);
		fuv(j,dske[i])mnz(dp[dske[i][j]],min(A[i],dp[i]));
	}
	pr(ans);

	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
}


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

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

    ll n,m;
    cin>>n>>m;
    ll x;
    set<ll>s;

    for(int i=0;i<n;i++)
    {
        cin>>x;
        s.insert(x);
    }

    for(int i=0;i<m;i++)
    {
        cin>>x;

        if(s.find(x)==s.end())
        {
            s.insert(x);
        }
        else
        {
            s.erase(x);
        }
    }

    for(auto it:s)
    {
        cout<<it<<" ";
    }
}

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;
const vector<int> h_idx = {-1, 0,0,1};
const vector<int> w_idx = { 0,-1,1,0};

int si,sj;
int now_i,now_j;
vector<vector<int>> tile(50, vector<int>(50));
vector<vector<int>> profit(50, vector<int>(50));
vector<bool> seen(2505,false);
string ans;
string all_ans;
ll best_score;

clock_t start_time;
clock_t now_time;

mt19937 mt((int)time(0));

bool check_time_limit(){
    now_time = clock();
    if ((double)(now_time - start_time) / CLOCKS_PER_SEC > 1.95) return true;
    else return false;
}
// 実行時間が1.95秒を越したらtrue,それまではfalse

void all_resize(){
    return;
}

void all_input(){
    cin >> si >> sj;

    all_resize();

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> tile[i][j];
        }
    }

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> profit[i][j];
        }
    }

    seen[tile[si][sj]] = true;

    return;
}

ll calc_score(string &s){
    int tmp_now_i = si,tmp_now_j = sj;

    ll res = profit[si][sj];

    for (auto x : s){
        if (x == 'U'){
            tmp_now_i += h_idx[0];
            tmp_now_j += w_idx[0];
        }
        else if (x == 'L'){
            tmp_now_i += h_idx[1];
            tmp_now_j += w_idx[1];
        }
        else if (x == 'R'){
            tmp_now_i += h_idx[2];
            tmp_now_j += w_idx[2];
        }
        else{
            tmp_now_i += h_idx[3];
            tmp_now_j += w_idx[3];
        }

        res += profit[tmp_now_i][tmp_now_j];
    }

    return res;
}

void all_output(){

    cout << all_ans << endl;

    return;
}

bool check_range_and_seen(int i,int j){
    if (i < 0 || i >= 50 || j < 0 || j >= 50) return false;

    if (seen[tile[i][j]]) return false;
    else return true;
}

bool random_walk(int &i,int &j){
    if (check_time_limit()) return false;

    vector<int> possible_direction;

    for (int k = 0; k < 4; k++){
        int tmp_next_i = i + h_idx[k];
        int tmp_next_j = j + w_idx[k];

        if (check_range_and_seen(tmp_next_i,tmp_next_j)) possible_direction.push_back(k);
    }

    if (possible_direction.size() == 0) return false;

    int num = mt() % (possible_direction.size());
    int direction = possible_direction[num];

    int next_i = i + h_idx[direction];
    int next_j = j + w_idx[direction];

    if (direction == 0){
        ans.push_back('U');
    }
    else if (direction == 1) ans.push_back('L');
    else if (direction == 2) ans.push_back('R');
    else ans.push_back('D');

    i = next_i;
    j = next_j;
    seen[tile[i][j]] = true;

    return true;
}

void random_walk_all(){
    ans = "";
    now_i = si;
    now_j = sj;

    while (random_walk(now_i,now_j));

    if (chmax(best_score,calc_score(ans))){
        // cout << best_score << endl;
        all_ans = ans;
    }

    return;
}

void solve(){

    ll counter = 0;

    while (!check_time_limit()){
        random_walk_all();
        counter++;

    }

    // cout << counter << endl;

    return;
}

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

    all_input();

    solve();

    all_output();
}

// 乱択


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

typedef long long LL;

const int N=200000;

int n,a[N*2+9],ord[N*2+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n<<1;++i){
	scanf("%d",&a[i]);
	ord[i]=i;
  }
}

stack<int>sta;
char ans[N*2+9];

void Get_ans(){
  sort(ord+1,ord+n*2+1,[&](const int &x,const int &y){return a[x]<a[y];});
  for (int i=1;i<=n;++i) a[ord[i]]=0;
  for (int i=n+1;i<=n<<1;++i) a[ord[i]]=1;
  for (int i=1;i<=n<<1;++i)
	if (sta.empty()||a[i]==a[sta.top()]) sta.push(i);
    else{
	  ans[sta.top()]='(';
	  ans[i]=')';
	  sta.pop();
	}
}

void work(){
  Get_ans();
}

void outo(){
  for (int i=1;i<=n<<1;++i)
	putchar(ans[i]);
  puts("");
}

int main(){
  int T=1;
  //scanf("%d",&T);
  for (;T--;){
	into();
	work();
	outo();
  }
  return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for(T &x : v) is >> x;
    return is;
}
struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;
/*-------------------------------------------*/

int main() {
    int n;
    cin >> n;
    vector<int> a(n * 2);
    cin >> a;

    vector<int> p(n * 2);
    iota(ALL(p), 0);
    sort(ALL(p), [&](int i, int j) { return a[i] < a[j]; });

    rep(i, n * 2) a[p[i]] = (i < n);

    stack<int> st;
    string ans(n * 2, '.');

    rep(i, n * 2) {
        if(st.empty() || a[st.top()] == a[i])
            st.push(i);
        else {
            ans[st.top()] = '(';
            ans[i] = ')';
            st.pop();
        }
    }

    cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 998244353;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <u32 M>
struct modint {
    u32 val;
public:
    static modint raw(int v) { modint x; x.val = v; return x; }
    modint() : val(0) {}
    template <class T>
    modint(T v) { ll x = (ll)(v%(ll)(M)); if (x < 0) x += M; val = u32(x); }
    modint(bool v) { val = ((unsigned int)(v) % M); }
    modint& operator++() { val++; if (val == M) val = 0; return *this; }
    modint& operator--() { if (val == 0) val = M; val--; return *this; }
    modint operator++(int) { modint result = *this; ++*this; return result; }
    modint operator--(int) { modint result = *this; --*this; return result; }
    modint& operator+=(const modint& b) { val += b.val; if (val >= M) val -= M; return *this; }
    modint& operator-=(const modint& b) { val -= b.val; if (val >= M) val += M; return *this; }
    modint& operator*=(const modint& b) { u64 z = val; z *= b.val; val = (u32)(z % M); return *this; }
    modint& operator/=(const modint& b) { return *this = *this * b.inv(); }
    modint operator+() const { return *this; }
    modint operator-() const { return modint() - *this; }
    modint pow(long long n) const { modint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
    modint inv() const { return pow(M-2); }
    friend modint operator+(const modint& a, const modint& b) { return modint(a) += b; }
    friend modint operator-(const modint& a, const modint& b) { return modint(a) -= b; }
    friend modint operator*(const modint& a, const modint& b) { return modint(a) *= b; }
    friend modint operator/(const modint& a, const modint& b) { return modint(a) /= b; }
    friend bool operator==(const modint& a, const modint& b) { return a.val == b.val; }
    friend bool operator!=(const modint& a, const modint& b) { return a.val != b.val; }
};
using mint = modint<MOD>;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<mint> A(k+1), B(k+1);
    for (int i = 1; i <= k; ++i) {
        A[i] = mint(i).pow(n);
    }
    for (int i = k; i >= 1; --i) {
        A[i] -= A[i-1];
    }
    for (int i = k; i >= 1; --i) {
        B[i] = mint(k-i+1).pow(m);
    }
    if(n == 1 || m == 1) for (int i = 1; i < k; ++i) {
        B[i] -= B[i+1];
    }
    mint ans = 0;
    for (int i = 1; i <= k; ++i) {
        ans += A[i]*B[i];
    }
    cout << ans.val << "\n";
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define pll pair<ll,ll>
#define vpll vector< pll >
#define mpll map<ll,ll>
#define MOD 998244353
#define all(v) v.begin(),v.end()
#define s(v) v.size()
#define test ll t;cin>>t;while(t--)
#define vec vector<ll>
#define read0(v,n) for(int i=0;i<n;i++)cin>>v[i];
#define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i];
#define trav(a,x) for (auto& a: x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define cut(x) {cout<<x;return 0;}
#define print(x) {cout<<x<<nl;continue;}
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define err1(a) {cout<<#a<<' '<<a<<nl;}
#define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;}

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define nl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
ll gcd(ll a, ll b)
{
	if (b==0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll bpow(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main()
{
	fast
	ll n,m,k;
	cin>>n>>m>>k;
	ll ans=0;
	if(n==1 and m==1)cut(k)
    if(n==1)
    {
        ans=bpow(k,m);
        cut(ans)
    }
    if(m==1)
    {
        ans=bpow(k,n);
        cut(ans)
    }
	FOR(i,1,k)
	{
	    ll p=(ll)i,q=(ll)(k-i+1);
	    if(q<0)break;
	    p=(bpow(p,n)-bpow(p-1,n)+MOD)%MOD;q=bpow(q,m);
	    ans=(ans+(p*q)%MOD)%MOD;
	}
	cut(ans)
}


#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// 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; }

using namespace std;

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

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  // ll ans = 0;

  string str;
  cin >> str;

  deque<char> dq;

  bool rev = false;

  rep(i, str.size()) {
    char ch = str[i];
    if (ch == 'R') {
      rev = !rev;
      continue;
    }
    if (!rev) {
      if (dq.size() >= 1 && dq.front() == ch) {
        dq.pop_front();
      } else {
        dq.push_front(ch);
      }
    } else {
      if (dq.size() >= 1 && dq.back() == ch) {
        dq.pop_back();
      } else {
        dq.push_back(ch);
      }
    }
  }

  string ans;
  for (;;) {
    if (dq.size() == 0) break;

    ans += dq.back();
    dq.pop_back();
  }

  if (rev) {
    reverse(ans.begin(), ans.end());
  }

  cout << (ans) << endl;

  // cout << ans << endl;
}

/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define ld double
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define F(i,a,b) for(i=a;i<b;i++)
//#include <ext/pb_ds/assoc_container.hpp> // policy based data structure header files
//#include <ext/pb_ds/tree_policy.hpp> // policy based data structure header files
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
//using namespace __gnu_pbds; // for pbds
//#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // have functions like order_of_key, find_by_order
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e18;
const ll MAXN=100200;
ll i,j,mask;
void solve()
{
    string s;
    cin>>s;
    deque<char> dq;
    ll f=0;
    for(auto x:s)
    {
        if(x=='R')
        {
            f^=1;
            continue;
        }
        if(!f)
        {
            if(dq.empty() || dq.back()!=x)
            {
                dq.push_back(x);
            }
            else
            if(!dq.empty())
            {
                dq.pop_back();
            }
        }
        else
        {
            if(dq.empty() || dq.front()!=x)
            {
                dq.push_front(x);
            }
            else
            if(!dq.empty())
            {
                dq.pop_front();
            }
        }
    }
    if(f)
    reverse(all(dq));
    for(auto x:dq)
    {
        cout<<x;
    }
}
int main()
{
    IOS
    /*#ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    ll t,test=1;
    //cin>>test;
    F(t,1,test+1) {
        //cout<<"Case #"<<t<<": ";
        solve();
        nl
    }
    return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define fk cerr<<"fk"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
const int N=2100;
int h,w,vis[N][N],dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
char mat[N][N];
vector< pair<int,int> > idx[30];
bool ok(int x,int y){
    if(x<1 || x>h || y<1 || y>w) return false;
    if(mat[x][y]=='#') return false;
    if(vis[x][y]==1) return false;
    return true;
}
int bfs(int sx,int sy){
    queue< pair< pair<int,int>,int > > q;
    q.push(mp(mp(sx,sy),0));
    vis[sx][sy]=1;
    while(!q.empty()){
        pair< pair<int,int>,int > now=q.front();
        q.pop();
        int nx=now.fi.fi,ny=now.fi.se;
        if(mat[nx][ny]=='G') return now.se;
        char temp=mat[nx][ny];
        if(temp>='a' && temp<='z'){
            for(pair<int,int> np:idx[int(temp-'a')]){
                vis[np.fi][np.se]=1;
                q.push(mp(mp(np.fi,np.se),now.se+1));
            }
            idx[int(temp-'a')].clear();
        }
        for(int i=0; i<4; ++i){
            int tx=nx+dir[i][0];
            int ty=ny+dir[i][1];
            if(ok(tx,ty)){
              //  if(mat[tx][ty]=='G') return now.se+1;
                vis[tx][ty]=1;
                q.push(mp(mp(tx,ty),now.se+1));
            }
        }
    }
    return -1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>h>>w;
    int sx,sy;
    for1(i, h){
        for1(j, w){
            cin>>mat[i][j];
            if(mat[i][j]>='a' && mat[i][j]<='z'){
                int num=int(mat[i][j]-'a');
                idx[num].eb(mp(i,j));
            }
            if(mat[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
    }
    ms(vis,0);
    cout<<bfs(sx,sy)<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define sec second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

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

ll n,m;

bool isvalid(ll x,ll y)
{
	if(x>=0 && y>=0 && x<n && y<m)
	{
		return true;
	}
	return false;
}

int main()
{
		fast;

		cin>>n>>m;
		ll i,j;
		string s;
		vector<string>g;

		for(i=0;i<n;i++)
		{
			cin>>s;
			g.pb(s);
		}

		ll a[n+1][m+1];
//		ll vis[n+1][m+1];

		ll inf=1e17;
		ll sx=0,sy=0,ex=0,ey=0;

		vector<vector<pair<ll,ll> > >tp(26);

		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				a[i][j]=inf;
				if(g[i][j]=='S')
				{
					a[i][j]=0;
					sx=i;
					sy=j;
				}
				if(g[i][j]=='G')
				{
					ex=i;
					ey=j;
				}
				if(g[i][j]>='a' && g[i][j]<='z')
				{
					char c=g[i][j];
					tp[c-'a'].pb(mp(i,j));
				}
			}
		}

		queue<pair<ll,ll> >q;

		q.push(mp(sx,sy));

		while(!q.empty())
		{
			ll x,y;
			pair<ll,ll>now =q.front();
			q.pop();

			x=now.fi;
			y=now.sec;

			for(i=0;i<4;i++)
			{
				ll nx,ny;
				pair<ll,ll>next = mp(x+dx[i],y+dy[i]);

				nx=next.fi;
				ny=next.sec;

				if(isvalid(nx,ny))
				{
					if(g[nx][ny]!='#' && a[nx][ny]==inf)
					{
						a[nx][ny]=a[x][y]+1;
						q.push(mp(nx,ny));
					}
				}

			}

			char c=g[x][y];

			if(islower(c))
			{
				for(auto next:tp[c-'a'])
				{
					ll nx,ny;
					nx=next.fi;
					ny=next.sec;

					if(a[nx][ny]==inf)
					{
						a[nx][ny]=a[x][y]+1;
						q.push(mp(nx,ny));
					}
				}

				tp[c-'a'].clear();

			}

		}

		ll ans=a[ex][ey];

		if(ans==inf)
		{
			cout<<-1<<Endl;
		}
		else
		{
			cout<<ans<<endl;
		}

	return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main() {

	long int n, x;
	string s;
	cin>>n>>x;
	cin>>s;
	for(int i = 0; i < s.size(); i++) {

		if(s[i] == 'x' && x != 0)
			x--;
		else if(s[i] == 'o')
			x++;
	}
	cout<<x<<endl;
	return 0;
}

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

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

	int n,a,b;
	cin>>n>>a>>b;
	cout<<n-a+b;
}


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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int sum(int a, int b,int mod){return (a+b) % mod;}
int sub(int a, int b,int mod){return (a + mod - b) % mod;}
int mul(int a, int b,int mod){return (1ll * a * b) % mod;}
int power(int a,int b,int mod){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a,mod);
		b >>= 1;
		a = mul(a,a,mod);
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a,b,c; cin >> a >> b >> c;
	vi res;
	set<int> seen;
	ll act = a%10;
	while(1){
		if(seen.count(act))break;
		res.pb(act);
		seen.insert(act);
		act = mul(act,a,10);
	}
	int pos = power(b,c,res.size());
	pos = sub(pos,1,res.size());
	//debug(res,pos);
	cout << res[pos] << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/

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

int main() {
    int N, A[20], min = INT32_MAX;
    cin >> N;
    rep(i, N) cin >> A[i];

    for (int bit = 0; bit < (1 << (N - 1)); bit++) {
        int OR = 0, XOR = 0;
        for (int i = 0; i < N - 1; i++) {
            OR = OR | A[i];
            if (bit & (1 << i)) {
                XOR = XOR ^ OR;
                OR = 0;
            }
        }
        OR = OR | A[N - 1];
        XOR = XOR ^ OR;

        if (min > XOR) min = XOR;
    }
    cout << min << endl;
}


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

int main(){
  int a,b,x,y;
  cin >> a >> b >> x >> y;
  int z=min(2*x,y);
  if(a==b){cout << x;return 0;}
  if(a>b){cout << x+(a-b-1)*z;return 0;}
  cout << x+(b-a)*z;
  return 0;
}

//Created By:Hardik Kapoor
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
//template begins
#define int long long int
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itt vector<int>:: iterator
#define pb push_back
#define mp make_pair
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define db long double
#define itp vector<pair<int,int> >:: iterator
#define ff first
#define ss second
#define endl "\n"
typedef pair<int,int> pii;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
	find_by_order() - Returns an iterator to the k-th largest element (counting from zero)
	order_of_key()  - The number of items in a set that are strictly smaller than our item
	Rest same as set
*/
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;
const long long mod = 1000000007;
// const long long mod = 998244353;
int pow(int x, unsigned int y, int p){
	int 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;
}
int _pow(int a, int b){
	if(!b)
		return 1;
	int temp = _pow(a, b / 2);
	temp = (temp * temp);
	if(b % 2)
		return (a * temp);
	return temp;
}
int invmod(int a,int m){
	return pow(a,m-2,m);
}
int cl(int a,int x){
	if(a%x==0)
		return a/x;
	else
		return a/x+1;
}
//template ends

signed main(){
	ios
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int Tests=1;
	while(Tests--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(a==b)
			cout<<c<<endl;
		else if(b==c)
			cout<<a<<endl;
		else if(a==c)
			cout<<b<<endl;
		else
			cout<<0<<endl;
	}
}