#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int,int> pii;
#define ALL(x) x.begin(),x.end()
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define FORD(i,a,n) for(ll i=n-1;i>=a;i--)
#define SIZE(x) ll(x.size())
#define F first
#define S second
#define __lcm(a,b) (ll(a)/__gcd(ll(a),ll(b)))*ll(b)

int main() {
    int n;
    cin >> n;
    vi x(n);
    REP(i,n)
    cin >> x[i];
    vi p = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    ll ans = pow(2,60);
    for (int i=0;i<(1<<15);i++) {
        vi v(n,0);
        ll c = 0;
        ll a = 1;
        for (int j=0;j<15;j++) {
            if (i & 1<<j) {
                a *= p[j];
                REP(k,n) {
                    if(x[k]%p[j]==0) {
                        v[k]++;
                        if (v[k]==1)
                        c++;
                    }
                }
            }
        }
        if (c==n) {
            if (ans>a)
            ans = a;
        }
    }
    cout << ans;
}

#include<iostream>
#include<vector>
#include<chrono>

#define int long long
#define fi first
#define se second

using namespace std;

//const int MAXN = 100005;
const int MOD = 1e9 + 7;
//const int INF = 1e18;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main() {
    cin.tie(0);
    cout.tie(0);
    ios_base :: sync_with_stdio(0);
    int n;
    cin >> n;
    int t[n];
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    int p[n + 1];
    p[0] = 1;
    for (int i = 1; i <= n; i++) {
        p[i] = p[i - 1] * 2 % MOD;
    }
    int dp[n][2];
    dp[0][0] = t[0];
    dp[0][1] = 0;
    int a = 1, b = 0;
    for (int i = 1; i < n; i++) {
        int c = (a + b) % MOD;
        b = a;
        a = c;
        dp[i][0] = (3 * MOD + dp[i - 1][0] + dp[i - 1][1] + t[i] * a % MOD) % MOD;
        dp[i][1] = (2 * MOD + dp[i - 1][0] - t[i] * b % MOD) % MOD;
    }
    cout << (dp[n - 1][0] + dp[n - 1][1]) % MOD;
    return 0;
}


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

void solve(){
    string s;
    cin >> s;
    int countl = 0 ,countu = 0;
    rep(i,0,s.size()){
          if((i+1) % 2 == 0){
               if(isupper(s[i]))countu++;
          }
          else{
                if(islower(s[i]))countl++;
          }
    }
    if(countl + countu == s.size()){
          cout << "Yes\n";
    }
    else{
          cout << "No\n";
    }

}

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

}

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

const int N = 4e5+5, mod = 3;

int n;
ll A[N],f[N],g[N];
ll answer = 0;

int C(int a,int b){
    if(f[b] > f[a] + f[b-a]){
        return 0;
    }

    int x = 4*g[b]/g[a]/g[b-a];
    if(x == 1) return 4;
    if(x == 2) return 2;
    if(x == 4) return 1;
    if(x == 8) return 2;
}

inline void test_case(){

    cin >> n;
    for(int i = 1; i <= n; i++){
        char c;
        cin >> c;
        if(c == 'B') A[i] = 0;
        if(c == 'W') A[i] = 1;
        if(c == 'R') A[i] = 2;
    }

    f[0] = 0; g[0] = 1;
    for(int i = 1; i <= n; i++){
        int cnt = 0;
        ll y = g[i-1]*i;
        while(y%3 == 0){
            y /= 3;
            cnt++;
        }
        y %= 3;
        f[i] = f[i-1] + cnt;
        g[i] = y;
        //cout << f[i] << " " << g[i] << endl;
    }

    for(int i = 1; i <= n; i++){
        //cout << C(i-1,n-1) << endl;
        //cout << A[i] << endl;
        answer += A[i]*C(i-1,n-1);
        answer %= 3;
    }

    //cout << answer << endl;

    if(n%2 == 0) answer = (mod - answer)%mod;

    if(answer == 0) cout << 'B' << endl;
    if(answer == 1) cout << 'W' << endl;
    if(answer == 2) cout << 'R' << endl;
}

 main(){
    ios::sync_with_stdio(0);

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


#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;
    cin>>n;
    int sum = 2*n;
    int i=1;
    while(1){
        if(i*(i+1) >= sum){
            break;
        }
        i++;
    }
    cout<<i;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define mod 1000000007

ll power(ll x, ll n) {
     ll ans = 1;
     while(n>0) {
         if(n&1){
             ans = (ans*x)%mod;
             n = n-1;
         }
         else {
            x = (x*x)%mod;
            n = n/2;
         }
    }
     return ans;
}

int main()
{
     fastIO;
    ll n;
    cin>>n;
    ll sum = 0;
    int i = 1;
    while(sum < n) {
        sum += i;
        i++;
    }
    cout<<i-1<<endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll N, K;
	cin >> N >> K;
	ll A[300010] = {};
	FOR(i,0,N){
		ll b;
		cin >> b;
		if(A[b]<K){
			A[b]++;
		}
	}

	ll now = K;
	ll sum = 0;

	FOR(i,0,N){
		ll c = A[i];
		if(c == 0){
			sum += (now - c) * i;
			break;
		}
		if(now<=c){
			continue;
		}
		sum += (now - c) * i;
		now = min(now, c);
	}

	cout << sum << endl;

	return 0;
}

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

int n;
vector<vector<int>> to;

vector<int> used,col;
vector<int> vs;

void dfs(int v)//引数は今見ている頂点
{
	if(used[v])//頂点に訪れていたならreturn
	{
		return;
	}
	used[v] = 1;//これがないと無限ループになる
	vs.push_back(v);
	for(int u : to[v])//vに隣接する頂点に対して
	{
		dfs(u);
	}
}

ll now;

void dfs2(int i)
{
	if(i == (int)vs.size())
	{
		now++;
		return;
	}
	int v = vs[i];//今見ている頂点
	rep(c,3)//色を0,1,2で表す
	{
		col[v] = c;//vをc色に塗る
		bool ok = true;
		for(int u : to[v])
		{
			if(col[u] == c)
			{
				ok = false;
			}
		}
		if(!ok)
		{
			continue;
		}
		dfs2(i+1);
	}
	col[v] = -1;
}

int main() {
	int m;
	cin >> n >> m;
	to = vector<vector<int>>(n);
	rep(i,m)
	{
		int a,b;
		cin >> a >> b;
		--a;
		--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	ll ans = 1;
	used = vector<int>(n); /*dfsの判定に使う*/
	col = vector<int>(n,-1);/*塗り方を試すために使う*/

	rep(i,n)
	{
		if(used[i])
		{
			continue;
		}
		ans *= 3;
		vs = vector<int>();//dfsの順番で頂点を入れていく
		dfs(i);
		col[vs[0]] = 0;
		now = 0;
		dfs2(1);//色塗りを探索
		ans *= now;
	}
	cout << ans << endl;
return 0;
}


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

int main()
{
    ll n,m;  cin>>n>>m;
    vector<ll>a(n),b(m);

    map<ll,ll>mp;

    for(auto &it : a)
    {
        cin>>it;
        mp[it]++;
    }
     for(auto &it : b)
    {
        cin>>it;
        mp[it]++;
    }
    for(auto i : mp)
    {
        if(i.second ==1) cout<<i.first<<" ";
    }
    cout<<endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long
#define ull unsigned long long
#define ld long double
#define F first
#define S second
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

using namespace __gnu_pbds;
using namespace std;

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

template <typename T>
void ckmin(T& a, const T b) {a = min(a, b);}

template <typename T>
void ckmax(T& a, const T b) {a = max(a, b);}

template <typename T>
void print(vector <T> v) {
    for (T i : v) cout << i << " ";
    cout << '\n';
}

template <typename T>
void print(vector <vector <T>>& v) {
    for (vector <T>& vv : v) {
        for (T& i : vv)
            cout << i << " ";
        cout << '\n';
    }
}

template <typename T>
void read(vector <T>& v) {for (T& i : v) cin >> i;}

template <typename T>
void read(T&& t) {cin >> t;}

template <typename T, typename... Args>
void read(T&& t, Args&&... args)
{
    cin >> t;
    read(forward<Args>(args)...);
}

template <typename T>
void print(T&& t) {cout << t << '\n';}

template <typename T, typename... Args>
void print(T&& t, Args&&... args)
{
    cout << t << " ";
    print(forward<Args>(args)...);
}

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".txt").c_str(), "w", stdout);
    }
}

void solve()
{
    ll a, b;
    cin >> a >> b;
    print(2*a+100-b);
}

int32_t main()
{
    usaco();
    int t = 1;
    while (t--) solve();
}


#include <bits/stdc++.h>

#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

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>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

template <typename T>
struct coord_comp {
    vector<T> v;
    bool sorted = false;

    coord_comp() {}

    int size() { return v.size(); }

    void add(T x) { v.push_back(x); }

    void build() {
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        sorted = true;
    }

    int get_idx(T x) {
        assert(sorted);
        return lower_bound(v.begin(), v.end(), x) - v.begin();
    }
};

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> G[n][26];
    bool E[n][n];
    rep(i, n) rep(j, n) E[i][j] = false;
    rep(i, m) {
        int a, b;
        char c;
        scanf("%d%d %c", &a, &b, &c);
        --a;
        --b;
        G[a][c - 'a'].push_back(b);
        G[b][c - 'a'].push_back(a);
        E[a][b] = E[b][a] = true;
    }
    rep(i, n) rep(c, 26) {
        sort(G[i][c].begin(), G[i][c].end());
        G[i][c].erase(unique(G[i][c].begin(), G[i][c].end()), G[i][c].end());
    }

    int d[n][n];
    rep(i, n) rep(j, n) d[i][j] = mod;
    d[0][n - 1] = 0;
    queue<pii> que;
    que.emplace(0, n - 1);
    while (!que.empty()) {
        auto [u, v] = que.front();
        if (E[u][v]) {
            printf("%d\n", d[u][v] + 1);
            return 0;
        }
        que.pop();
        rep(c, 26) for (auto nu : G[u][c]) for (auto nv : G[v][c]) {
            if (chmin(d[nu][nv], d[u][v] + 2)) {
                if (nu == nv) {
                    printf("%d\n", d[nu][nv]);
                    return 0;
                }
                que.emplace(nu, nv);
            }
        }
    }
    puts("-1");
}

#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

using ll = long long int;

int n, m;
vector<int> g[1001][30];
int d[1001][1001];
bool g2[1001][1001];

int res;
constexpr int INF = 987654321;

