#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define F first
#define S second
#define pss pair<string,string>
#define pcc pair<char,char>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define piii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define vs vector<string>
#define vl vector<ll>
#define vs vector<string>
#define vll vector<pll>
#define vss vector<pss>
#define vcc vector<pcc>
#define MP make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=n-1;i>=0;i--)
#define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 1e5+5;
int mod=10;
const int INF=0x3f3f3f3f;
inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll lowbit(ll x){return (x&-x);}
inline ll kissme(ll x,ll y)
{
	ll res=1;
	if(x==0)return 1;
	if(x==1)return y;
	res=kissme(x/2,y);
	res=res*res%mod;
	if(x%2==1)res=res*y%mod;
	return res;
}
ll a,b,c;vi v[20];
void init()
{
	v[0].pb(0);
	v[1].pb(1);
	v[2].pb(2);
	v[2].pb(4);
	v[2].pb(8);
	v[2].pb(6);
	v[3].pb(3);
	v[3].pb(9);
	v[3].pb(7);
	v[3].pb(1);
	v[4].pb(4);
	v[4].pb(6);
	v[5].pb(5);
	v[6].pb(6);
	v[7].pb(7);
	v[7].pb(9);
	v[7].pb(3);
	v[7].pb(1);
	v[8].pb(8);
	v[8].pb(4);
	v[8].pb(2);
	v[8].pb(6);
	v[9].pb(9);
	v[9].pb(1);
}
signed main()
{
	Very_fast;
	init();
	cin>>a>>b>>c;
	mod=v[a%10].size();
	cout<<v[a%10][(kissme(c,b)-1+mod)%mod];
	return 0;
}

#include <iostream>
#include <cstring>

using namespace std;
using ll = long long;
const int N = 200005, P = 1e9 + 7;

char s[N];
int n, k;
ll f[N][17];

int to_num(char c)
{
    if ('0' <= c && c <= '9')
        return c ^ '0';
    return 10 + c - 'A';
}

void init()
{
    f[0][k] = 1;
    for (int i = 1; i < n; ++i)
        for (int j = k; ~j; --j)
            f[i][j] = (j * f[i - 1][j] + (16 - j) * f[i - 1][j + 1]) % P;
}

ll dp(char s[])
{
    ll res = 0;
    int i = 0, cnt = 0;
    bool st[16];
    memset(st, 0, sizeof st);
    for (int j = 1; j < n; ++j)
        res = (res + f[j][0] - f[j - 1][1]) % P;
    while (i < n)
    {
        int c = to_num(s[i]), l = n - i - 1;
        for (int j = 0; j < c; ++j)
            if (st[j])
                res = (res + f[l][cnt]) % P;
            else if (i || j)
                res = (res + f[l][cnt + 1] % P);
        if (!st[c])
            ++cnt, st[c] = true;
        if (++i == n && k == cnt)
            ++res;
    }
    return res;
}

int main()
{
    scanf("%s%d", s, &k);
    n = strlen(s);
    init();
    cout << dp(s) << endl;
}


//abc185_a.cpp
//Thu Dec 17 12:35:08 2020

#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a[4];
	rep(i,4) cin >> a[i];

	int ans = a[0];
	rep(i,4)ans = min(ans,a[i]);

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>
//#include<boost/multiprecision/cpp_int.hpp>

using namespace std;
//using namespace boost::multiprecision;

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

template<typename A, typename B> using P = pair<A, B>;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A & a, const B & b) { a = max(a, (A)b); };

int main() {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	PRI(min(min(min(a, b), c), d));
	return 0;
}


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

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}

const int xn = 1e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 1e9 + 7;//998244353;
const int base = 257;

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

int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
 freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
cin >> n;
int d = 0;
int ans = inf;
for(int i = 0; i < n; i++){
    cin >> a[i];
}
for(int i = 0; i < n; i++){
    cin >> b[i];
}
sort(a, a + n);
sort(b, b + n);
if(b[0] >= a[n - 1]){
    ans = b[0] - a[n - 1] + 1;
}else{
    ans = 0;
}
cout << ans;
}

/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <fstream>
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#include <random>
#include <initializer_list>
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 3;
//const long long MAXIMUM = INFINITY;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    /*FILE* in = freopen("answer.txt", "w", stdout);
    ifstream ifs("in.txt"); // 巨大ケースは in.txt に書いてifsで標準入力*/

    int N;cin >> N;
    vector<int> A(N),B(N);
    for(int i = 0;i<N;i++) cin >> A.at(i);
    for(int i = 0;i<N;i++) cin >> B.at(i);
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    int ans = 0;
    for(int i = A.front();i<=1001;i++){
        for(int j = 0;j<N;j++){
            if(B.at(j) < i){
                goto NG;
            }
        }
        ans++;
        NG:;
    }
    cout << ans << endl;
}


#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <fstream>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))
#define sq5(x) ((x) * (x) * (x) * (x) * (x))
#define N 400005

ll t[N * 4];

void push(int v) {
	if (t[v]) {
		t[v * 2] += t[v];
		t[v * 2 + 1] += t[v];
		t[v] = 0;
	}
}

void upd(int v, int tl, int tr, int l, int r, ll val) {
	if (l > r) {
		return;
	}

	if (tl == l && tr == r)  {
		t[v] += val;

		return;
	}

	push(v);
	int tm = (tl + tr) / 2;

	upd(v * 2, tl, tm, l, min(tm, r), val);
	upd(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
}

ll get(int v, int tl, int tr, int pos) {
	if (tl == tr) {
		return t[v];
	}

	push(v);
	int tm = (tl + tr) / 2;
	if (pos <= tm) {
		return get(v * 2, tl, tm, pos);
	}
	else {
		return get(v * 2 + 1, tm + 1, tr, pos);
	}
}

vector<vi>g;
int tIn[N], tOut[N];
int tt = 0;

void dfs(int v, int p = -1) {
	tIn[v] = tt++;

	REP(i, sz(g[v])) {
		int u = g[v][i];
		if (u != p) {
			dfs(u, v);
		}
	}

	tOut[v] = tt++;
}

bool inner(int a, int b) {
	return tIn[b] <= tIn[a] && tOut[a] <= tOut[b];
}

int main(void) {
	int n;
	scanf("%d", &n);
	g.resize(n);
	CL(tIn, -1);
	CL(tOut, -1);
	vii edges;
	REP(i, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--, y--;
		g[x].pb(y);
		g[y].pb(x);
		edges.pb(mp(x, y));
	}

	dfs(0);

	int q;
	scanf("%d", &q);
	REP(i, q) {
		int type, e;
		ll x;
		scanf("%d%d%lld", &type, &e, &x);
		e--;
		if (type == 1) {
			if (inner(edges[e].X, edges[e].Y)) {
				upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], x);
			}
			else {
				upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x);
				upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], -x);
			}
		}
		else {
			if (inner(edges[e].Y, edges[e].X)) {
				upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], x);
			}
			else {
				upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x);
				upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], -x);
			}
		}
	}

	REP(i, n) {
		printf("%lld\n", get(1, 0, n * 2 - 1, tIn[i]));
	}

}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
//const ll INF=1ll<<60;
const ll MOD=1e9+7;
inline void read(int &x){
//	short neg=1;
	x=0;
	char c=getchar();
	/*while(c<'0'||c>'9'){
		if(c=='-')neg=-1;
		c=getchar();
	}*/
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+(c^48),c=getchar();
	}
//	x*=neg;
}
ll quick_mod(ll A,ll B){//A^B
    ll ret=1;
    A%=MOD;
    while(B)
    {
        if(B&1)ret=ret*A%MOD;
        B>>=1;
        A=A*A%MOD;
    }
    return ret;
}
int n;
string s;
int q;
int t,a,b;
bool flag=0;
int main(void){
	cin>>n>>s;
	cin>>q;
	REP(ii,q){
		cin>>t>>a>>b;
		a--;
		b--;
		if(t==1){
			if(flag){
				if(a>=n)a-=n;
				else a+=n;
				if(b>=n)b-=n;
				else b+=n;
			}
			swap(s[a],s[b]);
		}
		else{
			flag=!flag;
		}
	}
	if(flag)cout<<s.substr(n,n)<<s.substr(0,n);
	else cout<<s;
	return 0;
}


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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max((a+b),max((b+c),(c+a)));
    return 0;
}

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

