#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  map<ll,P> m;
  rep(i,n) {
    if(!m.count(a[i].S)) m[a[i].S]=P(a[i].F,a[i].F);
    m[a[i].S].F=min(m[a[i].S].F,a[i].F);
    m[a[i].S].S=max(m[a[i].S].S,a[i].F);
  }
  vector<P> p;
  p.pb(P(0,0));
  tr(it,m) {
    P q=it->S;
    p.pb(P(q.F,q.S));
  }
  p.pb(P(0,0));
  n=p.size();
  ll dp[n][2];
  rep(i,n)rep(j,2)dp[i][j]=MAXL;
  dp[0][0]=dp[0][1]=0;
  REP(i,1,n) {
    dp[i][0]=min(dp[i][0],dp[i-1][0]+abs(p[i-1].F-p[i].S)+abs(p[i].F-p[i].S));
    dp[i][0]=min(dp[i][0],dp[i-1][1]+abs(p[i-1].S-p[i].S)+abs(p[i].F-p[i].S));
    dp[i][1]=min(dp[i][1],dp[i-1][0]+abs(p[i-1].F-p[i].F)+abs(p[i].F-p[i].S));
    dp[i][1]=min(dp[i][1],dp[i-1][1]+abs(p[i-1].S-p[i].F)+abs(p[i].F-p[i].S));
  }
  pr(dp[n-1][0]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

#include <bits/stdc++.h>

using namespace std;

#define debug(x) cerr << #x << " = " << x << endl
#define boost ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) { cout << endl; }

template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

template<typename T>
inline void read(T& x) {
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template<typename T, typename ...Args>
inline void read(T& x, Args&... args) { read(x), read(args...); }

constexpr int MAXN = 2e5 + 5, MOD = 1e9 + 7;
#define int long long

int n;
array<long long, MAXN> x, c, l, r;
long long dp[MAXN][2];

signed main() {
    boost;
    cin >> n;
    vector<int> vc;
    memset(dp, 0x3f, sizeof(dp));
    fill(l.begin(), l.end(), 2e9);
    fill(r.begin(), r.end(), -2e9);
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> c[i];
        l[c[i]] = min(l[c[i]], x[i]);
        r[c[i]] = max(r[c[i]], x[i]);
        vc.push_back(c[i]);
    }
    sort(vc.begin(), vc.end());
    int cnt = unique(vc.begin(), vc.end()) - vc.begin();
    for (int i = 0; i < cnt; i++) {
        int co = vc[i], L = l[co], R = r[co], prePos = 0;
        if (i == 0) {
            if (R * L < 0) {
                dp[0][0] = R * 2 - L; // stop at left
                dp[0][1] = 2LL * (-L) + R;
            } else {
                if (R > 0) {
                    dp[0][0] = 2LL * R - L;
                    dp[0][1] = R;
                } else {
                    dp[0][0] = -L;
                    dp[0][1] = 2LL * (-L) - R;
                }
            }
        } else {
            prePos = l[vc[i - 1]];
            if ((R - prePos) * (L - prePos) < 0) {
                dp[i][0] = min(dp[i][0], dp[i - 1][0] + (R - prePos) * 2 - (L - prePos));
                dp[i][1] = min(dp[i][1], dp[i - 1][0] + 2LL * (-(L - prePos)) + (R - prePos));
            } else {
                if ((R - prePos) > 0) {
                    dp[i][0] = min(dp[i][0], dp[i - 1][0] + 2LL * (R - prePos) - (L - prePos));
                    dp[i][1] = min(dp[i][1], dp[i - 1][0] + R - prePos);
                } else {
                    dp[i][0] = min(dp[i][0], dp[i - 1][0] + (-(L - prePos)));
                    dp[i][1] = min(dp[i][1], dp[i - 1][0] + 2LL * (-(L - prePos)) - (R - prePos));
                }
            }

            prePos = r[vc[i - 1]];
            if ((R - prePos) * (L - prePos) < 0) {
                dp[i][0] = min(dp[i][0], dp[i - 1][1] + (R - prePos) * 2 - (L - prePos));
                dp[i][1] = min(dp[i][1], dp[i - 1][1] + 2LL * (-(L - prePos)) + (R - prePos));
            } else {
                if ((R - prePos) > 0) {
                    dp[i][0] = min(dp[i][0], dp[i - 1][1] + 2LL * (R - prePos) - (L - prePos));
                    dp[i][1] = min(dp[i][1], dp[i - 1][1] + R - prePos);
                } else {
                    dp[i][0] = min(dp[i][0], dp[i - 1][1] + (-(L - prePos)));
                    dp[i][1] = min(dp[i][1], dp[i - 1][1] + 2LL * (-(L - prePos)) - (R - prePos));
                }
            }
        }
    }
    cout << min(dp[cnt - 1][0] + abs(l[vc.back()]), dp[cnt - 1][1] + abs(r[vc.back()]));
    return 0;
}


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

#define X real()
#define Y imag()

using namespace std;
typedef long long ll;
typedef complex<double> point;

#define INF numeric_limits<int>::max()

//Graphs
class AdjGraph{
		ll V;
		list<ll> *l;
		vector<ll> checker;
		vector<bool> visited;
	public:
		AdjGraph(ll Vert){
			this->V = Vert;
			l = new list<ll>[Vert];
			vector<bool> vs(Vert,false);
			this->visited = vs;
		}
		void AddEdge(ll x,ll y){
			l[x].push_back(y);
			l[y].push_back(x);
		}
		//Template for DFS
		void DFS(ll at){
			this->visited[at] = true;
			for(int x:l[at]){
				if(this->visited[x] != true){
					DFS(x);
				}
			}
		}
		bool CheckConnect(ll x,ll y){
			DFS_c(x);
			reset_visited();
			for(ll t: checker){
				if(t == y){
					checker.erase(checker.begin(),checker.end());
					return true;
				}
			}
			checker.erase(checker.begin(),checker.end());
			return false;
		}
		void reset_visited(){
			vector<bool> new_visited(this->V,false);
			this->visited = new_visited;
		}

	private:

		void DFS_c(ll at){
			this->visited[at] = true;
			checker.push_back(at);
			for(ll x:l[at]){
				if(this->visited[x] != true){
					DFS_c(x);
				}
			}
		}

};

class AdjGraphWeight{

		ll V;
		vector<pair<ll,ll> > *edge;
		vector<bool> *visited;
	public:

		AdjGraphWeight(ll Vert){
			this->V = Vert;
			edge = new vector<pair<ll,ll> >[Vert];
			visited = new vector<bool>(Vert,false);
		}

};

//Number Theory
bool isPrime(ll x){
	for(int i = 2;i < sqrt(x)+1;i++){
		if(x % i == 0){
			return false;
		}
	}
	return true;
}

vector<ll> prime_divs(ll x){
	vector<ll> divs;
	for(int i = 0;i < sqrt(x)+1;i++){
		if((isPrime(i) == true) && (x % i == 0)){
			divs.push_back(i);
			if(isPrime(x/i) == true){
				divs.push_back(x/i);
			}
		}
	}
	return divs;
}

vector<ll> exponents(ll x){
	vector<ll> divs = prime_divs(x);
	vector<ll> res;
	for(int i = 0; i< divs.size();i++){
		ll temp = 0;
		double expression = x/pow(divs[i],temp);
		while(ceil(x/pow(divs[i],temp)) == x/pow(divs[i],temp)){
			temp++;
		}
		res.push_back(temp);
	}
	return res;
}

vector<ll> get_all_divs(ll x){
	vector<ll> divs;
	divs.push_back(1);
	divs.push_back(x);
	if(isPrime(x) != true){
		for(int i = 2;i < sqrt(x)+1;i++){
			if(x % i == 0){
				divs.push_back(i);
				if(i*i != x){
					divs.push_back(x/i);
				}
			}
		}
	}
	return divs;
}

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

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

int main(){
	ios::sync_with_stdio(false);
	double x,y,z;
	cin >>  x >> y >> z;
	double temp = y/x;
	if(x == z){
		cout << y-1 << endl;
	}else{
		double res = floor(temp*z-1/x);
		if(res == x){
			cout << res-1 << endl;
		}else{
			cout << res << endl;
		}
	}
	return 0;
}

#include <iostream>

int main() {
    double x, y, z;
    scanf("%lf %lf %lf", &x, &y, &z);

    // y/x > z/?

    int answer = 0;
    for (int v = 0; v < 1e9; ++v) {
        if (x/y >= z/v) {
            break;
        } else {
            answer = v;
        }
    }

    std::cout << answer;

    return 0;
}


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

const int maxn=200005;
int n,ql,qr,lst,s,t;
vector<int>edge[maxn];
int dist[maxn],par[maxn],dep[maxn],que[maxn],ans[maxn];
bool bad[maxn];

void bfs(int s){
	for(int i=1;i<=n;i++)dist[i]=-1;
	dist[s]=0;
	ql=1;qr=0;
	que[++qr]=s;
	while(ql<=qr){
		int x=que[ql++];
		for(int i=0;i<int(edge[x].size());i++){
			int y=edge[x][i];
			if(dist[y]<0)dist[y]=dist[x]+1,par[y]=x,que[++qr]=y;
		}
	}
}

void dfs(int x,int p){
	lst=x;
	int yy=0;
	for(int i=0;i<int(edge[x].size());i++){
		int y=edge[x][i];
		if(y==p)continue;
		if(!bad[y])
			ans[y]=ans[lst]+dist[lst]+dist[y]-2*dist[x],dfs(y,x);
		else yy=y;
	}
	if(yy)
		ans[yy]=ans[lst]+dist[lst]+dist[yy]-2*dist[x],dfs(yy,x);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	bfs(1);
	for(int i=1;i<=n;i++)if(!s||dist[i]>dist[s])s=i;
	bfs(s);
	for(int i=1;i<=n;i++)if(!t||dist[i]>dist[t])t=i;
	while(t!=s)bad[t]=true,t=par[t];
	ans[s]=1;
	dfs(s,0);
	for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' ');
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double lf;
typedef long double Lf;
typedef pair<int, int> pii;

const int maxn = 2e5 + 5;

int n;
int dep[maxn], ans[maxn], mx[maxn];
vector<int> g[maxn];

inline void findFar(int u, int p, int &s){
	if(~p)
		dep[u] = dep[p] + 1;
	else
		dep[u] = 0;
	if(!~s || dep[u] > dep[s])
		s = u;
	mx[u] = 1;
	FOR(i, 0, g[u].size()) if(g[u][i] != p)
		findFar(g[u][i], u, s), mx[u] = max(mx[u], mx[g[u][i]] + 1);
	return;
}

inline void dfs(int u, int p, int &clk){
	ans[u] = clk;
	vector<pii> son;
	FOR(i, 0, g[u].size()){
		int v = g[u][i];
		if(v == p)
			continue;
		son.PB(MP(mx[v], v));
	}
	sort(son.begin(), son.end());
	FOR(i, 0, son.size())
		dfs(son[i].snd, u, ++clk);
	++clk;
	return;
}

int main(){
	scanf("%d", &n);
	FOR(i, 1, n){
		int u, v; scanf("%d%d", &u, &v);
		--u; --v;
		g[u].PB(v); g[v].PB(u);
	}

	int s = -1, t = -1;
	findFar(0, -1, s);
	findFar(s, -1, t);

	int clk = 1;
	dfs(s, -1, clk);

	FOR(i, 0, n)
		printf("%d ", ans[i]); puts("");
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int where[1 << 20];
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	VI a(n), b(n), p(n);
	FOR(i, 0, n)
		cin >> a[i];
	FOR(i, 0, n)
		cin >> b[i];
	vector<PII> arr;
	FOR(i, 0, n)
	{
		cin >> p[i];
		p[i]--;
		where[p[i]] = i;
		if(i == p[i]) continue;
		if(a[i] <= b[p[i]])
		{
			cout << "-1" << endl;
			return 0;
		}
		arr.PB(MP(a[i], i));
	}
	vector<PII> ans;
	sort(ALL(arr));
	FOR(j, 0, SZ(arr))
	{
		int i = arr[j].Y;
		if(p[i] == i) continue;
		ans.PB(MP(i, where[i]));

		where[p[i]] = where[i];
		swap(p[i], p[where[i]]);
	}

	cout << SZ(ans) << endl;
	FOR(i, 0, SZ(ans))
		cout << ans[i].X + 1 << " " << ans[i].Y + 1 << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N;
vector<LL> dp;
vector<string> S;
vector<bool> used;

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

void dfs(int v) {
  used[v] = true;
  dp[v]++;
  for (int i = 0; i < N; ++i) {
    if (!used[i] && S[v][i] == '1') {
      dfs(i);
    }
  }
}

int main() {
  cin >> N;
  S.resize(N);
  for (int i = 0; i < N; ++i) cin >> S[i];

  dp.resize(N, 0);
  for (int i = 0; i < N; ++i) {
    used = vector<bool>(N, false);
    dfs(i);
  }

  double sum = 0;
  for (double v : dp) {
    sum += N / v;
  }
  printf("%.15f\n", sum / N);
}


#include<bits/stdc++.h>

using namespace std;

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

template<class T>
ostream& operator <<(ostream& os, const vector<T>& v){
	if(!v.empty()){
		for(int i=0, size=v.size(); i<size-1; ++i)os << v[i] << " ";
		os<<v.back();
	}
	return os;
}

int main(){

	int n, w;
	cin >> n >> w;

	vector<long long> times(200010, 0);

	for(int i=0; i<n; ++i){
		int s, t, p;
		cin >> s >> t >> p;
		times[s]+=p;
		times[t]-=p;
	}

	for(int i=1, size= times.size(); i<size; ++i){
		times[i] += times[i-1];
	}

	for(auto&& t : times){
		if(t > w){
			cout <<"No"<<endl;
			fflush(stdout);
			return 0;
		}
	}

	cout <<"Yes"<<endl;
	fflush(stdout);
	return 0;
}

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n; lnt w;
	std::cin >> n >> w;
	V<lnt> cost((int)3e5,0);
	rep(i,n) {
		int s,t; lnt p;
		std::cin >> s >> t >> p;
		cost[s]+=p;
		cost[t]-=p;
	}
	rep(i,(int)3e5-4) {
		cost[i+1]+=cost[i];
		if(cost[i]>w) {
			print("No");
			return 0;
		}
	}
	print("Yes");
}


#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, fa[N], ans[N], vis[N];
vector<pair<int, int> > G[N];
int Find(int x) {
	return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
void dfs(int u, int lst) {
	for (auto &e : G[u]) {
		int v = e.first;
		if (v == lst) continue;
		if (ans[u] == e.second) ans[v] = -1;
		else ans[v] = e.second;
		dfs(v, u);
	}
	if (ans[u] == -1) {
		for (auto &e : G[u]) {
			int v = e.first;
			if (v == lst) continue;
			vis[ans[v]] = 1;
		}
		if (ans[lst] >= 1) vis[ans[lst]] = 1;
		for (int i = 1; i <= n; i++) if (!vis[i]) {
			ans[u] = i;
			break;
		}
		for (auto &e : G[u]) {
			int v = e.first;
			if (v == lst) continue;
			vis[ans[v]] = 0;
		}
		if (ans[lst] >= 1) vis[ans[lst]] = 0;
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i <= m; i++) {
		int u, v, c;
		scanf("%d%d%d", &u, &v, &c);
		if (Find(u) != Find(v)) {
			fa[Find(u)] = Find(v);
			G[u].emplace_back(v, c);
			G[v].emplace_back(u, c);
		}
	}
	ans[1] = -1;
	dfs(1, 0);
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

/* by Hyperhydrochloric Acid */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); ++i)
#define cont(i, n)          for(int i = 1; i <= (n); ++i)
#define circ(i, a, b)       for(int i = (a); i <= (b); ++i)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

int n, m;
vector<pair<int, int> > nei[1 << 17];
bool lgl[1 << 17];
int res[1 << 17];

void inline dfs(int now, int col, bool sme = 0) {
	if(!sme) res[now] = col;
	else res[now] = col % n + 1;
	lgl[now] = 1;
	loop(i, SZ(nei[now])) {
		int to = nei[now][i].first, co = nei[now][i].second;
		if(lgl[to]) continue;
		dfs(to, co, co == res[now]);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	cont(i, m) {
		int a, b, c; scanf("%d%d%d", &a, &b, &c);
		nei[a].pub(mak(b, c)); nei[b].pub(mak(a, c));
	}
	dfs(1, 1);
	cont(i, n) printf("%d\n", res[i]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ii pair<int,int>
#define fi first
#define se second
#define ld long double
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define eb emplace_back

const int mxn = 1e5+5;

void multi(int64_t &a, int64_t b, const int64_t &MOD){
	a%=MOD; b%=MOD;
	a=((a*b)%MOD+MOD)%MOD;
}

void add(int64_t &a, int64_t b, const int64_t &MOD){
	a%=MOD; b%=MOD;
	a=((a+b)%MOD+MOD)%MOD;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	const int64_t MOD = (int64_t)998244353;
	int n; cin>>n;
	vector<int64_t>a(n); for(auto &x:a)cin>>x;
	int64_t ans=0;
	map<pair<int,int>,int>cnt;
	sort(all(a));
	//naive
	if(0){
		for(int mask=1; mask<(1<<n); mask++){
			int64_t mn=MOD,mx=MOD;
			cerr<<mask<<": ";
			for(int i=0; i<n; i++){
				if((mask>>i)&1){
					cerr<<"1";
					if(mn==MOD){
						mn=a[i];
						mx=a[i];
					}else{
						mn=min(mn,a[i]);
						mx=max(mx,a[i]);
					}
				}else{
					cerr<<"0";
				}
			}
			cerr<<": ";
			if(mn==MOD)continue;
			cerr<<mn<<" "<<mx<<" ";
			cnt[{mn,mx}]++;
			multi(mn,mx,MOD);
			add(ans,mn,MOD);
			cerr<<mn<<" "<<ans<<"\n";
		}
	}

	int64_t prev = 0;
	for(int i=0; i<n; i++){
		add(prev,prev,MOD);
		if(i)add(prev,-a[i-1],MOD);
		add(prev,a[i],MOD);
		int64_t cur = prev;
		multi(cur,a[i],MOD);
		add(ans,cur,MOD);
	}

	cout<<ans<<"\n";
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define Pll pair<long,long>
#define mp make_pair
#define INF 1000000001
#define INFl 1000000000000000001
#define ll long long
using namespace std;

struct edge{long to,cost,k;};

int main() {
    int N;cin>>N;
    vector<long> A(N);
    rep(i,N)cin>>A[i];
    sort(all(A));
    long c=0;
    long mod=998244353;
    long a=A[N-1];
    rep(i,N-1){
        int j=N-i-2;
        c+=A[j]*a;
        c%=mod;
        a*=2;
        a%=mod;
        a+=A[j];
        a%=mod;
    }
    rep(i,N){
        c+=A[i]*A[i];
        c%=mod;
    }
    cout<<c%mod<<endl;
}


#include <bits/stdc++.h>
using namespace std;
/* overload to_string   */
template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) {  return '"' + s + '"';}string to_string(const char* s) {  return to_string((string) s);}string to_string(bool b) {  return (b ? "true" : "false");}string to_string(vector<bool> v) {  bool first = true;  string res = "{";  for (int i = 0; i < static_cast<int>(v.size()); i++) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(v[i]);  }  res += "}";  return res;}template <size_t N>string to_string(bitset<N> v) {  string res = "";  for (size_t i = 0; i < N; i++) {    res += static_cast<char>('0' + v[i]);  }  return res;}template <typename A>string to_string(A v) {  bool first = true;  string res = "{";  for (const auto &x : v) {    if (!first) {      res += ", ";    }    first = false;    res += to_string(x);  }  res += "}";  return res;}template <typename A, typename B>string to_string(pair<A, B> p) {  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
/* claim debug    不能打印普通数组、自定义结构体 */
void debug_out() { cout << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {  cout << " " << to_string(H);  debug_out(T...);}
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
/* read  ---  只能输入整数数字(int , ll) */
template<typename T> void read(T &x){ x = 0;char ch = getchar();long long f = 1; while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;}
template<typename T, typename... Args> void read(T &first, Args& ... args) { read(first); read(args...);}  // read end
/*-------------------------------------------------------------------------------------------------------------------------*/
#define rep(i, a, b)        for(register int (i) = (a); (i) <= (int)(b); (i)++)
#define repd(i, b, a)       for(register int (i) = (b); (i) >= (int)(a); (i)--)
#define set(a, x)           memset((a), (x), sizeof(a))
#define get(a, id)          get<(id)>(a)

#define int                 long long    /* int 变成 long long */

typedef pair<int, int> pii;
typedef long long ll;
/*--------------------------------------------------------------------------------------------------------------------------*/
const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;

int n;

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    if( a== b){
        cout << c;
    }else if (a == c) {
        cout << b;
    }else if( b == c){
        cout << a;
    }else
        cout << 0 << endl;
}

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

    int T = 1;
    // cin >> T;
    rep(i, 1, T){
        // cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}

#include <iostream>
using namespace std;
int main() {
int a,b,c;
cin>>a>>b>>c;
if(a==b){
cout<<c;
}
else if(b==c){
cout<<a;
}
else if(a==c){
cout<<b;
}
else{
cout<<"0";
}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pb push_back
#define pii pair<int,int>
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9 + 7,mxn=2e5 + 5;

signed main(){

  gok

  int n,m;
  cin>>n>>m;
  int gr[n][m];
  int mi=1e9;
  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
          cin>>gr[i][j];
          mi = min(mi,gr[i][j]);
      }
  }

  int an=0;

  for(int i=0;i<n;i++)
  {
      for(int j=0;j<m;j++)
      {
         an += gr[i][j]-mi;
      }
  }

cout<<an;

    return 0;
    }

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;
int main() {
	int n, q;
	cin >> n >> q;
	vector<ll> a;
	for(int i = 0; i < n; ++i) {ll x; cin >> x; a.push_back(x);}
	sort(a.begin(), a.end());
	//for (int i = 0; i < n; ++i) cout << a[i] << " ";
	//cout << endl;
	vector<ll>su;
	su.push_back(a[0] - 1);
	for (int i = 1; i < n; ++i) {
		ll k = (a[i] - a[i - 1] - 1);
		if (k < 0) k = 0;
		su.push_back(k);
	}
	//for (int i = 0; i < n; ++i) cout << su[i] << " ";
	//cout << endl;
	for (int i = 1; i < n; ++i) su[i] += su[i - 1];
	//for (int i = 0; i < n; ++i) cout << su[i] << " ";
	//cout << endl;
	while(q--) {
		ll k1;
		cin >> k1;
		int in = lower_bound(su.begin(), su.end(), k1) - su.begin();
		if (in > 0) {
			ll suc = k1 - su[in - 1];
			//cout << "SU " << in << endl;
			//cout << suc << " " << k1  << " " << su[in - 1] << endl;
			cout << a[in - 1] + suc << endl;
		} else {
			//cout << "IN 0" << endl;
			cout << k1 << endl;
		}
	}
}


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

int main() {

  int X, Y, Z;
  cin >> X >> Y >> Z;

  int ans = 0;
  if(Y*Z % X == 0) ans = Y*Z/X - 1;
  else ans = Y*Z/X;

  cout << ans << endl;

}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) for(int i=((n)-1);i>=0;--i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    ld x,y,z;
    cin>>x>>y>>z;
    ld a=y/x;
    rep(i,1000010){
        if(y/x<=(ld)i/z){
            cout<<i-1;
            return 0;
        }
    }
}


#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>

using namespace std;

bool mark[400000];
char s[400001];

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

    vector<pair<int, int>> v;
    for (int i = 0; i < 2 * N; i++) {
        int x;
        scanf("%d", &x);
        v.emplace_back(x, i);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < N; i++) {
        mark[v[i].second] = true;
    }

    stack<int> st;
    for (int i = 0; i < 2 * N; i++) {
        if (st.size() == 0 || mark[st.top()] == mark[i]) st.push(i);
        else {
            s[st.top()] = '(';
            s[i] = ')';
            st.pop();
        }
    }

    printf("%s\n", s);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int mod = 998244353;
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    n *= 2;
    int a[n], tag[n];
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) cin >> a[i], v.push_back({a[i], i});
    sort(v.begin(), v.end());
    for (int i = 0; i < n / 2; i++) tag[v[i].se] = 1;
    for (int i = n / 2; i < n; i++) tag[v[i].se] = -1;
    int ans[n]{}, pre[n + 1]{};
    map<int, queue<int>> v2;
    for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + tag[i], v2[pre[i + 1]].push(i);
    for (int i = 0; i < n; i++){
        if (ans[i]) continue;
        ans[i] = 1;
        v2[pre[i + 1]].pop();
        int p = v2[pre[i]].front();
        v2[pre[i]].pop();
        ans[p] = 2;
        //cout << pre[i] << ' ' << p << '\n';
    }
    for (int i = 0; i < n; i++) cout << (ans[i] == 1 ? '(' : ')');
}


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

#define     I(X)            scanf("%d",&(X))
#define     II(X, Y)        scanf("%d%d",&(X),&(Y))
#define     III(X,Y,Z)      scanf("%d%d%d",&(X),&(Y),&(Z))
#define     IL(X)           scanf("%lld",&(X))
#define     IIL(X, Y)       scanf("%lld%lld",&(X),&(Y))
#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     all(v)          v.begin(),v.end()
#define     pii             pair<int,int>
#define     MAX             100000000000014
#define     MIN             -100000000000014
#define     gti             greater<int>
#define     PI1             acos(-1.0)
#define     pi2             2.0*acos(0.0)
#define     endl            '\n'

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

   map<int,int>Hash;
   for(int i = 0 ; i < n; i++){
    int x;
    cin>>x;
    Hash[x]++;
   }
   vector<int>ans;
   for(int i = 0 ; i < m; i++){
    int x;
    cin>>x;
        Hash[x]++;
   }
   for(auto i : Hash)
    if(Hash[i.first] == 1)
        cout<<i.first<<" ";
   cout<<endl;

}

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// clang-format off
#define PI 3.14159265358979323846264338327950L
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep2(i,s,n) for (int i=(s); i<(int)(n); ++i)
#define prep_ios(do_flush) if(!do_flush){ ios::sync_with_stdio(false);cin.tie(nullptr);constexpr char endl='\n'; } cout<<fixed<<setprecision(20)
#define put(expr) cout<<expr<<'\n'
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "[ "; for (auto v: vec) os << v << " "; os << "]"; return os; }template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "< "; for (auto v: vec) os << v << " "; os << ">"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{ "; for (auto v: vec) os << v << " "; os << "}"; return os; }template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{ "; for (auto v: vec) os << v << " "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{ "; for (auto v: mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{ "; for (auto v: mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f80;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef map<int, int> mii;
typedef __int128_t i128; i128 parse(string &s) { i128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } istream &operator>>(istream &is, i128 &v) { string s; is >> s; v = parse(s); return is; } ostream &operator<<(ostream &os, const i128 &v) { if (v == 0) return (os << "0"); i128 num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) s.push_back('0' + (char)(num % 10)); reverse(s.begin(), s.end()); return (os << s); }
template <typename T> bool chmax(T &now, const T &cand) { if (now < cand) { now = cand; return true; } return false; } template <typename T> bool chmin(T &now, const T &cand) { if (now > cand) { now = cand; return true; } return false; }
template <typename T> T gcd(const T &a, const T &b) { if (a % b == 0) return b; return gcd(b, a % b); } template <typename T> T lcm(const T &a, const T &b) { return a * b / gcd(a, b); }
template <typename T> T nCr(const T &n, T k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; int result = n; for (int i = 2; i <= k; ++i) { result *= (n - i + 1); result /= i; } return result; }
const int INF = 1<<30; /* INF > 10^9 */ const i64 INFLL = 1LL<<60; /* INFLL > 10^18 */ const string YES = "Yes", NO = "No";

// clang-format on?

int main() {
  prep_ios(true);

  vi anss = vi(1010);

  i64 N, M;
  cin >> N >> M;

  rep(i, N) {
    i64 tmp;
    cin >> tmp;
    ++anss[tmp];
  }

  rep(i, M) {
    i64 tmp;
    cin >> tmp;
    ++anss[tmp];
  }

  bool first = true;
  rep(i, anss.size()){
    if (anss[i]==1){
      if (first) {
        first = false;
      } else{
        cout << ' ';
      }
      cout<<i;
    }
  }
  cout<<endl;
}


#include "bits/stdc++.h"

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(x) cerr << #x << " == " << (x) << '\n';
#define all(X) begin(X), end(X)
#define size(X) (int)std::size(X)

using ll = long long;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int main()
{ _
    int n, m;
    cin >> n >> m;

    constexpr int mmax = 20;

    int cnt[2]{};

    for (int i = 0; i < n; ++i)
    {
        bitset<mmax> b;
        cin >> b;
        cnt[b.count() % 2] += 1;
    }

    ll res = 1LL * cnt[0] * cnt[1];
    cout << res << endl;

    exit(0);
}

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

using namespace std;

#define LL long long
#define mem(s, v) memset(s, v, sizeof s)
#define FILEIN(s) freopen(s".in", "r", stdin)
#define FILEOUT(s) freopen(s".out", "w", stdout)

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

const int maxn = 1e5 + 5;

int n, m;

int a[maxn];
long long ans;
int cnt1[maxn], cnt2[maxn];
char op[30];

int main() {
	n = read(); m = read();
	for (int i = 1; i <= n; ++ i) {
		scanf("%s", op + 1);
		int res = 0;
		for (int j = 1; j <= m; ++ j) {
			if (op[j] == '1') ++ res;
		}
		cnt1[i] = cnt1[i - 1];
		cnt2[i] = cnt2[i - 1];
		if (res & 1) ans += cnt2[i], cnt1[i]++;
		else ans += cnt1[i], cnt2[i] ++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define ZERO {puts("0"); return 0;}
#define NO {puts("No"); return 0;}
#define ALL(obj) begin(obj), end(obj)
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vl>

template<class T> void chmin(T& a, T b) { if (a > b) a = b; }
template<class T> void chmax(T& a, T b) { if (a < b) a = b; }

int const X = 101;
double dp[X][X][X];

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

	for (int i = 99; i >= a; --i)
		for (int j = 99; j >= b; --j)
			for (int k = 99; k >= c; --k)
			{
				double now = 0;
				now += dp[i+1][j][k] * i;
				now += dp[i][j+1][k] * j;
				now += dp[i][j][k+1] * k;
				dp[i][j][k] = now / (i+j+k) + 1;
			}
	printf("%.10f\n", dp[a][b][c]);
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
 long  double  r,x,y;
   long double  d;
    cin>>r>>x>>y;
    d=sqrt((x*x)+(y*y));

    if(d==r)
    cout<<1;
    else
    if(d<=(2*r))
    cout<<2;
    else
    cout<<ceil(d/r);

    return 0;
}


/*
ID: gurban1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=5e3+5;
const int mod=998244353;
int n,m;
ll f[maxn],inv[maxn];
ll dp[maxn][maxn];

ll binmod(ll a,ll b) {if(b==0)return 1;ll x=binmod(a*a%mod,b>>1);return b&1?x*a%mod:x;}

ll choose(int a,int b){
	return (((f[a] * inv[b]) % mod)*inv[a-b])%mod;
}

int main(){
	// freopen("","r",stdin);
	// freopen("","w",stdout);

	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;

	f[0] = 1;
	for(int i = 1;i <= n;i++) f[i] = (f[i-1] * i) % mod;
	inv[n] = binmod(f[n],mod-2);

	for(int i = n-1;i >= 0;i--) inv[i] = ((i+1) * inv[i+1])%mod;

	for(int i = 0;i <= n;i += 2) dp[0][i] = choose(n,i);

	// for(int i = 0;i <= n;i+=2) cout<<i<<' '<<dp[0][i]<<'\n';

	int lg = __lg(m);
	for(int i = 1;i <= lg;i++){
		for(int j = 0;j <= n;j += 2){
			for(int k = (j<<i);k <= m;k += 2){
				ll cnt = (choose(n,j) * dp[i-1][k-(j<<i)])%mod;
				dp[i][k] = (dp[i][k] + cnt)%mod;
			}
		}
	}
	cout<<dp[lg][m];
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define X 200010
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n,p[200010],place[200010];
	cin>>n;
	rep(i,n){
		cin>>p[i]; p[i]--;
		place[p[i]]=i;
	}
	vector<ll> v;
	bool ok=1;
	ll s=0;
	while(1){
		ll i=place[s]-1;
		if(i<s){ok=0;break;}
		for(;i>=s;i--){
			v.push_back(i);
			swap(p[i+1],p[i]);
		}
		s=place[s];
		if(s==n-1)break;
	}
	rep(i,n)ok&=(p[i]==i);
	if(ok){
		rep(i,v.size())cout<<v[i]+1<<"\n";
	}
	else cout<<-1<<endl;
}


#include <bits/stdc++.h>

#include <iostream>
#include <set>
#include <vector>

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

using namespace std;
typedef long long ll;

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

int main() {
  ll a,b,c;
  cin >> a >>b >>c;
  cout << (7-a)+(7-b)+(7-c) << endl;
  return 0;
}

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

int main() {
  int A,B,C;cin>>A>>B>>C;int s[4];
  A%=10;
  B%=4;
  s[1]=A;s[2]=(A*A)%10;s[3]=s[2]*A%10;s[0]=s[3]*A%10;
  if(B==0||B==1)cout<<s[B];
  else if(B==2){
    if(C==1)cout<<s[2];
    else cout<<s[0];
  }
  else{
    if(C%2==0)cout<<s[1];
    else cout<<s[3];
  }cout<<endl;
}


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

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

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

	int T;
	cin >> T;

	rep(t, T) {
		int L, R;
		cin >> L >> R;

		ll LR = R - L;
		ll tmp = LR - L;
		if (tmp >= 0) co((tmp + 2) * (tmp + 1) >> 1);
		else co(0);
	}

	Would you please return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(ll i = a; i < (n); ++i)
#define repD(i, a, n) for(ll i = a; i > (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (long long) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
// #define mp make_pair
#define pb push_back

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
const long double PI = 3.141592653589793238462643383;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<double> vd;
typedef vector<pii> vii;
long long Ceil(long long a, long long b){
    if(a%b==0) return a/b;
    else return (a/b)+1;
}
ll p=1000000007;
// ll p = 1000000000000000000+5;
float E = 0.00000000000001;
ll power(ll x, ll y){
    if(y==0){
        return 1;
    }
    if(y%2==0){
        ll q=power(x,y/2);
        q=q%p;
        return (q*q)%p;
    }
    ll q=power(x,y/2);
    q=q%p;
    return ((x%p)*((q*q)%p))%p;
}
bool isPowerOfTwo (long long x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}

long long int gcd(long long int a, long long int b){
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long int mod(long long int a, long long int b) {
    long long int ret = a%b; return ret>=0? ret: ret+b;
}
int backward(int i, string &s, vector<int> &back){
    if(i == 0)
        return 0;
    if(s[i-1] == 'R')
        return back[i-1];
    else
        return 0;
}
int forward(int i, string &s, vector<int> &forw){
    int n = s.size();
    if(i == n)
        return 0;
    if(s[i] == 'L')
        return forw[i+1];
    else
        return 0;
}
int main(){
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    cin>>t;
    while(t--){
        ll l,r;cin>>l>>r;
        // long long ans = 0;int diff = l;
        // for(int i = l ; i <= r ; i++){
        //     ans += max(0, r-(i+diff)+1);
        // }
        // long long upp = min(r, r-l+1);
        // if(l == r){
        //     if(l == 0)
        //         cout<<1<<endl;
        //     else
        //         cout<<0<<endl;
        //     continue;
        // }
        // ll upp = r-l+1;
        // cout<<(r-l+1)*(upp-l+1)-(upp*(upp+1))/2 + ((l-1)*l)/2<<endl;
        // cout<<ans<<endl;
        ll num = r-2*l+1;
        if(num>0)
            cout<<num*(num+1)/2<<endl;
        else
            cout<<0<<endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <functional>
#include <utility>
#include <tuple>
#include <numeric>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <regex>
#include <stack>
#include <limits>
#include <climits>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	long long n;
	cin >> n;
	n *= 2;
	int res = 0;
	for (long long i = 1; i*i < n; ++i) {
		if (n % i == 0) {
			long long d = i;
			if ((n / d - d + 1) % 2 == 0) ++res;
			d = n / i;
			if ((n / d - d + 1) % 2 == 0) ++res;
		}
	}
	cout << res << endl;
	return 0;
}

#include<bits/stdc++.h>
#define Pair pair<ll,int>
#define ar array
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std ;
const ll LLMAX = 9223372036854775807;

int main(){
    ll n;
    cin>>n;
    ll cur_low = n;
    ll num_len = 1;
    ll sum = n;
    ll res = 0;
    while(cur_low>0){
        if((sum-n)%num_len==0){
            ll diff = (sum-n)/num_len;
            if(diff<0)
                break;
            res++;
            cur_low-=diff;
            sum = n+cur_low-1;
            //cout<<"cur low "<<cur_low<<endl;
            //cout<<"num len "<<num_len<<endl;
            cur_low--;
            num_len++;
        }
        else{
            cur_low--;
            sum+=cur_low;
            num_len++;
        }
    }
    /*
    res = 1+res*2;
    ll s = sqrt(1+8*n);
    if(s*s == 1+8*n){
        if((-1+s)%2==0)
            res++;
    }
    */
    cout<<2*res<<endl;
}


#include <stdio.h>
#include <iostream>

int main(){
   int n;
   int *a;
   int max1_i=0;
   int max2_i=0;
   std::cin >> n;
   a = new(int[2<<(n-1)]);
   int max1 = 0;
   int max2 = 0;

   for (int i=0; i< (2<<(n-1)); i++) {
      std::cin >> a[i];
      if (n >= 2) {
         if (i< (2<<(n-2))) {
            if (max1 < a[i]) {
               max1 = a[i];
               max1_i = i+1;
            }
         }else{
            if (max2 < a[i]) {
               max2 = a[i];
               max2_i = i+1;
            }
         }
      }
   }

   if (n == 1) {
      if (a[0] < a[1] ) {
         std::cout << "1" << std::endl;
      }else{
         std::cout << "2" << std::endl;
      }
      return 0;
   }

   if (max1 < max2) {
      std::cout << max1_i << std::endl;
   }else{
      std::cout << max2_i << std::endl;
   }
   return 0;
}

#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define dpll deque<pll>
#define mapll map<ll,ll>
#define umapll umap<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define ms(a,x) memset(a,x,sizeof(a))
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
template<class T>using uset=unordered_set<T,custom_hash>;
int32_t main()
{
    clock_t clk = clock();
    fast_az_fuk
    ll testcase; cin>>testcase;
    for(ll test=1;test<=testcase;test++)
    {//cout<<"Case #"<<test<<": ";
        ll n; cin>>n;
        if(n&1) cout<<"Odd\n";
        else if((n/2)&1) cout<<"Same\n";
        else cout<<"Even\n";
    }
    // cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
    return 0;
}


#include <cstdio>
#include <algorithm>
#define int long long
const int N = 200005;
int n, x[N], y[N], o[N], pp[N], p, qth, q, m;
struct ABC{
    int k, co, b;
}dx, dy;
struct AandB{
    int A, B, id;
}qu[N];
struct Anss{
    int x, y, id;
}ans[N];
bool cmp(AandB x, AandB y){ return x.A < y.A; }
bool cmp2(Anss x, Anss y){ return x.id < y.id; }
signed main() {
    scanf("%lld", &n);
    for(int i = 1; i <= n; i++)
        scanf("%lld%lld", &x[i], &y[i]);
    scanf("%lld", &m);
    for(int i = 1; i <= m; i++){
        scanf("%lld", &o[i]);
        if(o[i] >= 3) scanf("%lld", &pp[i]);
    }
    scanf("%lld", &q);
    for(int i = 1; i <= q; i++){
        scanf("%lld%lld", &qu[i].A, &qu[i].B);
        qu[i].id = i;
    }
    std::sort(qu+1, qu+1+q, cmp);
    qth = 1;
    while(qth <= q && qu[qth].A == 0){
        ans[qth].x = x[qu[qth].B], ans[qth].y = y[qu[qth].B];
        ans[qth].id = qu[qth].id;
        qth++;
    }
    dx.co = 0, dx.k = 1;
    dy.co = 1, dy.k = 1;
    ABC temp = dx;
    for(int i = 1; i <= m; i++){
        int op = o[i];
        if(op == 1){
            temp = dx; dx = dy; dy = temp;
            dy.k = -dy.k; dy.b = -dy.b;
        }
        else if(op == 2){
            temp = dx; dx = dy; dy = temp;
            dx.k = -dx.k; dx.b = -dx.b;
        }
        else if(op == 3){
            p = pp[i];
            dx.k = -dx.k; dx.b = -dx.b;
            dx.b += 2*p;
        }
        else if(op == 4){
            p = pp[i];
            dy.k = -dy.k; dy.b = -dy.b;
            dy.b += 2*p;
        }
        while(qth <= q && qu[qth].A == i){
            if(dx.co == 0) ans[qth].x = x[qu[qth].B], ans[qth].y = y[qu[qth].B];
            else ans[qth].x = y[qu[qth].B], ans[qth].y = x[qu[qth].B];
            ans[qth].x = ans[qth].x * dx.k + dx.b;
            ans[qth].y = ans[qth].y * dy.k + dy.b;
            ans[qth].id = qu[qth].id;
            qth++;
        }
//       printf("%d %d %d | %d %d %d\n", dx.co, dx.k, dx.b, dy.co, dy.k, dy.b);
    }
    std::sort(ans+1, ans+1+q, cmp2);
    for(int i = 1; i <= q; i++)
        printf("%lld %lld\n", ans[i].x, ans[i].y);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
int n,x[N],y[N],m,q;
ll fx[N],fy[N],px[N],py[N];
int jg[N];
int main(){
	scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	scanf("%d",&m);
	fx[0]=fy[0]=1;
	for(int i=1;i<=m;i++){
		fx[i]=fx[i-1],fy[i]=fy[i-1],px[i]=px[i-1],py[i]=py[i-1],jg[i]=jg[i-1];
		int op,p;scanf("%d",&op);
		if(op>2) scanf("%d",&p);
		else swap(fx[i],fy[i]),swap(px[i],py[i]),jg[i]^=1;
		if(op==1) fy[i]=-fy[i],py[i]=-py[i];
		else if(op==2) fx[i]=-fx[i],px[i]=-px[i];
		else if(op==3) fx[i]=-fx[i],px[i]=2*p-px[i];
		else fy[i]=-fy[i],py[i]=2*p-py[i];
	}
	scanf("%d",&q);while(q--){
		int a,b;scanf("%d%d",&a,&b);
		if(!jg[a]) printf("%lld %lld\n",fx[a]*x[b]+px[a],fy[a]*y[b]+py[a]);
		else printf("%lld %lld\n",fx[a]*y[b]+px[a],fy[a]*x[b]+py[a]);
	}
	return 0;
}


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

using ll = long long;
using ld = long double;

vector <int> graf[200005];
int in[200005];
int out[200005];

int tjm;

vector <int> vec[500005];

void dfs(int v, int d){
    in[v] = ++tjm;
    vec[d].push_back(in[v]);
    for(auto c : graf[v]) dfs(c, d+1);
    out[v] = ++tjm;
}

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=2; i<=n; i++){
        int x;
        cin >> x;
        graf[x].push_back(i);
    }
    dfs(1, 0);
    int q;
    cin >> q;
    while(q--){
        int u, d;
        cin >> u >> d;
        auto l = lower_bound(vec[d].begin(), vec[d].end(), in[u]);
        auto r = lower_bound(vec[d].begin(), vec[d].end(), out[u]);
        r--;
        if(l == vec[d].end()){
            cout << "0\n";
            continue;
        }
        cout << r-l+1 << "\n";
    }
    return 0;
}

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