int main(void)
{
#ifdef CUBE_PS
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(int i = 0; i < m; ++i) {
        int a, b;
        char c;
        cin >> a >> b >> c;
        g[a][c - 'a'].push_back(b);
        g[b][c - 'a'].push_back(a);
        g2[a][b] = true;
        g2[b][a] = true;
    }
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= n; ++j) {
            d[i][j] = INF;
        }
    }
    res = INF;

    queue<pair<int, int>> q;
    q.push({ 1, n });
    d[1][n] = 0;
    while(q.empty() == false) {
        int s = q.front().first;
        int e = q.front().second;
        q.pop();

        if(s == e) {
            res = min(res, d[s][e]);
        } else if(g2[s][e] == true) {
            res = min(res, d[s][e] + 1);
        }

        for(int i = 0; i <= 'z' - 'a'; ++i) {
            for(int ns : g[s][i]) {
                for(int ne : g[e][i]) {
                    if(d[ns][ne] > d[s][e] + 2) {
                        d[ns][ne] = d[s][e] + 2;
                        q.push({ ns, ne });
                    }
                }
            }

        }
    }

    if(res == INF) res = -1;
    cout << res;

    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb                    push_back
#define ll                    long long
#define ld                    long double
#define sz(x)                 (ll)x.size()
#define vll                   vector<long long>

#define infi                  INT_MAX
#define infl                  LONG_LONG_MAX
#define infd                  LDBL_MAX
#define f(i,a,b)              for(ll i=a;i<b;i++)
#define fi(i,a,b)             for(ll i=(b-1);i>=a;i--)
#define F                     first
#define S                     second
#define G(a,b)                get<a>(b)
#define MP                    make_pair
#define MT                    make_tuple
#define pll                   pair<ll,ll>
#define endl                  "\n"
#define ALL(v)                v.begin(),v.end()
#define nl                    cout<<"\n";
#define pr(x)                 cout<<x;
#define pr1(x)                cout<<x<<" ";
#define pr2(x,y)              cout<<x<<" "<<y;
#define pr3(x,y,z)            cout<<x<<" "<<y<<" "<<z;
#define pr4(x,y,z,w)          cout<<x<<" "<<y<<" "<<z<<" "<<w;
#define deb                   cout<<"***************************************************************************************\n";
#define moshi                 cout<<"moshi moshi ! \n";
#define hi                    cout<<"hi ! \n";
#define bye                   cout<<"bye bye ! \n";
#define kawai                 cout<<"O kawai koto ! \n";
#define o_set                 tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
#define eb                    emplace_back
const ld PI=3.1415926535897932384626433;

auto clk=clock();
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

//**********************************************************  Code begins  ***********************************************

const ll N=2e5+5;
ll n,m,a[N],dp[N];
vll adj[N];

void solve()
{
  cin>>n>>m;
  f(i,1,n+1) cin>>a[i];
  f(i,1,m+1)
  {
    ll x,y;
    cin>>x>>y;
    adj[x].pb(y);
  }

  ll ans=-infl;
  fi(i,1,n+1)
  {
    dp[i]=-infl;
    for(auto &j:adj[i])
    {
        dp[i]=max(dp[i],max(a[j],dp[j]));
    }

    if(dp[i]!=-infl)  ans=max(ans,dp[i]-a[i]);
  }
  if(ans!=-infl) cout<<ans<<"\n";
  else cout<<"0\n";
}

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

    ll test_cases=1;
    //cin>>test_cases;

    f(i,1,test_cases+1)
    {
        solve();
        //clr();
    }

    #ifdef rd
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif

    return 0;
}

// #pragma GCC optimise ("O1")
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define _rep(i,n)   for(ll i=n-1;i>=1;i--)
#define scn(a)       scanf("%lld",&a)
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld",a)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define srt(v)       sort(v.begin(),v.end())
#define read(a)       for(auto &it:a) cin>>it;
#define write(a)      for(auto it:a) cout<<it<<" ";
#define yeS(GOOD)      GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define mem(a,b)     memset(a,b,sizeof(a))
#define nl           printf("\n")
#define inf          1e9
#define zer          INT_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll N=3e5+5;
int n,a[N];

int tree[4*N];

void build(int st,int se,int node)
{
    if(st==se)
    {
        tree[node] = a[st];

        return;
    }

    int mid=(st+se)/2;

    build(st,mid,2*node);
    build(mid+1,se,2*node+1);

    tree[node] = tree[2*node]^tree[2*node+1];
}

void update(int st,int se,int ind,int val,int node)
{
    if(st == se)
    {
        tree[node]^= val;
		a[ind]^= val;

        return;
    }

    int mid = st+(se-st)/2;

    if(ind <= mid)
    update(st,mid,ind,val,2*node);
    else
    update(mid+1,se,ind,val,2*node+1);

    tree[node] = tree[2*node]^tree[2*node+1];
}

int get(int st,int se,int qs,int qe,int node)
{
    if(st>qe || se<qs)
    return 0;

    if(st>=qs && se<=qe)
    return tree[node];

    int mid=(st+se)/2;

    return get(st,mid,qs,qe,2*node)^get(mid+1,se,qs,qe,2*node+1);
}

void f()
{
	// saafsafai();
	ll q;
	cin>>n>>q;

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

	build(0,n-1,1);

    ll ans=0;

    while(q--)
    {
        int type,x,y; cin>>type>>x>>y;

        if(type == 1)
        {
            update(0,n-1,x-1,y,1);
        }
        else
        {
            int ans = get(0,n-1,x-1,y-1,1);

            cout<<ans<<endl;
        }
    }

   	// cout<<solve(1,n);
}

int main()
{
	  int queries=1;
	  // cin>>queries;
	  while(queries--)
	  {
	    f();
	  }
}


#include<bits/stdc++.h>
#define ll long long int
#define ld long  double
using namespace std;
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define maxpq priority_queue<ll>
#define minpq priority_queue<ll, vector<ll>, greater<ll> >
#define vi vector<ll>
#define pii pair<ll, ll>
#define vii vector<pii>
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)

#define INT_MAXI 9000000000000000000
#define INT_MINI -9000000000000000000

ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}

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

ll n,m;
ll arr[200005];
ll arr2[200005];
bool visited[200005];
ll ans=0,maxi=0;
vector<ll>vec[200005];
vi vec2,ans2;

/*void dfs(ll node,ll mini)
{
	vec2.pb(node);
	ans=max(ans,arr[node]-mini);

	for(auto itr:vec[node])
	{
		if(!visited[itr])
		{
			visited[itr]=1;
			maxi=max(maxi,arr[itr]);
			dfs(itr,min(mini,arr[itr]));

		}
		else
		{
			ans=max(ans,arr2[itr]-mini);

		}

	}

}*/

map<ll,ll>mpp;

ll func(ll x,ll y)
{

	if(x>=y)
	return x-y;
	if(mpp.count(y))
	return mpp[y];
	ll count=INT_MAXI;
	count=abs(x-y);
	if(y%2==0)
	{
		count= min(count,1+func(x,y/2));
	}
	else
	{
		count=min(count,min(func(x,y/2),func(x,y/2+1))+2);
	}
	return mpp[y]= count;

}

int main()
{

	fio;
    ll t,i,j,u,v,x,k,p,c,y,a,b;
    cin>>x>>y;
    ll ans=func(x,y);
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
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 pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000005
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
unordered_map<int,int>dp;
unordered_map<int,int>vis;
int x,y;
int calc(int val)
{
    if(val<=x)return (x-val);
    if(vis.count(val))return dp[val];
    vis[val]=1;
    int ans=abs(val-x);
    if(val & 1)
    {
        ans=min(ans,2 + calc((val+1)/2));
        ans=min(ans,2 + calc((val-1)/2));
    }
    else
    {
        ans=min(ans,1 + calc(val/2));
    }
    return dp[val]=ans;

}
void solve()
{

    cin>>x>>y;
    if(x>=y)
    {
        cout<<(x-y)<<endl;
        return;
    }
    cout<<calc(y)<<endl;

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int tests;
   //cin>>tests;
   tests=1;
   for(int i=0;i<tests;i++)
   {
       solve();
   }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
const long long INF = 1LL << 60;
const int SINF = 1LL << 30;
const ll mod = 1000000000+7;
const ll MOD = 998244353;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> 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; }

ll c[61][61];

int main() {
    int a, b;
    ll k;
    cin >> a >> b >> k;
    c[0][0] = 1;
    for(int i=1; i<=60; i++) {
        for(int j=0; j<=60; j++) {
            if(j-1 >= 0) c[i][j] += c[i-1][j-1];
            c[i][j] += c[i-1][j];
        }
    }

    string ans = "";
    while(a + b > 0) {
        if(b > 0 && k > c[a+b-1][b]) {
            ans.push_back('b');
            k -= c[a+b-1][b];
            b--;
        }
        else if(a > 0) {
            ans.push_back('a');
            a--;
        }
        else {
            ans.push_back('b');
            b--;
        }
    }
    cout << ans << endl;
}

/*
	ॐ
		JAI SHREE RAM

		Hare Krishna Hare Krishna Krishna Krishna Hare Hare
		Hare Rama Hare Rama Rama Rama Hare Hare

												ॐ
*/

//Written by Bhuwanesh Nainwal
#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;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
pbds;

#define fast            	ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL)
#define int					long long int
#define vci              	vector<int>
#define vcvci             	vector<vector<int>>
#define vcpi             	vector<pair<int,int>>
#define vcs					vector<string>
#define pb              	push_back
#define mpii             	map<int , int>
#define mpsi             	map<string , int>
#define mpci             	map<char , int>
#define umpii             	unordered_map<int , int>
#define umpsi             	unordered_map<string , int>
#define umpci             	unordered_map<char , int>
#define all(x)				auto it = x.begin() ; it != x.end() ; it++
#define vcc              	vector<char>
#define vcs              	vector<string>
#define sti            		set<int>
#define stc            		set<char>
#define sts            		set<string>
#define pqmx				priority_queue<int>
#define pqmn				priority_queue<int , vi , greater<int>>
#define null            	NULL
#define ff            		first
#define ss              	second
#define stb(x)				__builtin_popcount(x)
#define lzr(x)				__builtin_clz(x)
#define tzr(x)					__builtin_ctz(x)
#define prc(x , y)          fixed << setprecision(y) << x
#define max3(a, b, c)   	max(a, max(b, c))
#define min3(a, b, c)   	min(a, min(b, c))

using namespace std;

const int mod = 1e9 + 7;
const int INF = 1e9;
const int LINF = 1e18;
const int N = 1e4;
const int chkprc = 1e-9;  // Check for precision error in double

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

	int dp[62][62];
	dp[0][0] = 1;
	for(int i = 1 ; i <= 60 ; i++)
	{
		dp[i][0] = 1;
		for(int j = 1 ; j < i ; j++)
		{

			dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1];
		}

		dp[i][i] = 1;
	}

	int n = a + b;
	for(int i = 0 ; i < n ; i++)
	{
		int cnt = dp[a + b - 1] [b];
		if(cnt >= k)
		{
			cout << 'a';
			a--;
		}
		else
		{
			cout << 'b';
			b--;
			k -= cnt;
		}

	}
}