int main()
{
    double sx,sy,gx,gy,i,j;
    double ans = 0.0;

    std::cin >> sx>>sy>>gx>>gy;

    ans = ((gx-sx)*sy)/(gy+sy);
     ans += sx;
    cout << fixed << setprecision(12) << ans <<endl;

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int a[5][3030];
int a1[5][5] = {};
int i1[5];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[0][i] >> a[1][i] >> a[2][i] >> a[3][i] >> a[4][i];
		for (int j = 0; j < 5; j++) {
			if (a1[j][j] < a[j][i]) {
				for (int k = 0; k < 5; k++) {
					a1[k][j] = a[k][i];
				}
				i1[j] = i;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 5; k++) {
				if (i1[k] == i || i1[k] == j)continue;
				int na = max({ a[0][i],a[0][j],a1[0][k] });
				for (int l = 1; l < 5; l++) {
					int nb= max({ a[l][i],a[l][j],a1[l][k] });
					na = min(na, nb);
				}
				ans = max(ans, na);
			}
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
//const ll mod = 1e9 + 7;
const ll mod = 998244353;

int main() {

	int n;
	cin >> n;
	int ok = INF;
	int ng = 0;
	VVI a(n,VI(5));
	REP(i, n)REP(j, 5)cin >> a[i][j];

	while (ok - ng > 1) {
		bool ok3 = false;
		int mid = (ok + ng) / 2;
		VVB k(n, VB(5, false));
		bool check[5];
		REP(i, 5)check[i] = false;
		REP(i, n) {
			REP(j, 5) {
				if (a[i][j] >= mid) {
					k[i][j] = true;
					check[j] = true;
				}
			}
		}
		REP(i, n) {
			if (ok3)break;
			REP(j, i) {
				bool ok2[5];
				int cnt = 0;
				REP(l, 5)ok2[l] = false;
				REP(l, 5) {
					if (k[i][l] || k[j][l]) {
						ok2[l] = true;
						cnt++;
					}
				}
				if (cnt == 5) {
					ok3 = true;
					break;
				}
				else if (cnt == 4) {
					REP(l, 5) {
						if (!ok2[l] && check[l]) {
							ok3 = true;
							break;
						}
					}
				}
			}
		}
		if (ok3) {
			ng = mid;
		}
		else {
			ok = mid;
		}
	}
	cout << ng << endl;
}


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

std::vector<long long> divisor_enum(long long N){
    /*
    Copyright (c) 2021 0214sh7
    https://github.com/0214sh7/library/
    */
    std::vector<long long> R;
    if(N<=0)return R;
    long long s=0;
    for(long long i=1;i*i<=N;i++){
        if(N%i==0){
            R.push_back(i);
            if(i*i!=N)s++;
        }
    }
    for(long long i = s-1;i>=0;i--){
        R.push_back(N/R[i]);
    }
    return R;
}

int main(void){

    ll A,B;
    cin >> A >> B;

    vector<ll> C(214514,0);
    for(int i=A;i<=B;i++){
        vector<ll> Y = divisor_enum(i);
        REP(j,Y.size()){
            C[Y[j]]++;
        }
    }

    ll Ans = 1;
    REP(i,C.size()){
        if(C[i]>=2){
            Ans=max(Ans,i);
        }
    }
    cout << Ans << endl;

    return 0;
}

//c
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <queue>

#define	INF   1010101010LL
#define INFLL 1010101010101010101LL

using namespace std;

const int mod = 1000000007;
//const int mod = 998244353;

long long gcd(long long a, long long b)
{
	if (a < b) {
		long long t = a;
		a = b;
		b = t;
	}

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

	long long r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main()
{
	int a, b;
	cin >> a >> b;
	/*long long mx = 0;
	for (int i = a; i <= b; i++) {
		for (int j = i + 1; j <= b; j++) {
			mx = max(mx, gcd(i, j));
		}
	}
	cout << mx << endl;*/
	vector<vector<int>> t(b + 1);
	for (int i = 1; i <= b; i++) {
		for (int j = i; j <= b; j += i) {
			t[j].emplace_back(i);
		}
	}

	vector<int> ans;
	for (int i = a; i <= b; i++) {
		for (int j = 0; j < t[i].size(); j++) {
			ans.emplace_back(t[i][j]);
		}
	}
	sort(ans.rbegin(), ans.rend());

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

	return 0;
}


#include <bits/stdc++.h>

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 998244353
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;
lli binpow(lli a,lli b,lli m){lli res=1;for(b%=m-1,a%=m;b>0;b>>=1,a=a*a%m)if(b&1)res=res*a%m;return res;}
lli gcd(lli a, lli b) {return b? gcd(b, a%b) : a;}

//#define int lli //CAREFUL
using namespace std;

const int mx=1e6+5;

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

    while(t--)
    {
		string s;
		cin>>s;

		deque<char> dq;
		int n = s.length();

		int turn = 0;
		forf(i,0,n)
		{
			if(s[i] == 'R')
			turn = 1-turn;
			else if(turn == 0)
			dq.push_back(s[i]);
			else
			dq.push_front(s[i]);
		}

		string ns;
		while(!dq.empty())
		{
			char temp = dq.front();
			dq.pop_front();
			ns += temp;
		}

		if(turn == 1)
		reverse(ns.begin(), ns.end());
		n = ns.length();

		vector<char> ans;
		ans.pb('R');
		int len = 1;
		char prev = ans[len - 1];

		forf(i,0,n)
		{
			if(ns[i] == prev)
			{
				ans.pop_back();
				len--;
				prev = ans[len - 1];
			}
			else
			{
				ans.pb(ns[i]);
				prev = ns[i];
				len++;
			}
		}
		n = (int)ans.size();
		forf(i,1,n)
		{
			cout<<ans[i];
		}
	}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()

const int mod = 1000000007;
const int N = 2e5 + 7;
int vis[N] = {0};

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    while (t--)
    {
        int n;
        cin >> n;
        int a[n];
        vector<int> ans;
        int ma = 0;
        int pos = 0;

        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
        }
        // for (int i = 0; i < n; ++i)
        // {
        //     if (a[i] != 0)
        //     {
        //         vis[a[i]] = 1;
        //         ans.push_back(0);
        //     }
        //     else
        //     {
        //         pos = i;
        //         break;
        //     }
        // }
        int g = 0;

        for (int i = 0; i < n; ++i)
        {
            vis[a[i]] = 1;
            for (int j = g; j < i + 2; ++j)
            {
                if (!vis[j])
                {
                    ans.push_back(j);
                    g = j;
                    break;
                }
            }
        }
        for (int i : ans)
            cout << i << "\n";
    }
}
/*

10 10 3 3
3 6 8
1 6 10

10 10 4 1
1 2 3 10
5

*/


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

///--->>> CONTAINERS <<<---///
using i64 = int64_t;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;

///--->>> TEMPLATES <<<---///
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update >;

///--->>> MACROS<<<---///
const ll mx = 3e5+123;
#define MOD 998244353
#define mod 1000000007
#define isb(z) __builtin_popcount(z)
#define lisb(z) __builtin_popcountll(z)
#define iclz(z) __builtin_clz(z)
#define lclz(z) __builtin_clzll(z)
#define ictz(z) __builtin_ctz(z)
#define lctz(z) __builtin_ctzll(z)
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf ()  {        cerr << endl;}
template < typename T, typename ... hello>void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}

///--->>> RANDOMIZER<<<---///
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */

int main(int argc, char* argv[]){
    fastio;
    cin.exceptions(cin.failbit);
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ///cout<<fixed<<setprecision(20);
    ll n; cin>>n;
    vi a(n);
    ll sum = 0, maxPref = 0, update = 0, prefSum = 0;///, maxPref = 0;
    for(ll i=0;i<n;++i){
        cin>>a[i];
        sum +=a[i];
        update = max(update, sum);
        maxPref = max(maxPref, prefSum + update);
        prefSum +=sum;
       /// dbg(sum, maxPref, prefSum, update);
    }
    cout<<maxPref<<endl;

return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iomanip>
using namespace std;

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

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

    ll n;
    cin>>n;
    vector<ll> a(n+1),wa(n+1),maxFromzero(n+1);
    FOR(i,1,n){
        cin>>a[i];
    }
    FOR(i,1,n){
        wa[i] = wa[i-1] + a[i];
    }
    FOR(i,1,n){
        maxFromzero[i] = max(maxFromzero[i-1],wa[i]);
    }
    ll ans=0,x=0;
    FOR(i,1,n){
        x+=wa[i-1];
        ans=max(ans,x+maxFromzero[i]);
    }
    // cout<<wa<<ln<<maxFromzero<<ln;
    cout<<ans<<ln;

    return 0;
}


#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
#include <utility>

