#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

int n;
int g[N], v[N<<1], nxt[N<<1], tot;
int fa[N], son[N];
int dfn[N], sec;

inline void add(int x, int y) {
	v[++tot] = y, nxt[tot] = g[x], g[x] = tot;
}

void dfs0(int x, int f, int dis, int &t, int &mn) {
	fa[x] = f;
	if (dis > mn) t = x, mn = dis;
	for (int i = g[x]; i; i = nxt[i]) {
		int y = v[i];
		if (y == fa[x]) continue;
		dfs0(y, x, dis + 1, t, mn);
	}
}

void dfs1(int x) {
	dfn[x] = ++sec;
	for (int i = g[x]; i; i = nxt[i]) {
		int y = v[i];
		if (y == fa[x] || y == son[x]) continue;
		dfs1(y);
		sec++;
	}
	if (son[x]) dfs1(son[x]);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int x, y; scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
	}
	int s, t, mn = -1;
	dfs0(1, 0, 0, s, mn);
	mn = -1;
	dfs0(s, 0, 0, t, mn);
	//直径 s -> t
	for (int i = t; i != s; i = fa[i]) son[fa[i]] = i;
	dfs1(s);
	for (int i = 1; i <= n; i++) printf("%d ", dfn[i]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

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

signed main(){

    int T; cin >> T;
    REP(_, T){
        int N; cin >> N;
        vec p(N); cin >> p;
        REP(i, N) p[i]--;

        vec ans;
        if(N == 2){
            if(p[0] == 1) ans.pb(0);
        }else{
            IFOR(t, 3, N){
                int now = -1;
                REP(i, N) if(p[i] == t) now = i;
                if(now == t) continue;
                if(now % 2 != SZ(ans) % 2){
                    if(now == 0){
                        ans.pb(1);
                        swap(p[1], p[2]);
                    }else{
                        ans.pb(now - 1);
                        swap(p[now - 1], p[now]);
                        now--;
                        ans.pb(now + 1);
                        swap(p[now + 1], p[now + 2]);
                    }
                }
                while(now != t){
                    ans.pb(now);
                    swap(p[now], p[now + 1]);
                    now++;
                }
            }
            while(p[0] != 0 || p[1] != 1 || p[2] != 2){
                if(SZ(ans) % 2 == 0){
                    ans.pb(0);
                    swap(p[0], p[1]);
                }else{
                    ans.pb(1);
                    swap(p[1], p[2]);
                }
            }
        }
        Out(SZ(ans));
        for(int x: ans) cout << x + 1 << " ";
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    ll k, n, m; cin >> k >> n >> m;
    VI a(k); REP(i,k) cin >> a[i];
    ll sum=0;
    VI b(k);
    vector<P> p(k);
    REP(i,k){
        b[i]=a[i]*m/n;
        p[i]={a[i]*m-b[i]*n,i};
        sum+=b[i];
    }
    sort(ALL(p));
    REP(i,m-sum){
        b[p[k-1-i].second]++;
    }
    for(auto i:b){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

#include<cstdio>
typedef __int128 ll;
inline ll in();
inline void wr(ll);
inline ll quick_mod(ll,ll);
int main(int argc,char**argv){
	register ll n=in();
	register bool tp=1;
	for(register ll i=1;i<=100&&tp;++i)
		for(register ll j=1;j<=100&&tp;++j)
			if(quick_mod(3,i)+quick_mod(5,j)==n&&quick_mod(3,i)>0&&quick_mod(5,j)>0)
				wr(i),putchar(' '),wr(j),putchar('\n'),tp=0;
	if(tp)wr(-1),putchar('\n');
}
inline ll quick_mod(ll x,ll y){
	register ll s=1;
	while(y){
		if(y&1)
			if(s*x>s)s=s*x;
			else s=0;
		x=x*x;y>>=1;
	}
	return s;
}
inline ll in(){
	register char c=getchar();
	register ll x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


#include <bits/stdc++.h>

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

using namespace std;

int MOD;
class mint{
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n,k; scanf("%d%d%d",&n,&k,&MOD);

	int m=n*(n+1)/2*k;
	static mint buf[3000000];
	mint* a=&buf[1500000];
	a[0]=1;
	for(int i=1;i<=n;i++){
		// * (1-X^{(k+1)*i})
		for(int j=m;j>=(k+1)*i;j--) a[j]-=a[j-(k+1)*i];
		// / (1-X^i)
		rep(j,m+1-i) a[j+i]+=a[j];
	}

	for(int x=1;x<=n;x++){
		// * (1-X^{n+1-x})
		for(int j=m;j>=-m+n+1-x;j--) a[j]-=a[j-(n+1-x)];
		// / (1-X^{(k+1)*(n+1-x)})
		for(int j=-m;j<=m-(k+1)*(n+1-x);j++) a[j+(k+1)*(n+1-x)]+=a[j];

		if(x==1){
			// * k+1
			for(int j=-m;j<=m;j++) a[j]*=k+1;
		}

		if(x>=2){
			// * X^{-k*(x-1)}
			for(int j=-m;j<=m-k*(x-1);j++) a[j]=a[j+k*(x-1)];
			// * (1-X^{(k+1)*(x-1)})
			for(int j=m;j>=-m+(k+1)*(x-1);j--) a[j]-=a[j-(k+1)*(x-1)];
			// / (1-X^(x-1))
			for(int j=-m;j<=m-(x-1);j++) a[j+(x-1)]+=a[j];
		}

		cout<<a[0]-1<<'\n';
//printf("x = %d:\n",x); for(int i=-6;i<=6;i++) printf("a[%d] = %d\n",i,a[i].to_int());
	}

	return 0;
}

/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
// #define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 102, MAXM = 560000;
int n,k,mod,dp[MAXN][MAXM];

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

  cin >> n >> k >> mod;
  dp[0][0]=1;

  for(int i=1;i<=n;i++){
    vi presum(i+1,0);
    for(int j=0;j<MAXM;j++){
      int rem = j%i;
      presum[rem] = (presum[rem]+dp[i-1][j])%mod;
      if(j-(k+1)*i>=0){
        presum[rem] = (presum[rem]-dp[i-1][j-(k+1)*i]+mod)%mod;
      }
      dp[i][j] = presum[rem];
    }
  }

  for(int i=1;i<=n;i++){
    int ans = 0;
    for(int j=0;j<MAXM;j++){
      ans = (ans+dp[i-1][j]*dp[n-i][j]%mod)%mod;
    }
    ans = (ans*(k+1)%mod - 1 + mod)%mod;
    cout << ans << endl;
  }

return 0;
}
///....


constexpr bool isDebugMode = false;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // cin >> testcase;
    while(testcase--) solve();
    return 0;
}

void solve(){
    ll N, M; cin >> N >> M;
    vector<ll> h(N);
    vector<ll> w(M);
    rep(i, N) cin >> h[i];
    rep(i, M) cin >> w[i];
    sort(all(h));
    vector<ll> head(N / 2);
    vector<ll> tail(N / 2);
    ll hn = N / 2;
    rep(i, hn){
        head[i] = abs(h[2 * i] - h[2 * i + 1]);
        tail[i] = abs(h[N - 1 - 2 * i] - h[N - 2 - 2 * i]);
    }
    vector<ll> shead(hn + 1);
    vector<ll> stail(hn + 1);
    rep(i, hn){
        shead[i + 1] = shead[i] + head[i];
        stail[i + 1] = stail[i] + tail[i];
    }
    // enu(shead);
    // enu(stail);
    ll ans = INF;
    rep(i, M){
        ll ins = lower_index(h, w[i]);
        if(ins % 2 == 0){
            chmin(ans, shead[ins / 2] + abs(w[i] - h[ins]) + stail[N / 2 - ins / 2]);
        }else{
            chmin(ans, shead[ins / 2] + abs(w[i] - h[ins - 1]) + stail[N / 2 - ins / 2]);
        }
    }
    pt(ans);
}

#include <bits/stdc++.h>

using namespace std;

#define ll int64_t
#define ull uint64_t
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define FOR(i, n) for (int i = 0; i < n; i++)
#define CONCAT_INNER(a, b) a ## b
#define CONCAT(a, b) CONCAT_INNER(a, b)
#define REP(n) FOR(CONCAT(_i, __COUNTER__), n)
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define IN(x, l, r) (l < x && x < r)
#define MOD 1000000007
#define EPS 10e-9
#define ii pair<int, int>
#define DIR4 {{0,1}, {1,0}, {0,-1}, {-1,0}}
#define DIR8 {{0,1}, {0,-1}, {1,0}, {-1,0}, {-1,-1}, {-1,1}, {1,-1}, {1,1}}
#define fst(x) (x).first
#define snd(x) (x).second
#define SZ(x) ((int) (x).size())
#define inc(c, v) (c.find(v) != c.end())
#define SKIP(c) if (c) continue
#define MODM(n, m) ((n) % m + m) % m
#define LOG2I(n) (31 - __builtin_clz(n))

void test_case() {
  int x, y;
  cin >> x >> y;
  if (x == y) cout << x << endl;
  else cout << 3 - x - y << endl;
}

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

  // cout << fixed << setprecision(6);

  int t = 1;
  // cin >> t;
  FOR(i, t) {
    test_case();
  }
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int count = 0;
    rep(i,h){
        int len = 0;
        rep(j,w){
            if(s[i][j]=='#' ){
                count += max(0,len-1);
                len = 0;
            }else{
                ++len;
                if(j==w-1) count += max(0,len-1);
            }
        }
    }
    rep(i,w){
        int len = 0;
        rep(j,h){
            if(s[j][i]=='#' ){
                count += max(0,len-1);
                len = 0;
            }else{
                ++len;
                if(j==h-1) count += max(0,len-1);
            }
        }
    }
    cout << count << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long a[2000005],sum=0,mx=105;
int main(){
	long long n,m;
	cin>>n>>m;
	for(int i=0;i<n*m;i++){
		cin>>a[i];
		if(a[i]<mx){
			mx=a[i];
		}
	}
	for(int i=0;i<m*n;i++){
		sum=sum+a[i]-mx;
	}
	cout<<sum;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> cnt(n,0);
    rep(i,n){
        ll a;
        cin >> a;
        cnt[a] ++;
    }
    ll p = cnt[0];
    for(ll i=1;i<n;i++){
        cnt[i] = min(cnt[i],p);
        p = cnt[i];
    }
    vector<ll> ans(k,0);
    rep(i,n){
        rep(j,cnt[i]){
            if(j>=k) break;
            ans[j] = i+1;
        }
    }
    ll res = accumulate(ans.begin(),ans.end(),0);
    cout << res << endl;
    return 0;
}

#include<bits/stdc++.h>
#define maxn 300010
#define ll long long
using namespace std;
ll n,m,now,ans,sum;
ll a[maxn],nm[maxn];
struct nod{
	ll pos,num;
};
bool operator < (nod aa,nod bb){
	return aa.num==bb.num?aa.pos>  bb.pos:aa.num>bb.num;
}
priority_queue <nod> q;
int main(){
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;++i) scanf("%lld",&a[i]),nm[a[i]]++;
	sort(a+1,a+n+1);
	for(ll i=0;i<=n;++i)
		q.push((nod){i,nm[i]});
	if(a[1]==0) {
	now=1;
	for(ll i=2;i<=n;++i){
	if(a[i]==a[i-1]||a[i]==a[i-1]+1) now=a[i]+1;else break;
	}
}
	while(m&&!q.empty()){
		nod v=q.top();
		q.pop();
		if(v.num==0) continue;
		if(v.pos>now) continue;
		ans+=now*min(m,v.num-sum);
		m-=min(m,v.num-sum);
		sum=v.num;
		now=v.pos;
	}
	cout<<ans;
	return 0;
}
/*
12 4
0 1 2 3 4 0 1 2 0 1 1 0
*/


#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}

string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,ans=0;
    cin>>n;
    for (ll i=999,c=1;i<n;i=i*1000+999,++c)
        ans+=((min({i*1000+999,n})-i)*c);
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){

	long long n; cin >> n;
	vector<long long> vec;

	for(int i=1; i <= sqrt(n); i++){
		if(n % i == 0){
			if(n /i == i){
				vec.push_back(i);
			}
			else{
				vec.push_back(i);
				vec.push_back(n/i);
			}
		}
	}
	sort(vec.begin(), vec.end());

	for(auto x : vec){
		cout << x << endl;
	}

}


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

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(begin(a), end(a));
	map<int, int> mp;
	for (const auto& [v, i] : a) {
		mp[i] = v;
	}
	vector<vector<int>> g(n);
	while (m--) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		g[x].push_back(y);
	}
	int ans = -(1 << 30);
	vector<bool> seen(n, false);
	for (const auto& [v, i] : a) {
		queue<int> q;
		q.push(i);
		while (!q.empty()) {
			int p = q.front();
			q.pop();
			for (const auto& ni : g[p]) {
				if (seen[ni]) continue;
				ans = max(ans, mp[ni] - v);
				q.push(ni);
				seen[ni] = true;
			}
		}
	}
	cout << ans << '\n';
}

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
};