void local()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

int32_t main()
{

    fast;
    //local();
    int T = 1;
    // cin>>T;

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

    return 0;
}


// E - Traveler
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)

int main(){
	ll INF = 1e9 + 1;
	int n; cin>>n;
	vector<pair<ll,ll>> A(n+1);
	rep(i, n) A[i] = {INF, -INF};
	rep(i, n){
		ll x, c; cin>>x>>c; --c;
		auto[mn, mx] = A[c];
		A[c] = {min(mn, x), max(mx, x)};
	}

	ll pre_mn, pre_mx;
	int pre = -1;
	rep(now, n+1){
		auto[mn, mx] = A[now];
		if(mn == INF) continue;
		ll p_mn = 0, p_mx = 0;
		if(pre < 0) pre_mn = pre_mx = 0;
		else tie(p_mn, p_mx) = A[pre];
		ll a = pre_mn + abs(p_mn - mn);
		ll b = pre_mn + abs(p_mn - mx);
		ll c = pre_mx + abs(p_mx - mn);
		ll d = pre_mx + abs(p_mx - mx);
		ll e = mx - mn;
		pre_mn = min(b, d) + e;
		pre_mx = min(a, c) + e;
		pre = now;
	}
	cout<< pre_mn <<endl;
}

//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=(1e5+5)*2;
const ll szz=1e6+6;
const ll mod=1e9+7;

ll C[sz][2],dp[sz][2];

ll ss;

ll solve(ll pos,ll flag)
{
    if(pos==0)
    {
        return 0;
    }

    ll &ans = dp[pos][flag];
    if(ans!=-1)
        return ans;

    ans = abs(C[pos][0]-C[pos][1]);
    ans+=min(solve(pos-1,0)+abs(C[pos-1][0] - C[pos][flag^1]), solve(pos-1,1)+abs(C[pos-1][1] - C[pos][flag^1]));
    return ans;
}

int main()
{
    IOS;

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

    clock_t startTime=clock();

    ll n;
    cin>>n;
    ll ar[n];
    map<ll,ll> l,r;
    rep(i,0,n)
    {
        ll x,c;
        cin>>x>>c;
        if(l.count(c))
        {
            l[c]=min(l[c],x);
            r[c]=max(r[c],x);
        }
        else
        {
            l[c]=r[c]=x;
        }
    }

    ss=0;
    for(auto x:l)
    {
        C[++ss][0]=x.second;
        C[ss][1]=r[x.first];
    }

    memset(dp,-1,sizeof dp);
    cout<<solve(ss+1,0);

    cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...


#include<bits/stdc++.h>
using namespace std;
char s[1000005];
int f[1000005],mn[205];
int main()
{
    int n;
    scanf("%d%s",&n,s+1);
    memset(f,0x3f,sizeof(f));
    memset(mn,0x3f,sizeof(mn));
    f[0]=0,mn[s[1]-'a']=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=25;j++)
            if(j!=s[i]-'a')f[i]=min(f[i],mn[j]+1);
        if(i<n)mn[s[i+1]-'a']=min(mn[s[i+1]-'a'],f[i]);
    }
    if(f[n]<=n)printf("%d\n",f[n]);
    else puts("-1");
    return 0;
}