using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,n;cin>>n;
	llint ans=0;
	vector<int>sco(n);
	for(i=0;i<n;i++){llint A;cin>>A;ans+=A;sco[i]=-A;}
	for(i=0;i<n;i++){llint B;cin>>B;sco[i]+=B;}
	vector<llint>gu(n/2);
	vector<llint>ki(n/2);
	for(i=0;i<n/2;i++){
		gu[i]=sco[i+i];
		ki[i]=sco[i+i+1];
	}
	SO(gu);SO(ki);
	for(i=n/2-1;i>=0;i--){
		if(gu[i]+ki[i]>0){ans+=gu[i]+ki[i];}
		else{break;}
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

namespace IO {
  char buf[1000000], *p1 = buf, *p2 = buf;
  inline char gc() {
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
    return p1 == p2 ? EOF : *(p1++);
  }
  template <class T> inline void read(T &n) {
    n = 0; RI ch = gc(), f;
    while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
    f = (ch == '-' ? ch = gc(), -1 : 1);
    while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
    n *= f;
  }
  char Of[105], *O1 = Of, *O2 = Of;
  template <class T> inline void print(T n, char ch = '\n') {
    if (n < 0) putchar('-'), n = -n;
    if (n == 0) putchar('0');
    while (n) *(O1++) = (n % 10) ^ 48, n /= 10;
    while (O1 != O2) putchar(*(--O1));
    putchar(ch);
  }
}

using IO :: read;
using IO :: print;

int const MAXN = 1e5 + 5;
int a[MAXN], b[MAXN];
priority_queue <int> q1, q2;

signed main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n; read(n);
  for (RI i = 1; i <= n; ++i) read(a[i]);
  for (RI i = 1; i <= n; ++i) read(b[i]);
  LL ans = 0;
  for (RI i = 1; i <= n; ++i) {
    ans += a[i];
    if (i & 1)
      q1.push(b[i] - a[i]);
    else
      q2.push(b[i] - a[i]);
  }
  while (!q1.empty() && !q2.empty() && q1.top() + q2.top() > 0) {
    ans += q1.top() + q2.top();
    q1.pop(), q2.pop();
  }
  print(ans);

  return 0;
}

// created by Daniel yuan
/*
     ________
    /        \
   / /      \ \
  / /        \ \
  \            /
   \  ______  /
    \________/
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;

ll rd(){
	ll x = 0;
	int f =1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

int main(){
	ll s = rd();
	ll p = rd();
	for(int i = 1;(ll)i * i <= p;i++){
		if(p % i) continue;
		ll j = p / i;
		if(i + j == s) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int main(){
  int A;
  rd(A);
  int B;
  rd(B);
  int C;
  rd(C);
  if(A>B||(A==B&&C==1)){
    wt_L("Takahashi");
    wt_L('\n');
  }
  else{
    wt_L("Aoki");
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210103-1 [bug fixed 1]

// --- original code ---
// {
//   int @A, @B, @C;
//   wt(if[A>B||(A==B&&C==1), "Takahashi", "Aoki"]);
// }


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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

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

    ll num=10005;

    rep(i,n){
        num=min(num,abs(a[i]-a[i+1]));
    }

    cout << num << endl;

    for(ll i=0;i<num;i++){
        for(ll j=0;j<n+1;j++){
            if(j) cout << " ";
            ll ans=a[j]/num;
            ll amari=a[j]%num;
            if(amari==0){
                cout << ans;
                continue;
            }
            if(i+amari>=num){
                cout << ans+1;
            }else{
                cout << ans;
            }
        }
        cout << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define MAX (int) (3*pow(10,5) + 10)
#define pb(a) push_back(a)
using namespace __gnu_pbds;
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;

void deal(){
	ll n;
	cin>>n;

	{
		string s;
		cin>>s;
	}

	n++;

	vector<ll> arr(n,0);
	fori(n){
		cin>>arr[i];
	}

	ll mn = inf;

	for(ll i = 1; i<n; i++){
		ll dif = arr[i] - arr[i-1];

		if(dif < 0){
			dif = -dif;
		}

		mn = min(mn, dif);
	}

	vector<vector<ll> > val(mn, vector<ll>(n));

	fori(mn){
		forj(n){
			ll vl = arr[j] / mn;
			ll extra = arr[j] % mn;

			val[i][j] = vl;
			if(i<extra){
				++val[i][j];
			}
		}
	}

	cout<<mn<<'\n';

	fori(mn){
		forj(n){
			cout<<val[i][j]<<' ';
		}
		cout<<'\n';
	}

}

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


#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <functional>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <bitset>
#include <cassert>
#include <math.h>
#include <complex>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long
#define pb(x) push_back(x)

template<typename T1>
void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    cout << "{";
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "}" : " ");
    }
}
void dbg_pr(string V) {cout << "\"" << V << "\"";}
template<typename T1>
void dbg_pr(T1 V) {cout << V;}
template<typename T1, typename T2>
void dbg_pr(map<T1, T2> M) {
    cout << "{";
    for(const auto m : M) {
        dbg_pr(m.first);
        cout << ":";
        dbg_pr(m.second);
        cout << ",";
    }
    cout << "}";
}
#ifdef _OLIMPOLOCAL
    #define dbg(...) cerr << "\033[1;36m[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define dbg(...) 1337
#endif
void debug_out() { cout << "\033[0m\n";}
template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " "; dbg_pr(A); debug_out(B...); }
int test = 1;
#define out(x) {cout << x << "\n";return;}
#define all(N) N.begin(),N.end()
#define allr(N) N.rbegin(),N.rend()
void setupFastCin() {ios::sync_with_stdio(false);cin.tie(0);}

template<typename T1>
T1 chmin(T1 &x, const T1 v) { return x = min(x,v); }
template<typename T1>
T1 chmax(T1 &x, const T1 v) { return x = max(x,v); }
template<typename T1>
void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = V.size() - 1;
    for (int i = start; i <= end; i++) {
        cout << V[i] + add << ((i == end) ? "\n" : " ");
    }
}
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define repsr(i, s, n) for (int i = n-1; i >= s; i--)
#define PI pair<int,int>
#define PLL pair<ll, ll>
template<typename T1>
T1 gcd(const T1 &a, const T1 &b) {
    if (a == 0 || b == 0) return a + b;
    return gcd(b, a %b);
}
//-------------------------- ^ DONT TOUCH ^-----------------------------------------------------------------

#define MAX 1000000
#define MAXP 21
//#define MOD 998244353ll
#define MOD 1000000007ll

long long power(long long x, long long n) {
    long long p = x;
    long long s = 1;
    while (n > 0) {
        if (n & 1) s = (s * p) % MOD;
        p = (p * p) % MOD;
        n /= 2;
    }
    return s;
}

int n;
ll x;
ll C[2][100005];
ll D[2][100005];
void solve() {
    cin >> n;

    C[0][0] = 1;
    cin >> D[0][0];
    D[1][0] = C[1][0] = 0;
    reps(i, 1, n) {
        cin >> x;
        C[0][i] = C[0][i-1] + C[1][i-1];
        C[1][i] = C[0][i-1];
        C[0][i] %= MOD;
        C[1][i] %= MOD;

        D[0][i] = D[0][i-1] + D[1][i-1] + (C[0][i] * x) % MOD;
        D[1][i] = D[0][i-1] - (C[1][i] * x) % MOD;
        D[0][i] %= MOD;
        D[1][i] %= MOD;
        dbg(D[0][i], D[1][i]);
    }
    out((D[0][n-1] + D[1][n-1] + MOD + MOD + MOD) % MOD)

}

int main() {
    setupFastCin();
    int T = 1;
#ifdef _OLIMPOLOCAL
    cin >> T;
#endif
    reps(t, 1, T + 1){
        solve();
    }

    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

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

    vector<long long> dp(2, 0);
    vector<long long> cnts(2, 0);
    auto ndp = dp;
    auto ncnts = cnts;
    cnts[1] = 1;

    const long long MOD = 1000000007;
    for (auto x : A) {
        fill(ndp.begin(), ndp.end(), 0);
        fill(ncnts.begin(), ncnts.end(), 0);

        {
            ncnts[0] = (cnts[0] + cnts[1]) % MOD;
            ndp[0] = (dp[0] + cnts[0] * 1LL * x % MOD) % MOD;
            (ndp[0] += (dp[1] + cnts[1] * 1LL * x % MOD) % MOD) %= MOD;
        }
        {
            ncnts[1] = cnts[0];
            ndp[1] = (dp[0] - cnts[0] * 1LL * x % MOD + MOD) % MOD;
        }
        swap(ndp, dp);
        swap(ncnts, cnts);
    }
    long long res = 0;
    res += dp[0];
    res += dp[1];
    res %= MOD;

    cout << res << '\n';

    return 0;
}


// ＵＴＦ−８

#include<bits/stdc++.h>

using namespace std;
using ll = long long int;
using lc = complex<double>;

/* #include<atcoder/all> */
/* using namespace atcoder; */

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

template <typename T>
struct SegmentTree {
    using F = function<T(T, T)>;

    const T e;
    const F f;
    size_t sz;
    vector<T> tree;

    SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) {
        sz = 1;
        while(sz < n) sz <<= 1;
        tree.assign(2*sz, e);
    }

    void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) {
        copy(begin, end, tree.begin() + sz);
        for(size_t k=sz-1; k>0; k--)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    void update(size_t k, const T &x) {
        k += sz;
        tree[k] = x;
        while(k >>= 1)
            tree[k] = f(tree[2*k+0], tree[2*k+1]);
    }

    T query(size_t a, size_t b) const {
        b = min(b, sz);
        a = max((size_t)0, a);
        T l = e, r = e;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) l = f(l, tree[a++]);
            if(b & 1) r = f(tree[--b], r);
        }
        return f(l, r);
    }

    T operator[](const size_t k) const {
        return tree[sz + k];
    }
};

int main(void) {
    constexpr ll MOD = 0 ? 1e9+7 : 998244353;
    const double PI = acos(-1);
    constexpr double eps = 1e-10;
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    if(1) {
        ll n;
        cin >> n;
        vector<ll> a(n), b(n), c(n);
        for(auto &e: a) cin >> e;
        for(auto &e: b) cin >> e;

        map<ll,vector<ll>> m;
        for(ll i=0; i<n; i++)
            m[a[i]+i].push_back(i);
        map<ll,ll> idx;

        for(ll i=0; i<n; i++) {
            ll x = b[i]+i;
            auto &v = m[x];
            ll y = idx[x]++;
            if(y == v.size()) {
                cout << -1 << endl;
                return 0;
            }
            c[i] = v[y];
        }

        ll r = 0;
        SegmentTree<ll> st(n, [&](ll a, ll b){return a + b;}, 0);
        for(ll i=0; i<n; i++) {
            r += i - st.query(0, c[i]);
            st.update(c[i], st[c[i]]+1);
        }

        cout << r << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define ll long long
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
const int N=2e5+5;
struct node{int v,id;}a[N],b[N];
bool cmp(node x,node y){return x.v==y.v?x.id<y.id:x.v<y.v;}
int n,A[N],t[N];
void I(int pos){for(int i=pos;i<=n;i+=i&-i)++t[i];}
int Q(int pos){int res=0;for(int i=pos;i;i-=i&-i)res+=t[i];return res;}
ll ans;
int main(){
    n=read();
    rep(i,1,n)a[i]={read()+i,i};
    rep(i,1,n)b[i]={read()+i,i};
    sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp);
    rep(i,1,n){
        if(a[i].v!=b[i].v)return puts("-1"),0;
        A[a[i].id]=b[i].id;
    }
    for(int i=n;i;i--){
        I(A[i]);ans+=Q(A[i]-1);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {
	int a, b; cin >> a >> b;
	int ret = 4;
	if (a+b >= 15 && b >= 8) ret = 1;
	else if (a+b >= 10 && b >= 3) ret = 2;
	else if (a+b >= 3) ret = 3;
	cout << ret << '\n';
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <cstring>
#include <functional>
#include <map>
#define LL long long
#define lson(rt) (rt << 1)
#define rson(rt) (rt << 1 | 1)
using namespace std;

const int N = 1e6 + 10;
map<LL, LL> memo;
LL x, y;

LL fun (LL y)
{
    if(x >= y) return abs(x - y);
    if(memo.find(y) != memo.end()) return memo[y];
    if(y & 1) {
        return memo[y] = min(abs(x - y), min(fun(y + 1) + 1, fun(y - 1) + 1));
    } else {
        return memo[y] = min(abs(x - y), fun(y / 2) + 1LL);
    }
}

void solve()
{
    cin >> x >> y;
    cout << fun(y) << endl;
}

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

    solve();

    return 0;
}


//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;
string to_string(char c) { return string(1,c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return (string)s; }
string to_string(string s) { return s; }
template<class A> string to_string(complex<A> c) {
	stringstream ss; ss << c; return ss.str(); }
string to_string(vector<bool> v) {
	string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]);
	res += "}"; return res; }
template<size_t SZ> string to_string(bitset<SZ> b) {
	string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]);
	return res; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) { // containers with begin(), end()
	bool fst = 1; string res = "{";
	for (const auto& x: v) {
		if (!fst) res += ", ";
		fst = 0; res += to_string(x);
	}
	res += "}"; return res;
}
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
#else
#define wis(...) 0
#endif
typedef long long ll;
#define all(x) (x).begin(), (x).end()

const vector<pair<int ,int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int MAXN = 1510;
char grid[MAXN][MAXN];
bitset <MAXN> mark[4][MAXN];
int h, w, n, m;

void dfs(int x, int y, int dir){
	if(mark[dir][x][y]){
		return;
	}
	wis(x, y);
	mark[dir][x][y] = 1;
	grid[x][y] = 'r';
	x = x + moves[dir].first;
	y = y + moves[dir].second;
	if(x >= 0 && y >= 0 && x < h && y < w && grid[x][y] != 'm'){
		dfs(x, y, dir);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin >> h >> w >> n >> m;
	vector<pair<int, int>> a(n);
	for(int i = 0; i < n; i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		a[i] = {x, y};
	}
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		x--, y--;
		grid[x][y] = 'm';
	}
	for(auto [x, y] : a){
		dfs(x, y, 0);
		dfs(x, y, 1);
		dfs(x, y, 2);
		dfs(x, y, 3);
	}
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			ans += grid[i][j] == 'r';
		}
	}
	cout << ans << '\n';
}

#include<bits/stdc++.h>

#define HAS_TEST_CASE 0