int main(){
  int n,m; cin >>n >>m;
  vector<li> a(n);
  rep(i,n) cin >>a[i];
  vector<vector<int>> adj(n);
  rep(i,m) {
    int x,y; cin >>x >>y; x-- ; y--;
    adj[x].push_back(y);
  }
  li s=0; for(li x:a) s=max(s,x);
  if(df)print("s",s);
  vector<li> dp(n,s*2);
  rep(i,n){
    for(int x:adj[i]){
      dp[x]=min({dp[x],a[i],dp[i]});
    }
  }
  if(df)print(dp);
  li   ans=-s;
  rep(x,n){
    ans=max(ans,a[x]-dp[x]);
  }
  print(ans);
}


/*
author : seryu
title : ABC180B_"Various distances"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
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; }

void solve()
{
    int n;
    cin >> n;
    double man = 0, euc = 0, che = 0;
    rep(i, n)
    {
        double x;
        cin >> x;
        man += abs(x);
        euc += x*x;
        chmax(che, abs(x));
    }
    euc = pow(euc, 0.5);
    cout << man << endl;
    cout << euc << endl;
    cout << che << endl;
    return;
}

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

#include <cstdio>
#include <algorithm>

const int N = 2e5 + 5;

int a[N];
int b[N];
int ans[N];

int main() {
//#ifndef ONLINE_JUDGE
	//freopen("in", "r", stdin);
//#endif
	int n;
	while (~scanf("%d", &n)) {
		for (int i = 1; i <= n; ++i) {
			scanf("%d", &a[i]);
			b[a[i]] = i;
		}
		int cnt = 0;
		for (int i = n; i >= 1; --i) {
			for (int k = b[i]; k < i; ++k) {
				std::swap(a[k], a[k + 1]);
				std::swap(b[a[k]], b[a[k + 1]]);
				ans[cnt++] = k;
				if (cnt >= n - 1) {
					break;
				}
			}
			if (cnt >= n - 1) {
				break;
			}
		}
		if (std::is_sorted(a, a +n) && cnt == n - 1) {
			for (int i = 0; i < cnt; ++i) {
				printf("%d\n", ans[i]);
			}
		} else {
			printf("-1\n");
		}
	}
	return 0;
}


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

#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define rrep(i, n) for(long long i = (long long)(n - 1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;

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

	double x0, y0, x2, y2;

	cin >> x0 >> y0 >> x2 >> y2;

	const double PI = 3.14159265358979323846;
	double cx = (x2 + x0) / 2.0, cy = (y2 + y0) / 2.0;
	double l = sqrt(pow(cx - x0, 2) + pow(cy - y0, 2));

	auto dir = atan2(y0 - cy, x0 - cx);
	dir += 2 * PI / n;

	cout << fixed << setprecision(30);
	cout << cx + cos(dir) * l << " " << cy + sin(dir) * l << endl;

	return 0;
}

#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define MOD 998244353

int W[100],fact[1000];
int dp[2][10001][101];
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&W[i]);

    int j,k;
    int sum = 0;
    dp[1][0][0] = 1;
    fact[0] = 1;
    for (i = 1; i < 1000; i++) fact[i] = ((LLI) i*fact[i-1]) % MOD;
    for (i = 0; i < N; i++) {
        int p = i & 1;
        sum += W[i];
        for (j = 0; j <= sum; j++) {
            for (k = 0; k <= i+1; k++) {
                dp[p][j][k] = dp[!p][j][k];
                if ((j-W[i] >= 0) && (k > 0)) {
                    dp[p][j][k] += dp[!p][j-W[i]][k-1];
                    if (dp[p][j][k] >= MOD) dp[p][j][k] -= MOD;
                }
            }
        }
    }
    LLI ans = 0;
    if (!(sum & 1)) {
        i = sum/2;
        for (j = 0; j <= N; j++) {
            ans += (((LLI) dp[(N-1) & 1][i][j]*fact[j]) % MOD)*fact[N-j];
            ans %= MOD;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define pb              push_back
#define SZ(x)           (int)x.size()
#define F               first
#define S               second
#define ALL(x)          x.begin(), x.end()
#define fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i, a, b)    for(int i = a; i < b; ++i)

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

const ll INF = 1e18;
const int MOD = 998244353;
const ld PI = acosl(-1.0);
const ld EPS = 1e-9;

#define int long long
const int N = 51;
int adj[N][N], arr[N][N];
int vis[N];
int n, k;
ll f[N];
void dfs(int node, int &cnt) {
        if(vis[node]) return;
        vis[node] = 1;
        cnt++;
        FOR(nxt, 1, n+1) {
                if(adj[node][nxt]) {
                        dfs(nxt, cnt);
                }
        }
}

void solve() {
        cin >> n >> k;
        FOR(i, 1, n+1) FOR(j, 1, n+1) cin >> arr[i][j];
        f[0] = 1;
        FOR(i, 1, n+1) f[i] = (f[i-1] * i) % MOD;
        ll ans = 1;
        FOR(i, 1, n+1) FOR(j, 1, n+1) adj[i][j] = 0;
        FOR(i, 1, n+1) vis[i] = 0;
        FOR(x, 1, n+1) {
                FOR(y, x+1, n+1) {
                        bool ok = true;
                        FOR(r, 1, n+1) {
                                if(arr[r][x] + arr[r][y] > k) {
                                        ok = false;
                                        break;
                                }
                        }
                        if(ok) {
                                adj[x][y] = 1;
                                adj[y][x] = 1;
                        }
                }
        }

        ll cur = 1;
        FOR(i, 1, n+1) {
                if(!vis[i]) {
                        int cnt = 0;
                        dfs(i, cnt);
                        cur = (cur * f[cnt]) % MOD;
                }
        }
        ans = (ans * cur) % MOD;

        FOR(i, 1, n+1) FOR(j, 1, n+1) adj[i][j] = 0;
        FOR(i, 1, n+1) vis[i] = 0;
        FOR(x, 1, n+1) {
                FOR(y, x+1, n+1) {
                        bool ok = true;
                        FOR(c, 1, n+1) {
                                if(arr[x][c] + arr[y][c] > k) {
                                        ok = false;
                                        break;
                                }
                        }
                        if(ok) {
                                adj[x][y] = 1;
                                adj[y][x] = 1;
                        }
                }
        }

        cur = 1;
        FOR(i, 1, n+1) {
                if(!vis[i]) {
                        int cnt = 0;
                        dfs(i, cnt);
                        cur = (cur * f[cnt]) % MOD;
                }
        }
        ans = (ans * cur) % MOD;
        cout << ans << endl;
}

signed  main() {
        fast;
        int T = 1;
        // cin >> T;
        while(T--) {
                solve();
        }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }

//bool callback(int from, int to)
template <class Graph, class Callback>
void bfs(Graph& g, int start, Callback callback) {
    vector<bool> visited(g.size());
    queue<int> q;
    q.push(start);
    visited[start] = true;
    while (!q.empty()) {
        auto v = q.front(); q.pop();
        for (auto u : g[v]) {
            if (visited[u]) continue;
            visited[u] = true;
            if (callback(v,u)) q.push(u);
        }
    }
}

ll dp[1<<17][17];
int main() {
    fastio;
    ll ans=Inf;
    ll N,M,K;
    cin >> N >> M;
    vector<vector<int>> g(N);
    rep(i,M) {
        int a,b;
        cin >> a >> b, --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cin >> K;
    vector<ll> c(K);
    rep(i,K) cin >> c[i], --c[i];
    ll d2[17][17]{};
    rep(i,K) rep(j,K) d2[i][j] = Inf;
    rep(i,K) {
        vector<ll> d(N, Inf);
        d[c[i]] = 0;
        bfs(g, c[i], [&](int from, int to){
            d[to] = 1 + d[from];
            return true;
        });
        rep(j,K) if (i != j) d2[i][j] = d[c[j]];
    }
    rep(i,1<<K) rep(j,K) dp[i][j] = Inf;
    rep(i,K) dp[1<<i][i] = 0;
    rep(p,1<<K) rep(i,K) {
        if (!(p>>i&1)) continue;
        rep(j,K) {
            if (p>>j&1) continue;
            updmin(dp[p|(1<<j)][j], dp[p][i] + d2[i][j]);
        }
    }
    rep(i,K) updmin(ans, dp[(1<<K)-1][i]);
    if (ans == Inf) ans = -1;
    else ans++;
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {
        int ans = 0;
        int n;
        cin >> n;
        vector<int> a(n);
        rep(i,0,n) cin >> a[i];
        rep(i,0,n) ans += (n-1)*a[i]*a[i];
        // trace(ans);
        int sum = 0;
        rep(i,0,n) sum += a[i];
        // trace(sum);
        rep(i,0,n){
            ans -= a[i]*(sum - a[i]);
            // trace(a[i]*(sum-a[i]))
        }
        cout << ans << endl;
    }
}

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

int main(void){
    int n;
    cin >> n;
    vector<ll> cnt_dummy(401);
    decltype(cnt_dummy)::iterator cnt = cnt_dummy.begin() + 200;
    rep (i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    ll ans = 0;
    for (ll i = -200; i <= 199; i++) {
        for (ll j = i+1; j <= 200; j++) {
            ans += (j-i) * (j-i) * cnt[i] * cnt[j];
        }
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); }
        template <typename T>
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    int N;
    cin >> N;
    Vl A(N), B(N), P(N), invP(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (ll i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (ll i = 0; i < N; i++) {
        int p;
        cin >> p;
        --p;
        P[i] = p;
        invP[p] = i;
    }
    Vi ord(N);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int l, int r) { return A[l] < A[r]; });
    vector<Pii> ans;
    for (ll i = 0; i < N; i++) {
        int u = ord[i];
        int to = invP[u];
        if (u == to) continue;
        if (A[u] <= B[P[u]] || A[to] <= B[P[to]]) {
            prints()(-1);
            return;
        }
        int t = P[u];
        ans.emplace_back(u, to);
        P[u] = u;
        P[to] = t;
        invP[u] = u;
        invP[t] = to;
    }

    prints()(ans.size());
    for (auto [a, b] : ans) {
        prints()(a + 1, b + 1);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long  int ll;
typedef long double db;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7 ;
ll inf = 1e18;
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
//GCD
ll gcd (ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n;
	db a[n];
	rep(i, n) cin >> a[i];
	db d1 = 0, d2 = 0, d3 = 0;
	rep(i, n) {
		d1 += abs(a[i]);
		d2 += pow(a[i], 2);
		d3 = max(d3, abs(a[i]));
	}
	cout << fixed << setprecision(10) << d1 << "\n" << pow(d2, 0.5) << "\n" << d3;

#ifndef ONLINE_JUDGE
	time();
#endif

	return 0;

}


#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) int(x.size())
#define fk cerr<<"fk"<<endl
#define db(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//1.integer overflow (1e5 * 1e5) (2e9 + 2e9)
//2.runtime error
//3.boundary condition
const int N=(int)1e3+100;
int n,m,a[N],b[N],dp[N][N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif
    cin>>n>>m;
    forn(i, n) cin>>a[i];
    forn(i, m) cin>>b[i];
    ms(dp,0x3f);
    dp[0][0]=0;
	for(int i=0; i<=n; ++i){
		for(int j=0; j<=m; ++j){
			if(i+1<=n) uin(dp[i+1][j],dp[i][j]+1);
			if(j+1<=m) uin(dp[i][j+1],dp[i][j]+1);
			if(i+1<=n && j+1<=m){
				uin(dp[i+1][j+1],dp[i][j]+(a[i]!=b[j]));
			}
		}
	}
    cout<<dp[n][m]<<'\n';
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

#include<bits//stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
ll mod = 998244353;
ll fanc(int n,int k){
    return min(k-1,2*n+1-k);
}
int main(){
    int n,k;cin >>n>>k;
    ll sum = 0;
    for(int i = max(2,2+k);i<=min(2*n,2*n+k);i++){
        sum += fanc(n,i)*fanc(n,i-k);
    }cout << sum <<endl;
}


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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 1000;
class shuturyoku_unko {
public:
	char C[MAX * 4];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 3) {
				C[i * 4 + 2 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 4 + 3] = ' ';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char* dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(int A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	if (A >= 1000) {
		int dig = 1;
		if (A >= 100000) dig = 3;
		else if (A >= 10000) dig = 2;
		memcpy(di, f.C + A / 1000 * 4 + 3 - dig, dig);
		memcpy(di + dig, f.C + A % 1000 * 4, 4);
		di += dig + 4;
	}
	else {
		int dig = 1;
		if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 4 + 3 - dig, dig + 1);
		di += dig + 1;
	}
}

int N;
int to[400001], ne[400001], he[200001];
int Q[200001], vis[200001], p, q;
ll are[200001];

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

	N = getint();
	rep1(i, N * 2 - 2) {
		int a = getint(), b = getint();
		to[i] = b;
		ne[i] = he[a];
		he[a] = i++;
		to[i] = a;
		ne[i] = he[b];
		he[b] = i;
	}

	Q[q++] = 1;
	while (p < q) {
		int u = Q[p++];
		vis[u] = -1;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] == 0) {
				Q[q++] = to[i];
			}
		}
	}
	int tmp = Q[N - 1];
	p = 0;
	q = 0;
	Q[q++] = tmp;
	vis[tmp] = 0;
	while (p < q) {
		int u = Q[p++];
		int mae = 0;
		for (int i = he[u]; i; i = ne[i]) {
			if (vis[to[i]] < 0) {
				vis[to[i]] = u;
				Q[q++] = to[i];
				mae = i;
			}
			else {
				if (mae) ne[mae] = ne[i];
				else he[u] = ne[i];
			}
		}
	}
	ll m = (1ll << 20) - 1, m0 = ~m, m1 = 1ll << 20;
	for (int i = N - 1; i >= 0; i--) {
		int u = Q[i];
		ll kari = (are[u] & m0) + m1 + u;
		if (are[vis[u]] < kari) are[vis[u]] = kari;
	}

	int k = 0;
	q = 0;
	Q[q++] = tmp;
	while (q) {
		k++;
		int u = Q[q - 1];
		if (u < 0) q--;
		else {
			vis[u] = -k;
			Q[q - 1] = -u;
			int nanika = are[u] & m;
			if (nanika) Q[q++] = nanika;
			for (int i = he[u]; i; i = ne[i]) {
				int v = to[i];
				if (v != nanika) {
					Q[q++] = v;
				}
			}
		}
	}

	rep1(i, N) putint(-vis[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pbp(f, s) pb(mp(f, s));
using namespace std;
typedef long long int ll;
typedef pair<int, int> PI;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
/*--------------------------------------------------*/
string x;
ll m;
/*--------------------------------------------------*/
void speedUpIO() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
}