using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair;
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){if(b%2!=0)res=res*a;b/=2; a=a*a;}return res;}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,cnt=0,ans=0,tot=0,x,y;
    vector<ll>v;
    cin>>n;
    fr(i,0,n)
    {
        cin>>x>>y;
        tot+=x;
        v.pb(y+2*x);

    }
    sort(v.begin(),v.end());

    frr(i,v.size()-1,0)
    {
        ans+=v[i];
        cnt++;
        if(ans>tot)
        {
            cout<<cnt<<endl;
            return 0;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define fornext(x, i) for(int i = head[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define mset(a, b) memset(a, b, sizeof(a))
#define Rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define dRep(i, a, b) for(int i = (a); i >= (b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define endl '\n'
#define int ll
#define un unsigned
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "

template<typename _T>
inline void rd(_T &_d) {
	int _f; char _c;
	_f=_d=0;
	while(_c=getchar(),!isdigit(_c)) if (_c=='-') _f=1;
	while(isdigit(_c)) _d=_d*10+_c-'0',_c=getchar();
	if (_f) _d=-_d;
}

template <typename _T,typename ...Args>
inline void rd(_T &_d,Args &..._a) {
	rd(_d);
	rd(_a...);
}

#define mod(x) (x=(x>=M?x-M:x))
const int N=2e5+5,M=998244353;
int n,k,c[305][305],a[N],p[N][305],s[305];

signed main() {
	rd(n,k);
	Rep(i,1,n) rd(a[i]);
	Rep(i,0,k) c[i][0]=1;
	Rep(i,1,k) Rep(j,1,k) c[i][j]=c[i-1][j]+c[i-1][j-1],mod(c[i][j]);
	int tmp;
	Rep(i,1,n) {
		tmp=1;
		Rep(j,1,k) tmp=tmp*a[i]%M,s[j]+=tmp,mod(s[j]),p[i][j]=tmp;
	}
	Rep(i,1,n) p[i][0]=1;
	s[0]=n;
	int ans,inv=499122177;
	Rep(i,1,k) {
		ans=0;
		Rep(j,0,i) {
			ans=(ans+c[i][j]*s[j]%M*s[i-j]%M+M-s[i]*c[i][j]%M)%M;
		}
		cout<<ans*inv%M<<endl;
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<set>
#include<map>
#include<iostream>

#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define N 300005

using namespace std;

int A[N], B[N], C[N], n, tree[N];

multiset<int> st, num[N];

int lowbit(int x) { return x & -x; }

int ask(int x)
{
	int s = 0;
	for ( ; x; x -= lowbit(x)) s += tree[x];
	return s;
}

void insert(int x)
{
	for ( ; x <= n; x += lowbit(x)) tree[x] += 1;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &A[i]);
		A[i] += i;
		st.insert(A[i]);
		C[++C[0]] = A[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		scanf("%d", &B[i]); B[i] += i;
		if (st.find(B[i]) == st.end())
		{
			puts("-1");
			return 0;
		}
		st.erase(st.find(B[i]));
	}
	sort(C + 1, C + C[0] + 1);
	C[0] = unique(C + 1, C + C[0] + 1) - (C + 1);
	for (int i = 1; i <= n; ++i)
	{
		A[i] = lower_bound(C + 1, C + C[0] + 1, A[i]) - C;
		num[A[i]].insert(i);
		B[i] = lower_bound(C + 1, C + C[0] + 1, B[i]) - C;
	}
	long long ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		int pos = *num[B[i]].begin();
		num[B[i]].erase(pos);
		int realpos = pos + (i - 1) - ask(pos);
		insert(pos);
		ans += realpos - i;
	}
	printf("%lld\n", ans);
}

#include <bits/stdc++.h>

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

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

struct num {
  ll x, i;
  bool operator < (const num &n) const { return x<n.x||(x==n.x&&i<n.i); };
};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct SegTree {
  ll size;
  vector<ll> pos;
  SegTree(ll N) { size = 1; while(size<N) size<<=1; pos.resize(2*size,0); }
  ll operator[](const ll &x) const { return pos[x+size]; }

  void set(ll x, const ll v) { pos[x+size] = v; }
  void update(ll x, const ll v) { set(x,v); x+=size; while (x>>=1) operate(x); }
  ll query(ll a, ll b) {
    ll L = 0, R = 0;
    for (a+=size, b+=size; a<b; a>>=1, b>>=1) {
      if (a&1) { L = q(L,pos[a]); a++; }
      if (b&1) { b--; R = q(pos[b],R); }
    }
    return q(L,R);
  }
  void operate(ll i) { pos[i] = q(pos[i*2], pos[i*2+1]); }
  ll q(ll x, ll y) { return x + y; }
};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  ll N; cin >> N;
  num A[N]; rep(i,N) { ll x; cin >> x; A[i] = {x+i,i}; }
  num B[N]; rep(i,N) { ll x; cin >> x; B[i] = {x+i,i}; }
  sort(A,A+N); sort(B,B+N);
  rep(i,N) {
    if (A[i].x!=B[i].x) {
      cout << -1 << endl;
      return 0;
    }
  }
  // rep(i,N) cout << A[i].i << " "; cout << endl;
  // rep(i,N) cout << B[i].i << " "; cout << endl;

  ll to[N] = {}; rep(i,N) to[A[i].i] = B[i].i;
  // debug(to,to+N);

  ll result = 0;
  SegTree st(N);
  rep(i,N) {
    result += st.query(to[i],N);
    st.update(to[i],1);
  }

  cout << result << endl;
  return 0;
}


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

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

  	unordered_set<string> h(s.begin(), s.end());
  	for(string t : s) if(h.count('!' + t)){
    	cout << t << endl;
      	return 0;
    }

  	cout << "satisfiable" << endl;
}

//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define read(x)    freopen(x, "r", stdin);
#define write(x)   freopen(x, "w", stdout);
#define ll long long
#define lli long long int
#define mod 1000000007
#define mx 1000005

         //   #define sazzad

int main()
{
    #ifdef sazzad
read("input.txt");
// write("output.txt");
     #endif

      int a,n,flag=0,sum=0,check,min1= INT_MAX,min2 = INT_MAX,summin= INT_MAX;

      cin>>n;
      a = n;
      vector<int>v;
      vector<int>vv;
      while(a--)
      {
          int x , y;
          cin>>x>>y;
          v.push_back(x);
          vv.push_back(y);

          sum = x+y;

          summin = min(summin,sum);

      }

      for(int i=0;i<v.size();i++)
      {
          if( v[i] < min1 )
          {
              min1 = v[i];
              flag = i;
          }
      }
      //cout<< flag<<endl;
      for(int i=0; i<vv.size();i++ )
      {
          if( i != flag ) min2 = min(min2,vv[i]);
      }
     // cout<<min2<<endl;
      int res = max(min1,min2);
      cout<< min(summin,res)<<endl;

}


#include<iostream>
#include<vector>

using namespace std;

int main(){
  string S;
  string T="";
  cin >> S;

  for(int i=S.size()-1; i>=0; i--){
    T += S[i];
  }

  for(int i=0;i<T.size();i++){
    if(T[i]=='6'){
      T[i] = '9';
    }else if(T[i] == '9'){
      T[i] = '6';
    }
  }

  cout << T << endl;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll>
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second
#define M 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll min(ll a,ll b){if(a<b) return a; return b;}
ll mod=998244353;

ll po(ll x, ll y){
    if(y==0)
    return 1;
    if(y%2){
        return ((x)*(po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
    }
   return ((po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
}

void seive(bool prime[]){
    //bool prime[100002];

    for (ll p=2; p*p<=1000001; p++)
    {
        if (prime[p])
        {
            for (ll i=p*p; i<=1000001; i+=p)
                prime[i] = false;
        }
    }
}

ll powermod(ll x,ll y,ll p)  {
  ll res = 1;
    x = x % p;
 if (x == 0) return 0;
    while (y > 0)
    {     if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll gcd(ll x, ll y){
    if (y == 0)
    return x;
    else
    return gcd(y, x % y);
}

ll nck(ll n, ll k){
    ll C[k + 1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j]%M + C[j - 1]%M)%M;
    }
    return C[k]%M;
}

/*void call(vll &primefactor,int N){
    for(int i=1;i<N;i++)
    {
        primefactor[i]=i;
    }
    for(int i=2;i<N;i++)
    {
        if(primefactor[i]!=i)
            continue;
        for(int j=i;j<N;j+=i)
            primefactor[j]=i;
    }
}*/

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
    //cin>>t;
    while(t--){
        string s; cin>>s;
        ll n=s.size();
        fo(i,n)
        if(s[i]=='9')
        s[i]='6';
        else if(s[i]=='6')
        s[i]='9';
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 200010
int mod;

vector<int> getCycle(int val) {
    vector<int> v;
    int now = val % 10;
    while (v.empty() or v.front() != now) {
        v.push_back(now);
        now *= val;
        now %= 10;
    }
    return v;
}

int pw(int a, int b, int m) {
    if (b == 0)
        return 1;
    if (b & 1)return a * pw(a, b - 1, m) % m;
    return pw(a * a % m, b / 2, m);
}

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

    vector<int> prt = getCycle(a);
    int ans = pw(b, c, prt.size()) - 1;
    if(ans < 0)ans += prt.size();
    cout << prt[ans] << endl;
}

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

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

    while (t--)
        solve();
    return 0;
}

//CODED BY SUMIT KUMAR PRAJAPATI
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;

#define PI 3.1415926535897932384626
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define watch(x) cerr<<#x<<" = "<<x<<'\n'
#define rep(i,n) for(ll i=0;i<n;i++)
#define repe(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n'
#define curtime chrono::high_resolution_clock::now()
#define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count()

const int INF=1e9;
const int MX=1e5+5;
const int MD=1e9+7;
const int MDL=99824453;
auto time0 = curtime;

ll A,B,C,phi=4;

ll bin_power(ll a,ll b,ll md){
    ll res=1;
    while(b){
        if (b&1)
            res=(res*a)%md;
        a=(a*a)%md;
        b>>=1;
    }
    return res;
}

void solve(){

   cin>>A>>B>>C;

   A%=10;
   if (A==0){
    cout<<"0";
   }
   else if(A==1){
    cout<<"1";
   }
   else if (A==2){
        ll x=bin_power(B,C,4);
        ll m[4]={6,2,4,8};
        cout<<m[x];

   }
   else if (A==3){
        ll x=bin_power(B,C,4);
        ll m[4]={1,3,9,7};
        cout<<m[x];

   }
   else if (A==4){
        ll x=bin_power(B,C,2);
        ll m[2]={6,4};
        cout<<m[x];

   }
   else if(A==5){
    cout<<"5";

   }
   else if (A==6){
       cout<<6;

   }
   else if (A==7){
        ll x=bin_power(B,C,4);
        ll m[4]={1,7,9,3};
        cout<<m[x];

   }
   else if (A==8){
        ll x=bin_power(B,C,4);
        ll m[4]={6,8,4,2};
        cout<<m[x];

   }
   else if(A==9){
        ll x=bin_power(B,C,2);
        ll m[2]={1,9};
        cout<<m[x];
   }

}

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

    srand(time(0));
    time0 = curtime;

    ll t=1;
    //cin>>t;
    repe(tt,t){
        //cout<<"Case #"<<tt<<": ";
        solve();
    }

    cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n";
    return 0;

}


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

//macros
#define fi first
#define se second
#define pb push_back
#define ReadInputFile() freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define FAST_IO() ios_base::sync_with_stdio(false);cin.tie(nullptr);
const int MAX = 1e9+1;
const long long int Pinf = INT_MAX, Ninf = INT_MIN;
const long int mod = 1e9+7;

//debug template
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

int main(){
	ll n; cin >> n;
	vector<pair<ll, ll>> arr(n);
	for(ll i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		arr[i] = {x,y};
	}
	debug(arr);
	ll sum = 0;
	for(auto i : arr){
		int a = i.fi, b = i.se;
		ll d = b-a+1;
		sum += (d*b) - (d*(d-1))/2;
	}
	cout << sum << endl;
}

#include<bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)

using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}
using namespace std;

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

  ll sum = 0;
  rep(i, N) {
    ll A, B; cin >> A >> B;
    sum += ((A+B)*(B-A+1))/2;
  }
  cout << sum << endl;

}


// Problem: F - Sugoroku2
// Contest: AtCoder - AtCoder Beginner Contest 189
// URL: https://atcoder.jp/contests/abc189/tasks/abc189_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int,int> tii;
typedef tuple<ll,ll> tll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<tii> vtii;
typedef vector<tll> vtll;
typedef vector<vector<int>> vvi;
#define INF 0x3f3f3f3f
#define X(t) get<0>(t)
#define Y(t) get<1>(t)
#define Z(t) get<2>(t)
#define pb push_back
#define dlt decltype
#define debug(...) _debug(#__VA_ARGS__, __VA_ARGS__)
#define prt(...) printf(__VA_ARGS__)
#ifdef LOCAL
constexpr const bool local=true;
#else
constexpr const bool local=false;
#endif

template <typename T>
void _debug(const char* format,const T t) {
    if (local) cerr << format << '=' << t << endl;
}

template <class First, class... Rest>
void _debug(const char* format,const First first,const Rest... rest) {
    if (local){
        while (*format != ',') cerr << *format++;
        cerr << '=' << first << ",";
        _debug(format + 1, rest...);
    }
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& V) {
    if (local) os << "[";
    for (const auto& vv : V) os << vv << " ";
    if (local) os << "]";
    return os;
}

template<class Tuple,size_t N>
struct TuplePrinter {
    static void print(ostream& os,const Tuple& t) {
        TuplePrinter<Tuple, N-1>::print(os,t);
        os << " " << get<N-1>(t);
    }
};
template<class Tuple>
struct TuplePrinter<Tuple,1>{
    static void print(ostream& os,const Tuple& t) {
    	os << get<0>(t);
    }
};

template<typename... Rest>
ostream& operator<<(ostream& os, const tuple<Rest...>& V) {
    if (local) os << "(";
	TuplePrinter<decltype(V),sizeof...(Rest)>::print(os,V);
    if (local) os << ")";
    return os;
}
template<class T1,class T2>
bool cmin(T1 &a,const T2 b){return a>b?a=b,1:0;}
template<class T1,class T2>
bool cmax(T1 &a,const T2 b){return a<b?a=b,1:0;}
template<class T1,class T2,class ...T3>
bool cmin(T1 &a,const T2 b,const T3 ...rest){return cmin(a,b)|cmin(a,rest...);}
template<class T1,class T2,class ...T3>
bool cmax(T1 &a,const T2 b,const T3 ...rest){return cmax(a,b)|cmax(a,rest...);}

ll _gcd(ll a,ll b){return b==0?a:_gcd(b,a%b);}
ll gcd(ll a,ll b){if (a<b) swap(a,b);return _gcd(a,b);}
ll gi(){
    ll i=0;bool f=false;char c;
    while (!isdigit(c=cin.get())&&cin.good()) f=c=='-';
    if (!cin.good()) return 0;
    do i=(i<<3)+(i<<1)+c-'0'; while (isdigit(c=cin.get()));
    return f?-i:i;
}

struct lnr{
	double a,b;
	lnr():a(0),b(0){}
	lnr(double b):a(0),b(b){}
	lnr(double a,double b):a(a),b(b){}
	lnr operator*(double x){return {a*x,b*x};}
	lnr& operator*=(double x){a*=x;b*=x;return *this;}

	lnr operator/(double x){return {a/x,b/x};}
	lnr& operator/=(double x){a/=x;b/=x;return *this;}

	lnr operator+(lnr x){return {a+x.a,b+x.b};}
	lnr& operator+=(lnr x){a+=x.a;b+=x.b;return *this;}
	lnr& operator-=(lnr x){a-=x.a;b-=x.b;return *this;}

	lnr operator()(const lnr &l){
		return {a*l.a,a*l.b+b};
	}
	double operator()(const double &l){
		return a*l+b;
	}
};

int n,m,k;
bitset<100010> b;
lnr f[100010];
struct solution{
	solution(){
		b.reset();
		memset(f,0,sizeof(f));
		n=gi();m=gi();k=gi();
		for (int i=1;i<=k;i++)
			b[gi()]=1;
	}
	void solve(){
		lnr sumf=0;
		for (int i=n-1;i>=0;i--){
			if (b[i]) f[i]=lnr(1,0);
			else f[i]=sumf/m+1;
			//debug(i,f[i].a,f[i].b);
			sumf+=f[i];
			if (i+m<=n) sumf-=f[i+m];
		}
		//x==f[0].a*x+f[0].b
		if (fabs(f[0].a-1)<1e-6){
			cout << -1 << endl;
		}else{
			printf("%.4lf",f[0].b/(1-f[0].a));
		}
	}
};

int main(){
	ios::sync_with_stdio(false);
	int T=1;
	while (T--&&cin.good()){
		solution().solve();
	}
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}

int main()
{
    ios::sync_with_stdio(false);
    ll b,c; cin>>b>>c;
    if(c==0) {cout<<1; return 0;}
    if(c==1) {cout<<2-(b==0); return 0;}
    ll d=c/2, e=(c-1)/2;
    if(abs(b)>c/2)
    {
        if(c%2)
            cout<<2*(d+e)+1;
        else
            cout<<3*d+e;
    }
    else if(abs(b)<=c/2)
    {
        if(b>0)
            if(c%2)
                cout<<2*d+2*b;
            else
                cout<<2*b+2*e+1;
        else
            if(c%2)
                cout<<2*(-b)+2*e+1;
            else
                cout<<2*(-b)+2*d;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, d;
long long m;
char s[1005];

int debug() {
    int res = 0;
    bool gg = 0;
    for (int base = d + 1; ; base++) {
        long long num = 0LL;
        for (int i = 0; i < n; i++) {
            if (num > (m - (s[i] - '0')) / base) {
                gg = 1;
                break;
            }
            num = num * base + (s[i] - '0');
        }
        if (gg) break;
        res++;
    }
    return res;
}

int main() {
    scanf("%s", s);
    scanf("%lld", &m);

    n = strlen(s);

    for (int i = 0; i < n; i++) {
        d = max(d, s[i] - '0');
    }

    if (n == 1) {
        if (s[0] - '0' <= m) printf("1\n");
        else printf("0\n");
    }
    else if (n == 2) {
        printf("%lld\n", max(0LL, (m - (s[1] - '0')) / (s[0] - '0') - d));
    }
    else if (n == 3) {
        double a = (s[0] - '0');
        double b = (s[1] - '0');
        double c = (s[2] - '0') - m;
        double delta = b * b - 4.0 * a * c;
        if (delta < 0) return 0 * printf("0\n");
        double rt1 = (-b + sqrt(delta)) / (2.0 * a);
        long long lim = (long long)rt1;
        printf("%lld\n", max(0LL, lim - d));
    }
    else {
        int res = 0;
        bool gg = 0;
        for (int base = d + 1; ; base++) {
            long long num = 0LL;
            for (int i = 0; i < n; i++) {
                if (num > (m - (s[i] - '0')) / base) {
                    gg = 1;
                    break;
                }
                num = num * base + (s[i] - '0');
            }
            if (gg) break;
            res++;
        }
        printf("%d\n", res);
    }
}

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

int main()
{
    string x; cin>>x;
    long long m; cin>>m;
    vector<long long> x1,x2;
    bool flag=true;
    for (int i = 0; i < x.length(); i++) x1.push_back(x[i]-'0');
    long long n=*max_element(x1.begin(),x1.end());
    n++;
    long long m1=m;
    while (m1>0) {x2.push_back(m1%n); m1/=n;}
    reverse(x2.begin(),x2.end());
    if (x1.size()>x2.size()) {cout<<0<<endl; return 0;}
    else if (x1.size()==x2.size())
    {
        for (int i = 0; i < x2.size(); i++)
        {
            if (x1[i]>x2[i]) {cout<<0<<endl; return 0;}
            else if (x1[i]<x2[i]) break;
        }
    }
    if (x.size()==1) {cout<<1<<endl; return 0;}
    while (flag)
    {
        vector<long long> x3;
        n*=2; m1=m; flag=true;
        while (m1>0) {x3.push_back(m1%n); m1/=n;}
        reverse(x3.begin(),x3.end());
        if (x1.size()>x3.size()) flag=false;
        else if (x1.size()==x3.size())
        {
            for (int i = 0; i < x3.size(); i++)
            {
                if (x1[i]>x3[i]) flag=false;
                else if (x1[i]<x3[i]) break;
            }
        }
    }
    long long n1=n/2;
    while (n-n1>1)
    {
        long long n2=(n+n1)/2; m1=m; vector<long long> x3;
        while (m1>0) {x3.push_back(m1%n2); m1/=n2;}
        reverse(x3.begin(),x3.end());
        if (x1.size()>x3.size()) n=n2;
        else if (x1.size()==x3.size())
        {
            flag=true;
            for (int i = 0; i < x3.size(); i++)
            {
                if (x1[i]>x3[i]) {n=n2; flag=false;}
                else if (x1[i]<x3[i]) break;
            }
            if (flag) n1=n2;
        }
        else n1=n2;
    }
    long long ans=n1-*max_element(x1.begin(),x1.end());
    cout<<ans<<endl;
}


#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

int n;
double A[100010];
double f(double x) {
  double res=0;
  rep(i,n){
    res+=x+A[i]-min(A[i],2.0*x);
  }
  return res;
}

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

  cin>>n;
  rep(i,n) cin>>A[i];

  double low = 0.0;
  double high = 10000000000;

  int cnt = 500;
  while (cnt--) {
      double c1 = (low * 2 + high) / 3;
      double c2 = (low + high * 2) / 3;

      if (f(c1) > f(c2)) low = c1;
      else high = c2;
  }

  cout<<fixed<<setprecision(10)<<f(low)/n<<endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;
using int64 = long long;
using int128 = __int128;

constexpr int DEBUG = 0;

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

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

  int64 z = 0;
  while (true) {
    if (static_cast<int128>(x) * a >= x + b) break;
    if (static_cast<int128>(x) * a >= y) break;
    x = x * a;
    z++;
    // cout << x << " " << z << endl;
  }

  z += (y - x - 1) / b;

  cout << z << endl;
}


#include <iostream>
using namespace std;

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

    if(s[0] == s[1] && s[1] == s[2]) cout << "Won\n";
    else cout << "Lost\n";
}

#include <bits/stdc++.h>

#define debug(var)  do{std::cout << #var << " :";std::cout << std::endl;view(var);}while(0)
template<typename T> void view(T e){ std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; }
template<typename T, typename U> void view(const std::pair<T, U>& v){ std::cout << v.first << ", " << v.second << std::endl; }
template<typename T> void view(const std::set<T>& v){ int c = v.size(); std::cout << "{"; for(const auto& e : v){ std::cout << e; if (--c) std::cout << ", "; } std::cout << "}" << std::endl; }
template<typename T, typename U> void view(const std::map<T, U>& v){ std::cout << "{" << std::endl; for(const std::pair<T, U>& e : v){ std::cout << e.first << ", " << e.second << std::endl; } std::cout << "}" << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cout << "{" << std::endl; for(const auto& v : vv){ view(v); } std::cout << "}" << std::endl; }

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
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; }
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const double PI = acos(-1);

int main() {
    string s; cin >> s;
    bool won = true;
    for (int i = 1; i < s.size(); ++i) {
        if (s[i - 1] != s[i]) won = false;
    }

    cout << (won ? "Won" : "Lost") << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> field(h);
    for(int i=0;i<h;i++) cin>>field[i];
    vector<vector<int>> dp(h,vector<int>(w,2e9));
    dp[h-1][w-1]=0;
    for(int i=h-1;i>=0;i--){
        for(int j=w-1;j>=0;j--){
            if(0<=i-1){
                if((i+1+j)%2){
                    int op=0;
                    if(field[i][j]=='+')op++;
                    else op--;
                    if(dp[i-1][j]!=2e9)dp[i-1][j]=max(dp[i][j]+op,dp[i-1][j]);
                    else dp[i-1][j]=dp[i][j]+op;
                }
                else{
                    int op=0;
                    if(field[i][j]=='+')op--;
                    else op++;
                    if(dp[i-1][j]!=2e9)dp[i-1][j]=min(dp[i][j]+op,dp[i-1][j]);
                    else dp[i-1][j]=dp[i][j]+op;
                }
            }
            if(0<=j-1){
                if((j+1+i)%2){
                    int op=0;
                    if(field[i][j]=='+')op++;
                    else op--;
                    if(dp[i][j-1]!=2e9)dp[i][j-1]=max(dp[i][j]+op,dp[i][j-1]);
                    else dp[i][j-1]=dp[i][j]+op;
                }
                else{
                    int op=0;
                    if(field[i][j]=='+')op--;
                    else op++;
                    if(dp[i][j-1]!=2e9)dp[i][j-1]=min(dp[i][j]+op,dp[i][j-1]);
                    else dp[i][j-1]=dp[i][j]+op;
                }
            }
        }
    }
    //for(int i=0;i<h;i++){

    if(dp[0][0]<0){
        cout<<"Takahashi"<<endl;
    }
    else if(dp[0][0]==0){
        cout<<"Draw"<<endl;
    }
    else cout<<"Aoki"<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define pi pair<int, int>
#define mp make_pair
#define F first
#define S second

int h, w;
string s;
vector<vi> a;
vector<vi> dp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> h >> w;
    a.rsz(h, vi(w, -1));
    dp.rsz(h, vi(w, 0));
    F0R(i, h) {
        cin >> s;
        F0R(j, w) if (s[j]=='+') a[i][j]=1;
    }
    R0F(i, h) R0F(j, w) {
        if (i==h-1 && j==w-1) continue;
        dp[i][j]=INT_MIN;
        if (i<h-1) dp[i][j]=max(dp[i][j], a[i+1][j]-dp[i+1][j]);
        if (j<w-1) dp[i][j]=max(dp[i][j], a[i][j+1]-dp[i][j+1]);
    }
    if (dp[0][0]>0) cout << "Takahashi\n";
    else if (dp[0][0]==0) cout << "Draw\n";
    else cout << "Aoki\n";
}


#include <bits/stdc++.h>

using namespace std;

// ******************* SNIPPET TEMPLATE - STARTS***************
#define range(t) for (int i = 0; i < t; i++)
#define rep(i, t, q) for (int i = t; i < q; i++)
#define pb(t) push_back(t)
#define rangeG(i, t) for (i = 0; i < t; i++)
#define printVec(vec)      \
    for (auto c : vec)     \
    {                      \
        cout << c << endl; \
    }

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;

template <typename first>
void print(first f)
{
    cout << f << endl;
}

template <typename first, typename... args>
void print(first f, args... a)
{
    cout << f << " ";
    print(a...);
}

int inp(string s = "")
{
    cout << s;
    int t = 0;
    cin >> t;
    return t;
}
// X--------------X---------X SNIPPET TEMPLATE - ENDS* X--------------X---------X

void solve()
{
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    set<int> a, b;
    range(n)
    {
        int temp;
        cin >> temp;
        a.insert(temp);
    }

    range(m)
    {
        int temp2;
        cin >> temp2;
        b.insert(temp2);
    }
    //sort(a.begin(), a.end());
    //sort(b.begin(), b.end());

    set<int> result;
    for (int ax : a) {
        if (count(b.begin(), b.end(), ax) == 0) {
            result.insert(ax);
        }
    }

    for (int bx : b) {
        if (count(a.begin(), a.end(), bx) == 0) {
            result.insert(bx);
        }
    }
    //sort(result.begin(), result.end());
    for (int ans : result) {
        cout << ans << " ";
    }
    cout << "\n";
    return 0;
}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <numeric>
#include <chrono>
#include <random>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstring>
#include <cassert>
#include <climits>
#include <complex>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    for(int cn = 1; cn <= tc; cn++) {
        int n, m; cin >> n >> m;
        vector<int> res;
        vector<bool> a(N, 0), b(N, 0);
        for(int i = 0; i < n; i++) {
            int x; scanf("%d", &x);
            a[x] = 1;
        }
        for(int i = 0; i < m; i++) {
            int x; scanf("%d", &x);
            b[x] = 1;
        }

        for(int i = 1; i <= 1e3; i++) {
            if(a[i] ^ b[i]) cout << i << ' ';
        }
        cout << endl;
    }
    return 0;
}


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