const int maxn = 200005;
vector<int> G[maxn];
vector<P> g[maxn];
struct node
{
    int u, d;
} arr[maxn];
int siz[maxn], hson[maxn], ans[maxn], d[maxn], d1[maxn];
int dfs0(int u, int f, int t)
{
    siz[u] = 1;
    d[u] = t;
    int maxx = 0;
    for (int i = 0; i < G[u].size(); i++)
    {
        int v = G[u][i];
        if (v == f)
            continue;
        siz[u] += dfs0(v, u, t + 1);
        if (siz[v] > maxx)
        {
            hson[u] = v;
            maxx = siz[v];
        }
    }
    return siz[u];
}

void jisuan(int u, int w, int ad)
{
    d1[d[u]] += ad;
    for (auto v : G[u])
    {
        if (v == w)
            continue;
        jisuan(v, w, ad);
    }
}

void dfs1(int u, int f, int keep)
{
    for (int i = 0; i < G[u].size(); i++)
    {
        int v = G[u][i];
        if (v == f || v == hson[u])
            continue;
        dfs1(v, u, 0);
    }
    if (hson[u] != 0)
        dfs1(hson[u], u, 1);
    jisuan(u, hson[u], 1); /*
    cout << u << "-------" << d[u] << endl;
    for (int i = 0; i <= 8; i++)
        cout << d1[i] << " ";
    cout << endl;*/
    for (auto p : g[u])
    {
        ans[p.second] = d1[p.first];
    }
    if (!keep)
    {
        jisuan(u, 0, -1);
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int n, m, i, j;
    cin >> n;
    for (i = 2; i <= n; i++)
    {
        cin >> m;
        G[m].push_back(i);
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].emplace_back(y, i);
    }
    dfs0(1, 1, 0);
    dfs1(1, 1, 0);
    for (i = 0; i < q; i++)
        cout << ans[i] << '\n';
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

const int maxn = 200005;
int tree[maxn], hm[maxn], wm[maxn];
vector<int> vec[maxn];
void add(int k, int v) {
    k++;
    for (int i = k; i < maxn; i+=i&-i) tree[i] += v;
}
int qry(int k) {
    k++;
    int res = 0;
    for (int i = k; i >= 1; i-=i&-i) res += tree[i];
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 0; i < maxn; i++) tree[i] = 0;
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 0; i <= h; i++) hm[i] = w;
    for (int i = 0; i <= w; i++) wm[i] = h;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        hm[x] = min(hm[x], y-1);
        wm[y] = min(wm[y], x-1);
    }
    for (int i = 1; i <= h; i++) if (hm[i-1] == 0) hm[i] = 0;
    for (int i = 1; i <= w; i++) if (wm[i-1] == 0) wm[i] = 0;
    int res = 0;
    for (int i = 1; i <= h; i++) {
        res += hm[i];
        if (hm[i] != 0) vec[hm[i]].push_back(i);
        else add(i,1);
    }
    for (int i = 1; i <= w; i++) {
        if (wm[i] != 0) res += qry(wm[i]);
        for (int p : vec[i]) add(p, 1);
    }
    cout << res << '\n';
}
/*

 */

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


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
	int ret = 1; while (b > 0) {
		if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
	} return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