namespace rG{

typedef long long ll;

const int N=2e3;

int a[N+10][N+10];
int n,m;
bool can[N+10][N+10];

void main(){
	int T1,T2;
	scanf("%d%d%d%d",&n,&m,&T1,&T2);
	for(int i=1;i<=T1;i++){
		int x,y;scanf("%d%d",&x,&y);
		a[x][y]=1;
	}
	for(int i=1;i<=T2;i++){
		int x,y;scanf("%d%d",&x,&y);
		a[x][y]=2;
	}
	for(int i=1;i<=n;i++){
		bool now=0;
		for(int j=1;j<=m;j++){
			if(a[i][j]==1)can[i][j]|=1,now=1;
			if(a[i][j]==2)now=0;
			if(a[i][j]==0)can[i][j]|=now;
		}
		now=0;
		for(int j=m;j>=1;j--){
			if(a[i][j]==1)can[i][j]|=1,now=1;
			if(a[i][j]==2)now=0;
			if(a[i][j]==0)can[i][j]|=now;
		}
	}
	for(int j=1;j<=m;j++){
		bool now=0;
		for(int i=1;i<=n;i++){
			if(a[i][j]==1)can[i][j]|=1,now=1;
			if(a[i][j]==2)now=0;
			if(a[i][j]==0)can[i][j]|=now;
		}
		now=0;
		for(int i=n;i>=1;i--){
			if(a[i][j]==1)can[i][j]|=1,now=1;
			if(a[i][j]==2)now=0;
			if(a[i][j]==0)can[i][j]|=now;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			ans+=can[i][j];
	printf("%d\n",ans);
}

} // namespace rG

int main(){
#if defined(LOCAL)&&HAS_TEST_CASE
	freopen("tmp.out","w",stdout);
#endif
#if HAS_TEST_CASE
	int T;scanf("%d",&T);
	while(T--)rG::main();
#else
	rG::main();
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

ll a[210000];

int main(){
  int n;
  cin>>n;
  rep(i,n) cin>>a[i];
  ll base=0;
  ll befo=0;
  ll MAX=0;
  rep(i,n){
    base+=befo+a[i];
    befo+=a[i];
    chmax(MAX,a[i]);
    cout<<base+MAX*(i+1)<<endl;
  }
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5;
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8';
  if (i == 9) return '9';
  return ' ';
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int A, B;
  cin >> A >> B;
  cout << 2 * A + 100 - B << endl;
}


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

int main()
{
    int n;
    cin >> n;
    ll x1,x2,x3,x4,y1,y2,y3,y4;
    x1 = x2 = y1 = y2 = -1e9-1;
    x3 = x4 = y3 = y4 = 1e9+1;
    int x11,x22,x33,x44,y11,y22,y33,y44;

    rep(i,n){
        ll x,y;
        cin >> x >> y;
        if(x>=x1){
            x2 = x1;
            x22 = x11;
            x1 = x;
            x11 = i;
        }
        else if(x>=x2){
            x2 = x;
            x22 = i;
        }
        if(x<=x4){
            x3 = x4;
            x33 = x44;
            x4 = x;
            x44 = i;
        }
        else if(x<=x3){
            x3 = x;
            x33 = i;
        }
        if(y>=y1){
            y2 = y1;
            y22 = y11;
            y1 = y;
            y11 = i;
        }
        else if(y>=y2){
            y2 = y;
            y22 = i;
        }
        if(y<=y4){
            y3 = y4;
            y33 = y44;
            y4 = y;
            y44 = i;
        }
        else if(y<=y3){
            y3 = y;
            y33 = i;
        }
    }
    vector<ll> ans;
    if(x11 == y11 && x33 == y33){
        ans.push_back(max(x1-x3,y1-y3));
    }
    else{
        ans.push_back(x1-x3);
        ans.push_back(y1-y3);
    }

    if(x11 == y11 && x44 == y44){
        ans.push_back(max(x1-x4,y1-y4));
    }
    else{
        ans.push_back(x1-x4);
        ans.push_back(y1-y4);
    }

    if(x22 == y22 && x33 == y33){
        ans.push_back(max(x2-x3,y2-y3));
    }
    else{
        ans.push_back(x2-x3);
        ans.push_back(y2-y3);
    }

    if(x22 == y22 && x44 == y44){
        ans.push_back(max(x2-x4,y2-y4));
    }
    else{
        ans.push_back(x2-x4);
        ans.push_back(y2-y4);
    }
    sort(ans.rbegin(),ans.rend());
    cout << ans[1] << endl;
    return 0;
}

//Don't act like a loser.
//This code is written by huayucaiji
//You can only use the code for studying or finding mistakes
//Or,you'll be punished by Sakyamuni!!!
#include<bits/stdc++.h>
#define int long long
using namespace std;

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

const int MAXN=2e5+10;

int n;
priority_queue<int> q;
struct point {
	int x,y,id;
}p[MAXN];
map<pair<int,int>,bool> mp;

int dist(point a,point b) {
	return max(abs(a.x-b.x),abs(a.y-b.y));
}

bool cmpx(point a,point b) {
	if(a.x!=b.x)
		return a.x<b.x;
	return a.y<b.y;
}
bool cmpy(point a,point b) {
	if(a.y!=b.y)
		return a.y<b.y;
	return a.x<b.x;
}
pair<int,int> mk(int a,int b) {
	return make_pair(max(a,b),min(a,b));
}

void get(point a,point b) {
	if(!mp[mk(a.id,b.id)]) {
		mp[mk(a.id,b.id)]=1;
		q.push(dist(a,b));
	}
}

signed main() {
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	cin>>n;
	for(int i=1;i<=n;i++) {
		p[i].x=read();p[i].y=read();
		p[i].id=i;
	}

	sort(p+1,p+n+1,cmpx);
	get(p[1],p[n]);
	get(p[1],p[n-1]);
	get(p[2],p[n]);

	sort(p+1,p+n+1,cmpy);
	get(p[1],p[n]);
	get(p[1],p[n-1]);
	get(p[2],p[n]);

	q.pop();
	cout<<q.top()<<endl;

	//fclose(stdin);
	//fclose(stdout);
	return 0;
}


/**
 *    Author : Tanbin_Hasan
 *    Created : 22.02.2021
**/
#include <bits/stdc++.h>

using namespace std ;

int main(void) {
  ios::sync_with_stdio(false) ; cin.tie(0) ;
  int n ;
  cin >> n ;
  long long ans = 0 ;
  for (int i = 1 ; i < n + 1 ; ++i) {
    for (int j = 1 ; j < n + 1 ; ++j) {
      if (i * j > n) {
        break ;
      }
      for (int k = 1 ; k < n + 1 ; ++k) {
        if (i * j * k > n) {
          break ;
        }
        ++ans ;
      }
    }
  }
  cout << ans ;
  return 0 ;
}

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

const int N=2e5+100;
#define ll long long
char str[N]; int n, b[N], c[N], sum[N], cnt;
ll ans;
int main() {
	scanf("%s",str+1), n=strlen(str+1);
	for(int i=1;i<=n;++i) {
		if(i != 1 && str[i] == str[i-1])
			++b[cnt];
		else c[++cnt]=str[i]-'a', b[cnt]=1;
	}
	for(int i=1;i<=cnt;++i) sum[i]=b[i]+sum[i-1];
	for(int i=cnt;i>=1;--i) {
		if(b[i] == 1) continue;
		for(int j=i+1, r=0;j<=cnt;++j) {
			if(c[j] == c[i] && b[j] >= 2) {
				ans += sum[j-1]-sum[i]-r;
				break;
			}
			if(b[j] >= 2 && c[j] != c[i]) {
				ans += n-r-sum[i];
				break;
			}
			if(b[j] == 1 && c[j] == c[i]) ++r;
			if(j == cnt) ans += n-sum[i]-r;
		}
	}
	cout<<ans<<endl; return 0;
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S moddw_L(S a, const T b){
  a %= b;
  if(a < 0){
    a += b;
  }
  return a;
}
template<class T> void arrRot(int k, int N, T A[], T B[] = NULL, void *mem = wmem){
  int i;
  int fg = 0;
  (k = moddw_L(k,N));
  if(B==NULL){
    walloc1d(&B, N, &mem);
    fg = 1;
  }
  for(i=(k);i<(N);i++){
    B[i-k] = A[i];
  }
  for(i=(0);i<(k);i++){
    B[N-k+i] = A[i];
  }
  if(fg){
    for(i=(0);i<(N);i++){
      A[i] = B[i];
    }
  }
}
char S[6];
int main(){
  wmem = memarr;
  rd(S);
  arrRot(1, 3, S);
  wt_L(S);
  wt_L('\n');
  return 0;
}
// cLay version 20210327-1 [beta]

// --- original code ---
// char S[6];
// {
//   rd(S);
//   arrRot(1, 3, S);
//   wt(S);
// }

#include<cstdio>

#define p() *p3++='\n'
#define P() *p3++=' '

#define N 1010

using namespace std;

static char obuf[1<<23],*p3=obuf;

template<typename T>
inline void read(T&x) {
	T s=0,w=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48),ch=getchar();}
	x=w*s;
}

template<typename T>
inline void write(T x) {
	if(x<0) x=~x+1,*p3++='-';
	if(x>9) write(x/10);
	*p3++=x%10+'0';
}

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

int main() {
	read(n),read(m);
	for(int i=1; i<=n; ++i) {
		read(a[i]);
		tong[a[i]]++;
	}
	for(int i=1; i<=m; ++i) {
		read(b[i]);
		tong[b[i]]++;
	}
	for(int i=1; i<=N; ++i) {
		if(tong[i]==1) write(i),P();
	}
	fwrite(obuf,p3-obuf,1,stdout);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

int ans = 0;
int n, k;
long t[8][8];

void saiki(int count, int go, long dist, int now) {
  if (count == n-1) {
    if (dist + t[now][0] == k) {
      ans++;
    }
  }
  else {
    for (int i = 1; i < n; i++) {
      if (((1 << i) & go) == 0) {
        saiki(count + 1, (go | (1 << i)), dist + t[now][i], i);
      }
    }
  }
}

int main() {
  int go = 0;

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> t[i][j];
    }
  }
  saiki(0, 0, 0, 0);

  cout << ans;
}

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

#define endl "\n"
#define int long long
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define trace(x) cerr<<#x<<" : "<<x<<endl;

int cnt = 0;
bool vis[2002];

void dfs(int idx, vector<int> v[])
{
    vis[idx] = true;
    for(auto it:v[idx])
    {
        if(!vis[it])
        {
            dfs(it, v);
            cnt++;
        }
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;

    vector<int> v[n];

    for (int i = 0; i < m;i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        v[x].push_back(y);
    }

    int ans = 0;
    for (int i = 0; i < n;i++)
    {
        cnt = 0;
        memset(vis, false, sizeof(vis));
        dfs(i, v);
        ans += cnt;
    }
    cout << ans + n;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    for(int i=0;i<t;i++) solve();
    return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

using ll = long long int;
const ll MOD=1e9+7;
const int MAXN=1e3+5;

ll factorial[MAXN];
int N;
char cAA,cAB,cBA,cBB;

ll fast_power(ll base,ll exp){
    if (exp==0) return 1ll;

    auto temp=fast_power(base,exp/2);
    if (exp%2) return temp*temp%MOD*base%MOD;
    else return temp*temp%MOD;
}

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

ll C(int n,int m){
    auto nominator=factorial[n],denom=factorial[m]*factorial[n-m]%MOD;
    return nominator*inv(denom)%MOD;
}

int main(){

    scanf("%d\n",&N);
    scanf("%c\n%c\n%c\n%c",&cAA,&cAB,&cBA,&cBB);

    // factorial[0]=1ll;
    // for(int i=1;i<=N;i++) factorial[i]=factorial[i-1]*i%MOD;

    ll len=max(0,N-3);
    if (cAB!=cBA&&((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A'))){
        printf("%lld\n",fast_power(2ll,len));
    }else if ((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A')){
        ll A=1,B=0;
        for(int i=0;i<N-2;i++){
            ll tA=B,tB=(A+B)%MOD;
            A=tA,B=tB;
        }
        printf("%lld\n",(A+B)%MOD);
    }else puts("1");

    return 0;
}

#include <bits/stdc++.h>
#include <map>
#include <iostream>

using namespace std;
typedef long long ll;
typedef long double ld;
#define BIG 200005
ll M = 1000000000+7;

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    vector<int> c; // A=0, B=1
    for(int i=0;i<4;i++){
        char cc;
        cin >> cc;
        c.push_back(cc - 'A');
    }
    if(N<=3){
        printf("%d\n", 1);
        return 0;
    }
    // ab = Aにする
    if(c[1]==1){
        for(int i=0;i<4;i++){
            c[i] = 1 - c[i];
        }
        swap(c[0], c[3]);
    }
    ll ans;
    if(c[0]==0){
        ans = 1;
    }else{
        // aa = B
        if(c[2]==1){
            // 2^(N-3)
            ans = mpow(2ll, ll(N-3));
        }else{
            ll pre = 0;
            ll p = 1;
            for(int i=0;i<N-2;i++){
                ll current = (p + pre) % M;
                pre = p;
                p = current;
            }
            ans = p;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a); i<(n); i++)
#define rep2(i,a,n) for (int i=(a); i<=(n); i++)
using ll = long long;
using dl = double long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
int main() {
  vector<int> l(3);
  rep(i,0,3) cin >> l[i];
  sort(l.begin(),l.end());
  cout << l[1]+l[2] << endl;
}

#include<iostream>

using namespace std;

int main(){
    int A[4];
    for(int i = 0; i < 4; i++){
        cin >> A[i];
    }
    cout << A[0] * A[3] - A[1] * A[2] << endl;
}


/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <time.h> //clock
#define endl "\n";
using namespace std;

using PLL = pair<long long,long long>;
typedef tuple<int,int,int> TUP;
using P = pair<int,int>;
const long long INF = 3000000000000000001;
const int inf = 1001001001;
long long MOD = 1000000007;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

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

    int H,W;cin >> H >> W;
    vector<vector<int>> ban(H,vector<int>(W));
    int mini = inf;
    int ans = 0;
    for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) cin >> ban.at(i).at(j), mini = min(mini,ban.at(i).at(j));
    for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) ans += ban.at(i).at(j)-mini;
    cout << ans << endl;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr int kN = 73;

bitset<kN> bs[kN];
int n;
ll ans;
unordered_map<__int128, ll> ma;

void solve(bitset<kN> cur) {
	int id = cur._Find_first();
	__int128 val = 0;

	for (int i = n - 1; i >= id; i--) if (cur[i]) val |= __int128(1) << (n - 1 - i);
	if (ma.find(val) != ma.end()) {
		ans += ma[val];
		return ;
	}

	ll cur_ans = ans;
	ans++;
	for (int i = id; i < n; i = cur._Find_next(i)) solve(cur & bs[i]);

	ma[val] = ans - cur_ans;
	return ;
}

int main() {
	ll a, b; scanf("%lld%lld", &a, &b);
	n = b - a + 1;

	for (ll i = a; i <= b; i++) for (ll j = i + 1; j <= b; j++) if (__gcd(i, j) == 1) bs[i - a][j - a] = true;

	bitset<kN> cur;
	for (int i = 0; i < n; i++) cur[i] = true;
	solve(cur);

	printf("%lld\n", ans);
}


#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)
using namespace std;
typedef long long LL;
const int N=500500;
int read(int &n)
{
	bool q=0;n=0;char ch=' ';
	for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
	if(ch=='-')ch=getchar(),q=1;
	for(;ch>='0'&&ch<='9';ch=getchar())n=(n<<3)+(n<<1)+ch-48;
	return q?n=-n:n;
}
int n,m;
int a[N],a0[N];
int Ans[N];
int JS(int q,int w,int i,int j)
{
	return abs(q-i)+abs(w-j);
}

int main()
{
	int q,w,_;
	read(_);
	while(_--)
	{
		read(n);
		fo(i,1,n)read(a[i]),a0[i]=a[i];
		Ans[0]=0;

		fo(I,1,n)
		{
			int nw;
			fo(i,1,n)if(a[i]==I){nw=i;break;}
			if(nw==I)continue;
			if(((nw-1)&1)==(Ans[0]&1))
			{
				fod(i,n-1,1)if((i&1)!=(Ans[0]&1)){q=i;break;}
				if(q==nw)
				{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					Ans[++Ans[0]]=q-1,swap(a[q],a[q-1]);
					++nw;
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}else if(q<I)
				{
					fo(i,1,n)if((i&1)!=(Ans[0]&1)){q=i;break;}
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
					if(q%2!=Ans[0]%2)
					{
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					}else{
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);

					}

				}
				else{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}
			}else{
				fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
			}
		}

		// fo(i,1,Ans[0])
		// {
		// 	q=Ans[i];
		// 	if(Ans[i]%2 !=(i&1))printf("dfwefwefe\n");
		// 	swap(a0[q],a0[q+1]);
		// }
		// fo(i,1,n-1)if(a0[i]>a0[i+1])printf("wefverbrtbrtbrterth\n");
		printf("%d\n",Ans[0]);
		fo(i,1,Ans[0])printf("%d ",Ans[i]);printf("\n");
	}

	return 0;
}

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b, lli mod){
	lli res =1;
	while(b){ if(b&1) res = (res * a)%mod; a = (a*a)%mod; b/=2; }
	return res;
}

vvc<int> graph(int n, int m, bool dir=1){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		if(dir)v[b].pb(a);
	}
	return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7
void solve(){
	int n; cin>>n;
	vc<lli>v(n),x(n),y(n);
	fore(i,0,n)cin>>x[i];
	fore(i,0,n)cin>>y[i];
	v[0]=x[0];
	fore(i,1,n)v[i]=max(x[i],v[i-1]);
	v[0]*=y[0];
	fore(i,1,n)v[i]=max(v[i-1],v[i]*y[i]);
	fore(i,0,n)cout<<v[i]<<ENDL;

//	cout<<ENDL;

}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


#include<iostream>
#include<vector>
#include<map>
#include<stack>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<string.h>
#include<set>
#include<algorithm>
#define Doura() ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL)
#define ll long long
using namespace std;
int main()
{
    Doura();
    int h,w,i,j,m=1000;
    cin>>h>>w;
    int a[h][w];
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin>>a[i][j];
            m=min(m,a[i][j]);
        }
    }
    int cnt=0;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cnt+=a[i][j]-m;
        }
    }
    cout<<cnt<<endl;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;

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