bool check(ll p) {
    V<ll> y;
    ll mm = m;
    while (mm > 0) {
        y.pb(mm % p);
        mm /= p;
    }
    reverse(all(y));
    if (x.size() < y.size()) return true;
    if (x.size() > y.size()) return false;
    rep(i, x.size()) {
        if (x[i] - '0' < y[i]) return true;
        if (x[i] - '0' > y[i]) return false;
    }
    return true;
}

int main() {
    speedUpIO();

    cin >> x >> m;
    if (x.size() == 1) {
        int xi = stoi(x);
        cout << (xi <= m ? 1 : 0) << "\n";
        return 0;
    }
    int d = 0;
    for (char c : x) d = max(d, c - '0');
    ll ok = d;
    ll ng = m + 1;
    // ll ng = 1e18 + 1;
    while (ng - ok > 1) {
        ll mid = ok / 2 + ng / 2;
        if (ok % 2 == 1 && ng % 2 == 1) mid++;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok - d << "\n";
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

using VL = vector<long long>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;

VL calc(bool is_front, const VL &a) {
	int n = a.size();
	int n2 = n / 2;

	VL b;
	if (is_front) {
		for (int i = 0; i < n2; i++) {
			b.emplace_back(a[i]);
		}
	} else {
		for (int i = n2; i < n; i++) {
			b.emplace_back(a[i]);
		}
	}

	VL points;

	int nb = b.size();
	int limit = 1 << nb;
	for (int i = 0; i < limit; i++) {
		long long val = 0;
		for (int j = 0; j < nb; j++) {
			if ((i >> j) & 1) {
				val += b[j];
			}
		}
		points.emplace_back(val);
	}

	sort(points.begin(), points.end());
	return points;
}

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

	VL a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	auto v1 = calc(true, a);
	auto v2 = calc(false, a);

	long long ans = 0;
	for (auto x: v1) {
		if (x > t) {
			break;
		}
		ans = max(ans, x);

		auto it = upper_bound(v2.begin(), v2.end(), t - x);
		if (it != v2.begin()) {
			ans = max(ans, x + *prev(it));
		}
	}

	cout << ans << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

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

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}
ll n,k;

void calc(ll arr[], ll x[], ll n, ll c) {
	for (int i=0; i<(1<<n); i++) {
        ll sum = 0;
        for (int j=0; j<n; j++)
            if (i & (1<<j))
                sum += arr[j+c];
        x[i] = sum;
    }
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		cin>>n>>k;
		ll arr[n];
		ll a[2000000+10],b[2000000+10];
		f(i,n) cin>>arr[i];
		calc(arr,a,n/2,0);
		calc(arr,b,n-n/2,n/2);
		int sa = 1<<(n/2);
    	int sb = 1<<(n-n/2);

	    sort(b, b+sb);
	    ll max = 0;
	    f(i,sa) {
	        if (a[i] <= k) {
	            int p = lower_bound(b, b+sb, k-a[i]) - b;

	            if (p == sb || b[p] != (k-a[i]))
	                p--;

	            if ((b[p]+a[i]) > max)
	                max = b[p]+a[i];
	        }
	    }
	    cout<<max<<"\n";
	}
 	return 0;
}


 #include <iostream>