#define int long long

int32_t main(){
	int n , m ;
	cin >> n >> m ;
	int a[n][m] ;
	int mn = 101 ;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			cin >> a[i][j] ;
			mn = min(mn , a[i][j]) ;
		}
	}
	int ans = 0 ;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			ans += a[i][j] - mn ;
		}
	}
	cout << ans ;
	return 0 ;
}

// Created at 2020/12/19 21:01
// {TODO}WA, {TODO}min
#include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (lint i = 0, i##_len = n; i < i##_len; i++)
#define rep2(i, n) for (lint i = 1, i##_len = n; i <= i##_len; i++)
#define rep3(i, s, e) for (lint i = s, i##_len = e; i < i##_len; i++)
#define all(i) (i).begin(), (i).end()
#define print(s) cout << s << enl;
#define mk_p make_pair
using namespace std;
//using namespace atcoder;
using lint = long long;
using pi = pair<int, int>;
using pl = pair<lint, lint>;
using vi = vector<int>;
using vl = vector<lint>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using qi = queue<int>;
using ql = queue<lint>;
const char enl = '\n';
const int INF = INT_MAX;
const lint INFl = LLONG_MAX;

template<class T>
inline void input(vector<T> &v) {
    for (T &x : v) cin >> x;
}

template<class T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &v : vec) is >> v;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << '[';
    for (auto v : vec) os << v << ',';
    os << ']';
    return os;
}

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

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