bool cmp0(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) {
  return get<0>(a) < get<0>(b);
}
bool cmp1(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) {
  return get<1>(a) < get<1>(b);
}

int main() {
  int n;cin>>n;
  vector<tuple<ll, ll, int>> xy;
  rep(i, n) {
    ll x, y;cin>>x>>y;
    xy.push_back(make_tuple(x, y, i));
  }
  vector<tuple<ll, ll, int>> v0 = xy;
  sort(all(v0), cmp0);
  vector<tuple<ll, ll, int>> v1 = xy;
  sort(all(v1), cmp1);
  vector<int> ind;
  if(get<0>(v0[n-1]) - get<0>(v0[0]) > get<1>(v1[n-1]) - get<1>(v1[0])) {
    ind.push_back(get<2>(v0[0]));
    ind.push_back(get<2>(v0[n-1]));
  } else {
    ind.push_back(get<2>(v1[0]));
    ind.push_back(get<2>(v1[n-1]));
  }
  // cout << ind[0] << endl;
  // cout << ind[1] << endl;
  ll ans = -INF;
  rep(i, 2) {
    vector<tuple<ll, ll, int>> temp = xy;
    temp.erase(temp.begin() + ind[i]);
    vector<tuple<ll, ll, int>> v0 = temp;
    sort(all(v0), cmp0);
    vector<tuple<ll, ll, int>> v1 = temp;
    sort(all(v1), cmp1);
    chmax(ans, max(get<0>(v0[n-2]) - get<0>(v0[0]), get<1>(v1[n-2]) - get<1>(v1[0])));
  }
  cout << ans << endl;

}


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

using namespace std;

//-------------------------------------------------------//
#define fast() 	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define endl '\n'
#define pb push_back
#define mp make_pair
#define PI 3.141592653589793238462
#define sz(x) ((int)(x).size())
#define all(x)	(x).begin(), (x).end()
#define rep(iter, from, to, increment)	for(iter = (from); iter<(to); iter+=(increment))

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

