#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >

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

	double ans = 0;
	FOR(i,1,N){
		ans += 1.0 * N / i;
	}
	out(10) << ans << endl;
}

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

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<double> dp(n+1);
	dp[1]=0;
	for(int i=1;i<n;i++){
		dp[i+1]=dp[i]+n/(double)(n-i);
	}
	printf("%.9f\n",dp[n]);
}


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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  long N;
  cin >> N;
  vector<tuple<long, long, long>> V(N);
  for (long i = 0; i < N; i++) {
    long a, b, c;
    cin >> a >> b >> c;
    V.at(i) = {a, b, c};
  }

  long ans = LONG_MAX;
  for (const auto& [a, b, c] : V) {
    if (a >= c) continue;
    cmin(ans, b);
  }
  if (ans == LONG_MAX) ans = -1;
  cout << ans << '\n';
}

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

using ll = long long;

void solve(long long N){
    set<ll> se;
    for(ll i = 2;i <= sqrt(N) + 10;i++){
        ll _i = i * i;
        for(;_i <= N;_i *= i){
            /*
            if(_i == 0){
                exit(0);
            }
            */
            //cout<<_i<<endl;
            se.insert(_i);
        }
    }
    cout<<N - se.size()<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second

ll MOD=998244353;
int h, w, k;
char g[5005][5005];
ll dp[5005][5005], emp[5005][5005], po3[200005], inv;

ll modpow(ll x, ll e){
	if(x==0) return 0;
	if(e==0) return 1;
	ll y=modpow(x, e/2);
	if(e%2==0) return (y*y)%MOD;
	return ((y*y)%MOD*x)%MOD;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>k;
	po3[0]=1;
	for(int i=1;i<200005;i++){
		po3[i]=(po3[i-1]*3)%MOD;
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			g[i][j]='.';
		}
	}
	for(int i=0;i<k;i++){
		int x, y;
		char c;
		cin>>x>>y>>c;
		g[x][y]=c;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			emp[i][j]=emp[i-1][j]+emp[i][j-1]-emp[i-1][j-1]+(g[i][j]=='.');
		}
	}
	if(g[1][1]=='.') dp[1][1]=3;
	else dp[1][1]=1;
	inv=modpow(3, MOD-2);
	for(int x=1;x<=h;x++){
		for(int y=1;y<=w;y++){
			if(x+y==2) continue;
			ll &ans=dp[x][y];
			ll c=po3[emp[x][y]-emp[x][y-1]], r=po3[emp[x][y]-emp[x-1][y]];
			if(g[x][y-1]=='R' || g[x][y-1]=='X'){
				ans+=(dp[x][y-1]*c)%MOD;
				ans%=MOD;
			}
			if(g[x-1][y]=='D' || g[x-1][y]=='X'){
				ans+=(dp[x-1][y]*r)%MOD;
				ans%=MOD;
			}
			if(g[x][y-1]=='.'){
				ans+=(((2*inv*dp[x][y-1])%MOD)*c)%MOD;
				ans%=MOD;
			}
			if(g[x-1][y]=='.'){
				ans+=(((2*inv*dp[x-1][y])%MOD)*r)%MOD;
				ans%=MOD;
			}
			//cout<<ans<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[h][w]<<endl;
	/*for(int i=1;i<=2;i++){
		for(int j=1;j<=2;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
}

#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define rsrt(v) sort(v.begin(), v.end(), greater<int>())
#define rsrtl(v) sort(v.begin(), v.end(), greater<ll>())
#define fi(i, a, b) for (int i = a; i < b; i++)
#define fll(i, a, b) for (ll i = a; i < b; i++)
#define srt(v) sort(v.begin(), v.end())
#define pb push_back
#define g(v, i, j) get<i>(v[j])
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(),(x).end()
#define ll long long
ll md = 1000000007;
#define theartofwar                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define F first
#define S second
#define sz(v) v.size()
using namespace std;
#define dbg(x) cerr << #x << " = " << x << endl;
template <typename T>
T pw(T a, T b){
    T c = 1, m = a;
    while (b){
        if (b & 1) c = (c * m);
        m = (m * m), b /= 2;
    }
    return c;
}
template <typename T>
T ceel(T a, T b){
    if (a % b == 0)
        return a / b;
    else
        return a / b + 1;
}
template <typename T>
T my_log(T n, T b){
    T i = 1, ans = 0;
    while (1){
        if (i > n){
            ans--;
            break;
        }
        if (i == n) break;
        i *= b, ans++;
    }
    return ans;
}
template <typename T>
T gcd(T a, T b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwmd(ll a, ll b){
    ll c = 1, m = a;
    while (b){
        if (b & 1) c = (c * m) % md;
        m = (m * m) % md;
        b /= 2;
    }
    return c;
}
ll modinv(ll n){
    return pwmd(n, md - 2);
}
ll inverse(ll i){
    if (i == 1)
        return 1;
    return (md - ((md / i) * inverse(md % i)) % md + md) % md;
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b){
    return (a.second < b.second);
}
int main()
{
    theartofwar;
    ll n, a;
    cin >> n;
    vll v;
    fll(i, 0, n) cin >> a, v.pb(a);
    ll dp[n][n + 1];
    fll(i, 0, n) fll(j, 0, n + 1) dp[i][j] = 0;
    ll last[n + 1][n];
    fll(i, 0, n + 1) fll(j, 0, n) last[i][j] = -1;
    dp[0][1] = 1;
    fll(i, 2, n + 1) last[i][v[0] % i] = 0;
    ll s = v[0];
    fll(i, 1, n){
        dp[i][1] = 1;
        s += v[i];
        fll(j, 2, i + 2){
            ll p = s % j;
            if (last[j][p] == -1) continue;
            ll o = last[j][p];
            dp[i][j] = (dp[i][j] + dp[o][j]) % md;
            dp[i][j] = (dp[i][j] + dp[o][j - 1]) % md;
        }
        fll(j, 2, n + 1) last[j][s % j] = i;
    }
    ll ans = 0;
    fll(i, 1, n + 1) ans = (ans + dp[n - 1][i]) % md;
    cout << ans;
}


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

using ll = long long;
const int mod = 1e9+7;

int main(){
    int N; cin >> N;
    vector<ll> A(N), sum(N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum[i+1] = sum[i]+A[i];
    }
    vector<vector<int>> dp(N+2,vector<int>(N+2));
    dp[1][0]++;
    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=N; 1<=j; j--){
            dp[j+1][sum[i+1]%(j+1)] += dp[j][sum[i+1]%j];
            dp[j+1][sum[i+1]%(j+1)] %= mod;
            if(i == N-1){
                ans += dp[j][sum[i+1]%j];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
//#pragma GCC optimize "trapv"
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk      ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll               long long
#define lll              __int128
#define ull              unsigned ll
#define ld               long double
#define pb               push_back
#define pf               push_front
#define dll              deque<ll>
#define vll              vector<ll>
#define vvll             vector<vll>
#define pll              pair<ll,ll>
#define vpll             vector<pll>
#define dpll             deque<pll>
#define mapll            map<ll,ll>
#define umapll           umap<ll,ll>
#define endl             "\n"
#define all(v)           v.begin(),v.end()
#define ms(a,x)          memset(a,x,sizeof(a))
#define random(l,r,T)    uniform_int_distribution<T>(l,r)(rng)

//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;

#ifdef LOCAL
    #include <debug.h>
#endif

template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,const vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,const pair<T1,T2> &p){ out<<p.first<<' '<<p.second; return out;}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;

const ll MOD = 1e9 + 7;
int32_t main()
{
    #ifdef LOCAL
        freopen("error.txt", "w", stderr);
        clock_t clk = clock();
    #endif
    fast_az_fuk
    ll n; cin>>n; vll a(n); cin>>a; a.insert(a.begin(),0);
    vvll pre(n+1,vll(n+1));
    for(int i=1;i<=n;i++){
        vll last(n+1,0);
        int j=1; ll sum = 0;
        while(j <= n){
            sum += a[j];
            pre[i][j] = last[sum%i];
            last[sum%i] = j; j++;
        }
    }
    vvll dp(n+1,vll(n+1));
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        dp[i][1] = 1;
        for(int j=2;j<=n;j++){
            dp[i][j] = (dp[i][j] + dp[pre[j][i]][j])%MOD;
        }
        if(i == n) break;
        for(int j=n;j>=2;j--){
            dp[i][j] = (dp[i][j-1] + dp[pre[j][i]][j]) % MOD;
        }
    }
    ll ans = 0;
    for(int i=n;i>=1;i--){
        ans = (ans + dp[n][i])%MOD;
    }
    cout<<ans<<endl;
    #ifdef LOCAL
        cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    #endif
    return 0;
}


#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <memory>
#include <list>
#include <deque>
#include <queue>
#include <iomanip>
#include <set>
#include <stack>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <string.h>
#include <functional>

using namespace std;

#define REP(i,n) for (decltype(n) i = 0; i < n; i++)
#define THE_MOD 1'000'000'007

using ll = long long;
using ivec = vector<int>;
using lvec = vector<long>;
using ipair = pair<int, int>;
using llvec = vector<ll>;
using llpair = pair<ll, ll>;

#define umap unordered_map
#define uset unordered_set

template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { auto n = v.size(); REP(i,n) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &e : v) is >> e; return is; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }

void in() {} template <typename T, typename... Args> void in(T& t, Args& ...args) { cin >> t; in(args...); }
void out() { cout << endl; } template <typename T, typename... Args> void out(const T& t, const Args& ...args) { cout << t; if (sizeof...(args)) cout << " "; out(args...); }

constexpr ll LLINF = numeric_limits<ll>::max();

template<class T> void sort(T& v) {	sort(v.begin(), v.end()); }
template<class T> void rsort(T& v) { sort(v.begin(), v.end(), greater<typename T::value_type>()); }

void YN(bool b) {	cout << (b ? "Yes" : "No") << endl; }

ll run()
{
	ll v,t,s,d;in(v,t,s,d);
	if (v * t <= d && d <= v * s) return false;
	return true;
}

int main()
{
	cout << fixed << setprecision(15);
	auto r = run();
	YN(r);
	//cout << r << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll po(ll x,ll n){
  ll i,ans=1;
  for(i=0;i<n;i++){
    ans*=x;
  }
  return ans;
}
int main(){
  ll n,i,j;
  cin >> n;
  for(i=1;i<=38;i++){
    for(j=1;j<=27;j++){
      if(po(3,i)+po(5,j)==n){
        printf("%lld %lld\n",i,j);
        return 0;
      }
    }
  }
  cout << -1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define vp vector <pair<int,int>>
#define f(x,y,z) for(x=y;x<z;x++)
#define pb push_back
#define mp make_pair
#define ld long double
#define fb(x,y,z) for(x=y;x>z;x--)
#define ps(x,y) fixed << setprecision(y) << x
#define PI 3.1415926535
#define mod 1000000007
#define mods 998244353
#define setbits(x) __builtin_popcountll(x)
#define all(x) (x).begin(), (x).end()
#define fill(a,b) memset(a,b,sizeof(a))

// AUTHOR ALOK KUMAR
int lcm(int a,int b)
{
    return (a*b)/(__gcd(a,b));
}
int power(int a,int b)
{
    int c=1;
    while(b)
    {
        if(b&1)
        c*=a;
        a*=a;
        b>>=1;
    }
    return c;
}

void solve()
{
    int n;
    cin>>n;
    int a[3];
    int sum=0;
    fill(a,0);
    int count=0;
    while(n)
    {
        int i,j;
        j=n%10;
        a[j%3]++;
        n/=10;
        sum+=j;
        count++;
    }
    if(sum%3==0)
    cout<<"0\n";
    else if(sum%3==1)
    {
        if(a[1]&&count>1)
        cout<<"1\n";
        else
        {
            if(a[2]>=2&&count>2)
            cout<<"2\n";
            else
            cout<<"-1\n";
        }
    }
    else
    {
        if(a[2]&&count>1)
        cout<<"1\n";
        else
        {
            if(a[1]>=2&&count>2)
            cout<<"2\n";
            else
            cout<<"-1\n";
        }
    }

}

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

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int T; cin >> T;
	string U = "atcoder";
	while(T--){
		string S; cin >> S;
		int N = S.size();
		bool alla = true;
		for(int i = 0; i < N; i++){
			if(S.at(i) != 'a') alla = false;
		}
		if(alla){
			cout << -1 << "\n"; continue;
		}
		if(S > U){
			cout << 0 << "\n"; continue;
		}
		int ans = 1919;
		for(int i = 1; i < N; i++){
			string V = S;
			int cnt = 0;
			for(int j = i; j >= 1; j--){
				swap(V.at(j-1), V.at(j));
				cnt++;
				if(V > U){
					ans = min(ans, cnt);
					break;
				}
			}
		}
		cout << ans << "\n";
	}
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint A[N];
  REP(i,N)cin>>A[i];
  lint ans=0;
  lint dmax=0;
  lint s=0;
  lint p=0;
  REP(i,N){
    s+=A[i];
    dmax=max(dmax,s);
    ans=max(ans,p+s);
    ans=max(ans,p+dmax);
    p+=s;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(int argc, char *argv[])
{
  int n, k;
  cin >> n >> k;
  int sum = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= k; j++) {
      sum += i * 100 + j;
    }
  }
  cout << sum << endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <numeric>

using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    cout << (1 + N) * N / 2 * K * 100 + (1 + K) * K / 2 * N;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int k;
long long x;
int main()
{
	scanf("%lld%d",&x,&k);
	while(k--)
	{
		if(x%200) x=x*1000+200;
		else x/=200;
	}
	printf("%lld",x);
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define pb emplace_back
#define lb(v,k) (lower_bound(all(v),(k))-v.begin())
#define ub(v,k) (upper_bound(all(v),(k))-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define all(a) a.begin(),a.end()
#define rsort(a) {sort(all(a));reverse(all(a));}
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void outset(T s){auto itr=s.begin();while(itr!=s.end()){if(itr!=s.begin())cout<<' ';cout<<*itr;itr++;}cout<<'\n';}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n,k;cin>>n>>k;
    rep(i,k){
        if(n%200){
            n=n*1000+200;
        }
        else n/=200;
    }
    out(n);
}


// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) a.begin(), a.end()
#define sz(x) x.size()
#define yn(p) cout << (p?"Yes":"No") << endl;
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;
const int INF = 1000000000;
const int MOD = 1000000007;
const ll llINF = 1000000000000000000;

/**
#include <atcoder/all>
using namespace atcoder;
#include <boost/multiprecision/cpp_int.hpp>
using lll = boost::multiprecision::cpp_int;
using mint = modint1000000007;
using mint2 = modint998244353;
**/

void solve() {
  int x,y;
  cin>>x>>y;
  cout<<(6-x-y)%3<<endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  solve();
  return 0;
}

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

int main(){
    int n,w;
    cin >> n >> w;
    cout << n/w <<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  int64_t M,z=0;
  cin>>S>>M;
  int64_t N=S.size(),K=*max_element(S.begin(),S.end())-'0';
  if(N<2){
    cout<<(M<K?0:1);
    return 0;
  }
  int64_t ok=0,ng=M+10;
  while(ng-ok>1){
    __int128 m=(ok+ng)/2,sum=0,temp=1,l=0;
    for(int j=N-1;j>=0;temp*=m,j--){
      sum+=(S[j]-'0')*temp;
      if(temp>M){
        l=1;
        break;
      }
    }
    if(l||sum>M)ng=m;
    else ok=m;
  }
  cout<<max(z,ok-K);
}

#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>

char x[110];
std::vector<int> V;

int main()
{
	long long int b;
	scanf("%s",x+1);
	scanf("%lld",&b);
	int a = strlen(x+1);
	if(a==1)
	{
		if(x[1]-'0'<=b) printf("1");
		else printf("0");
		return 0;
	}

	for(int i=1;i<=a;i++) V.push_back(x[i]-'0');

	long long int min = 2;
	for(int i=0;i<V.size();i++) min = min>V[i]+1?min:V[i]+1;
	long long int C = min;
	long long int ans = min-1;
	long long int max = (long long int)1e18;
	while(min<=max)
	{
		long long int h = (min+max)/2;
		long long int sum = 0;
		for(int i=0;i<V.size();i++)
		{
			if(sum  > (double)(b-V[i])/h)
			{
				max = h-1;
				goto u;
			}
			sum *= h;
			sum += V[i];
		}
		ans = h;
		min = h+1;
		u:;
	}
	//printf("%lld %lld!!\n",ans,C);
	printf("%lld",ans-C+1);
}


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

int main()
{
  int N;
  string S;
  cin>>N>>S;
  int ans=0;

  rep(i,S.size()){
    int cnt1=0;
    int cnt2=0;
    for(int j=i;j<S.size();j++){
      if(S[j]=='A') cnt1++;
      else if(S[j]=='T') cnt1--;
      else if(S[j]=='G') cnt2++;
      else cnt2--;
      if(cnt1==0 && cnt2==0){
      	ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int _;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int n,ans,cnt[26][100050];
string s,str="ATCG";

int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	cin >> s;
	for(int i=1;i <= n;i++)
		for(int j=0;j<4;j++)
		{
			cnt[str[j]-'A'][i]=cnt[str[j]-'A'][i-1]+(s[i-1] == str[j]);
		//	D(i,str[j],cnt[str[j]-'A'][i]);
		}
	for(int i=0;i<n;i++)
		for(int j=0;j <= i;j++)
			if(cnt['A'-'A'][i+1]-cnt['A'-'A'][j] == cnt['T'-'A'][i+1]-cnt['T'-'A'][j] && cnt['C'-'A'][i+1]-cnt['C'-'A'][j] == cnt['G'-'A'][i+1]-cnt['G'-'A'][j])
			{
		//		D(i,j);
				ans++;
				}
	printf("%d\n",ans);
	return 0;
}


#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
vector<int>to[100005];
int dp[100005];
int sz[100005];

void dfs(int v, int p = -1) {
	int csub = 0;
	dp[v] = 1;
	sz[v] = 1;
	vector<int>c;
	for (int e : to[v]) {
		if (p == e) {
			continue;
		}
		dfs(e, v);
		sz[v] += sz[e];
		int num = dp[e];
		if ((num < 0) && (0 == (sz[e] % 2))) {
			//case1
			dp[v] += num;
		}
		else if ((num >= 0) && (0 == (sz[e] % 2))) {
			//case2
			csub += num;
		}
		else {
			//case3
			c.push_back(num);
		}
	}
	sort(all(c));
	c.push_back(csub);
	rep(i, c.size()) {
		if (0 == i % 2) {
			dp[v] += c[i];
		}
		else {
			dp[v] -= c[i];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	rep(i, N - 1) {
		int p;
		cin >> p;
		p--;
		to[i + 1].push_back(p);
		to[p].push_back(i + 1);
	}
	dfs(0);
	int ans = (dp[0] + N) / 2;
	cout << ans << endl;
	return 0;
}

// Problem: C - MAD TEAM
// Contest: AtCoder - ZONe Energy Programming Contest
// URL: https://atcoder.jp/contests/zone2021/tasks/zone2021_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 3002;

int n;
ll a[MAX_N][5];

void solve()
{
	int lo=1, hi=1e9+1;
	while(lo+1<hi){
		int mid=(lo+hi)/2;
		vector<int> b(32, 0);
		for(int i=0;i<n;++i){
			int f = 0;
			for(int j=0;j<5;++j)if(a[i][j]>=mid) f|=(1<<j);
			b[f]++;
		}
		bool found=false;
		for(int i=0;i<32;++i)if(b[i])for(int j=i;j<32;++j)if(b[j])
		for(int k=j;k<32;++k)if(b[k]){
			if((i|j|k) == 31 && b[i]+b[j]+b[k]>=3) found=true;
		}
		if(!found) hi=mid;
		else lo=mid;
	}
	cout<<lo<<'\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> n;
	for(int i=0;i<n;++i)for(int j=0;j<5;++j)cin>>a[i][j];
	solve();
	return 0;
}


// Author : heyuhhh
// Created Time : 2020/12/18 17:02:09
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(m + 1));
    for (int i = 0; i <= n; i++) {
        dp[i][0] = i;
    }
    for (int j = 0; j <= m; j++) {
        dp[0][j] = j;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + (a[i - 1] != b[j - 1])});
        }
    }
    cout << dp[n][m] << '\n';
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

const int N = 500000 + 10;

int n, a[N], x;

void Solve() {
	scanf("%d %d", &n, &x);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if (x != a[i]) {
            printf("%d ", a[i]);
        }
    }

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("data.in", "r", stdin);
    freopen("std.out", "w", stdout);
    clock_t st = clock();
#endif
    int T = 1;
    while (T--) {
        Solve();
    }
#ifndef ONLINE_JUDGE
    clock_t ed = clock();
    printf("time : %.6lfs\n", 1.0 * (ed - st) / CLOCKS_PER_SEC);
#endif
    return 0;
}


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

#define ll long long int

void solve()
{
     int a[4];
     int mx=INT_MAX;
    int ans=INT_MAX;
     for(int i=0;i<4;i++)
     {
       cin>>a[i];
       if(a[i]<ans)
       {
         ans=a[i];
       }

     }

    cout<<ans<<endl;

}

int main(){
      solve();

    return 0;
}

#include<iostream>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<vector>
#include<math.h>
#define rep(i,n) for (int i = 0, i < n; i++)
using namespace std;

int main(){
    int a,b,w;
    cin >> a >> b >> w;
    w *= 1000;
    int kmax = floor(double(w)/a), kmin = ceil(double(w)/b);
    if (kmin * a <= w){
        cout << kmin << " " << kmax << endl;
    } else {
        cout << "UNSATISFIABLE" << endl;
    }
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
const int len = 400010;
vi f(len), g(len);
int main(){
  rep(i, len) g[i] = i % 3;
  int num = 3, cnt = 1;
  while(num < len){
    for(int i = 1; i * num < len; i++){
      f[i * num] = cnt;
      g[i * num] = i % 3;
    }
    cnt++;
    num *= 3;
  }
  g[0] = 1;
  //rep(i, 30) cout << g[i] << " ";
  for(int i = 1; i < len; i++){
    f[i] += f[i - 1];
    (g[i] *= g[i - 1]) %= 3;
  }

  int n;
  cin >> n;
  vector<char> c(n);
  int ans = 0;
  rep(i, n){
    cin >> c[i];
    //n-1 C i
    if(f[n - 1] != f[i] + f[n - i - 1]) continue;
    if(c[i] == 'B'){
      ans += 0 * g[n - 1] * g[i] * g[n - i - 1] % 3;
    }
    if(c[i] == 'W'){
      ans += 1 * g[n - 1] * g[i] * g[n - i - 1] % 3;
    }
    if(c[i] == 'R'){
      ans += 2 * g[n - 1] * g[i] * g[n - i - 1] % 3;
    }
    ans %= 3;
  }
  if(!(n & 1)) ans = (-ans + 3) % 3;
  if(ans == 0) cout << "B\n";
  if(ans == 1) cout << "W\n";
  if(ans == 2) cout << "R\n";
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long  int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> x >> y >> z;
	z *= 1000;
	ll mn = 0, mx = 0;
	v<ll> vec;
	rep(i, 1000005) {
		mn += x;
		mx += y;
		if (z >= mn && z <= mx) {
			vec.pb(i + 1);
		}
	}
	if (vec.size() == 0) cout << "UNSATISFIABLE";
	else {
		cout << vec.front() << ' ' << vec.back();
	}

	return 0;

}


//QwQcOrZ yyds!!!
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define R(i,a,b) for (int i=(a);i<(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,x) for (int i=head[x];i;i=e[i].nx)
#define mp make_pair
#define pb push_back
#define pa pair < int,int >
#define fi first
#define se second
#define re register
#define be begin()
#define en end()
#define sqr(x) ((x)*(x))
#define ret return puts("-1"),0;
#define put putchar('\n')
#define inf 1000000005
#define mod 998244353
#define int ll
#define N 100005
using namespace std;
inline char gc(){static char buf[100000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}
#define gc getchar
inline ll read(){char c=gc();ll su=0,f=1;for (;c<'0'||c>'9';c=gc()) if (c=='-') f=-1;for (;c>='0'&&c<='9';c=gc()) su=su*10+c-'0';return su*f;}
inline void write(ll x){if (x<0){putchar('-');write(-x);return;}if (x>=10) write(x/10);putchar(x%10+'0');}
inline void writesp(ll x){write(x),putchar(' ');}
inline void writeln(ll x){write(x);putchar('\n');}
int n,t[N],l[N],r[N],x,y,ans;
signed main()
{
	n=read();
	for (int i=1;i<=n;i++)
	{
		t[i]=read(),l[i]=read(),r[i]=read();
	}
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
		{
			x=i,y=j;
			if (l[x]>l[y]) swap(x,y);
			if (l[y]<r[x]) ans++;else
			if (l[y]==r[x])
			{
				if ((t[x]==1||t[x]==3)&&(t[y]==2||t[y]==1)) ans++;
			}
		}
	writeln(ans);

}
/*

*/

// Problem:
// 			F - Close Group
//
//
// Contest: AtCoder - AtCoder Beginner Contest 187
// URL: https://atcoder.jp/contests/abc187/tasks/abc187_f
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

const int N = 18;
int connect[N],f[1 << N];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for(int i = 0;i < n;++i)	connect[i] |= (1 << i);

	for(int i = 0;i < m;++i)
	{
		int u,v;scanf("%d%d",&u,&v);
		--u;--v;
		connect[u] |= (1 << v);
		connect[v] |= (1 << u);
	}

	f[0] = 0;
	for(int i = 1;i < (1 << n);++i)
	{
		f[i] = 1e5+7;
		bool indp = 1;
		for(int j = 0;j < n;++j)
			if((i >> j & 1) && (connect[j] & i) != i)
				indp = 0;
		if(indp)	f[i] = 1;
		for(int s = (i - 1) & i;s;s = (s - 1) & i)
			f[i] = min(f[i],f[s] + f[i ^ s]);
	}
	printf("%d",f[(1 << n) - 1]);
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

const ll big = 1000000001;
int main(){
  ll n; cin >> n;
  vector<ll> m1(n, big), m2(n, -big);
  rep(i, n){
    ll x, c;
    cin >> x >> c;
    c--;
    m1[c] = min(m1[c], x);
    m2[c] = max(m2[c], x);
  }
  P now1 = P(0, 0); // now/sum
  P now2 = P(0, 0); // now/sum
  ll next1, next2;
  rep(i, n){
    if (m1[i] == big) continue;
    next1 = now1.second + abs(now1.first-m2[i]) + abs(m1[i]-m2[i]);
    next1 = min(next1, now2.second + abs(now2.first-m2[i]) + abs(m1[i]-m2[i]));
    next2 = now1.second + abs(now1.first-m1[i]) + abs(m1[i]-m2[i]);
    next2 = min(next2, now2.second + abs(now2.first-m1[i]) + abs(m1[i]-m2[i]));
    now1 = P(m1[i], next1);
    now2 = P(m2[i], next2);
  }
  ll ans = min(abs(now1.first)+now1.second, abs(now2.first)+now2.second);
  cout << ans << endl;
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>>ve;
int N,l,r,L,R;
long long LL,RR,tr,tl;
string getss(){//用getchar()读入string
	string k="";
	char a;
	a=getchar();
	while(a==-1||a==32||a==10)a=getchar();
	while(a!=-1&&a!=32&&a!=10){
		k+=a;
		a=getchar();
	}
	return k;
}
int main(){
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		ve.push_back(make_pair(b,a));
	}
	sort(ve.begin(),ve.end());
	pair<int,int>cur;
	cur=*ve.begin();
	LL=RR=l=r=L=R=0;
	L=cur.second;
	R=cur.second;
	for(pair<int,int>g:ve){
		if(g.first==cur.first){
			L=min(L,g.second);
			R=max(R,g.second);
		} else{
			cur=g;

			tr=R-L+min(LL+abs(L-l),RR+abs(L-r));
			tl=R-L+min(LL+abs(R-l),RR+abs(R-r));
			RR=tr;
			LL=tl;
			//cout<<RR<<" "<<LL<<endl;
			l=L;
			r=R;
			L=R=cur.second;
			//cout<<l<<" "<<r<<" "<<L<<" "<<R<<endl;
		}
	}
	tr=R-L+min(LL+abs(L-l),RR+abs(L-r));
	tl=R-L+min(LL+abs(R-l),RR+abs(R-r));
	RR=tr;
	LL=tl;
	//cout<<RR<<" "<<LL<<endl;
	//cout<<l<<" "<<r<<" "<<L<<" "<<R<<endl;
	printf("%lld",min(LL+abs(L),RR+abs(R)));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define Test int T;cin>>T;while(T--)
#define PI acos(-1)
#define endl "\n"
#define fx(x) fixed<<setprecision(x)
#define sz(s) (int)s.size()
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define mem(a,n) memset((a),n,sizeof (a))
#define INF 1e9
#define ii pair<ll,ll>
ll gcd(ll x,ll y){return(!y?x:gcd(y,x%y));}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
void file(){
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    //freopen("bridges.in", "r", stdin);
    //freopen("bridges.out", "w", stdout);
#endif
}
void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    file();
}
int dx[]= {-1,0,1,0};
int dy[]= {0,1,0,-1};
const double eps=1e-9;
const int mod=1e9+7;
const int N=3e5+5;
int main(){
    fast();
    int a,b,c;
    cin>>a>>b>>c;
    if(c==0){
        if(a>b)cout<<"Takahashi";
        else cout<<"Aoki";
    }
    else{
        if(a>=b)cout<<"Takahashi";
        else cout<<"Aoki";
    }
}

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

#define ll long long

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

    int a,b,c;

    cin>>a>>b>>c;

    if(c==0)
    {
        if(a<=b)
        {
            cout<<"Aoki\n";

        }
        else
        cout<<"Takahashi\n";
    }
    else if(c==1)
    {
        if(a>=b)
        cout<<"Takahashi\n";
        else
        cout<<"Aoki\n";

    }

    return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize("-Ofast")
//#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")

#define vi vector<int>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define forn(i, n) for (int i = 0; i < n; ++i)

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

const int N = 5e5 + 7;
const ll mod = 1e9 + 7;
const ll inf = 2e18;

auto ra = [] {char *p = new char ; delete p ; return ll(p) ; };
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1));

int n;
int a, b, x, y;
int d[N];
vector<pair<int, int>> adj[N];

void edge(int u, int v, int w)
{
        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
}

int dijkstra()
{
        priority_queue<pair<int, int>> q;
        q.push({0, a});
        fill(d, d + N, 1e9);
        d[a] = 0;
        while (q.size())
        {
                pair<int, int> t = q.top();
                q.pop();
                for (auto u : adj[t.second])
                {
                        if ( u.second - t.first < d[u.first])
                        {
                                d[u.first] = u.second - t.first;
                                q.push({-d[u.first], u.first});
                        }
                }
        }
        return d[b + 100];
}

int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        //freopen("in.in", "r", stdin);
        cin >> a >> b >> x >> y;
        for (int i = 1; i <= 100; ++i)
        {
                edge(i, i + 100, x);
                if (i < 100)
                {
                        edge(i, i + 1, y);
                        edge(i + 100, i + 101, y);
                        edge(i + 100, i + 1, x);
                }
        }
        cout << dijkstra();
        return 0;
}

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

int main() {
  long a,b,x,y,ans;
  cin>>a>>b>>x>>y;
  ans=0;
  if(a-b==1 || a==b){
    ans=x;
  }
  else if(a>b){
    ans=x+min(y,2*x)*(abs(a-b)-1);
  }
  else{
    ans=x+min(y,2*x)*(abs(a-b));
  }
  cout<<ans;
}


#include<bits/stdc++.h>
#define LL long long
#define ull unsigned long long
#define F(i,j,k) for(int i=(j);i<=(k);i++)
#define DF(i,j,k) for(int i=(j);i>=(k);i--)
#define P pair
#define dui priority_queue
using namespace std;
template<typename T>inline void read(T &n){
    T w=1;n=0;char ch=getchar();
    while(!isdigit(ch)&&ch!=EOF){if(ch=='-')w=-1;ch=getchar();}
    while(isdigit(ch)&&ch!=EOF){n=(n<<1)+(n<<3)+(ch^48);ch=getchar();}
    n*=w;
}
template<typename T>inline void write(T x){
    ull y=0;
    T l=0;
    if(x<0){x=-x;putchar('-');}
    if(!x){putchar(48);return;}
    while(x){y=y*10+x%10;x/=10;l++;}
    while(l){putchar(y%10+48);y/=10;l--;}
}
template<typename T>inline void writeln(T x){
    write(x);
    puts("");
}
template<typename T>inline void writes(T x){
    write(x);
    putchar(' ');
}
template<typename T>inline void checkmax(T &a,T b){a=a>b?a:b;}
template<typename T>inline void checkmin(T &a,T b){a=a<b?a:b;}
const int N=1e5+100;
LL ans,a[N],b[N],c[N];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;read(n);
	F(i,1,n)read(a[i]);F(i,1,n)read(b[i]);
	F(i,1,n)if(i&1)ans+=a[i],c[i]=b[i]-a[i];else ans+=b[i],c[i]=a[i]-b[i];
	sort(c+1,c+n+1);
	F(i,n/2+1,n)ans+=c[i];
	writeln(ans);
    return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

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

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

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

  struct record {
    ll t;
    ll l;
    ll r;
  };

  vector<record> rlist;
  rep(i, N) {
    ll t, l, r;
    scanf("%lld %lld %lld", &t, &l, &r);
    rlist.emplace_back(record{t, l, r});
  }

  ll ans = 0;

  for (ll i = 0; i < N - 1; i++) {
    for (ll j = i + 1; j < N; j++) {
      auto rec1 = rlist[i];
      auto rec2 = rlist[j];

      if (rec1.r < rec2.l || rec2.r < rec1.l) {
        // 全く重ならない
        continue;
      }
      // ちょうど重なるパターン
      if (rec1.r == rec2.l) {
        bool ok1 = (rec1.t == 1 || rec1.t == 3);
        bool ok2 = (rec2.t == 1 || rec2.t == 2);
        if (!(ok1 && ok2)) {
          continue;
        }
      }

      // ちょうど重なるパターン
      if (rec2.r == rec1.l) {
        bool ok1 = (rec2.t == 1 || rec2.t == 3);
        bool ok2 = (rec1.t == 1 || rec1.t == 2);
        if (!(ok1 && ok2)) {
          continue;
        }
      }

      //
      // cout << "i:" << (i) << ",j:" << (j) << endl;
      ans++;
    }
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t,k;
char s[maxn];
int p[maxn];
char win[110][110];

char bat(char x,char y){
    if(x == y) return x;
    if(x == 'R' && y == 'S') return x;
    if(x == 'S' && y == 'P') return x;
    if(x == 'P' && y == 'R') return x;
    return y;
}

int main(){
    read(n);read(k);

    scanf("%s",s);
    p[0]=1;
    fo(i,1,k) p[i]=p[i-1]*2%n;
    fo(i,0,n-1) {
        win[i][0] = s[i];
    }

    fo(i,1,k){
        fo(j,0,n-1){
            win[j][i] = bat(win[j][i-1],win[(j+p[i-1])%n][i-1]);
        }
    }

    printf("%c\n",win[0][k]);
    Please AC;
}


#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <algorithm>
#include <set>
#include <sstream>
#include <time.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <assert.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rew(i, n) for (int i = 1; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
const double PI = 3.14159265358979323846;
using Graph = vector <vector<pair<ll, ll>>>;

int main() {
	ll maxval = 1e18;
	ll N; cin >> N;
	vector<bool>exist(N + 1, false);
	vector<ll>left(N + 1, maxval), right(N + 1, -maxval);
	rep(i, N) {
		ll X, C; cin >> X >> C;
		exist[C] = true;
		left[C] = min(left[C], X);
		right[C] = max(right[C],X);
	}
	ll lft = 0, rgt = 0;
	ll posl = 0, posr = 0;
	rep(i, N + 1) {
		if (!exist[i])continue;
		ll dist = right[i] - left[i];
		ll temp1 = min(lft + abs(posl - left[i]) + dist, rgt + abs(posr - left[i]) + dist);

		ll temp2 = min(rgt + abs(posr - right[i]) + dist,lft + abs(posl - right[i]) + dist);
		rgt = temp1;
		lft = temp2;
		posl = left[i];
		posr = right[i];
	}
	ll ans = min(lft + abs(posl), rgt + abs(posr));
	cout << ans << endl;
}


//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#ifdef bhole_ka_saaya
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
	#define booga cerr << "booga" << endl
#else
	#define debug(...) ;
	#define booga ;
#endif

template <typename T> std::ostream& operator<<(std::ostream& stream, const vector<T>& vec){ for(int x : vec)stream << x << ' '; return stream; }
template <typename T> std::istream& operator>>(std::istream& stream, vector<T>& vec) { for(int &x : vec)stream >> x;return stream; }
template <typename T> void operator+=(vector<T>& vec, const T value) { for(int &x : vec)x += value; }
template <typename T> void operator-=(vector<T>& vec, const T value) { for(int &x : vec)x -= value; }
template <typename T> void operator++(vector<T>& vec) { vec += 1; }
template <typename T> void operator++(vector<T>& vec,T) { vec += 1; }
template <typename T> void operator--(vector<T>& vec) { vec -= 1; }
template <typename T> void operator--(vector<T>& vec,T) { vec -= 1; }
template <typename T> void operator*=(vector<T>& vec, const T value) { for(int &x : vec)x *= value; }
template <typename T> void operator/=(vector<T>& vec, const T value) { for(int &x : vec)x /= value; }

template <typename A, typename B>string to_string(pair<A, B> p);
template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(char c) {string s;s += c;return s; }
string to_string(const char* s) {return to_string((string) s); }
string to_string(bool b) {return (b ? "1" : "0"); }
string to_string(vector<bool> v) {bool first = true;string res = "{";for (int i = 0; i < static_cast<int>(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;}
template <size_t N>string to_string(bitset<N> v) {string res = "";for (size_t i = 0; i < N; i++) {res += static_cast<char>('0' + v[i]);}return res;}
template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
template <typename T> void ckmin(T& change, T val){change = min(change,val);}
template <typename T> void ckmax(T& change, T val){change = max(change,val);}

void debug_out() { cerr << endl; } template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
void bharo(int N_N) { return; }template <typename Head, typename... Tail>void bharo(int N_N, Head &H, Tail & ... T) {H.resize(N_N);bharo(N_N,T...);}
void safai() { return; }template <typename Head, typename... Tail>void safai(Head &H, Tail & ... T) {H.clear();safai(T...);}

void testcase(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	ll lar = -1,sum = 0,here = 0;
	for(int i = 0; i < n; i++){
		ckmax(lar,a[i]);
		sum += a[i];
		here += sum;
		cout << here + lar*(ll)(i+1) << '\n';
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while(tt--){
		testcase();
	}
	return 0;
}

#include <cstdio>

#define uint unsigned int
#define i64 long long
#define u64 unsigned i64

int Max(int a, int b) { return (a > b) ? a : b; }
int Min(int a, int b) { return (a < b) ? a : b; }

int rint()
{
	int x = 0, fx = 1; char c = getchar();
	while (c < '0' || c > '9') { fx ^= (c == '-' ? 1 : 0); c = getchar(); }
	while ('0' <= c && c <= '9') { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	if (!fx) return -x;
	return x;
}

const int MAX_n = 2e5;

int n, v[MAX_n + 5];
int maxv[MAX_n + 5];

i64 dp[MAX_n + 5];
i64 sum[MAX_n + 5];

int main()
{
	n = rint();
	for (int i = 1; i <= n; i++)
	{
		v[i] = rint();
		sum[i] = sum[i - 1] + v[i];
		maxv[i] = Max(maxv[i - 1], v[i]);
		dp[i] = dp[i - 1] + sum[i];
		printf("%lld\n", dp[i] + 1LL * maxv[i] * i);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
  ll n, x; cin >> n >> x;
  map<ll,ll> p;
  REP(i,n) {
    ll a,b,c; cin >> a >> b >> c;
    p[a]+=c;
    p[b+1]-=c;
  }
  ll lastat = 0;
  ll ans = 0;
  ll nowpay = 0;
  for (auto ite=p.begin();ite!=p.end();ite++) {
    ll nowat = ite->first;
    ans += (nowat-lastat)*min(x,nowpay);
    ll plus = ite->second;
    nowpay+=plus;
    lastat = nowat;
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define pb(x)           push_back(x)
#define mp              make_pair
#define sz(x)           (int)x.size()
#define mem(x ,y)       memset(x , y , sizeof x )
#define all(a )         a.begin() , a.end()
#define pii             pair<int,int >
#define endl            "\n"
#define forn(i,x,y )    for(int i= x; i<=y ; i++ )
#define ford(i,x,y )    for(int i= x; i>=y ; i-- )
#define rep(i,n )       for(int i= 0; i<n ; i++ )
#define repi(i,n )      for(int i= 1; i<=n ; i++ )
#define repit(i, c)     for( __typeof((c).begin()) i = (c).begin(); i != (c).end();++i )
#ifndef ONLINE_JUDGE
    #define dbg(args...)    do {   cout << #args << ' ' ;  print(args); } while(0); cerr<< endl ;
#else
    #define dbg(args...)   ;
#endif
typedef long long ll  ;
typedef unsigned long long ull  ;
ll  mod =  1e9+7, mod2 =     998244353;
int setbit(int n, int pos  ) { return n = n|(1LL<< pos) ; }
int resetbit(int n,int pos ) { return n = n & ~(1LL<<pos ); }
bool checkbit(int n,int pos) { return (bool ) (n&(1LL<<pos))  ; }
template<typename T>T add(T x, T y, T mod = mod ){ x%= mod ;  y%= mod ;   return (x+y)%mod ;  }
template<typename T>T sub(T x, T y, T mod = mod ){ return ((x-y)%mod+mod )%mod;  }
template<typename T>T mul(T x, T y, T mod = mod ){ x %= mod ; y %= mod ; return (x*y)%mod  ;  }
template<typename T> void print(const T& v) {    cout << v << ' ' ;}
template<typename T1,typename... T2> void print( const T1& first, const T2&... rest ){ print(first); print(rest...) ;}
template<typename T> void dbg_a(T a[] ,int n=10 ) {cerr << "[ "; for(int i=0;i <= n ; i++ )cerr<<a[i]<<' ' ; cerr<< " ]" <<  endl; }
template<typename F,typename S>ostream& operator<<( ostream& os, const pair< F, S > & p ){return os << "[ " << p.first << ", " << p.second << " ]";}
template<typename T>ostream &operator<<(ostream & os, const vector< T > &v ){os << "[ "; for(int i=0; i<sz(v) ; i++ )  os << v[i] << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const map< T ,T> &Map ){os << "[ "; repit(it , Map ) os << "[" <<(*it).ff << ' ' << (*it).ss << "] "    ; return os << "]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const set< T > &Set  ){os << "[ "; repit(it , Set ) os <<  *it  << ' ' ; return os << " ]\n" ; }
template<typename T>ostream &operator<<(ostream & os, const multiset< T > &Set) {os << "[ "; repit(it , Set )os <<  *it  << ' ' ; return os << " ]\n" ; }
#define  int  ll
const int maxn  = (int)  1e5+  123;
const int inf  =  1e9; //0xc0  ;//0x3f ;
/////////////////////////////////////////////////

int n ,m,sum , k ;
int a[maxn  ]  , _p[maxn ]  , _x[maxn  ]  ;

void  solve() {
    int x,y,z,p,q  ,  tot = 0  , ans = 0 , mx =0 , mn     ;

    cin  >> n ;
    ans  = inf +inf ;
    rep( i ,n )  {
        cin >> a[i] >> _p[i] >> _x[i]  ;
        if( _x[i ]-a[i] > 0  ) {

            if( ans  > _p[i] ) ans = _p[i] ;
        }

    }
    if(ans >  inf ) ans = -1  ;
    cout << ans << endl  ;

}
signed main() {

    ios :: sync_with_stdio(false);  cin.tie(0);
    cout << fixed << setprecision( 12) ;
    int t = 1 , cs =0   ;
    // cin >> t  ;
    while(t--)   {
        solve()  ;
    }
    return 0 ;
}


#include <bits/stdc++.h>
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define rep(i,n) Rep(i,0,n)
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define _GLIBCXX_DEBUG

int main(){
  int N;cin>>N;
  vector<int> a(N); rep(i,N) cin >> a[i];
  sort(all(a));
  bool test=true;
  rep(i,N){
    if(a[i]==i+1) continue;
    else test=false;
  }
  if(test) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  string s, t, tmp;
  cin >> s;
  bool flag = false;
  for(int i = 0; i < (int)s.size(); ++i){
    if(s[i] == 'R'){flag = !flag;}
    else if(s[i] != 'R' && flag == false){t += s[i];}
    else{t.insert(0, {s[i]});}
  }
  if(flag == true){reverse(t.begin(), t.end());}

  stack<char> stk;
  if(t.size() == 0){cout << endl; return(0);}
  for(int i = 0; i < t.size(); ++i){
    if(stk.empty() || stk.top() != t[i]){stk.push(t[i]);}
    else{stk.pop();}
  }

  char w;
  string ans;
  int loopnum = stk.size();
  for(int i = 0; i < loopnum; ++i){
     w = stk.top(); stk.pop(); ans += w;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(ll i = ll(ini); i < ll(lim); i++)
#define ford(i, ini, lim) for(ll i = ll(ini); i >= ll(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;

ll g1(ll x) {
    if (x == 0) return 0;
    string s = to_string(x);
    sort(begin(s), end(s), greater<char>());
    return stoi(s);
}

ll g2(ll x) {
    if (x == 0) return 0;
    string s = to_string(x);
    sort(begin(s), end(s));
    return stoi(s);
}

ll f(ll x) {
    return g1(x) - g2(x);
}

void solve() {
    ll n, k;
    cin >> n >> k;
    ll x = n;
    fori (i, 0, k) {
        x = f(x);
    }
    cout << x << endl;
}

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

#include<bits/stdc++.h>
#include<string>
using namespace std;
//functions like ceil() and floor() are used to truncate the decimal values
//countsort is great

#define ll long long
#define int long long
#define vi vector<int>
#define vlli vector<ll>
#define pii pair<int,int>
#define pb push_back
#define mpr make_pair
#define ft first
#define sec second
#define f0r(n) for(int i=0;i<n;i++)
#define f1r(n) for(int j=0;j<n;j++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define txtinp(); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define inp(n,arr); for(int i=0;i<n;i++){cin>>arr[i];}
#define srt(arr); sort(arr.begin(),arr.end());
#define rsrt(arr); sort(arr.rbegin(),arr.rend());

int dp[2];

int solve(int n){
	vi arr;
	while(n){
		arr.pb(n%10);
		n /= 10;
	}
	int s = arr.size();
	srt(arr);
	dp[0] = 0;dp[1] = 0;
	f0r(s){
		dp[0] = dp[0]*10 + arr[i];
		dp[1] = dp[1]*10 + arr[s-1-i];
	}

	return abs(dp[0] - dp[1]);
}

signed main(){
    fastio();
    // txtinp();
    int testc=1;//cin>>testc;
    while(testc--){
    	int n,k;cin>>n>>k;
    	int ans = n;
    	f0r(k){
    		ans = solve(ans);
    	}cout<<ans<<endl;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 998244353
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define endl '\n'
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}

int fact[100005],fact_inv[100005];
int ncr(int n,int r){
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
    //return x;
}
int n;
int dp[5005][15],vis[5005][12];
int solve(int m,int i)
{
    if(vis[m][i]==true)
    return dp[m][i];
    vis[m][i]=true;
    if(i==0)
    {
        if(n>=m&&m%2==0)
        {
           dp[m][i]=ncr(n,m);

        }
        else dp[m][i]=0;
        return dp[m][i];
    }

    int ans=0;
    for(int j=0;j<=n;j+=2)
    {
        int x=m-j*(1ll<<i);
        if(x>=0)
        {
            ans+=(solve(x,i-1)*ncr(n,j))%mod;
            ans%=mod;
        }
    }
    dp[m][i]=ans;
    return dp[m][i];
}

signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
fact[0]=1;
    for(int i=1;i<100005;i++){
        fact[i]=(fact[i-1]*i)%mod;
        fact_inv[i]=power(fact[i],mod-2);
    }

while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int m;
    cin>>n>>m;
    int ans=solve(m,12);
    cout<<ans<<endl;
}

return 0;
}

#include<iostream>
using namespace std;
typedef long long int ll;
const int mod = 998244353;
int n;
ll fact[5001],inv[5001];
ll dp[5001][51];
ll po(ll a, int p){
	if(p==0) return 1ll;
	ll ret=po(a,p/2);
	ret=ret*ret%mod;
	if(p%2) ret=ret*a%mod;
	return ret;
}
ll ncr(int n, int r){
	return (fact[n]*inv[n-r]%mod)*inv[r]%mod;
}
ll solve(int m, int j){
	if(m==0) return 1ll;
	if((1<<j)>m) return 0;
	if(dp[m][j]!=-1) return dp[m][j];
	ll ans=0;
	for(int i=0;i<=n and i*(1<<j)<=m;i+=2) ans=(ans+ncr(n,i)*solve(m-i*(1<<j),j+1)%mod)%mod;
	return dp[m][j]=ans;
}
int main(){
	int m;
	cin>>n>>m;
	fact[0]=1ll;
	inv[0]=1ll;
	for(ll i=1;i<=5000;i++){
		fact[i]=fact[i-1]*i%mod;
		inv[i]=po(fact[i],mod-2);
	}
	for(int i=0;i<5001;i++) for(int j=0;j<51;j++) dp[i][j]=-1;
	cout<<solve(m,0)<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

// mod. m でのaの逆元a^{-1}を計算する
ll modinv(ll a, ll m) {
  ll b = m, u = 1LL, v = 0LL;
  while (b) {
    ll t = a/b;
    a -= t*b;
    swap(a, b);
    u -= t*v;
    swap(u, v);
  }
  u %= m;
  if (u<0) u += m;
  return u;
}

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  ll res = A%Mod;
  res = (res%Mod)*(B%Mod)%Mod;
  res = (res%Mod)*(C%Mod)%Mod;
  res = (res%Mod)*((A+1)%Mod)%Mod;
  res = (res%Mod)*((B+1)%Mod)%Mod;
  res = (res%Mod)*((C+1)%Mod)%Mod;
  cout << res*modinv(8, Mod)%Mod << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int T;
ll N;
const ll MOD = 998244353;
ll mult(ll a, ll b){
    return (a*b)%MOD;
}

ll fexp(ll b, ll e){
    ll res = 1;
    for(;e;e>>=1){
        if(e&1)res = (res*b)%MOD;
        b = (b*b)%MOD;
    }
    return res;
}

// INVERSO MOLTIPLICATIVO

ll inv(ll a){
    return fexp(a,MOD-2);
}

int main(){
    const ll mod = 998244353;
    ll a, b, c;
    cin >> a >> b >> c;
    cout <<mult(mult(mult(a,a+1),mult(mult(c,c+1),mult(b,b+1))),inv(8));
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_set>
#include <algorithm>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repll(i,n) for (ll i = 0; i < (ll)(n); i++)
#define fore(x,a) for(auto&(x) : (a))

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

#define ALL(a) (a).begin(), (a).end()

const ll INFL = 1e18;
const int INFI = 1e9;
const int MOD = 1e9 + 7;

int main(){
  int N;
  string S;
  cin >> N >> S;
  vll x(N+1);
  rep(i,N+1) {
    cin >> x[i];
  }
  ll M = INFL;
  rep(i,N) {
    chmin(M,abs(x[i]-x[i+1]));
  }
  vector<vector<ll>> res(M,vector<ll>(N+1));
  for (int j = 0; j <= N; j++) {
        ll r = x[j] % M;
        for (int i = 0; i < M; ++i) {
            res[i][j] = x[j] / M;
            if (i < r) res[i][j]++;
        }
  }
  cout << M << endl;
    for (int i = 0; i < M; ++i) {
        for (int j = 0; j <= N; ++j) cout << res[i][j] << " ";
        cout << endl;
    }
}

#include<cstdio>
#include<iostream>
#include<cstring>

using namespace std;

const int maxn=1e2+10;

int arr[maxn];
string s;
int n;
bool judge(int x){
    for(int i=0;i<n;i++){
        int a=arr[i]/x,b=arr[i+1]/x;
        int aa=arr[i]%x,bb=arr[i+1]%x;
        if(s[i]=='<'){
            if(a>=b) return false;
            if(b-a==1){
                if(aa>bb) return false;
            }
        }
        else{
            if(a<=b) return false;
            if(a-b==1){
                if(aa<bb) return false;
            }
        }
    }
    return true;
}
int main()
{
    cin>>n;
    cin>>s;

    for(int i=0;i<=n;i++) scanf("%d",arr+i);

    int l=0,r=20000;
    int x=0;

    while(l<=r){
        int mid=(l+r)>>1;
        //cout<<l<<","<<r<<":"<<mid<<endl;
        if(judge(mid)){
            x=max(x,mid);
            l=mid+1;
        }
        else r=mid-1;
    }
    printf("%d\n",x);
    for(int i=0;i<x;i++){
        for(int j=0;j<=n;j++)
            printf("%d ",arr[j]/x+(i<arr[j]%x));
        putchar('\n');
    }

    return 0;
}
/*
3
<><
3 8 6 10

3
<><
8 3 6 10
*/


#include <bits/stdc++.h>

#define     boost            ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pb               push_back
#define     pob              pop_back
#define     pof              pop_front
#define     pf               push_front
#define     mp               make_pair
#define     ff               first
#define     ss               second
#define     endl             "\n"

#define     rep(i,a,b)       for(ll i=a; i<b; i++)
#define     rev(i,a,b)       for(ll i=a; i>=b; i--)

#define     decimal(n)       fixed << setprecision(n)
#define     all(v)           v.begin(), v.end()
#define     rall(v)          v.rbegin(), v.rend()
#define     sz(v)            v.size()
#define     total_sum(v)     accumulate(all(v),0)

#define     make_unique(v)   v.erase(unique(all(v)),v.end())
#define     n_p(v)           next_permutation(all(v))
#define     p_p(v)           prev_permutation(all(v))

#define     for_each(it, X)  for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)

#define     re               return

using namespace std;

typedef     long long              ll;
typedef     unsigned long long     ull;
typedef     pair < int, int >      pii;
typedef     pair < ll, ll >        pll;
typedef     vector < pii >         vii;
typedef     vector < pll >         vll;
typedef     vector < int >         vi;
typedef     vector < ll >          vl;
typedef     vector < string >      vs;

ll gcd ( ll , ll );

ll lcm ( ll  , ll );

bool isPrime( ll );

ll power( ll , ll );

ll fact( ll );

void sieve_of_eratosthenes ( ll , vl &a);

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

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

	if(c) {

		if(b<=a) {
			c=1;
		}

		else
		c=0;

	}

	else {
		if(a<=b) {
			c=0;
		}

		else
		c=1;
	}

	if(c) {
		cout<<"Takahashi";
	}

	else
	cout<<"Aoki";
}

int main()
{
    boost;
    ll t=1;
//	cin>>t;

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

}

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

// HCF

ll gcd ( ll a , ll b )  {

	return __gcd ( a , b ) ;

	/*

	if ( a==0 )
	return b ;

	return gcd ( b%a , a ) ;

	*/
}

// LCM

ll lcm ( ll a , ll b )  {

	return ( a * b ) / ( __gcd ( a , b ) ) ;

}

// PRIME

bool isPrime( ll n )
{
    ll i=2;

    for( i ; i*i<=n ; i++)
	{
        if( n % i == 0)
        return false;
    }

    return true;
}

// POWER

ll power( ll b , ll a ) {

	if(a==0) {
		return 1;
	}

	ll c=1;

	rep(i,0,a) {
		c*=b;
	}

	return c;

}

// FACTORIAL

ll fact(ll n) {

	ll c=1;

	while(n>1) {
		c*=n;
		n--;
	}

	return c;

}

// SIEVE of ERATOSTHENES

void sieve_of_eratosthenes (ll n, vl &a) {

	a[1]=0;

	for(ll i=2; i*i<=n ; i++) {
		if(a[i]==1) {
			for(ll j=i+i; j<=n ; j+=i) {
				a[j]=0;
			}
		}
	}

}

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

#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin >> a >> b >> c;
    if (c == 0) {
        if (a > b) {
            cout << "Takahashi" << endl;
        } else {
            cout << "Aoki" << endl;
        }
    } else {
        if (a < b) {
            cout << "Aoki" << endl;
        } else {
            cout << "Takahashi" << endl;
        }
    }
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;

using namespace std;
typedef long long ll;

void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    ex_gcd(b, a % b, d, y, x);
    y -= a / b * x;
  }
}
ll inv(ll a, ll n) {
  ll d, x, y;
  ex_gcd(a, n, d, x, y);
  return d == 1 ? (x % n + n) % (n / d) : -1;
}
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

const int maxn = 400005;
const int mod = 998244353;

int a[maxn];
int idx[maxn], b[maxn];

int cal(int x, int n){
  return b[x]<n;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  for(int i=0;i<n+n;i++){
    cin>>a[i];
    idx[i] = i;
  }
  sort(idx, idx+n+n,[](int x, int y){
    return a[x]<a[y];
  });
  for(int i=0;i<n+n;i++){
    b[idx[i]]=i;
  }
  string ret=string(n+n,' ');
  stack<int>st;
  for(int i=0;i<n+n;i++){
    if((!st.empty())&&cal(st.top(), n)!=cal(i, n)) {
      ret[st.top()]='(';
      ret[i]=')';
      st.pop();
    } else {
      st.push(i);
    }
  }
  cout<<ret<<endl;
  return 0;
}

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

#define Mod(x) ((x>=P)&&(x-=P))
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=hd[a];i;nxt[i])

typedef long long ll;
void Max(int &x,int y){(x<y)&&(x=y);}
void Min(int &x,int y){(x>y)&&(x=y);}

bool vio;
char IO;
int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f|=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1e6+10;
int ans[M],stk[M],top,A[M],B[M],mk[M];
bool let;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	int n=rd();
	rep(i,1,2*n)B[i]=A[i]=rd();
	sort(B+1,B+2*n+1);
	int t=n;
	rep(i,1,n*2){
		if(A[i]<B[n])mk[i]=1,t--;
		if(A[i]>B[n])mk[i]=2;
	}
	int fl=0;
	rep(i,1,n*2)if(t&&A[i]==B[n])mk[i]=1,t--;
	rep(i,1,2*n)if(!mk[i])mk[i]=2;
	rep(i,1,2*n){
		if(top){
			if(mk[i]==fl)stk[++top]=i;
			else ans[stk[top--]]=1,ans[i]=2;
		}else {
			fl=mk[i];
			stk[++top]=i;
		}
	}
	rep(i,1,2*n)putchar(ans[i]==1?'(':')');
}


/*
                    author         : TAPAN SAVANI
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

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

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

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

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

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

    cout << (y * z - 1) / x << "\n";

    return 0;
}

#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> XY(M);
    rep(i, M) cin >> XY[i].first >> XY[i].second;
    XY.emplace_back(0, N);

    sort(all(XY));

    map<int, vector<pair<int, int>>> mp;
    rep(i, M + 1) {
        mp[XY[i].second].emplace_back(XY[i].first, i);
    }

    vv<int> graph(M + 1);
    rep(i, M + 1) {
        auto [x, y] = XY[i];
        int z;
        if (mp[y].back().second == i) {
            z = 2 * N + 1;
        }
        else {
            auto ub = lower_bound(all(mp[y]), make_pair(x + 1, 0));
            z = ub->first;
        }

        if (mp.find(y - 1) != mp.end()) {
            auto lb = lower_bound(all(mp[y - 1]), make_pair(x + 1, 0));
            auto ub = lower_bound(all(mp[y - 1]), make_pair(z + 1, 0));
            for (auto it = lb; it != ub; ++it) {
                graph[i].push_back(it->second);
            }
        }
        if (mp.find(y + 1) != mp.end()) {
            auto lb = lower_bound(all(mp[y + 1]), make_pair(x + 1, 0));
            auto ub = lower_bound(all(mp[y + 1]), make_pair(z + 1, 0));
            for (auto it = lb; it != ub; ++it) {
                graph[i].push_back(it->second);
            }
        }
    }

    vector<bool> can_visit(M + 1);
    can_visit[0] = true;
    auto dfs = [&](auto self, int u) -> void {
        for (int v : graph[u]) {
            if (can_visit[v]) continue;
            can_visit[v] = true;
            self(self, v);
        }
    };
    dfs(dfs, 0);

    set<int> ans;
    rep(i, M + 1) {
        auto [x, y] = XY[i];
        if (can_visit[i] && i == mp[y].back().second) {
            ans.insert(y);
        }
    }
    write((int)ans.size());
}


#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
signed main(){
	int n,m,x,y;
	cin>>n>>m;
	map<int,vector<int>>mp;
	while(cin>>x>>y)
		mp[x].push_back(y);
	set<int>st={n};
	for(auto&e:mp){
		vector<int>&ys=e.second,in,out;
		for(int y:ys){
			if(st.count(y))
				out.push_back(y);
			if(st.count(y-1)||st.count(y+1))
				in.push_back(y);
		}
		for(int y:out)
			st.erase(y);
		for(int y:in)
			st.insert(y);
	}
	cout<<st.size()<<endl;
}

// #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
// #pragma GCC optimize(3 , "Ofast" , "inline")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int n , m ;
vector<int> v[N] ;
vector<int>  dep[N] ;
int in[N] , out[N] , idx = 0 ;
void dfs(int u , int d) {
	in[u] = ++ idx ;
	dep[d].pb(in[u]) ;
	for(auto x : v[u])
		dfs(x , d + 1) ;
	out[u] = ++ idx ;
}
int work()
{
  cin >> n ;
  for(int i = 2; i <= n ;i ++ ) {
  	int x ;
  	cin >> x ;
  	v[x].pb(i) ;
  }
  cin >> m ;
  dfs(1 , 0) ;
  while(m -- ) {
  	int x , y ;
  	cin >> x >> y ;
  	cout << (int)(upper_bound(dep[y].begin() , dep[y].end() , out[x]) - lower_bound(dep[y].begin() , dep[y].end() , in[x]))<< "\n";
  }
  return 0 ;
}
int main()
{
  //   freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ;
  //   freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*

*/


#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std;
const int N=2e3+100,INF=0x3f3f3f3f;
char g[N][N];
int st[N][N];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	scanf("%s",g[i]+1);
	int ans=0;
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			if(g[i][j]!=g[i+1][j]){
				if(st[i][j-1]==0)
				ans++;
				st[i][j]=1;
			}
		}
	}

	memset(st,0,sizeof st);
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			if(g[i][j]!=g[i][j+1]){
				if(st[i-1][j]==0)
				ans++;
				st[i][j]=1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

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

#define pb push_back
#define mp make_pair
#define sz(s) (int)s.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define rep(i,a,b) for(int i = a; i < b; i++)
#define in insert
#define ff first
#define ss second
#define vt vector
#define up upper_bound
#define lb lower_bound
#define repp(i,n,a) for(int i = n; i >= a; i--)
#define re(a,n) rep(i,0,n) cin>>a[i];
const long double pi = 2 * acos(0.0);
const int mod = 1e9 + 7;
const int maxn = 2e5+5;

void solve(){
    int x,y;
    cin>>x>>y;
    if(x==y){
        cout<<x;
    }else{
        cout<<(3-(x+y)%3)%3;
    }

    return;
}

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

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

    return 0;
}


#include <bits/stdc++.h>
#define li long long int
#define lp(i,a,b) for(li i=a;i<b;i++)
using namespace std;
const li inf = 1e18+7;
void solve(){
    li n,m,mn=inf,ans=0;
    cin>>n>>m;
    li a[n][m];
    lp(i,0,n)
        lp(j,0,m){
            cin>>a[i][j];
            mn=min(a[i][j],mn);
        }
    lp(i,0,n)
        lp(j,0,m){
            if(a[i][j]!=mn) ans+=(a[i][j]-mn);
        }
    cout<<ans<<"\n";
}
int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // li t=1;
    // cin>>t;
    // while(t--){
        solve();
   // }

    return 0;
}

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

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

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

	int n; cin >> n;

	vector<int64_t> minc(n + 1, INT64_MAX);
	vector<int64_t> maxc(n + 1, INT64_MIN);
	vector<bool> hasb(n + 1);
	minc[0] = 0;
	maxc[0] = 0;

	FOR_LT(i, 0, n) {
		int64_t x, c; cin >> x >> c;
		hasb[c] = true;
		minc[c] = min(minc[c], x);
		maxc[c] = max(maxc[c], x);
	}

	vector<array<int64_t, 2>> dp(n + 2, { INT64_MAX, INT64_MAX });
	dp[0][0] = 0; dp[0][1] = 0;
	int pc = 0;
	FOR_LE(i, 0, n) {
		if (!hasb[i]) {
			dp[i + 1][0] = dp[i][0];
			dp[i + 1][1] = dp[i][1];
			continue;
		}
		//cout << minc[pc] << " " << maxc[pc] << " " << minc[i] << " " << maxc[i] << endl;

		{
			dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + abs(minc[pc] - maxc[i]) + abs(minc[i] - maxc[i]));
			dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + abs(minc[pc] - minc[i]) + abs(minc[i] - maxc[i]));
		}
		{
			dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + abs(maxc[pc] - maxc[i]) + abs(minc[i] - maxc[i]));
			dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + abs(maxc[pc] - minc[i]) + abs(minc[i] - maxc[i]));
		}
		//cout << dp[i + 1][0] << " " << dp[i + 1][1] << endl;
		pc = i;
	}

	cout << min(dp[n + 1][0] + abs(minc[pc]), dp[n + 1][1] + abs(maxc[pc])) << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

string s[3];
ll n[3];
int main(void) {
    ios_base::sync_with_stdio(false);
    set<char> ch;
    F(3) cin >> s[i];
    F(3) for(auto c: s[i]) ch.insert(c);
    bool ok = 1;
    if(ch.size()>10) ok=0;
    ll x=0;
    while(ch.size()<10) { ch.insert('A'+x); x++; }
    vector<char> v(all(ch));
    sort(all(v));
    if(ok) do {
        ok=0;
        F(3) {
            n[i]=0;
            for(auto c: s[i]) {
                ll cur;
                FF(10) if(c==v[j]) cur=j;
                n[i] = 10*n[i]+cur;
            }
        }
        bool cok = 1;
        F(3) cok &= to_string(n[i]).size()==s[i].size() && n[i]!=0;
        if(cok && n[0]+n[1]==n[2]) {
            ok=1;
            F(3) cout << n[i] << endl;
            break;
        }
    } while(next_permutation(all(v)));
    if(!ok) cout << "UNSOLVABLE" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
// using namespace atcoder;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define gcd __gcd
#define int long long
#define double long double
const int INF = 1e18, MOD = 1e9 + 7;
int pow(int x, int n) {
    return n < 1 ? 1 : pow(x * x, n / 2) * (n % 2 ? x : 1);
}
int modinv(int a) {
    int b = MOD, u = 1, v = 0;
    while (b) {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}
map<int, int> factorization(int n) {
    map<int, int> res;
    for(int i = 2; i * i <= n; i++) {
        if(i > 3) i++;
        while(!(n % i)) res[i]++, n /= i;
    }
    if(n > 1) res[n]++;
    return res;
}
vector<int> divisors(int n) {
    vector<int> res;
    for (int i = 1; i * i <= n; i++) {
        if(!(n % i)) {
            res.push_back(i);
            if(i * i < n) res.push_back(n / i);
        }
    }
    return res;
}
int combination(int n, int r) {
    int res = 1;
    for(int i = 1; i < r + 1; i++) {
        res *= n--, res /= i;
    }
    return res;
}
bool is_prime(int n) {
    if (n < 2) return false;
    for(int i = 2; i * i <= n; i++) {
        if(i > 3) i++;
        if(!(n % i)) return false;
    }
    return true;
}
signed main() {
    INCANT;
    string s1, s2, s3;
    set<char> list;
    cin>>s1>>s2>>s3;
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    reverse(s3.begin(), s3.end());
    for (char c: s1 + s2 + s3) {
        list.insert(c);
    }

    int digits[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
    int x, y, z, i;
    map<char, int> m;
    do {
        m.clear();
        x = y = z = i = 0;
        for (char c: list) {
            m[c] = digits[i++];
        }

        if (
            0 == m[s1[s1.size() - 1]] ||
            0 == m[s2[s2.size() - 1]] ||
            0 == m[s3[s3.size() - 1]]
        ) {
            continue;
        }

        i = 1;
        for (char c: s1) {
            x += i * m[c];
            i *= 10;
        }

        i = 1;
        for (char c: s2) {
            y += i * m[c];
            i *= 10;
        }

        i = 1;
        for (char c: s3) {
            z += i * m[c];
            i *= 10;
        }

        if (z == x + y) {
            cout<<x<<endl<<y<<endl<<z<<endl;
            return 0;
        }
    } while (next_permutation(digits, digits + 10));
    cout<<"UNSOLVABLE"<<endl;
}


#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 998244353

#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 3e5 + 1;
ll dp[N][30], fac[N];
ll dp2[N];
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

ll modi(ll a, ll m)
{
    return power(a, m - 2, m);

}

ll nCr(ll n, ll r, ll p)
{

    if (r == 0)
        return 1;
    if(r > n){
        return 0;
    }
    return (fac[n] * modi(fac[r], p) % p *
        modi(fac[n - r], p) % p) % p;
}
vector<ll> adj[N];
ll f(ll idx, ll len){
    ll res = 0;
    if(len == 1){
        return dp[idx][len] = 1;
    }
    if((int)adj[idx].size() == 0){
        return dp[idx][len] = 0;
    }
    if(dp[idx][len] != -1){
        return dp[idx][len];
    }
    for(auto u : adj[idx]){
        res += f(u, len - 1);
        res %= MOD;
    }
    return dp[idx][len] = res;
}
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    memset(dp, -1, sizeof(dp));
    //cin >> T;
    fac[0] = 1;
    for(i = 1; i < N; i++){
        fac[i] = i * fac[i - 1];
        fac[i] %= MOD;
    }
    while (T--) {
        ll n, m;
        cin >> n >> m;
        for(i = 1; i <= m; i++){
            for(j = 2 * i; j <= m; j += i){
                adj[i].pb(j);
                //cout << i << " $$ " << j << endl;
            }
        }
        ll ans = 0;
        for(j = 0; j <= n - 1; j++){
            dp2[j] = nCr(n - 1, j, MOD);
        }
        for(i = 1; i <= m; i++){
            for(j = 1; j <= 21; j++){
                ll mul = dp2[j - 1];
                //cout << n - 1 << " ## " << j - 1 << endl;
                ll x = f(i, j);
                ans += mul * x;
                assert(ans >= 0);
                //cout << mul << " " << x << endl;
                if(x != 0)
                assert(INF / x >= mul);
                //cout << mul << " " << f(i, j) << endl;
                //cout << f(i, j) << " ";
                ans %= MOD;
            }
            //cout << endl;
        }
        //cout << dp[m][1] << endl;
        cout << ans << endl;
    }
    return 0;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using PQ = priority_queue<T>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
inline void Yes() { cout << "Yes" << ENDL; }
inline void No() { cout << "No" << ENDL; }
inline void YES() { cout << "YES" << ENDL; }
inline void NO() { cout << "NO" << ENDL; }

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T>
vector<T> finddivisor(T x) {  //整数xの約数(xを含む)
  vector<T> divisor;
  for(T i = 1; (i * i) <= x; i++) {
    if(x % i == 0) {
      divisor.push_back(i);
      if(i * i != x) { divisor.push_back(x / i);}
    }
  }
  sort(divisor.begin(), divisor.end());
  return divisor;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

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

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,m;cin>>n>>m;

  V<ll> a(m),b(m);
  rep(i,0,m){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }

  ll k;cin>>k;
  V<ll> c(k),d(k);
  rep(i,0,k){
    cin>>c[i]>>d[i];
    c[i]--;
    d[i]--;
  }

  ll ans=0;
  rep(bit,0,1<<k){
    V<bool> aru(n,false);
    rep(i,0,k){
      if(bit & (1<<i))aru[c[i]]=true;
      else aru[d[i]]=true;
    }

    ll tmp=0;
    rep(i,0,m){
      if(aru[a[i]] && aru[b[i]])tmp++;
    }
    chmax(ans,tmp);
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) !
//CHECK overflow,vector_size,what to output?
//any other simpler approach?
//list all conditions, try mathematical and graphic observation


#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")

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

#define ll  long long
#define ull  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn =2e5+30;
const ll mod=998244353 ;
const ll base=1e18;

ll cnt[maxn];
ll mu(ll a,ll n)
{
    if (n==0)
        return 1;
    if (n==1)
        return a;
    ll t=mu(a,n/2);
    if (n%2==0)
        return (t*t)%mod;
    return ((t*t)%mod*a)%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    ll n, m, k ;
    cin>> n>> m>> k ;
    //1 3 2
    if (n==1||m==1)
    {
        if (n==1&&m==1)
        {
            cout <<k;
            return 0;
        }
        if (n==1)
        {
            ll ans=0;
            for (int i=1; i<=k; i++)
            {
               ll nw=(mu(k-i+1,m)-mu(k-i,m)+mod)%mod;
               ans=(ans+nw)%mod;
            }
            cout <<ans;
            return 0;
        }
        else
        {
             ll ans=0;
             for (int i=1;i<=k;i++)
             {
                 ll nw=(mu(i,n)-mu(i-1,n)+mod)%mod;
                  ans=(ans+nw)%mod;
             }
             cout <<ans;
             return 0;
        }

    }
    ll ans=0;
    for (int i=1; i<=k; i++)
    {
        ll nw=((mu(i,n)-mu(i-1,n)+mod)%mod*mu(k-i+1,m))%mod;
        ans=(ans+nw)%mod;
    }
    cout <<ans;

}

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

#define mod % 998244353
#define MAX 998244353
#define ll long long
using namespace std;

int main() {
  int high,wide,k;
  cin >> high;
  cin >> wide;
  cin >> k;
  ll ans = 0;
  if(high == wide and high == 1){
    cout << k mod << endl;
    return 0;
  }
  if(high == 1 or wide == 1){
    if(wide == 1){
      wide = high;
    }
    for(int i = 1;i <= k;i ++){
      int m = wide;
      vector<ll> mul(21);
      vector<ll> mult(21);
      mul[0] = i;
      mult[0] = i-1;
      ll pl = 1;
      ll plt = 1;
      for(int j = 0;j < 20;j++){
        mul[j+1] = (mul[j]*mul[j])mod;
        mult[j+1] = (mult[j]*mult[j])mod;
        if(m % 2 == 1){
          pl = (pl*mul[j])mod;
          plt = (plt*mult[j])mod;
        }
        m = m/2;
      }
      ans = (ans+MAX+pl-plt)mod;
    }
    cout << ans mod << endl;

    return 0;
  }

  for(int i = 1;i <= k;i ++){
    ll pl = 1;
    int m = wide;
    vector<ll> mul(21);
    mul[0] = k-i+1;
    for(int j = 0;j < 20;j ++){
      mul[j+1] = (mul[j]*mul[j])mod;
      if(m % 2 == 1){
        pl = (pl*mul[j]) mod;
      }
      m = m/2;
    }

    ll kakerua = 1;
    ll kakerub = 1;

    if(i == 1){
      kakerub = 0;
    }
    m = high;
    vector<ll> mult(21);
    mul[0] = i;
    mult[0] = i-1;
    for(int j = 0;j < 20;j ++){
      mul[j+1] = (mul[j]*mul[j])mod;
      mult[j+1] = (mult[j]*mult[j])mod;
      if(m % 2 == 1){
        kakerua = (kakerua*mul[j])mod;
        kakerub = (kakerub*mult[j])mod;
      }
      m = m/2;
    }
    kakerua = (MAX-kakerub+kakerua)mod;
    pl = (pl*kakerua)mod;
    ans = (ans +pl)mod;
  }
  cout << ans mod<< endl;

  return 0;
}