// 素数とその個数の pair の vector
template<class T>
vector<pair<T, T>> prime_factorize(T N) {
    vector<pair<T, T>> res;
    // 2 だけ別
    lint ex = 0;  // 指数
    // 割れる限り割り続ける
    while (N % 2 == 0) {
        ++ex;
        N /= 2;
    }

    // その結果を push
    if (ex != 0) res.push_back({2, ex});
    for (lint a = 3; a * a <= N; a += 2) {
        lint ex = 0;  // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        if (ex != 0) res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

template<class T>
T gcd(T x, T y) {
    if (x == 0) {
        if (y == 0)
            return 1;
        else
            return y;
    }
    if (y == 0) return x;
    if (x % y == 0)
        return y;
    else
        return gcd(y, x % y);
}

template<class T>
inline T lcm(T x, T y) {
    return x / gcd(x, y) * y;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(15);
    /*----------------------------------------------------*/
    int h, w;
    cin >> h >> w;
    vvi a(h, vi(w));
    int min = INF;
    rep(i, h) rep(j, w) {
        cin >> a.at(i).at(j);
        chmin(min, a.at(i).at(j));
    }
    int ans = 0;
    rep(i, h) rep(j, w) {
        ans += a.at(i).at(j) - min;
    }

    print(ans);
}


#include <bits/stdc++.h>
using namespace std;
// 型
#define ll int64_t                  // ll -> int64_t
using graph = vector<vector<int>>;  // グラフ型
// for文
#define lp(i,n) for(int i=0;i<n;i++)      // 変数 i をおいて n 回繰り返し
#define lp_(i,n) for(int i=0;i<=n;i++)    // 条件に＝つき
#define lpp(i,n,m) for(int i=n;i<m;i++)   // 開始と終了を指定して繰り返し
#define lpp_(i,n,m) for(int i=n;i<=m;i++) // 開始と終了を指定，条件に＝つき
// vector定義
#define _GLIBCXX_DEBUG
#define vec(v,n) vector<int> v(n)       // int
#define vec_(v,n,m) vector<int> v(n,m)  // int 初期条件あり
#define vec64(v,n) vector<ll> v(n)      // int64_t
#define vec64_(v,n,m) vector<ll> v(n,m) // int64_t 初期条件あり
#define vecc(v,n) vector<char> v(n)     // char
#define vecs(v,n) vector<string> v(n)   // string
#define vece(v) vector<int> v;          // int 空
#define vecec(v) vector<char> v;        // char 空
#define vec2i(v,h,w) vector<vector<int>> v(h,vector<int>(w))    // 二次元配列 int
#define vec2l(v,h,w) vector<vector<ll>> v(h,vector<ll>(w))
#define vec2c(v,h,w) vector<vector<char>> v(h,vector<char>(w))  // 二次元配列 char
// vector,string操作
#define all(v) v.begin(),v.end()
#define back(v) v.back()                         // 最後の要素
#define sum(v) accumulate(all(v),0)              // 総和
#define sort(v) sort(all(v))                     // ソート
#define reverse(v) reverse(all(v))               // 反転
#define lower(v,x) lower_bound(all(v),x)-v       // x<=a[i]となる最小のi / a[i]<xとなるiの個数
#define count(v,n) count(all(v),n)               // n の出現回数を数える
#define pb(v,n) v.push_back(n)                   // 最後尾に n を追加
#define ins(v,i,n) v.insert(v.begin()+i,n)       // 場所を指定してv[i]に n を追加
#define del(v) v.pop_back()                      // 最後尾を削除
#define del0(v) v.erase(v.begin())               // 最初の要素v[0]を削除
#define del_(v,i) v.erase(v.begin()+i)           // 場所を指定してv[i]を削除
#define del__(v,i,j) v.erase(v.begin()+i,v.begin()+j+1)  // 範囲を指定してv[i]~v[j]を削除
#define sub(s,i,j) s.substr(i,j-i+1)             // 範囲を指定してs[i]~s[j]を取得【stringのみ】
// others
#define maxp 1000000007
#define under(n) cout<<fixed<<setprecision(n) // 小数点以下の桁数を指定
#define cout(n) cout<<n<<endl

// JSC2021

int main()
{
  int n,m;
  cin>>n>>m;
  vec(a,n);
  vec(b,m);
  lp(i,n)
    cin>>a[i];
  lp(i,m)
    cin>>b[i];
  vec(c,2000);
  lp(i,n)
    c[a[i]]++;
  lp(i,m)
    c[b[i]]++;
  lp(i,2000)
  {
    if(c[i]==1)
      cout<<i<<" ";
  }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

int main(){
  ll a,b;
  cin >> a >> b;

  cout << max(2*a+100-b,(ll)0) << endl;

  return 0;
}


#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair

using namespace std;

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

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

ll extGcd(ll a, ll b, ll &p, ll &q) {
  if (b == 0) {
    p = 1;
    q = 0;
    return a;
  }
  ll d = extGcd(b, a % b, q, p);
  q -= a / b * p;
  return d;
}

pair<ll, ll> crt(const vector<ll> &b, const vector<ll> &m) {
  ll r = 0, M = 1;
  for (int i = 0; i < (int)b.size(); ++i) {
    ll p, q;
    ll d = extGcd(M, m[i], p, q);
    if ((b[i] - r) % d != 0) {
      return make_pair(0, -1);
    }
    ll tmp = (b[i] - r) / d * p % (m[i] / d);
    r += M * tmp;
    M *= m[i] / d;
  }
  return make_pair(mod(r, M), M);
}

int main() {
  ll T;
  scanf("%lld", &T);

  for (ll i = 0; i < T; i++) {
    ll N, S, K;
    scanf("%lld %lld %lld", &N, &S, &K);

    auto r1 = crt({0, N - S}, {K, N});
    // cout << r1.second << "k+" << r1.first << endl;  // 15k + 8

    ll ans;
    if (r1.second <= 0) {
      ans = -1;
    } else {
      ans = r1.first / K;
    }
    cout << (ans) << endl;
    // cout << ("") << endl;
  }

  //
}

#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 3e5+10;
const int N = 3e5+10;
typedef long long ll;
struct node
{
int val,i;
bool operator<(node x)const {
	return val<x.val;
}
}sn[inf];
ll tree[inf],b[inf],n;
void add(int i,ll x)
{
while(i<=n){
	tree[i]+=x;
	i+=i&-i;
}
}
ll query(int i)
{
ll sum=0;
while(i>=1)
{
	sum+=tree[i];
	i-=i&-i;
}
return sum;
}
int pai[inf];
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>pai[i];
        pai[i]++;
        sn[i].val=pai[i];
        sn[i].i=i;
    }
    sort(sn+1,sn+n+1);
    int cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(i>1&&sn[i].val>sn[i-1].val)
            cnt++;
        b[sn[i].i]=cnt;
    }
    ll ans=0;
    for(int i=1;i<=n;i++)
    {
        add(b[i],1);
        ans+=i-query(b[i]);
    }
    cout<<ans<<endl;
    for(int i = 1; i < n; i++ ){
        ll right = pai[i]-1;
        ll left;// = pai[i]+1;
        if(pai[i]==n)left = 0;
        else left = n - pai[i];
        ans = ans-right+left;
        cout<<ans<<endl;
    }
   // cout<<ans<<endl;
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

//0-indexed
class BIT{
public:
  int N;
  vector<ll> data;
  BIT(){}
  BIT(int n):N(n),data(n){}

  ll sum(int l,int r){//[l,r)
    return sum(r)-sum(l);
  }

  void add(int p,ll x){
    p++;
    while(p<=N){
      data[p-1]+=x;
      p+=p&(-p);
    }
  }

private:
  ll sum(int r){
      ll s=0;
      while(r>0){
          s+=data[r-1];
          r-=r&(-r);
      }
      return s;
  }
};

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

  int N;
  cin>>N;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];

  {
    ll asum=0,bsum=0;
    rep(i,N) asum+=A[i];
    rep(i,N) bsum+=B[i];
    if(asum!=bsum){
      cout<<-1<<endl;
      return 0;
    }
  }

  map<ll,vector<int>> vmp;
  for(int i=N-1;i>=0;i--) vmp[A[i]+i].push_back(i);

  vector<int> P(N,0);
  rep(i,N){
    ll tarv=B[i]+i;
    if(vmp.count(tarv)==false||vmp[tarv].empty()){
      cout<<-1<<endl;
      return 0;
    }
    int t=vmp[tarv].back();
    vmp[tarv].pop_back();
    P[t]=i;
  }

  BIT bit(N);
  ll ans=0;
  rep(i,N){
    ll res=bit.sum(P[i],N);
    ans+=res;
    bit.add(P[i],1);
  }
  cout<<ans<<endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> P;
ll gcd(ll a, ll b){return b? gcd(b, a % b): a;}
ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;}
// head

const int N = 2e5 + 5;
int a[N], b[N], n, num, ans, tmp[N];

map<pair<int, int>, int> mp;
map<int, int> cnt;

void merge(int l, int r) {
	int mid = (l + r) >> 1, i = l, j = mid + 1, now = l;
	while (i <= mid && j <= r) {
		if (a[i] < a[j]) tmp[now++] = a[i++];
		else {
			ans += mid - i + 1;
			tmp[now++] = a[j++];
		}
	}
	while (i <= mid) tmp[now++] = a[i++];
	while (j <= r) tmp[now++] = a[j++];
	for (int i = l; i <= r; i++) a[i] = tmp[i];
}

void merge_sort(int l, int r) {
	if (l == r) return;
	int mid = (l + r) >> 1;
	merge_sort(l, mid);
	merge_sort(mid + 1, r);
	merge(l, r);
}