bool revsort(ll a, ll b) {return a>b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
vector<ll> sieve(ll n){ int* arr = new int[n+1](); vector<ll> vect; for(int i = 2;i<=n; i++) if(arr[i]==0){ vect.push_back(i); for(int j = 2*i;j<=n;j+=i) arr[j] = 1;}return vect;}

void solveA(){
	float N;
	cin>>N;
	N *= 1.08;
	int out = N;
	if( out > 206) cout<<":("<<endl;
	else {
		if (out == 206) cout<<"so-so"<<endl;
		else cout<<"Yay!"<<endl;
	}
}

void solveB(){
	ll n;
	cin>>n;

	ll out = round(sqrt(2*n));
	cout<<out<<endl;

}
int main(){

	fast()

	//int T;
//	cin>>T;
//	while(T--)
		solveB();

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    n*=2;
    int res = sqrt(n);
    while(res*(res+1)<n){
        res++;
    }
    cout<<res<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n][2];
	for(int i=0;i<n;i++) cin >> a[i][0] >> a[i][1];
	int count=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			if(abs(a[i][1]-a[j][1])<=abs(a[i][0]-a[j][0])) count++;
		}
	}
	cout << count << endl;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull signed long long int
#define lli long long int
#define ll  long long
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl   vector<lli>
#define fro(i,a,b) for(int i=a;i<b;i++)
#define mii unordered_map<ll,ll>
#define pb push_back
double pi = 2*acos(0.0);
const int INF = 1e9 + 7;
//lli power(lli x, lli y,lli p){lli res = 1; x = x % p; if (x == 0) return 0;
//while (y > 0){if (y & 1)res = (res*x) % p;  y = y>>1;  } return res;  }

void func(vector<lli>v,lli k,lli n,lli &ans,lli h1,lli h2,lli cnt,vector<vector<bool>>&dp){

   if(n<0)
    return;
   if(h1>=k&&h2>=k){
      ans=min(ans,cnt);
      return;
   }
   if(dp[h1][h2]==true)
    return;

   func(v,k,n-1,ans,h1+v[n],h2,cnt+1,dp);
   dp[h1+v[n]][h2]=true;

   func(v,k,n-1,ans,h1,h2+v[n],cnt+1,dp);
   dp[h1][h2+v[n]]=true;

   func(v,k,n-1,ans,h1,h2,cnt,dp);
   dp[h1][h2]=true;

}

void WetPitch()
{
  lli n;
  cin>>n;
  double x[n];double y[n];
  fro(i,0,n){
    cin>>x[i]>>y[i];
  }

  lli ans=0;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if((y[j]-y[i])/(x[j]-x[i])>=-1&&(y[j]-y[i])/(x[j]-x[i])<=1)
        ans++;
    }
  }

  cout<<ans<<endl;

}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    lli tst;
    tst=1;
    //cin>>tst;int p=1;
    while(tst--)
    {
      WetPitch();
    }
    return 0;
 }


// ダイクストラ法 非負距離のみ
// O((N+M)log M)
// https://www.youtube.com/watch?v=iEfDi7wagfE&feature=youtu.be
#include <bits/stdc++.h>
using namespace std;

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF (1LL << 60)/2 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