using namespace std;

int main() {

int  a, b; cin >> a >>  b;

int sum =0;

int sum1 =0;

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

    sum  += ( a%10) ;

    sum1 += ( b%10) ;

    a/=10 ;

    b/=10 ;

}

cout<< max( sum1 , sum) ;

    return 0;}

// Problem: A - Large Digits
// Contest: AtCoder - AtCoder Beginner Contest 187
// URL: https://atcoder.jp/contests/abc187/tasks/abc187_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;

void solve(){
	string a,b;
	cin >> a >> b;
	ll sa = 0, sb = 0;
	for(ll i=0;a[i];i++){
		sa += (a[i]-'0');
		sb += (b[i] - '0');
	}
	if(sa>=sb)
	cout << sa ;
	else
	cout << sb;
}

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


#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
ll n, k;
bool bin_search(vector<vl> shite, ll n, ll ele)
{
	vector<vl> s(n+1, vl(n+1, 0));
	forr1(i, n)
	{
		forr1(j, n)
		{
			s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + shite[i-1][j-1];
		}
	}
	for(ll i=k; i<=n; i++)
	{
		for(ll j=k; j<=n; j++)
		{
			if (s[i][j]-s[i-k][j]-s[i][j-k]+s[i-k][j-k]>=ele)
			{
				return false;
			}
		}
	}
	return true;
}
void solve()
{
    cin>>n>>k;
    vector<vl> a(n, vl(n, 0));
    forr(i, n)
    {
    	forr(j, n)
    	{
    		cin>>a[i][j];
    	}
    }
    ll low=0, high=(ll)1e10;
    ll works=high;
    ll ele=(k*k-1)/2+1;
    while(high>=low)
    {
    	ll mid=low+(high-low)/2;
    	vector<vl> b(n, vl(n, 0));
    	forr(i, n)
    	{
    		forr(j, n)
    		{
    			if(a[i][j]<=mid) b[i][j]=1;
    			else b[i][j]=0;
    		}
    	}
    	if(!bin_search(b, n, ele))
    	{
    		high=mid-1;
    	}
    	else
    	{
    		low=mid+1;
    	}
    }
	cout<<low<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

// Qg3
// //g++ -std=c++17 -O2 -Wall a.cpp -o test
// _()_
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pi>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define debug2(x,y) cout<<"This side ----> "<<#x<<" -> "<<x<<" | "<<#y<<" -> "<<y<<endl;
#define debug(x) cout<<"This side    ----> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define mint map<int,int>
#define mall map<ll,ll>
#define ciN cin
#define gu(a,s) get<a>(s)
#define tin tuple<ll,ll,ll>
#define ter(x,y,z) ((x)?y:z)
#define endl "\n";

/////////////
const ll maxn = 1e5 + 3;
const ll max_val = 5e4 + 10;
ll mod = 1e9 + 7;
const ll bits = 18;
ll caseNumber = 1;
////////////////////////////////////////////////////////////////
int dp[26][maxn];
int n; string s;
int work(int lst, int ind) {
	if (ind >= n)return 1e8;
	if (ind == 0) {
		lst = s[ind] - 'a';
		return work(lst, ind + 1);
	}
	if (ind == n - 1) {
		if (lst != s[ind] - 'a') {
			return 1;
		}
		else {
			return 1e8;
		}
	}
	if (dp[lst][ind] != -1)return dp[lst][ind];
	else {
		int curr = 1e8;
		if (s[ind] - 'a' != lst) {
			int here = work(s[ind + 1] - 'a', ind + 1);
			if (here != -1) {
				curr = min(curr, here + 1);
			}
		}
		int ok = work(lst, ind + 1);
		if (ok != -1) {
			curr = min(curr, ok);
		}
		return dp[lst][ind] = curr;

	}
}
void solve() {
	cin >> n;
	cin >> s;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 26; j++) {
			dp[j][i] = -1;
		}
	}
	if (s.size() == 1) {
		cout << -1 << endl; return;
	}
	int fin = work(0, 0);
	if (fin == 1e8) {
		cout << -1 << endl; return;
	}
	cout << fin << endl;

}