void chadd(int& x, int y) { x = add(x, y); }
void chsub(int& x, int y) { x = sub(x, y); }
void chmul(int& x, int y) { x = mul(x, y); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, K, M;
const int MA = 251010;
int dp[101][MA];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K >> mod;

	dp[0][0] = 1;
	rep(i, 0, 100) rep(sm, 0, MA) rep(use, 0, K + 1) if (sm + use * (i + 1) < MA) {
		chadd(dp[i + 1][sm + use * (i + 1)], dp[i][sm]);
	}

	rep(x, 1, N + 1) {
		int lft = x - 1, rht = N - x;
		int ans = 0;
		rep(sm, 0, MA) chadd(ans, mul(dp[lft][sm], dp[rht][sm], K + 1));
		chsub(ans, 1);
		printf("%d\n", ans);
	}
}

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n)-1;i >= 0;i--)
#define repr(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (x).size()

constexpr ll mod = 1000000007;

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

ll inv(ll x){
    ll res = 1;
    ll k = mod - 2;
    ll y = x;
    while(k){
        if(k&1)res = (res*y)%mod;
        y = (y*y) % mod;
        k /= 2;
    }
    return res;
}

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

    ll n,p;
    cin >> n >> p;
    vll pp(60);
    rep(i,60) {
        if (i == 0) pp[i] = p-2;
        else {
            pp[i] = pp[i-1] * pp[i-1] % mod;
        }
    }
    ll ret = p-1;
    ll cnt = n-1;
    rep(i,60) {
        if ((cnt >> i) & 1) {
            ret = ret * pp[i] % mod;
        }
    }
    cout << ret << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[311111];