signed main(void){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] += i;
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		b[i] += i;
	}
	for (int i = 1; i <= n; i++) {
		mp[make_pair(++cnt[b[i]], b[i])] = ++num;
	}
	cnt.clear();
	for (int i = 1; i <= n; i++) {
		pair<int, int> now = make_pair(++cnt[a[i]], a[i]);
		if (!mp.count(now)) {
			cout << -1 << endl;
			return 0;
		}
		a[i] = mp[now];
		//cout<<a[i]<<" ";
	}//cout<<endl;
	merge_sort(1, n);
	cout << ans << endl;
	return 0;
}


 #include <bits/stdc++.h>

 #define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
 #define all(v) (v).begin(), (v).end()
 using namespace  std;
 #define forn(i,n) for (int i = 0; i < (n); ++i)
 using ll = long long;
 int mod = (ll)1e9 + 7;
 #define PI acos(-1)
 typedef pair<int, int> pairs;

 const int INF = 1e9 + 1;
 const int N = 2e5 + 100;
 const double eps = 1e-3;

 template <typename XPAX>
 void ckma(XPAX &x, XPAX y) {
     x = (x < y ? y : x);
 }
 template <typename XPAX>
 void ckmi(XPAX &x, XPAX y) {
     x = (x > y ? y : x);
 }

 void solve() {

 	int h, w;
 	cin >> h >> w;
 	vector<vector<int>> a(h, vector<int>(w - 1));
 	forn(i, h) forn(j, w - 1) cin >> a[i][j];

 	vector<vector<int>> b(h - 1, vector<int>(w));
 	forn(i, h - 1) forn(j, w) cin >> b[i][j];

 	using P = tuple<int, int, int>;

 	auto myid = [&](P p) {
 		int r, c , f;
 		tie(r, c, f) = p;
 		return f * (h * w) + r * w + c;
 	};
 	using Q = pair<int, P>;

 	vector<int> dist(2 * h * w + 1, INF);
 	priority_queue<Q, vector<Q>, greater<Q>>q;
 	auto push = [&](P p, int D){
 		if(dist[myid(p)] <= D)return;
 		dist[myid(p)] = D;
 		q.push({D, p});
 	};
 	push(P{0, 0, 0}, 0);
 	auto get = [&](P p, int &r, int &c, int &f ) {
 		tie(r, c, f) = p;
 	};

 	while(q.size()) {
 		Q s = q.top();
 		q.pop();
 		int D = s.first;
 		int r, c, f;
 		get(s.second, r, c, f);
 		if(r == h - 1 && c == w - 1) {
 			cout << D << endl;
 			return;
 		}
 		if(f == 0) {
 			push(P{r, c, 1}, D + 1);
 			if(c)
 				push(P{r, c - 1, f},D + a[r][c - 1]);
 			if(c + 1 < w) {
				push(P{r, c + 1, f},D + a[r][c]);
			}
			if(r + 1 < h)
				push(P{r + 1, c, f}, D + b[r][c]);

		}
		else {
			if(r) push(P{r - 1, c, f}, D + 1);

			push(P{r, c, 0}, D);
		}
	}

 }
 void test_case() {
     int t;
     cin >> t;
     forn(p, t) {

         //cout << "Case #" << p + 1 << ": ";
         solve();
     }
 }
 int main() {

     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cout.tie(nullptr);

     solve();

 }

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

using lli = long long int;
using ii = pair<int, int>;

const int MAXN = 500;

int r, c;
int a[MAXN+1][MAXN];
int b[MAXN][MAXN+1];

int cost[MAXN+1][MAXN+1];

int dijkstra() {
    memset(cost, -1, sizeof(cost));
    priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> pq;

    cost[1][1] = 0;
    pq.push({0, {1, 1}});

    while(!pq.empty()) {
        pair<int, ii> u = pq.top(); pq.pop();
        int curCost = u.first;
        ii pos = u.second;
        // printf("%d %d %d\n", curCost, pos.first, pos.second);

        if(pos.first == r and pos.second == c) {
            return curCost;
        }
        if(curCost > cost[pos.first][pos.second]) {
            continue;
        }

        if(pos.first < r and
        (cost[pos.first+1][pos.second] == -1 or
        curCost+b[pos.first][pos.second] < cost[pos.first+1][pos.second])) {
            cost[pos.first+1][pos.second] = curCost+b[pos.first][pos.second];
            pq.push({cost[pos.first+1][pos.second], {pos.first+1, pos.second}});
        }
        if(pos.second > 1 and
        (cost[pos.first][pos.second-1] == -1 or
        curCost+a[pos.first][pos.second-1] < cost[pos.first][pos.second-1])) {
            cost[pos.first][pos.second-1] = curCost+a[pos.first][pos.second-1];
            pq.push({cost[pos.first][pos.second-1], {pos.first, pos.second-1}});
        }
        if(pos.second < c and
        (cost[pos.first][pos.second+1] == -1 or
        curCost+a[pos.first][pos.second] < cost[pos.first][pos.second+1])) {
            cost[pos.first][pos.second+1] = curCost+a[pos.first][pos.second];
            pq.push({cost[pos.first][pos.second+1], {pos.first, pos.second+1}});
        }
        for(int i=1; i<pos.first; i++) {
            if(cost[pos.first-i][pos.second] == -1 or
            curCost+i+1 < cost[pos.first-i][pos.second]) {
                cost[pos.first-i][pos.second] = curCost+i+1;
                pq.push({cost[pos.first-i][pos.second], {pos.first-i, pos.second}});
            }
            else if(curCost+i+1 == cost[pos.first-i][pos.second]) {
                continue;
            }
            else {
                break;
            }
        }
    }
}