bool TestCase1 = 0;
bool isGoogles = 0;

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

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

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

	ios::sync_with_stdio(0);
	cin.tie(0);
	ll t;
	t = 1;

	if (TestCase1) {
		cin >> t;
	}
	for (int i = 0; i < t; i++) {
		solve();

	}
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH

*/


#include<bits/stdc++.h>
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
#define hi "visited\n" //sasta debugging
using namespace std;

//author::@whohet-->Het Patel

int findMaxGCD(int *arr, int n)
{
	// Calculating MAX in array
	int high = 0;
	for (int i = 0; i < n; i++)
		high = max(high, arr[i]);

	// Maintaining count array
	int count[high + 1] = {0};
	for (int i = 0; i < n; i++)
		count[arr[i]]++;

	// Variable to store the
	// multiples of a number
	int counter = 0;

	// Iterating from MAX to 1
	// GCD is always between
	// MAX and 1. The first
	// GCD found will be the
	// highest as we are
	// decrementing the potential
	// GCD
	for (int i = high; i >= 1; i--)
	{
		int j = i;
		counter = 0;

		// Iterating from current
		// potential GCD
		// till it is less than
		// MAX
		while (j <= high)
		{
			// A multiple found

			if (count[j] >= 2)
				return j;

			else if (count[j] == 1)
				counter++;

			// Incrementing potential
			// GCD by itself
			// To check i, 2i, 3i....
			j += i;

			// 2 multiples found,
			// max GCD found
			if (counter == 2)
				return i;
		}
	}
	return 1;
}
void solve()
{
	int a, b;
	cin >> a >> b;
	int n = b - a + 1;
	int arr[n];
	int tmp = a;
	for (int i = 0; i < n; i++)
	{
		arr[i] = tmp; tmp++;
	}
	cout << findMaxGCD(arr, n);
}
signed main()
{
	fasterthanlight;
	int T; T = 1;
	//cin >> T;
	while (T--)
	{
		solve();
	}

	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define swap(a,b) (a^=b^=a^=b)
#define ll long long int
#define ull unsigned long long int
#define uint unsigned int
#define format(a) memset(a,0,sizeof(a))
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define dec(x,y,z) for(int x=y;x>=z;x--)
#define mst(x) memset(x,0,sizeof(x))
const int maxn=105;
inline int read()
{
    int ans=0;
    char last=' ',ch=getchar();
    while(ch<'0'|ch>'9')last=ch,ch=getchar();
    while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    if(last=='-')ans=-ans;
    return ans;
}
int main()
{
    int a,b;
    cin>>a>>b;
    dec(i,b-a,1)
    {
        rep(j,(max(a,i)+i-1)/i*i,b-i)
        {
            if(__gcd(j,j+i)==i)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }

    return 0;
}
//100001 200000


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

int main(){
    ll B,C;
    cin >> B >> C;
    ll Al,Ar,Bl,Br;
    ll ans;
    Al = B - C/2;
    Ar = max(B,B + (C-2)/2);
    Bl = (-1)*B-(C-1)/2;
    Br = (-1)*B+(C-1)/2;
    if(B>0){
        ans = Ar-Al+1+Br-Bl+1;
        if(Br>=Al) ans -= (Br-Al+1);
    }
    if(B<0){
        ans = Ar-Al+1+Br-Bl+1;
        if(Ar>=Bl) ans -= (Ar-Bl+1);
    }
    if(B==0){
        ans = Br - Al +1;
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
constexpr int INF = 1000000010;

int main() {
    int h, w;
    cin >> h >> w;
    int mn = INF;
    mat a(h, vec(w));
    rep(i, h) rep(j, w) {
        int x;
        cin >> x;
        a[i][j] = x;
        mn = min(mn, x);
    }

    int res = 0;

    rep(i, h) rep(j, w) res += (a[i][j] - mn);

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


#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define V vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F first
#define S second
#define sqr(x) (x)*(x)
#define mp make_pair
#define mtp make_tuple
#define tpii tuple<int,int,int>
#define ckmax(a,b) a=max(a,b)
#define ckmin(a,b) a=min(a,b)
#define rep(n) for(int i=0;i<n;i++)
#define inf INT_MAX
#define debug(x) cerr<<x<<'\n';
#define quick ios_base::sync_with_stdio(0),cin.tie(0);long double nownow=clock();
#define total_time cerr<<(clock()-nownow)/CLOCKS_PER_SEC*1000<<" (ms)\n";
using namespace std;
template<typename T>void in(vector<T> &a){for(auto &i:a)cin>>i;}
template<typename T>void in(vector<T> &a,int n){for(auto i=0;i<n;i++)cin>>a[i];}
template<typename T>void out(vector<T> &a){for(auto &i:a)cout<<i;cout<<'\n';}
#define int long long
#define input freopen("/Users/wangkaiyu/Downloads/Q_6_24_3.in","r",stdin);

signed main(){
    quick
    int n,m;
    cin>>n>>m;
    vvi a(n+1);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        a[x].pb(y);
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        queue<int> q;
        q.push(i);
        vi f(n+1,0);
        f[i]=1;
        while(!q.empty()){
            cnt++;
            int t=q.front();
            for(int j:a[t]){
                if(f[j]==0)
                    q.push(j);
                f[j]=1;
            }
            q.pop();
        }
    }cout<<cnt<<'\n';
    total_time
    return 0;
}

#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#include <list>
#include <stack>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
void eras(map<int,int> &m,int x)
{
    m[x]--;
    if (!m[x]) m.erase(x);
}
ostream& operator <<(ostream &out,__int128 x)
{
    out<<(ll)x;
    re out;
}
istream& operator >>(istream &in,__int128 &x)
{
    ll temp;
    in>>temp;
    x=temp;
    re in;
}
const int N=(int)3e5+100;
const int M=(int)1e7+10;
const ll inf=(ll)1e18+100;
const double eps=1e-9;
#define filename ""
    int n;
    vector<pair<int,pair<int,int> > > v[N];
    ll d[N];
bool sss(int x,int y)
{
    if (d[x]==d[y]) re x<y;
    re d[x]<d[y];
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int m;
    cin>>n>>m;
    int i;
    fo(i,m)
    {
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;
        b--;
        v[a].pb({b,{c,d}});
        v[b].pb({a,{c,d}});
    }
    set<int,bool(*)(int,int)> s(sss);
    fr(i,1,n)
    {
        d[i]=inf;
        s.in(i);
    }
    s.in(0);
    while(!s.empty())
    {
        int x=*s.begin();
        s.er(x);
        for(auto y:v[x])
        {
            ll t=d[x]+1;
            ll c=y.ss/t;
            if (t*t<y.ss) t=sqrt(y.ss);
            t=max(t,d[x]+1);
            c=y.ss/t;
            ll len=y.sf+c+t-1;
            int k=6;
            while(c)
            {
                k--;
                if (!k) break;
                len=min(len,y.sf+c+t-1);
                t=y.ss/c+1;
                c=y.ss/t;
            }
            len=min(len,y.sf+c+t-1);
            if (d[y.fi]>len)
            {
                s.er(y.fi);
                d[y.fi]=len;
                s.in(y.fi);
            }
        }
    }
    if (d[n-1]==inf) d[n-1]=-1;
    cout<<d[n-1];
}


//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
//#define highest(x) (63 - __builtin_clzl(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
#define mp(x, y) make_pair(x, y)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int x, y; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class T> string to_string(complex<T> x){ return to_string(make_pair(x.real(), x.imag())); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int at(lint i, int j){ return (i >> j) & 1; }
random_device rnd;
bool is_in_board(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }
lint inv2 = power(2, mod - 2, mod);

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(s[0] != s.back()){
        cout << 1 << endl;
        return 0;
    }

    rep(i, n - 1){
        if(s[i] != s[0] && s[i + 1] != s[0]){
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define F first
#define S second
//#pragma GCC optimize("Ofast")

const int maxn = 2e5 + 5, md = 998244353;

int vis[maxn], n, f[maxn], cnt;
bool c[maxn];
vector<int> cycle, adjr[maxn];
ll ans = 1;

int dfs3(int v)
{
	int A = 1;
	for(auto u : adjr[v])
		A += dfs3(u);

	return A;
}

void dfs2(int v)
{
	c[v] = 1;
	if(!c[f[v]])
		dfs2(f[v]);
}

void dfs(int v)
{
	vis[v] = cnt;
	if(vis[f[v]] == cnt)
		cycle.pb(f[v]);
	else if(!vis[f[v]])
		dfs(f[v]);
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> f[i];
		adjr[f[i]].pb(i);
	}

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

	memset(vis, 0, maxn);

	for(auto v : cycle)
		if(!c[v])
		{
			//cout << v << " ";
			dfs2(v);
			ans = ans * 2 % md;
		}
	//return 0;

	/*for(int i = 1; i <= n; i++)
		if(c[f[i]]&& !c[i])
		{
			ans *= dfs3(i) + 1;
			ans %= md;
		}*/

	cout << ans - 1 << '\n';

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  lli x;
  cin >> a >> b;
  cin >> c >> x;
  ans = a * x - b * c;
  out(ans);
  // out((ans > 0 ? "Yes" : "No"));
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e;
    cin>>a>>b>>c>>d;
    e=(a*d)-(b*c);
    cout<<e<<endl;

    return 0;
}


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

#define int long long int
#define double long double

#define all(x) begin(x), end(x)
#define Done(x) cout<<x<<endl; return;
#define endl '\n'

void solve(){
	int n; cin>>n;
	int m; cin>>m;
	map<int,int>occur;
	for(int i=0;i<n;i++){
		int a; cin>>a;
		int b; cin>>b; b++;
		int c; cin>>c;
		occur[a]+=c;
		occur[b]-=c;
	}
	int ans=0;
	int curr=0;
	int last=0;
	for(auto p:occur){
		int dist=p.first-last;
		ans+=dist*min(curr,m);
		last=p.first;
		curr+=p.second;
	}
	cout<<ans<<endl;
}

int32_t main(){
	// Remove for Interactive Problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();

	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
	return 0;
}

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

    vector<int>G[200005],r[200005];
    int in[200005],out[200005],depth[200005];
    int id;

    void dfs(int i,int d=0){
      in[i]=id++;
      depth[i]=d;
      for(int u:G[i]){dfs(u,d+1);}
      out[i]=id;
    }

    void solve(){
      int n;
      cin>>n;
      rep(i,n-1){
        int p;
        cin>>p;
        p--;
        G[p].push_back(i+1);
      }
      dfs(0);
      rep(i,n){r[depth[i]].push_back(in[i]);}
      rep(i,n){sort(r[i].begin(),r[i].end());}
      int Q;
      cin>>Q;
      rep(i,Q){
        int u,d;
        cin>>u>>d;
        u--;
        int ans=lower_bound(r[d].begin(),r[d].end(),out[u])-lower_bound(r[d].begin(),r[d].end(),in[u]);
        cout<<ans<<endl;
      }
    }
    int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      solve();
      return 0;
    }


#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define N 100007
#define mod 19260817
#define mid ((l + r) >> 1)
using namespace std;
typedef long long ll;

inline ll rd() {
    ll x = 0;
    bool f = 0;
    char c = getchar();
    for(; !isdigit(c); c = getchar())
        if (c == '-') f = 1;
    for(; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

inline ll fpow(ll x, ll t, ll p) {
  ll res = 1;
  x = x % p;
  while (t) {
    if (t & 1) res = 1ll * res * x % p;
    x = 1ll * x * x % p; t >>= 1;
  }
  return res;
}

int main() {
    int a = rd();
    int b = rd();
    int c = rd();
    int t;
    if (b > 1 && c >= 2) t = fpow(b, c, 4) + 4;
    else t = fpow(b, c, 10000000);
    printf("%lld\n", fpow(a, t, 10));
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#define INF 0x7fffffff
#define IOS ios::sync_with_stdio(false);cin.tie();cout.tie(0)

using namespace std;
typedef long long ll;

const int N=1e5+100;
//const int mod=1e9+7;
string str;
bool st[N];

int main()
{
    IOS;
    int n;
    cin>>n;
    cin>>str;
    if(n==1) {cout<<"-1"<<endl;return 0;}
    if(str[0]!=str[n-1])
    {
        cout<<"1"<<endl;
    }
    else
    {
        int w1=0;
        for(int i=0;i<n;i++)
        {
            if(str[i]!=str[0])
                st[i]=true;
        }
        int flag=0;
        for(int i=1;i<n;i++)
            if(st[i-1]&&st[i]) flag=1;
        if(!flag) cout<<"-1"<<endl;
        else cout<<"2"<<endl;
    }
    return 0;
}


#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(v) for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

int main() {
  IN(ll, N);
  vector<ll> As(N);
  vector<ll> Bs(N);
  INALL(As);
  INALL(Bs);

  ll ans = 0;
  REP(i, N) {
    ans += As.at(i) * Bs.at(i);
  }

  if (ans == 0) yes();
  else no();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPE(i, l, n) for (ll i = l; i <= ll(n); i++)
#define FORA(i, I) for (const auto& i : I)
#define ALL(v) v.begin(), v.end()
#define UQ(v) v.erase(unique(ALL(v)), v.end())
#define ACM(v) accumulate(ALL(v), 0LL)
#define C cin >>
#define P(str) cout << str << endl
#define VLL vector<ll>
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
const long long INF = 1100000000000000000;
int main() {
    ll x, y, a, b;
    C x >> y >> a >> b;
    ll ans = 0;
    while (true) {
        if (x > (x + b) / a || x >= y / a) {
            break;
        }
        x *= a;
        ans++;
    }
    ans += (y - 1 - x) / b;
    cout << ans << endl;
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

#define rep(i,start,end) for(ll i = start; i <= end; ++i)
#define rrep(i,end,start) for(ll i = end; i >= start; --i)
#define parr(a,n) rep(i,0,n-1){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) rep(i,0,n-1)cin >> a[i]
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define mset(a,x) memset(a, x, sizeof(a))
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

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

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

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/
#define MX 100000

ll n;

vvl gr(400001,vl());

bool vis[400001];
bool cycle = false;

int dfs(int i, int p = -1) {
  if (vis[i]) {
    cycle = true;
    return 0;
  }

  vis[i] = 1;

  int ans = 1;
  ll cntP = 0;
  for (auto j: gr[i]) {
    if (j == p && !cntP) {
      cntP++;
      continue;
    }
    ans += dfs(j,i);
  }

  return ans;
}

void solve() {
  cin >> n;
  // vector<pll> vp(n);
  ll u,v;

  mset(vis,0);

  rep(i, 0, n - 1) {
    cin >> u >> v;
    gr[u].pb(v);
    gr[v].pb(u);
  }

  ll ans = 0;

  rep(i,0,400000) {
    if (gr[i].size() == 0 || vis[i]) {
      continue;
    }

    cycle = false;
    ans += dfs(i);
    // debug(ans, cycle);
    if (!cycle) ans--;
  }

  cout << ans << "\n";

}

int main() {
  IO();
  int t = 1;

  // cin >> t;

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

/*******************************************************/

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

vector<pair<int,int>>adj[205]; //wt vertex;

int32_t main() {

    fast

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

    // 100      200
    // 1 		101
    for(int i=1;i<=100;i++){
    	adj[i].push_back({x,i+100});
    	adj[i+100].push_back({x,i});
    	if(i!=100){
    		adj[i+1].push_back({x,i+100});
    		adj[i+100].push_back({x,i+1});
    	}
    }
    for(int i=1;i<=99;i++){
    	adj[i].push_back({y,i+1});
    	adj[i+1].push_back({y,i});
    	adj[100+i].push_back({y,i+101});
    	adj[101+i].push_back({y,100+i});
    }

    vector<int>d;
    d.assign(205,1e18);
    d[a] = 0;
    multiset<pair<int,int>>q; //dist vertex
    q.insert({0,a});
    while(!q.empty()){
    	auto curr = *q.begin();
    	q.erase(q.begin());
    	int v = curr.second;

    	for(auto neigh:adj[v]){
    		int to =neigh.second;
    		int len = neigh.first;
    		if(d[to]>d[v]+len){
    			q.erase({d[to],to});
    			d[to] = d[v]+len;
    			q.insert({d[to],to});
    		}
    	}
    }
    cout << d[b+100] << endl;

    // y = min(y,2*x);
    // if(a>b){
    // 	// int ans = (a-b)*x+(a-b-1)*(x);
    // 	// ans = min(ans,(a-b)*x+y);
    // }
    // else if(a!=b){
    // 	int ans = 2;
    // }
    // ans = (a-b-)
    // // if(b>a){
    // // 	swap(a,b);swap(x,y);
    // // }
    // // if()
    // // if(2*x<y){
    // int ans = abs(b - a) * (2 * x + x);
    // // if(a > b)
    //     ans = min(ans, max(0LL, (abs(b - a) - 1)) * y + x);
    // cout << ans << endl;
    // // }
    // // else{
    // // 	int ans = max(0LL,(abs(b-a)-1))*y+x;
    // // 	cout << ans << endl;
    // // }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define f first
#define s second
#define MOD (int)1e9+7
#define INF (int)1e9
#define endll "\n"
#define input(n, a) for (int i=0;i<n;++i) {cin>>a[i];}
#define Laylo cin.tie(0), cout.tie(0), cin.sync_with_stdio(0), cout.sync_with_stdio(0);

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef map<string, int> mpsi;
typedef map<int, int> mpii;

int main() {
    Laylo

    char x,y,z;
    cin >> x >>y >>z;
    if(x == y && x == z){cout <<"Won"<<endll;}
    else{cout <<"Lost"<<endll;}

}

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

int main(){
  string C;
  cin >> C;
  if(C[0]==C[1] && C[1]==C[2]) cout << "Won" << endl;
  else cout << "Lost" << endl;
  return 0;
}


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

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

using int64 = long long;

namespace {

void solve() {
    int n;
    int64 X;
    cin >> n >> X;

    vector<int64> as(n), ubs(n), xs(n);
    repeat (i, n) cin >> as[i];
    repeat (i, n - 1) ubs[i] = as[i + 1] / as[i];
    ubs[n - 1] = 1e18;

    for (int i = n - 1; i >= 0; i--) {
        xs[i] = X / as[i];
        X %= as[i];
    }

    vector<int64> dp(2, 0);
    dp[0] = 1;
    repeat (i, n) {
        vector<int64> next(2, 0);
        repeat (j, 2) repeat (nj, 2) {
            // x + z + j = y + as[i] * nj
            // z = as[i] * nj - x - j
            int64 z = ubs[i] * nj - xs[i] - j;
            if (0 <= z && z < ubs[i]) {
                next[nj] += dp[j];
            }
            // y = x + j - as[i] * nj
            int64 y = xs[i] + j - ubs[i] * nj;
            if (0 < y && y < ubs[i]) {
                next[nj] += dp[j];
            }
        }
        swap(dp, next);
    }
    cout << dp[0] << endl;
}

}

int main() {
    solve();

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a/gcd(a,b))*b;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){

}
ll dp[200010][16]={};
//i桁目まで決め,種類数がj
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  string s;

  cin >> s >> k;
  n = s.size();

  set<char> sc;
  vector<ll> dp2(n+1,0);
  for(i=0;i<n;i++){
    sc.insert(s[i]);
    dp2[i+1] = (ll)sc.size();
  }
  sc.clear();
  string ss="0123456789ABCDEF";
  //dp[1][1] = (ll)(s[0]>='A'?s[0]-'A'+10:s[0]-'0')-1;
  for(i=0;i<n;i++){
    ll tmp = (ll)(s[i]>='A'?s[i]-'A'+10:s[i]-'0');
    //cout << tmp << ' ';
    for(j=(i==0?1:0);j<tmp;j++){
      dp[i+1][dp2[i]+(sc.count(ss[j])?0:1)] += 1;
    }
    sc.insert(s[i]);
  }
  for(i=2;i<=n;i++){
    dp[i][1] += 15;
  }
  for(i=0;i<n;i++){
    for(j=1;j<=k;j++){
      dp[i+1][j] += dp[i][j] * (j);
      dp[i+1][j] %= MOD1;
      dp[i+1][j+1] += dp[i][j] * (16-j);
      dp[i+1][j+1] %= MOD1;
    }
  }
  result = dp[n][k]+(dp2[n]==k?1:0);
  result %= MOD1;

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


#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int MOD2 = 998'244'353;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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

int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    for(auto &e: A) std::cin >> e;
    std::vector<std::vector<int>> dp(N, std::vector<int>(N));
    for(int i{0}; i < N; ++i){
        for(int j{i}; j < N; ++j){
            int r{0};
            for(int k{i}; k <= j; ++k){
                r |= A[k];
            }
            dp[i][j] = r;
        }
    }
    int ans{2*INF};
    for(int i{0}, i_len{1 << (N -1)}; i < i_len; ++i){
        int res{}, prv{};
        for(int j{0}, j_len{N-1}; j < j_len; ++j){
            if((i >> j) & 1){
                res ^= dp[prv][j];
                prv = j + 1;
            }
        }
        res ^= dp[prv][N-1];
        chmin(ans, res);
    }
    std::cout << ans << std::endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll p[4000005],cnt[2005][2005],hell=pow(10,9)+7;
ll mul(ll x,ll y){
	x=(x*y)%hell;
	return x;
}
ll add(ll x,ll y){
	x+=y;
	if(x>=hell)
		x-=hell;
	return x;
}
ll sub(ll x,ll y){
	x-=y;
	if(x<0)
		x+=hell;
	return x;
}
void solve(){
	ll n,m,c=0;
	cin>>n>>m;
	vector<string> v(n);
	for(ll i=0;i<n;i++){
		cin>>v[i];
		for(ll j=0;j<m;j++)
			if(v[i][j]=='.')
				c++;
	}
	for(ll i=0;i<n;i++)
		for(ll j=0;j<m;j++){
			if(v[i][j]=='#')
				continue;
			ll k=j;
			while(k<m&&v[i][k]=='.')
				k++;
			ll x=k-j;
			while(j<k){
				cnt[i][j]=x;
				j++;
			}
			j--;
		}
	for(ll j=0;j<m;j++)
		for(ll i=0;i<n;i++){
			if(v[i][j]=='#')
				continue;
			ll k=i;
			while(k<n&&v[k][j]=='.')
				k++;
			ll x=k-i;
			while(i<k){
				cnt[i][j]+=x-1;
				i++;
			}
			i--;
		}
	ll res=0;
	for(ll i=0;i<n;i++)
		for(ll j=0;j<m;j++)
			if(v[i][j]=='.'){
				ll val=sub(p[cnt[i][j]],1);
				val=mul(val,p[c-cnt[i][j]]);
				res=add(res,val);
			}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    p[0]=1;
    for(ll i=1;i<4000005;i++)
    	p[i]=mul(p[i-1],2);
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


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

struct fastio{fastio(){cin.tie(nullptr);ios_base::sync_with_stdio(false);std::cout<<std::fixed<<setprecision(10);}}oitsaf;
#define rep(i,n) for(int i=0;i<int(n);++i)
constexpr char newl = '\n';
template<class T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){for(auto const& vi:v)os<<vi<<" ";return os;}
#if _local
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){std::cerr<<elm<<std::flush;return*this;}}dout;
#else
struct debug_structure{template<class T>debug_structure&operator<<(const T&elm){return*this;}}dout;
#endif
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  cin >> a;
  vector<int> S(2e6);
  set<int> st;
  rep(i, m) { S[a[i]]++; }
  rep(i, 2e6) if (S[i] == 0) st.emplace(i);
  int mex = 0;
  while (S[mex])
    mex++;
  int ans = mex;
  for (int i = m; i < n; ++i) {
    dout << mex << newl;
    S[a[i]]++;
    S[a[i - m]]--;
    if (S[a[i]] == 1) {
      st.erase(a[i]);
    }
    if (S[a[i - m]] == 0) {
      st.emplace(a[i - m]);
      if (chmin(mex, a[i - m])) {
        chmin(ans, mex);
      }
    }
    dout << mex << newl;
    if (S[a[i]] == 1 and a[i] == mex) {
      auto itr = st.upper_bound(mex);
      mex = *itr;
    }
  }
  cout << (ans) << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, s, k;
ll extgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = extgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
void solve()
{
	cin >> n >> s >> k;
	ll x, y, d;
	if ((d = extgcd(k, n, x, y)) != 1ll)
	{
		if (s % d)
		{
			puts("-1");
			return ;
		}
		else
		{
			k /= d, n /= d, s /= d;
		}
	}
	x *= -s;
	y *= -s;
	cout << (x % n + n) % n << endl;
}
int main()
{
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define sortv(v) sort(v.begin(),v.end())
#define sorta(A,N) sort(A,A+N)
#define rep(i,a,N) for(ll i=a;i<N;i++)
#define test(T) ll T; cin>>T; while(T--)
#define f first
#define s second
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll gcd(ll a,ll b){
    if(!a)
        return b;
    else
        return gcd(b%a,a);
}
ll power(ll a,ll b,ll mod=MOD){
    a%=mod;
    ll res=1;
    while(b){
        if(b&1)
            res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}/*
ll N=1e6+1;
vector<ll>prime(N);
void sieve(){
    rep(i,0,N) prime[i]=i;
    for(ll i=4;i<N;i+=2)
        prime[i]=2;
    for(ll i=3;i*i<N;i+=2){
        if(prime[i]==i)
            for(ll j=i*i;j<N;j+=i)
                if(prime[j]==j)
                    prime[j]=i;
    }
}
vector<ll> factor(ll N){
    vector<ll> fac;
    while(N!=1){
        fac.pb(prime[N]);
        N/=prime[N];
    }
    return fac;
}*/
void solve(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll N;
    cin>>N;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<string(N,'0')<<string(N,'1')<<"0\n";
}
int main(){
    speed;
    test(T){
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int t;
  cin>>t;
  for (int i = 0; i < t; ++i)
  {
    int n;
    cin>>n;
    string s;
    bool one = false, zero = false;
    for (int i = 0; i < 3; ++i)
    {
      cin>>s;
      if (s.front() == '0' && s.back() == '0') zero = true;
      else if (s.front() == '1' && s.back() == '1') one = true;
    }
    if (zero && one) {
      cout << 1;
      for (int i = 0; i < n; ++i)
      {
        cout << 0;
      }
      for (int i = 0; i < n; ++i)
      {
        cout << 1;
      }
    } else if (zero) {
      for (int j = 0; j < n; ++j)
      {
        cout << 1;
      }
      cout << 0;
      for (int j = 0; j < n; ++j)
      {
        cout << 1;
      }
    } else {
      for (int j = 0; j < n; ++j)
      {
        cout << 0;
      }
      cout << 1;
      for (int j = 0; j < n; ++j)
      {
        cout << 0;
      }
    }
    cout << "\n";
  }
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    vector<ll> data(n);
    rep(i,0,n){
        cin >> data[i];
    }
    ll m=0;
    ll y=0;
    ll t=0;
    rep(i,0,n){
        m += abs(data[i]);
        y += pow(data[i],2);
        if(t<abs(data[i])){
            t = abs(data[i]);
        }
    }
    double ans  = sqrt(y);
    cout << std::setprecision(15) << m <<endl;
    cout << std::setprecision(15) << ans <<endl;
    cout << std::setprecision(15) << t << endl;
    // cout << m << endl;
    // cout<< y <<endl;
    // cout<<t << endl;
    return 0;

}

#include <cstdio>
#include <cstring>
#include <algorithm>
#define rep(a,b,c) for(int a=b;a<=c;a++)
const int p=3;
const int N=4e5+5;
int fac[4],inv[4];
inline int C(int n,int m) { return (n>=m)?(1ll*fac[n]*inv[m]*inv[n-m]%p):0; }
inline int lucas(int n,int m) {
	if(!m) return 1;
	return 1ll*C(n%p,m%p)*lucas(n/p,m/p)%p;
}
int n,ans;
char s[N];
inline int get(char S) {
	if(S=='B') return 0;
	else if(S=='W') return 1;
	else return 2;
}
int main() {
	fac[0]=1; inv[0]=1; fac[1]=1; inv[1]=1; fac[2]=2; inv[2]=2;
	scanf("%d",&n);
	scanf("%s",s+1);
	rep(i,1,n) (ans+=lucas(n-1,i-1)*get(s[i]))%=p;
	if(!(n&1)) ans=(3-ans)%p;
	if(ans==0) putchar('B');
	if(ans==1) putchar('W');
	if(ans==2) putchar('R');
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int n, k;
  cin >> n >> k;

  int a = n;

  int g1 = 0;
  int g2 = 0;

  for (int i = 0; i < k; i++) {
    // 各桁の数値を取り出す
    int num = a;
    vector<int> v1, v2;
    while (true) {
      v1.push_back(num % 10);
      if (num < 10) {
        break;
      }
      num /= 10;
    }
    v2 = v1;

    // g1をつくる
    g1 = 0;
    sort(v1.begin(), v1.end(), greater<int>());
    for (size_t j = 0; j < v1.size(); j++) {
      g1 *= 10;
      g1 += v1[j];
    }

    // g2をつくる
    g2 = 0;
    sort(v2.begin(), v2.end());
    for (size_t j = 0; j < v2.size(); j++) {
      g2 *= 10;
      g2 += v2[j];
    }

    a = g1 - g2;
  }

//  cout << g1 << endl;
//  cout << g2 << endl;
  cout << a << endl;

  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 998244353;
// const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
// const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L
//cout << fixed << setprecision(10) << Min << endl << Max << endl;
int main() {
	int N; cin >> N;
	ll ans = 0;
	rep(i, N) {
		ll A, B;
		cin >> A >> B;
		ans += (B - A + 1)*(A+B)/2;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

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

const int max_n = 200111, inf = 1000111222;

vector<int> a, b;

int main()
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        a.PB(x);
    }
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        b.PB(x);
    }
    reverse(b.begin(), b.end());
    multiset<int> ms;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        ms.insert(a[i]);
        ms.insert(b[i]);
        auto it = (--ms.end());
        sum += *it;
        ms.erase(it);
    }
    cout << sum << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll inf=998244353;
int main(){
  ll n;cin>>n;
  vector<ll>a(n);
  for(ll i=0;i<n;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  ll ans=0;
  for(ll i=0;i<n;i++){ans+=a.at(i)%inf*a.at(i)%inf;ans%=inf;}
  ll tmp=a.at(n-1);
  for(ll i=n-2;i>=0;i--){
    ans+=a.at(i)*tmp%inf;
    ans%=inf;
    tmp*=2;
    tmp%=inf;
    tmp+=a.at(i);
    tmp%=inf;
  }
  cout<<ans<<endl;
}