ll sum[311111];
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		double ans = 0;
		for(int i = 1 ; i <= n ; i++){
			ans += (1.0/i)*n;
		}
		printf("%.6f\n",ans-1);
	}
	return 0;
}

#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define fsort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  cout << fixed << setprecision(15);
  ll n; cin >> n;
  ld ans=0;
  rep1(i,n-1){
    ans+=(ld)n/i;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define fo(i,n) for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ull unsigned long long
#define lld long double
#define all(x) x.begin(), x.end()
#define ps(x,y)         fixed<<setprecision(y)<<x
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define mod             1000000007
#define inf             1e18
typedef pair<int, int>    pii;
typedef pair<ll, ll>    pl;
typedef vector<int>        vi;
typedef vector<ll>        vl;
typedef vector<pii>        vpii;
typedef vector<pl>        vpl;
typedef vector<vi>        vvi;
typedef vector<vl>        vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//=======================

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
#endif
}

void solve() {

    vl v(3);
    fo(i, 3)cin >> v[i];
    sort(all(v));
    cout << v[1] + v[2];

}

int main() {

    c_p_c();

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

    return 0;
}

//

#include <iostream>

using namespace std;

int main() {
  short A, B, C; cin >> A >> B >> C;

  cout << max(A+B, max(A+C, B+C)) << "\n";

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<intt>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b)
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) {
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  freopen("OUt.txt","w",stdout);
  #endif
}