int main() {
    scanf("%d %d", &r, &c);
    for(int i=1; i<=r; i++) {
        for(int j=1; j<c; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=1; i<r; i++) {
        for(int j=1; j<=c; j++) {
            scanf("%d", &b[i][j]);
        }
    }

    printf("%d\n", dijkstra());
}


#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<int,int>;
const int INF=1001001001;
const int mod =1e9+7;

struct Unionfind{
   vector<int>d;
   vector<map<int,int>>mp;
   Unionfind(int n):d(n,-1),mp(n) {}
   int root(int x){
     if(d[x]<0){return x;}
     return d[x]=root(d[x]);
   }
   bool unite(int x,int y){
     x=root(x);y=root(y);
     if(x==y){return false;}
     if(d[x]>d[y]){swap(x,y);}
     for(auto p:mp[y]){
       mp[x][p.first]+=p.second;
     }
     d[x]+=d[y];
     d[y]=x;
     return true;
   }
   bool same(int x,int y){return root(x)==root(y);}
   int size(int x){return -d[root(x)];}
};
int main() {
  int N,Q;cin>>N>>Q;
  Unionfind uf(N);
  rep(i,N){
    int c;cin>>c;
    uf.mp[i][c]=1;//集団iの中でクラスiにいる人数
  }
  rep(i,Q){
    int q;cin>>q;
    if(q==1){
      int a,b;cin>>a>>b;a--;b--;
      uf.unite(a,b);
    }
    else{
      int x,y;cin>>x>>y;x--;
      int px=uf.root(x);
      cout<<uf.mp[px][y]<<endl;
    }
  }

  return 0;
}

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <ios>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

using namespace std;

using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using pi64 = pair<i64, i64>;

constexpr i64 MAXN = 3*100*1000LL+5LL;
constexpr i64 MOD = 1000000007LL;
constexpr i64 INF64 = MOD * MOD;
#define vec vector
#define let const
#define DRi64(x) i64 x; cin >> x;
#define DRS(x) string x; cin >> x;
#define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }}

#ifdef DEBUG
#define P(x) cerr << x << "\n"
#else
#define P(x)
#endif

i64
find_(const i64 a, vec<i64>& parents)
{
    if (parents[a] != a)
    {
        parents[a] = find_(parents[a], parents);
    }
    return parents[a];
}

void
union_(const i64 a, const i64 b, vec<i64>& parents, vec<i64>& sizes,
        vec<map<i64, i64>>& class_hists)
{
    let i64 r_a = find_(a, parents);
    let i64 r_b = find_(b, parents);
    if (r_a == r_b)
    {
        return;
    }
    if (sizes[r_a] < sizes[r_b])
    {
        union_(r_b, r_a, parents, sizes, class_hists);
        return;
    }
    sizes[r_a] += sizes[r_b];
    parents[r_b] = r_a;
    // merge map of smaller vertex into that of larger vertex
    for (let auto& [cls, cnt] : class_hists[r_b])
    {
        class_hists[r_a][cls] += cnt;
    }
}

int
main()
{
    ios_base::sync_with_stdio(false);

    DRi64(N); DRi64(Q);
    DRVi64(C, N);

    // Ci \in [1, N]
    vec<i64> class_hist(N + 1, 0);
    for (let i64 c : C)
    {
        ++class_hist[c];
    }

    vec<i64> parents(N + 1);
    iota(parents.begin(), parents.end(), 0LL);
    vec<i64> sizes(N + 1, 1);
    vec<map<i64, i64>> class_hists(N + 1);
    for (i64 i = 1; i <= N; ++i)
    {
        class_hists[i][C[i - 1]] = 1;
    }

    for (; Q-->0;)
    {
        DRi64(typ);
        if (typ == 1)
        {
            DRi64(A); DRi64(B);
            union_(A, B, parents, sizes, class_hists);
        }
        else if (typ == 2)
        {
            DRi64(X); DRi64(Y);
            if (let i64 r_X = find_(X, parents); class_hists[r_X].count(Y))
            {
                cout << class_hists[r_X][Y] << "\n";
            }
            else
            {
                cout << "0\n";
            }
        }
        else
        {
            abort();
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
const int mod=1e9+7;
int n,m;
int C[17][17];
char s[N];
int a[N];
int w[200];
inline int po(int x,int k){
	int ret=1;
	while(k){
		if(k&1) ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		k>>=1;
	}
	return ret;
}
inline int calc(int f,int c){
	if(c<m-f) return 0;
	int ret=0;
	for(int i=m;i>=f;i--){
		if(m-i&1) ret=(ret-1ll*C[m-f][i-f]*po(i,c)%mod+mod)%mod;
		else ret=(ret+1ll*C[m-f][i-f]*po(i,c))%mod;
	}
	return ret;
}
int cnt[17],tot;
int main(){
	int i,j;
	for(i='0';i<='9';i++) w[i]=i-'0';
	for(i='A';i<='F';i++) w[i]=i-'A'+10;
	for(i=0;i<17;i++){
		for(j=0;j<17;j++){
			if(j==0||j==i) C[i][j]=1;
			else C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		}
	}
	cin>>(s+1);n=strlen(s+1);
	for(i=1;i<=n;i++) a[i]=w[s[i]];
	cin>>m;
	int ans=0;
	for(i=2;i<=n;i++){
		ans=(ans+1ll*C[15][m]*calc(0,n-i+1))%mod;
		ans=(ans+1ll*C[15][m-1]*(m-1)%mod*calc(1,n-i))%mod;
	}
	ans=(ans+1ll*C[15][m-1]*(a[1]-1)%mod*calc(1,n-1))%mod;
	for(i=1;i<n;i++){
		cnt[a[i]]++;if(cnt[a[i]]==1) tot++;
		if(tot>m) break;
		if(a[i+1]==0) continue;
		int s1=0,s2=0;
		for(j=0;j<a[i+1];j++)
			if(cnt[j]) s1++;
		s2=tot-s1;
		int t1=a[i+1]-s1,t2=16-a[i+1]-s2;
		for(j=0;j<=t1&&j<=m-tot;j++)
			ans=(ans+1ll*C[t1][j]*C[t2][m-tot-j]%mod*(1ll*s1*calc(tot,n-i-1)+1ll*j*calc(tot+1,n-i-1)))%mod;
	}
	cnt[a[n]]++;if(cnt[a[n]]==1) tot++;
	if(tot==m) ans=(ans+1)%mod;
	cout<<ans;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

string s;
int add[200010], keep[200010], has[200010];
int f[200010][2][17];
int k;

inline int tonum(char c) {
    return (c <= '9' ? c - '0' : c - 'A' + 10);
}

inline int dfs(int pos, bool bound, int diff) {
    if (pos == s.size()) {
        return diff == k;
    }
    if (diff > k) {
        return 0;
    }

    if (f[pos][bound][diff] != -1) {
        return f[pos][bound][diff];
    }
    f[pos][bound][diff] = 0;

    if (!diff) {
        f[pos][bound][diff] = dfs(pos + 1, false, 0);
    }
    if (bound) {
        f[pos][bound][diff] += dfs(pos + 1, true, has[pos]);
        f[pos][bound][diff] %= mod;
        f[pos][bound][diff] += (LL)(diff ? add[pos] : add[pos] - 1) * dfs(pos + 1, false, diff + 1) % mod;
        f[pos][bound][diff] %= mod;
        f[pos][bound][diff] += (LL)keep[pos] * dfs(pos + 1, false, diff) % mod;
        f[pos][bound][diff] %= mod;
    }
    else {
        f[pos][bound][diff] += (LL)((diff ? 16 : 15) - diff) * dfs(pos + 1, false, diff + 1) % mod;
        f[pos][bound][diff] %= mod;
        f[pos][bound][diff] += (LL)diff * dfs(pos + 1, false, diff) % mod;
        f[pos][bound][diff] %= mod;
    }

    return f[pos][bound][diff];
}

inline void work() {
    cin >> s >> k;
    unordered_set<int> o;
    for (int i = 0; i < s.size(); ++i) {
        int jm = tonum(s[i]);
        for (int j = 0; j < jm; ++j) {
            if (!o.count(j)) {
                ++add[i];
            }
            else {
                ++keep[i];
            }
        }
        o.insert(jm);
        has[i] = o.size();
    }

    memset(f, -1, sizeof(f));
    int ans = dfs(0, 1, 0);
    cout << ans << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;

  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,1);
    rep(i,n){
      par[i] = i;
    }
  }

  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(size[x] < size[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};

int main()
{
  int n,q; cin >> n >> q;
  vi c(n);
  rep(i,n) cin >> c[i];
  UFT uf(n);
  vector<map<int,int>> mp(n);
  rep(i,n) {
    mp[i][c[i]]++;
  }
  rep(i,q) {
    int t,x,y; cin >> t >> x >> y;
    if(t == 1) {
      x--; y--;
      int a = uf.find(x), b = uf.find(y);
      uf.unite(x, y);
      if(b != uf.find(b)) {
	for(auto val: mp[b]) {
	  auto [id, num] = val;
	  mp[a][id] += num;
	}
      }
      if(a != uf.find(a)) {
	for(auto val: mp[a]) {
	  auto [id, num] = val;
	  mp[b][id] += num;
	}
      }
    }
    else {
      x--;
      cout << mp[uf.find(x)][y] << "\n";
    }
  }

  return 0;
}

#include <cstdio>
#include <vector>
inline int min(int a,int b){return a<b?a:b;}
inline int max(int a,int b){return a>b?a:b;}
const int maxn = 8e5+5;
int n,q,c[maxn];
int head[maxn],tot;
struct Edge{
	int next,to;
}e[maxn];
inline void add_edge(int x,int y){
	e[++tot].next = head[x];
	e[tot].to = y,head[x] = tot;
}
int ANS[maxn];
int ans[maxn],siz[maxn],son[maxn],in[maxn],out[maxn],id[maxn],tim;
inline void dfs1(int u){
	siz[u] = (u <= n);
	if(u <= n)in[u] = out[u] = ++tim,id[tim] = u;
	if(u > n){
		in[u] = n+1,out[u] = 0;
		for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
			dfs1(v);
//			printf("dfs:%d %d\n",u,v);
			siz[u] += siz[v];
			if(siz[v] > siz[son[u]])son[u] = v;
			in[u] = min(in[u],in[v]);
			out[u] = max(out[u],out[v]);
		}
	}
}
struct Query{int id,col;};
std :: vector <Query> qu[maxn];
inline void dfs2(int u){
	if(u <= n)++ans[c[u]];
	else{
		for(int i=head[u],v;v=e[i].to,i;i=e[i].next){
			if(v != son[u]){
	//			printf("vark :%d %d\n",u,ans[2]);
	//			printf("inertval : %d %d %d\n",v,in[v],out[v]);
				dfs2(v);

				for(int j=in[v];j<=out[v];++j)ans[c[id[j]]]--;
			}
		}
		dfs2(son[u]);
	//	printf("vark :%d %d\n",u,ans[2]);
		for(int i=head[u],v;v=e[i].to,i;i=e[i].next)
			if(v != son[u])
				for(int j=in[v];j<=out[v];++j)ans[c[id[j]]]++;
	}
	for(int i=0;i<qu[u].size();++i)ANS[qu[u][i].id] = ans[qu[u][i].col];
}
int fa[maxn<<1];
inline int getfa(int x){return fa[x] == x ? x : fa[x] = getfa(fa[x]);}
int nodcnt,ccnt;
int main(){
	scanf("%d %d",&n,&q);
	for(int i=1;i<=n;++i)scanf("%d",&c[i]);
	for(int i=1;i<=n*2;++i)fa[i] = i;
	nodcnt = n;
	for(int i=1;i<=q;++i){
		int ty,a,b;
		scanf("%d %d %d",&ty,&a,&b);
		a = getfa(a);
		if(ty == 1)b = getfa(b);
		if(ty == 1){
			if(a != b)
				add_edge(++nodcnt,a),add_edge(nodcnt,b),fa[a] = nodcnt,fa[b] = nodcnt;
		}
		else qu[a].push_back((Query){++ccnt,b});
	}
	for(int i=1;i<=2*n;++i)if(i == getfa(i))dfs1(i);
	for(int i=1;i<=2*n;++i)
		if(i == getfa(i)){
			dfs2(i);
			for(int j=in[i];j<=out[i];++j)--ans[c[id[j]]];
		}
//	for(int i=1;i<=2*n;++i)printf("%d %d\n",in[i],out[i]);
//	puts("");
//	for(int i=1;i<=2*n;++i){
//		for(int j=0;j<qu[i].size();++j)printf("%d %d\n",qu[i][j].col,qu[i][j].id);
//		puts("end1");
//	}
//	puts("");
	for(int i=1;i<=ccnt;++i)printf("%d\n",ANS[i]);
	return 0;
}
/*
5 5
2 2 2 2 2
1 1 2
1 1 3
1 2 3
2 2 2
2 4 2
*/


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

bool sumpro(lli s, lli p)
{
    if(s == p+1) return true;
    else if(s == p || s>p) return false;

    for(int i =1; i<int(sqrt(p)) + 1; i++)
    {
        if (p%i == 0)
        {
            if(p/i + i == s) return true;
        }
    }
    return false;
}

int main()
{
   lli s,p;
   cin>>s>>p;
   if(sumpro(s,p)) cout<<"Yes\n";
   else cout<<"No\n";

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

vector<ll> vec;

vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

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

    ll S,P;
    string A;
    cin >> S>>P;

    bool flag = false;

    vec = divisor(P);

    for (ll i = 0; i < vec.size(); i++)
    {
        ll M = P / vec.at(i);
        if(M+vec.at(i)==S){
            flag = true;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N;
vi A;

void solve() {
    int ans = 0, sum = 0, MAX = 0;
    for (int i = 0; i < N; i++) {
        chmax(MAX, A[i]);
        sum += A[i];
        ans += sum;
        cout << ans + MAX * (i + 1) << endl;
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    cin >> N;
    A.resize(N);
    for (auto&& a : A) {
        cin >> a;
    }

    solve();
    return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,T;
  cin >> N >> T;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  set<ll> pre;
  for(int bit=0; bit<(1LL<<(N/2)); bit++){
    ll sum = 0;
    for(int i=0; i<N/2; i++){
      if(bit & (1LL<<i)) sum += A[i];
    }
    pre.emplace(sum);
  }
  set<ll> suf;
  for(int bit=0; bit<(1LL<<(N-N/2)); bit++){
    ll sum = 0;
    for(int i=0; i<(N-N/2); i++){
      if(bit & (1LL<<i)) sum += A[N/2+i];
    }
    suf.emplace(-sum);
  }

  ll ans = 0;
  for(auto p: pre){
    if(p > T) break;
    ll now = T-p;
    ll s = *suf.lower_bound(-now);
    // cout << p << " " << s << "\n";
    chmax(ans,p-s);
  }
  cout << ans << "\n";
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;

int k;
ll res;

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    scanf("%d", &k);
    for (ll i = 1; i <= k; ++i) {
        for (ll j = 1; i * j <= k; ++j) {
            res += k / (i * j);
        }
    }
    printf("%lld\n", res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void run(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const int N=2e5+5;
int dp[19][3][19],n;
bool vis[19][3][19];
string s;
int sol(int i,int sum,int erased){
    sum%=3;
    if(i==n){
        return !(sum==0&&erased!=n)*1e9;
    }
    int &ret=dp[i][sum][erased];
    if(vis[i][sum][erased]==1)
        return ret;
    vis[i][sum][erased]=1;
    ret=1e9;
    ret=min(sol(i+1,sum,erased+1)+1,sol(i+1,sum+s[i]-'0',erased));
    return ret;
}
void solve(){
memset(dp,-1,sizeof dp);
cin>>s;
n=s.size();
cout<<(sol(0,0,0)>=1e9 ? -1:sol(0,0,0));
}
int main()
{
    run();
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}