////////////////////////////////////////////////
struct Edge {
    long long to; // 繋がる所
    long long cost; // 区間距離（コスト）
    Edge(long long to=0, long long cost=0): to(to), cost(cost) {}
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;

/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する（結果） dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる (disがINFなら到達不可)
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    Graph g0(N),g1(N);
    vector<long long> dis0, dis1, same(N, INF);
    rep(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        g0[a].emplace_back(b, c);
        g1[b].emplace_back(a, c);
        if(a==b) same[a]=min(same[a], (ll)c);
    }
    rep(i, N){
        dis0.clear();
        dis1.clear();
        dijkstra(g0, i, dis0);
        dijkstra(g1, i, dis1);
        ll dist=same[i];
        rep(j,N){
            if(j==i) continue;
            dist=min(dist, dis0[j]+dis1[j]);
        }
        if(dist>=INF) cout << "-1" << endl;
        else cout << dist << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define dbg(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T>
void dbs(string str, T t) {
    cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
    int idx = str.find(',');
    cerr << str.substr(0, idx) << " : " << t << ",";
    dbs(str.substr(idx + 1), s...);
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
void debug(T a, T b) {
    cerr << "[";
    for (T i = a; i != b; ++i) {
        if (i != a)
            cerr << ", ";
        cerr << *i;
    }
    cerr << "]\n";
}

const int N = 100100;

int root[N];

int getRoot(int n) {
    if (root[n] != n) {
        root[n] = getRoot(root[n]);
    }
    return root[n];
}

vector<pair<int, int>> adj[N];
int val[N];
bool visited[N];
int n, m;

void dfs(int u, int edgeVal) {
    val[u] = edgeVal;
    visited[u] = true;

    set<int> childVals;
    for (const auto& e : adj[u]) {
        if (visited[e.first]) {
            continue;
        }

        if (e.second == edgeVal) {
            dfs(e.first, edgeVal % n + 1);
        } else {
            dfs(e.first, e.second);
        }

        childVals.insert(val[e.first]);
    }

    if (val[u] == -1) {
        val[u] = 1;
        while (childVals.count(val[u])) {
            ++val[u];
        }
    }
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        adj[u].emplace_back(v, w);
        adj[v].emplace_back(u, w);
    }

    dfs(0, -1);

    for (int i = 0; i < n; ++i) {
        cout << val[i] << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	k=k*1000;
	int r,l;
	if(k%m==0)
	r=k/m;
	else
	r=k/m+1;
	l=k/n;
	if(r>l)puts("UNSATISFIABLE");
	else printf("%d %d",r,l);
	return 0;
}

/// In the name of ALLAH
/// I'm THEOVE46
#include<bits/stdc++.h>
using namespace std;

#define gap             " "
#define nn              "\n"
#define pi              2*acos(0.0)
#define db              double
#define ft              float
#define ll              long long int
#define ull             unsigned long long int
#define pf              printf
#define sf              scanf
#define ff              first
#define ss              second
#define sfi(n)          sf("%d",&n)
#define sfi2(n, m)      sf("%d%d",&n,&m)
#define sfl(n)          sf("%lld",&n)
#define sfl2(n, m)      sf("%lld%lld",&n,&m)
#define sff(n)          sf("%f",&n)
#define sfd(n)          sf("%lf",&n)
#define pfi(n)          pf("%d",n)
#define pfl(n)          pf("%lld",n)
#define pff(n)          pf("%f",f)
#define pfd(n)          pf("%lf",f)
#define bfi             cin.ignore()
#define bfs             cin.get()
#define bfc             getchar()
#define gl(s)           getline(cin, s)
#define loop(a,n)       for(i=a; i<n; i++)
#define mloop(i,a,n)    for(i=a; i<n; i++)
#define rloop(i,a,n)    for(i=a; i>=n; i--)
#define tloop(test)     for(ll tl=1; tl<=test; tl++)
#define case1(z)        cout<<"Case "<<z<<": "
#define case2(z)        printf("Case %d: ",z)
#define vi              vector<int>
#define vl              vector<ll>
#define vld(vc,rw)      vector<vector<ll> >vc(rw)
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define pis             pair<int,string>
#define psi             pair<string,int>
#define mls             map <ll,string>
#define msl             map <string,ll>
#define mll             map <ll,ll>
#define mp              make_pair
#define pb              push_back
#define itr             vector<int> :: iterator
#define atl(i, v)       for(auto i: v)
#define sz(s)           s.size()
#define sl(s)           s.length()
#define Sort(s)         sort(s.begin(), s.end())
#define SortR(s)        sort(s.rbegin(), s.rend())
#define all(x)          x.begin(),x.end()
#define rall(x)         x.end(), x.begin()
#define MEM(ar,val)     memset(ar, (val), sizeof(ar))
#define IN(A,B,C)       assert(B<=A && A<=C)
#define MOD             1000000007
#define EPS             1e-9
#define Max             1e9
#define Min             -1e9
#define bug1            " **1** "
#define bug2            " ****2**** "
#define artri(b,h)      0.5*b*h
#define artrap(b1,b2,h) (b1+b2)/2*h
#define arcrl(r)        pi*r*r
#define vlsyl(r,h)      pi*r*r*h
#define vlcone(r,h)     pi*r*r*(h/3)
#define vlsph(r)        (4/3)*pi*r*r*r
#define flush           fflush(stdout)
#define pcn(dg,val)     fixed << setprecision(dg) << val
#define ggl             pf("Case #%lld: ", tl)
#define FastIO          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define showsort(n, a)  for(int i=0; i<n; i++) cout << a[i] << gap; cout << endl;

inline string IntToString(ll a) {char x[100]; sprintf(x,"%lld",a); string s=x; return s;}
inline ll StringToInt(string a) {char x[100]; ll res; strcpy(x, a.c_str()); sscanf(x,"%lld",&res); return res;}
///THEOVE46

int main()
{
    FastIO;
    bool bl = true;
    ll a, b, w, mn, mx, x, y, s;
    sf("%lld%lld%lld", &a, &b, &w);
    w*=1000;

    mn = w/b;
    if(w%b!=0)
    {
        x = w%b;
        s = w - (a*mn);
        if(s<a)
        {bl = false;
        //cout << bug1 << endl;
        }
        mn++;
    }

    mx = w/a;
    if(w%a!=0)
    {
        x = w%a;
        s = (b-a)*mx;
        if(s<x)
        {bl = false;
        //cout << bug2 << x << " "  << mx << " " << s << endl;
        }
    }

    if(bl) cout << mn << " " << mx << nn;
    else cout << "UNSATISFIABLE" << endl;
    return 0;
}

///   check for integer overflow, array bounds
///   check for n=1
///   - - - The Ove 46


#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;

int main(){
    int n; cin >> n;
    vl a(n),m(n,0),ans(n,0),sum(n,0),sum2(n,0);
    ll  tmpmax = 0;

    for(int ix=0;ix<n;ix++){
        cin >> a[ix];
        tmpmax = max(a[ix],tmpmax);
        if(ix == 0) {m[ix] = a[ix]; sum[ix] = a[ix]; sum2[ix] = 0;}
        else {m[ix] = max(a[ix],m[ix-1]); sum[ix] = sum[ix-1] + a[ix]; sum2[ix] = sum2[ix-1] + sum[ix-1];}
    }
    /*
    for(auto x : sum) cout << x << endl;
    cout << endl;

    for(auto x : sum2) cout << x << endl;
    cout << endl;
    */
    for(int ix=0;ix<n;ix++){
        if(ix == 0) ans[ix] = sum[ix] + m[ix];
        else{
            ans[ix] = sum[ix] + (ix+1)*m[ix] + sum2[ix];
        }
    }
    for(auto x : ans) cout << x << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n{};
    cin>>n;
    vector <long long int> a(n+1),sum(n+1);
    for (int i{1};i<=n;i++){
        cin>>a.at(i);
        sum.at(i) = sum.at(i-1) + a.at(i);
    }
    long long int max{a.at(0)},sum1{};
    for (int i{1};i<=n;i++){
        if (max < a.at(i)){
            sum1 += (i-1)*(a.at(i) - max);
            max = a.at(i);
        }
        sum1 += max + sum.at(i);
        cout<<sum1<<endl;
    }
    return 0;
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
#define F first
#define S second
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;

int s(int x){
  int res = 0;
  rep(i, 4){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(int argc, char const* argv[])
{
  int a, b; cin >> a >> b;
  cout << max(s(a), s(b)) << endl;
  return 0;
}

#include<bits/stdc++.h>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define puts(x) cout << (x) << "\n"
using namespace std;
int input() { int t; cin >> t; return t; }
int n, x[300], y[300], R[300], xe[300], ye[300];
bool fb(int i, int j) {
	if (x[i] + xe[i] <= x[j])return 1;
	if (x[j] + xe[j] <= x[i])return 1;
	if (y[i] + ye[i] <= y[j])return 1;
	if (y[j] + ye[j] <= y[i])return 1;
	return 0;
}
bool fball(int i) {
	if (x[i] + xe[i] > 10000 || y[i] + ye[i] > 10000)return 0;
	for0(j, n) if (i != j && !fb(i, j))return 0;
	return 1;
}
signed main() {
	cin >> n;
	for0(i, n) {
		cin >> x[i] >> y[i] >> R[i];
		xe[i] = 1; ye[i] = 1;
	}
	for0(i, n) {
		int l = 1, r = (int)sqrt(R[i]) + 1;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			xe[i] = mid; ye[i] = mid;
			if (fball(i))l = mid; else r = mid;
		}
		xe[i] = l; ye[i] = l;
	}
	for0(valsq, 3000)for0(i, n) if (xe[i] * ye[i] < R[i]) {
		if (x[i] + xe[i] < 10000) { xe[i]++; if (fball(i))continue; xe[i]--; }
		if (y[i] + ye[i] < 10000) { ye[i]++; if (fball(i))continue; ye[i]--; }
	}
	for0(valsq, 3000)for0(i, n) if (xe[i] * ye[i] < R[i]) {
		if (y[i] > 0) { y[i]--; ye[i]++; if (fball(i))continue; y[i]++; ye[i]--; }
		if (x[i] > 0) { x[i]--; xe[i]++; if (fball(i))continue; x[i]++; xe[i]--; }
	}
	for0(i, n)cout << x[i] << ' ' << y[i] << ' ' << x[i] + xe[i] << ' ' << y[i] + ye[i] << endl;
}


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

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int n = 101;
  double e[n][n][n];
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      e[i][j][100] = 0;
      e[100][i][j] = 0;
      e[j][100][i] = 0;
    }
  }
  for(int i = n-2; i >= a; --i){
    for(int j = n-2; j >= b; --j){
      for(int k = n-2; k >= c; --k){
        e[i][j][k] = ((double)i*(e[i+1][j][k])
          + (double)j*(e[i][j+1][k])
          + (double)k*(e[i][j][k+1]))/(double)(i+j+k)
          + 1;
      }
    }
  }
  cout << fixed << setprecision(9) <<  e[a][b][c] <<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define drep(i,b,a) for(int i = (b)-1; i >= (a); i--)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(v) sort(v.begin(),v.end());
#define RSORT(v) sort(v.rbegin(),v.rend());
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool  odd(T x) { return x & 1; }
template<class T> inline bool even(T x) { return !(x & 1); }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill( (T*)array, (T*)(array+N), val );
}
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; }
//----------------------------------------------------------------------------------------------

double dpd[101][101];
double dpt[101][101][101];

int main()
{
    vector<int> v(3);
    rep(i,0,3) cin >> v[i];
    SORT(v);
    if(v[1] == 0) cout << 100-v[2] << endl;
    else if(v[0] == 0) {
        int a = v[1], b = v[2];
        for(int i = 99; i >= a; --i) {
            for(int j = 99; j >= b; --j) {
                dpd[i][j] += (double)i/(double)(i+j) * (dpd[i+1][j] + 1);
                dpd[i][j] += (double)j/(double)(i+j) * (dpd[i][j+1] + 1);
            }
        }
        cout << fixed << setprecision(10) << dpd[a][b] << endl;
    } else {
        int a = v[0], b = v[1], c = v[2];
        for(int i = 99; i >= a; --i) {
            for(int j = 99; j >= b; --j) {
                for(int k = 99; k >= c; --k) {
                    dpt[i][j][k] += (double)i/(double)(i+j+k) * (dpt[i+1][j][k] + 1);
                    dpt[i][j][k] += (double)j/(double)(i+j+k) * (dpt[i][j+1][k] + 1);
                    dpt[i][j][k] += (double)k/(double)(i+j+k) * (dpt[i][j][k+1] + 1);
                }
            }
        }
        cout << fixed << setprecision(10) << dpt[a][b][c] << endl;
    }
    return 0;
}


// atcoder/arc113/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  str s;
  while (cin >> s) {
    lli x = 0;
    map<char, int> m;
    for (int i = s.size() - 3; 0 <= i; --i) {
      ++m[s[i+2]];
      if (s[i] == s[i + 1] && s[i + 1] != s[i + 2]) {
        x += s.size() - (i+2) - m[s[i]];
        m.clear();
        m[s[i]] = s.size() - (i+2);
      }
    }
    cout << x << endl;
  }

  return 0;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1002003004;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
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) + ")";}

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 LINE_OUT() {
  cout << "--------------" << endl;
};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define LINE LINE_OUT();
#else
#define debug(...) 71
#define LINE 71;
#endif

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

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

  vi v(4);
  rep(i, 0, 4) cin >> v[i];
  sort(All(v));
  cout << v[0] << endl;

  return 0;
};


#include<bits/stdc++.h>
#define int long long int
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fastm_fast ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
const int  mod = 1e9 + 7;
const int MAX = 2e5+5;
typedef pair<int, int> pii;
typedef vector<int> vi ;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef map<int,int> mapii ;

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

    if( a==b ) cout << c ;
    else if(a == c) cout << b ;
    else if(b == c) cout << a ;

    else cout << 0;

}
int32_t main()
{
 fastm_fast;
//  int test;cin >> test;
//  for(int i = 1; i <= test; i++)
 { //cout << "Case #"<< test << ":";
     sujho();
 }
 return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-c<<endl;
    return 0;
}