int main()
{
    fast_io
    go();
    int a,b,c;cin>>a>>b>>c;
    if(c==0 && a==0){
      cout <<"Aoki" << "\n";
      return 0;
    }
    if(c==1 && b==0){
      cout << "Takahashi" << "\n";
       return 0;
    }
    while(1){
      if(c==0 && a>0){
        a--;
      }
      else if(c==0 && a==0){
        cout <<"Aoki" << "\n";
        break;
      }
      if(c==1 && b>0){
        b--;
      }
      else if(c==1 && b==0){
        cout << "Takahashi" << "\n";
        break;
      }
      c^=1;
    }
}

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ll long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//typedef long long  MOD=1000000009;
ll MOD=998244353;
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll lcm(ll x, ll y) {ll res = (x * y) / __gcd(x, y); return res;}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void iofoj(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
#define F first
#define S second

void solution()
{
    ll k,i,j,n,m,w;
    cin>>n>>m>>k;
    if(k==0)
    {
        if(n>m)
        {
            cout<<"Takahashi";
        }
        else cout<<"Aoki";
    }
    else
    {
        if(m>n)cout<<"Aoki";
        else cout<<"Takahashi";
    }
    //else cout<<"";
}

int main(){
    fio
    //iofoj();
    // ll t;
    // cin>>t;
    // for(ll i=1;i<=t;i++)
    solution();
    return 0;
}


#include <iostream>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <random>
#include <cassert>

typedef long long ll;
using namespace std;

constexpr ll mod007 = 1000000007;
constexpr ll mod998 = 998244353;

ll N, F[88];
set<int>st;

int main() {
	cin >> N;
	F[1] = 1;
	for (int i = 2; i < 88; i++) {
		F[i] = F[i - 1] + F[i - 2];
	}
	for (int i = 87; i; i--) {
		if (N >= F[i]) {
			N -= F[i];
			st.insert(i);
		}
	}
	cout << 86 + st.size() << endl;
	for (int i = 86; i; i--) {
		if (st.find(i + 1) != st.end()) {
			if (i % 2) {
				cout << 2 << endl;
			}
			else {
				cout << 1 << endl;
			}
		}
		if (i % 2) {
			cout << 3 << endl;
		}
		else {
			cout << 4 << endl;
		}
	}
}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
//const bool debug = false;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	long long n; cin >> n;
	long long x = 1;
	long long y = 0;
	vector<vector<int>>ans;
	ans.push_back({});
	vector<long long>f;
	rep(i, 43) {
		ans.push_back({ 4 });
		y += x;
		f.push_back(y);
		ans.push_back({ 3 });
		x += y;
		f.push_back(x);
	}
	//cout << ans.size() << endl;
	rrep(i, f.size()) {
		if (n >= f[i]) {
			n -= f[i];
			ans[(ans.size() - 1) - (i + 1)].push_back(1 + (i + 1) % 2);
		}
	}
	vector<int>a;
	rep(i, ans.size()) {
		rep(j, ans[i].size()) {
			if ((0 == a.size()) && (ans[i][j] >= 3))continue;
			a.push_back(ans[i][j]);
		}
	}
	cout << a.size() << endl;
	rep(i, a.size()) cout << a[i] << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
#include <iomanip>
using namespace std;

using ll = long long;

#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define Sort(a) sort((a).begin(),(a).end())
#define Rev(a) reverse((a).begin(),(a).end())
#define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a)

int main() {
	ll H, W;
	cin >> H >> W;
	vector<string> s(H);
	For(i, 0, H) {
		cin >> s[i];
	}
	ll N = H + W - 1;
	ll is;
	ll h, w;
	ll ans = 1;
	bool end = false;
	For(i, 0, N) {
		is = -1;
		h = 0;
		w = i;
		if (w >= W) {
			h = i % W + 1 + (i / W - 1) * W;
			w = W - 1;
		}
		for (;;) {
			if (s[h][w] == 'R') {
				if (is != 1) {
					is = 0;
				}
				else {
					end = true;
					break;
				}
			}
			else if (s[h][w] == 'B') {
				if (is != 0) {
					is = 1;
				}
				else {
					end = true;
					break;
				}
			}
			h++;
			w--;
			if (h >= H || w < 0) {
				if (is == -1) {
					ans *= 2;
					ans %= 998244353;
					//co(h << " " << w << " " << ans<<" "<<i);
				}
				break;
			}
		}
	}
	if (end) {
		co(0);
	}
	else {
		co(ans);
	}
}

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

int main(){
    ll h,w;cin>>h>>w;
    vector<string> v(h);rep(i,h)cin>>v[i];
    vvi cnt(h+w,vi(3));
    rep(i,h)rep(j,w){
        if(v[i][j]=='R')cnt[i+j][0]++;
        if(v[i][j]=='B')cnt[i+j][1]++;
        if(v[i][j]=='.')cnt[i+j][2]++;
    }
    ll ans=1;
    rep(i,h+w){
        if(cnt[i][0]&&cnt[i][1])dame(0);
        if(cnt[i][0]||cnt[i][1])continue;
        if(cnt[i][2])ans=ans*2%mod;
    }
    out(ans);
}


#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 123;
const int mod = 998244353;

int n, m;
int a[N];

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		a[i] = a[i - 1];
		int j = i;
		bool ok = 1;
		while(j > 1) {
			ok &= ((j % 10) != 7);
			j /= 10;
		}

		j = i;
		while(j) {
			ok &= ((j % 8) != 7);
			j /= 8;
		}
		if(ok)
			a[i]++;

	}
	cout << a[n];
	return 0;
}
//N?

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define printclock cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n";
#define deb3(x, y, z) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(x, y, z, w) cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << " | " << #w << ": " << w << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb1(x) cout << #x << ": " << x << endl
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define prec(n) fixed << setprecision(n)
#define all(a) a.begin(), a.end()
#define vvi vector<vector<int>>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define pii pair<int, int>
#define vii vector<int>
#define ld long double
#define int long long
#define MOD LLONG_MAX
#define mp make_pair
#define pb push_back
#define endl "\n";
inline void get(vector<int> &arr, int n)
{
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        arr.push_back(a);
    }
}
inline void print(vector<int> &arr, int n)
{
    for (int i = 0; i < n; i++)
        cout << arr[i] << " ";
    cout << endl;
}
/*----------------------------------TEMPLATE------------------------------------*/
int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    fast;
    /*----------------------------PEEPEEPOOPOO-------------------------------------*/
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int curr = i;
        bool valid = true;
        while (curr)
        {
            if (curr % 10 == 7)
            {
                valid = false;
                break;
            }
            else
            {
                curr = curr / 10;
            }
        }
        if (!valid)
            continue;
        curr = i;
        while (curr)
        {
            if (curr % 8 == 7)
            {
                valid = false;
                break;
            }
            else
            {
                curr = curr / 8;
            }
        }
        if (valid)
            ans++;
    }
    cout << ans << endl;
    return 0;
}
/*--------------------------------PEEPEEPOOPOO-------------------------------------*/


#define ll long long
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > a[100005];
ll dp[20][500000];
ll n,c;
ll rec(ll i,ll mask){
    ll j,k,s=0,p;
    if(dp[i][mask]!=-1) return dp[i][mask];
    for(j=0;j<a[i-1].size();j++){
        p=0;
        for(k=0;k<18;k++){
            if(mask>>k&1){
                if(k<=a[i-1][j].first) p++;
            }
        }
        if(p>a[i-1][j].second) return dp[i-1][mask]=0;
    }
    if(i==n) return 1;
    for(j=0;j<n;j++){
        if(((mask>>j)&1)!=1){
            s+=rec(i+1,mask|1<<j);
        }
    }
    return dp[i][mask]=s;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,k,m,x,y,z,t;
    cin>>n>>m;
    c=pow(2,n)-1;
    for(i=0;i<m;i++){
        cin>>x>>y>>z;
        a[x-1].push_back({y-1,z});
    }
    memset(dp,-1,sizeof(dp));
    k=rec(0,0);
    cout<<k<<endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
#define fi first
#define se second
#define ii pair<int,int>
//#define
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
string s[2022];
vector<ii>vec[28];
ii st,ed;
int n,m;
int use[2022][2022],dist[2022][2022];
signed main()
{
	cin>>n>>m;
	rep(i,n){
		cin>>s[i];
		rep(j,m){
			if (s[i][j]=='S')
				st=mp(i,j);
			if (s[i][j]=='G')
				ed=mp(i,j);
			if (islower(s[i][j]))
				vec[s[i][j]-'a'].pb(mp(i,j));
		}
	}
	queue<ii>q;
	q.push(st);
	use[st.fi][st.se]=1;
	rep(i,n)rep(j,m)dist[i][j]=1000000000;
	dist[st.fi][st.se]=0;
	while (!q.empty()){
		ii cur=q.front();q.pop();
		//cout<<'('<<cur.fi<<','<<cur.se<<')'<<'\n';
		rep(i,4){
			int nx=cur.fi+dx[i],ny=cur.se+dy[i];
			if (nx<n && nx>=0 && ny<m && ny>=0 && !use[nx][ny] && s[nx][ny]!='#'){
				//cout<<'('<<nx<<','<<ny<<')'<<'\n';
				dist[nx][ny]=dist[cur.fi][cur.se]+1;
				q.push(mp(nx,ny));
				use[nx][ny]=1;
				if (islower(s[nx][ny])){
					int tt=s[nx][ny]-'a';
					rep(j,sz(vec[tt])){
						if (vec[tt][j]==mp(nx,ny)){
							vec[tt].erase(vec[tt].begin()+j);
							break;
						}
					}
				}
			}
		}
		//cout<<"OK\n";
		if (islower(s[cur.fi][cur.se])){
			int tt=s[cur.fi][cur.se]-'a';
			rep(j,sz(vec[tt])){
				int nx=vec[tt][j].fi,ny=vec[tt][j].se;
				dist[nx][ny]=dist[cur.fi][cur.se]+1;
				q.push(mp(nx,ny));
				use[nx][ny]=1;
			}
			vec[tt]=vector<ii>(0);
		}
	}
	cout<<(dist[ed.fi][ed.se]==1000000000?-1:dist[ed.fi][ed.se]);
	re 0;
}


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

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

const long long INF = 1LL << 60;

template <typename T>
void chmin(T& a, T b) {
    if(a > b) {
        a = b;
    }
}

template <typename T>
void chmax(T& a, T b) {
    if(a < b) {
        a = b;
    }
}

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

    char sentou = S[0];
    S[0] = S[1];
    S[1] = S[2];
    S[2] = sentou;

    cout << S << endl;

    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <sstream>
#define INF 1000000009
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;

int main() {

    int n;

    cin >> n;
    vector<int> a(n+1,0);
    rep(i,n){
      int x;
      cin >> x;
      if(x<1||x>n){
        cout << "No" << endl;
        return 0;
      }
      if(a[x]!=0){
        cout << "No" << endl;
        return 0;
      }
      a[x]++;
    }
    cout << "Yes" << 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>
#if __cplusplus >= 201703L
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) {
#else
        void operator()(const Args&... args) const {
#endif
            print(args...);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
#else
        void pvec(const T& vec, size_t sz) const {
#endif
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
#else
        void pmat(const T& mat, size_t h, size_t w) const {
#endif
            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() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    char fc = S.front();
    char bc = S.back();
    if (fc != bc) {
        prints()(1);
        return;
    }
    for (ll i = 1; i < N - 2; i++) {
        if (S[i] != fc && S[i + 1] != fc) {
            prints()(2);
            return;
        }
    }
    prints()(-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>
using namespace std;

typedef long long ll;

#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)<(y)?(y):(x))

ll comb(ll n, ll k){
    if (k == 0 || k == n) return 1;
    if (k == 1 || k == n-1) return n;
    return comb(n-1,k)+comb(n-1,k-1);
}

int main(){
    ll n,k;cin >> n >> k;--k;
    ll ss=0;
    for(ll xyz=3;xyz<=n+1;++xyz) ss += (xyz-1)*(xyz-2)/2;
    if(ss <= k){
        k -= ss;
    }else{
        for(ll xyz=3;xyz<=n+1;++xyz){
            ll s = (xyz-1)*(xyz-2)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=1;x<=xyz-2;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }
    }
    ss=0;
    for(ll xyz=n+2;xyz < 2*n+1;++xyz) ss += ((3*n-xyz+2)*(xyz-n-1) + (xyz-2)*(2*n-xyz+1))/2;
    if(ss <= k){
        k -= ss;
    }else{
        for(ll xyz=n+2;xyz < 2*n+1;++xyz){
            ll s = (3*n-xyz+2)*(xyz-n-1)/2;
            if(s <= k){
                k -= s;
            }else{
                for(ll x=1;x<=xyz-n-1;++x){
                    ll c = 2*n-xyz+1+x;
                    if(c <= k){
                        k -= c;
                        continue;
                    }
                    ll y=xyz-n-x+k;
                    cout << x << " " << y << " " << (xyz-x-y) << "\n";
                    return 0;
                }
            }
            s = (xyz-2)*(2*n-xyz+1)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=xyz-n;x<=n;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }
    }
    for(ll xyz=2*n+1;xyz<=3*n;++xyz){
        ll s = (3*n-xyz+2)*(3*n-xyz+1)/2;
        if(s <= k){
            k -= s;
            continue;
        }
        for(ll x=xyz-2*n;x<=n;++x){
            ll c = 2*n-xyz+1+x;
            if(c <= k){
                k -= c;
                continue;
            }
            ll y=xyz-n-x+k;
            cout << x << " " << y << " " << (xyz-x-y) << "\n";
            return 0;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc
#define next          sdNNNmNNNNNNNmds
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot
#define read               tyhyt
#define rank              ytmNmo
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define int long long
typedef long long ll;
using namespace std;

int cel(int, int);
int flr(int a, int b) {
    if(a < 0 && b < 0 || b < 0) {
        return flr(-a, -b);
    } else if(a < 0) {
        return -cel(-a, b);
    }
    return a / b;
}
int cel(int a, int b) {
    if(a < 0 && b < 0 || b < 0) {
        return cel(-a, -b);
    } else if(a < 0) {
        return -flr(-a, b);
    }
    return (a + b - 1) / b;
}

const int X = 111111, M = 10000;

int solve() {
    double xd, yd, rd;
    cin >> xd >> yd >> rd;
    int cx = round(xd * M), cy = round(yd * M), r = round(rd * M);
    int ans = 0;
    rep(i, -X, X) {
        int dx = M * i;
        int x = cx / M * M + dx;
        dx = x - cx;
        int lo = 0, hi = X * M;
        while(lo < hi) {
            int mid = lo + (hi - lo + 1) / 2;
            int dist = dx * dx + mid * mid;
            if(dist > r * r) {
                hi = mid - 1;
            } else {
                lo = mid;
            }
        }
        if(dx * dx + lo * lo > r * r) continue;
        int y1 = cel(cy - lo, M);
        int y2 = flr(cy + lo, M);
        int add = y2 - y1 + 1;
        ans += add;
    }
    cout << ans << endl;
    return 0;
}

signed main() {
    srand(time(NULL));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}

#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< "]";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,set<T> a){
  os << "{ ";
  for(auto itr=a.begin();itr!=a.end();++itr){
    os<< *itr << " ";
  }
  os<< "}";
  return os;
}
template<class T>
void ans_array(T begin,T end){
  auto itr=begin;
  cout<<*itr;
  ++itr;
  for(;itr!=end;++itr){
    cout<<' '<<*itr;
  }
  cout<<endl;
}
template<class T>
void ans_array_newline(T begin,T end){
  for(auto itr=begin;itr!=end;++itr){
    cout<<*itr<<endl;
  }
}

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> u, std::vector<long long> v, std::vector<long long> w){
  vector<vector<pll>> graph(N);
  REP(N-1){
    graph[u[i]].push_back(pll(v[i],w[i]));
    graph[v[i]].push_back(pll(u[i],w[i]));
  }
  ll ans=0;
  For(numidx,62){
    ll mask=(1LL<<numidx);
    dump(mask);
    auto dfs1=[&](ll cur,ll parent,auto dfs)->pll{
      pll curstatus(1,0);
      for (auto &&i : graph[cur])
      {
        if(i.first==parent)continue;
        pll tmp=dfs(i.first,cur,dfs);
        if((i.second)&mask){
          curstatus.first+=tmp.second;
          curstatus.second+=tmp.first;
        }else{
          curstatus.first+=tmp.first;
          curstatus.second+=tmp.second;
        }
      };
      return curstatus;
    };
    auto res=dfs1(0,-1,dfs1);
    dump(res);
    auto dfs2=[&](ll cur,ll parent,ll curstatus,auto dfs)->ll{
      ll ret=(curstatus?res.first:res.second);
      for (auto &&i : graph[cur])
      {
        if(i.first==parent)continue;
        if(mask&i.second){
          ret+=dfs(i.first,cur,curstatus^1,dfs);
        }else{
          ret+=dfs(i.first,cur,curstatus,dfs);
        }
      }
      return ret;
    };
    ll tmp=dfs2(0,-1,0,dfs2)%MOD;
    dump(tmp);
    ans+=mask%MOD*tmp%MOD;
    ans%=MOD;
    dump(ans);
  }
  cout<<ans*((MOD+1)/2)%MOD<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long N;
    scanf("%lld",&N);
    std::vector<long long> u(N-1);
    std::vector<long long> v(N-1);
    std::vector<long long> w(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&u[i]);
        scanf("%lld",&v[i]);
        scanf("%lld",&w[i]);
        --u[i];--v[i];
    }
  solve(N, std::move(u), std::move(v), std::move(w));
  return 0;
}