#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

struct state
{
  int x;
  int y;
  int score;
  string path;
  vector<bool> used;
};

int main()
{
  struct timeval tmp_time;
  gettimeofday(&tmp_time, NULL);
  long long program_init_time = tmp_time.tv_sec*1000000+tmp_time.tv_usec;
  long long fin_time, current_time;
  fin_time = program_init_time + 1200000;

  int si, sj, count;
  cin >> si >> sj;
  vector<vector<int>> tiling(50,vector<int>(50)), grids(50,vector<int>(50));
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> tiling.at(i).at(j);
  }
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> grids.at(i).at(j);
  }
  vector<int> dx{1,-1,0,0}, dy{0,0,1,-1};
  string dir = "DURL";
  vector<bool> used(2500,false);
  used.at(tiling.at(si).at(sj)) = true;
  queue<state> que;
  state now_state, best_state;
  now_state.x = si, now_state.y = sj;
  now_state.score = grids.at(si).at(sj);
  now_state.path = "";
  now_state.used = used;
  best_state = now_state;
  que.push(now_state);
  count = 0;
  while (!que.empty())
  {
    count++;
    now_state = que.front();
    que.pop();
    for (int i = 0; i < 4; i++)
    {
      if (now_state.x+dx.at(i) < 0 || now_state.x+dx.at(i) >= 50 || now_state.y+dy.at(i) < 0 || now_state.y+dy.at(i) >= 50)
        continue;
      if (now_state.used.at(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))))
        continue;
      now_state.score += grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
      now_state.path += dir.at(i);
      now_state.used.at(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))) = true;
      now_state.x += dx.at(i), now_state.y += dy.at(i);
      if (best_state.score < now_state.score)
        best_state = now_state;
      que.push(now_state);
      now_state.x -= dx.at(i), now_state.y -= dy.at(i);
      now_state.score -= grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
      now_state.path.pop_back();
      now_state.used.at(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))) = false;
    }
    if (count % 100 == 0)
    {
      gettimeofday(&tmp_time, NULL);
      current_time = tmp_time.tv_sec*1000000 + tmp_time.tv_usec;
      if (current_time > fin_time)
        break;
    }
  }
  cout << best_state.path << endl;
}

//  ██████  ██    ██ ██████  ██ ██   ██  ██████
// ██       ██    ██ ██   ██ ██ ██  ██  ██    ██
// ██   ███ ██    ██ ██████  ██ █████   ██    ██
// ██    ██ ██    ██ ██   ██ ██ ██  ██  ██    ██
//  ██████   ██████  ██   ██ ██ ██   ██  ██████

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const int INF=1e9;
const double PI=acos(-1);

vector<vector<int>> t(50,vector<int>(50)), p(50,vector<int>(50));
vector<vector<P>> ti(2500);
vector<int> di={-1,0,0,1},dj={0,-1,1,0};
string dir="ULRD";
mt19937 mt(1);

pair<int,string> res(int si, int sj, vector<vector<int>> used) {
    int sc=p[si][sj];
    string ans;
    int tmp=t[si][sj];
    rep(m,ti[tmp].size()) {
        used[ti[tmp][m].first][ti[tmp][m].second]=1;
    }
    vector<P> tmp_p;
    rep(k,4) {
        int ni=si+di[k],nj=sj+dj[k];
        if (ni>=0 && ni<50 && nj>=0 && nj<50) {
            if (used[ni][nj]==0) {
                int pp=min(min(49-ni,ni),min(49-nj,nj));
                // tmp_p.push_back({pp,k});
                // tmp_p.push_back({p[ni][nj],k});
                tmp_p.push_back({p[ni][nj]+pp^3,k});
            }
        }
    }
    sort(tmp_p.begin(),tmp_p.end(),greater<>());
    vector<int> thresh={0,90,95,95};

    int max_sc=-1,max_ind=-1;
    string max_str="";
    rep(m,tmp_p.size()) {
        int k=tmp_p[m].second;
        int ni=si+di[k],nj=sj+dj[k];
        int r=mt()%100;
        // cout << r << ' ' << thresh[m] << endl;
        if (r>=thresh[m]) {
            pair<int,string> tmp=res(ni,nj,used);
            int tmp_sc=tmp.first;
            if (tmp_sc>max_sc) {
                max_sc=tmp_sc;
                max_ind=k;
                max_str=tmp.second;
            }
        }
    }
    if (max_sc==-1) return {0, ""};

    else {
        sc+=max_sc;
        si+=di[max_ind];
        sj+=dj[max_ind];
        ans.push_back(dir[max_ind]);
        ans+=max_str;
    }
    // cout << "si=" << si << ",sj=" << sj << ans << endl;
    return {sc, ans};
}

int main() {
    int si,sj;
    cin >> si >> sj;
    rep(i,50) {
        rep(j,50) {
            int tmp;
            cin >> tmp;
            t[i][j]=tmp;
            P pp={i,j};
            ti[tmp].push_back(pp);
            // cout << tmp << ' ' << i << ' ' << j << endl;
        }
    }
    rep(i,50) {
        rep(j,50) cin >> p[i][j];
    }

    string ans="";
    int max_score=0;
    // cout << "-------------------------------------" << endl;

    vector<vector<int>> used(50,vector<int>(50));
    pair<int,string> r=res(si,sj,used);
    cout << r.second << endl;

    return 0;
}


#include<iostream>
using namespace std;
typedef long long ll;
long long int gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}
long long int lcm(long long a,long long b){
  return a/gcd(a,b)*b;
}
int main(){
int a,b;
  cin >> a >> b;
  int as,bs;
  as=a%100%10+a/10%10+a/100;
  bs=b%100%10+b/10%10+b/100;
  cout << max(as,bs) << endl;
}

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

#define fastio			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int             long long
#define double 			long double
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define gcd(x,y)		__gcd(x,y)
#define MOD             (int)(1e9 + 7)
#define INF             (int)9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
int fastpow				(int a, int b, int m = MOD) { int res = 1; a %= m;
						while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) 			fastpow(a, MOD - 2)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree            <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
    fastio;
    int a,b;
    cin>>a>>b;
    int sum1=0,sum2=0;
    while(a)
    {
    	sum1+=a%10;
    	a=a/10;
    }
    while(b)
    {
    	sum2+=b%10;
    	b=b/10;
    }
    if(sum2>sum1)
    	cout<<sum2<<"\n";
   	else
   		cout<<sum1<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
        sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
        {
sim > struct rge
{
        c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
        ~debug()
        {
                cerr << endl;
        }
        eni(!=) cerr << boolalpha << i;
        ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
        ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
                *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
}
#else
        sim dor(const c &)
        {
                ris;
        }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define pb(n) push_back(n)
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n; cin >> n;
        if(n < 0) cout << 0;
        else cout << n;
}

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

#include <bits/stdc++.h>

// #pragma GCC optimize("O3")
#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt)
#define sz(x) (int)(x).size()
#define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()));
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/**
order_of_key(k) : nums strictly smaller than k
find_by_order(k): index from 0
**/

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }

const int N = 3e3 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
/**
Read problem statement carefully
**/

LL dp[N][N]; // dp[i][j], number of ways i, into j pieces
LL arr[N];

void solve(int T){
    int n;
    cin >> n;

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

    dp[0][0] = 1;
    // dp[i][j]: use i-1 elements, use j blocks
    for(int k = 0; k < n; ++k){ // block cnt
        vi mp(k+1);
        LL s = 0;
        mp[0] = dp[0][k];
        for(int i = 0; i < n; ++i){ // element cnt
            s += arr[i];
            s %= (k+1);
            dp[i+1][k+1] = mp[s];
            mp[s] = (mp[s] + dp[i+1][k]) % mod;
        }
    }

    LL res = 0;
    for(int k = 0; k < n; ++k){
        res = (res + dp[n][k+1]) % mod;
    }

    cout << res << "\n";
}

int main()
{
    Fast;
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // louisfghbvc
        solve(1);
    return 0;
}

/**
Enjoy the problem.
**/


#include <bits/stdc++.h>

using namespace std;

int main() {
    string s = "atcoder";
    int T;  cin >> T;
    while (T--) {
        string t;   cin >> t;
        int len = t.size();
        int ans = INT_MAX, sum = 0;
        for (auto cs : s) {
            int cnt = 0;
            for (auto it = t.begin(); it != t.end(); it++, cnt++) {
                if (*it > cs) {
                    ans = min(ans, sum + cnt);
                    break;
                }
            }
            cnt = 0;
            bool flag = false;
            for (auto it = t.begin(); it != t.end(); it++, cnt++) {
                if (*it > cs)   break;
                else if (*it == cs) {
                    flag = true;
                    sum += cnt;
                    t.erase(it);
                    break;
                }
            }
            if (!flag)  break;
        }
        if (t.size() && len - t.size() == s.size()) ans = min(ans, sum);
        printf("%d\n", ans == INT_MAX ? -1 : ans);
    }
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}

int main(){

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

    int T;
    cin >> T;

    vi ans;
    string a = "atcoder";
    rep(tt,T){
        string S;
        cin >> S;
        int an = 0;
        rep(i,len(a)){

            if(a[i] < S[i]) {
                an = 0;
                break;
            }else if(a[i] == S[i]){
                if(i == len(a)-1 && len(a) == len(S)) an = 1;
                if(i == len(S)-1 && i >= 1){
                    an = 1;
                    break;
                }
            }else{

                if(i >= 2) an = 1;
                else{
                    int aa = infi;
                    reps(j,i,len(S)){
                        if(S[j] > 't') {
                            aa = j-i;
                            break;
                        }
                    }
                    rep(j,len(S)){
                        if(S[j] > 'a') {
                            chmin(aa,j);
                            break;
                        }
                    }

                    if(aa == infi) an = -1;
                    else an = aa;
                }

                break;
            }
        }

        ans.pb(an);
    }

    rep(i,T) cout << ans[i] << endl;

    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int a,b,wk;
    cin >> a >> b >> wk;
    int w = wk * 1000;
    int dif = b - a;
    int min = 0;
    if(w%b==0){
        min = w/b;
    }else{
        min = w/b + 1;
    }
    int mmin = b * min - w;
    if(mmin > min * dif){
        min += 1;
    }
    int max = w/a;
    int mmax = w - a*min;
    if(mmax > dif * max){
        max -= 1;
    }

    if(min > max){
        cout << "UNSATISFIABLE" << endl;
    }else{
        cout << min << " " << max << endl;
    }
}

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

vector <int> dy = {0, 1, 0, -1};
vector <int> dx = {1, 0, -1, 0};

const int INF = 1000000000;
const ll INFLL = 100000000000000000;

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret *= x;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x *= x;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
    int x, y, z; cin >> x >> y >> z;
    for(int ans = 1; ans <= 10000000; ans ++){
        if(x * ans < z * y){
            continue;
        }
        cout << ans - 1 << endl;
        return 0;
    }
}


#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;
#define ll long long int
#include<fstream>
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(false);
#define io   cin.tie(NULL);
#define inp(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
#define print(arr,n) for(ll i=0;i<n;i++){cout<<arr[i]<<" ";}
ll power(ll a, ll b) { //a^b
  ll res = 1;
  a = a % MOD;
  while (b > 0) {
    if (b & 1) {res = (res * a) % MOD; b--;}
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
  ll multiply(ll a, ll b, ll mod)
{
   return ((a % mod) * (b % mod)) % mod;
}
ll func(ll arr[],ll siz)
{
  ll sum=0;
  ll ma=0;
  for(ll i=0;i<siz;i++)
  {
    sum+=arr[i];
    ma=max(sum,ma);
  }
  return ma;
}
long long gcd(long long int a, long long int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

// Function to return LCM of two numbers
long long lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}
std::vector<ll> adj[400005];
std::vector<ll> vis(400005,0);
ll coun;
int f;
void dfs(ll x,ll parent)
{
  vis[x]=1;
  coun+=1;
  for(ll k=0;k<adj[x].size();k++)
  {
    if(vis[adj[x][k]]==0)
      dfs(adj[x][k],x);
    else
      {
        if(adj[x][k]!=parent)
          f=1;
      }
  }
}
int main()
{
  ll t;
  t=1;
  while(t--)
  {
    ll n;cin>>n;set<ll> s;
    for(ll i=0;i<n;i++)
    {
      ll a,b;
      cin>>a>>b;
      s.insert(a);
      s.insert(b);
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    ll ans=0;
    for(auto it=s.begin();it!=s.end();it++)
    {
      if(vis[*it]==0)
      {
        coun=0;
        f=0;
        dfs(*it,-1);
        if(f==0)
          ans+=coun-1;
        else
          ans+=coun;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

template<class T>
vi compress(vector<T>&v)
{
	set<T> s;
	for (auto a: v) s.insert(a);
	vector<T> o(all(s));
	vi nv;
	for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
	return nv;
}

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

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

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

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

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

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

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

void ad(int&a,int b)
{
	a+=b;
	if (a>=MOD) a-=MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=400010,M=1<<18;
int t,n,h[N];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>n;
	multiset<int> s;
	ll an=0;
	for (int i=0;i<2*n;++i) cin>>h[i],an+=h[i];
	for (int i=1;i<=n;++i)
	{
		s.insert(h[n-i]);
		s.insert(h[n+i-1]);
		an-=*s.begin();
		s.erase(s.begin());
	}
	cout<<an<<en;
}


#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define RREP(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, b) for(int i=(a);i>=(b);--i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}

template <class T>
void debug(const vector<T> &v) {
  cout << "[";
  REP(i, SZ(v)) {
    if(i) cout << ", ";
    cout << v[i];
  }
  cout << "]" << endl;
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  return os << p.first << " " << p.second;
}

template <class T, class U>
void debug(const pair<T, U> &p) {
  cout << "(" << p.first << " " << p.second << ")" << endl;
}

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 (b < a) {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll MOD998 = 998244353;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int inf = INT_MIN;
const ll linf = LLONG_MIN;
const ld eps = 1e-9;

template<int m>
struct mint {
  int x;

  mint(ll x = 0) : x(((x % m) + m) % m) {}

  mint operator-() const { return x ? m - x : 0; }

  mint &operator+=(mint r) {
    if ((x += r.x) >= m) x -= m;
    return *this;
  }

  mint &operator-=(mint r) {
    if ((x -= r.x) < 0) x += m;
    return *this;
  }

  mint &operator*=(mint r) {
    x = ((ll) x * r.x) % m;
    return *this;
  }

  mint inv() const { return pow(m - 2); }

  mint &operator/=(mint r) { return *this *= r.inv(); }

  friend mint operator+(mint l, mint r) { return l += r; }

  friend mint operator-(mint l, mint r) { return l -= r; }

  friend mint operator*(mint l, mint r) { return l *= r; }

  friend mint operator/(mint l, mint r) { return l /= r; }

  mint pow(ll n) const {
    mint ret = 1, tmp = *this;
    while (n) {
      if (n & 1) ret *= tmp;
      tmp *= tmp, n >>= 1;
    }
    return ret;
  }

  friend bool operator==(mint l, mint r) { return l.x == r.x; }

  friend bool operator!=(mint l, mint r) { return l.x != r.x; }

  friend ostream &operator<<(ostream &os, mint a) {
    return os << a.x;
  }

  friend istream &operator>>(istream &is, mint &a) {
    ll x;
    is >> x;
    a = x;
    return is;
  }
};

using Int = mint<MOD>;

ll modpow(ll x, ll n, ll m) {
  ll res = 1;
  while(n > 0) {
    if(n & 1) {
      res *= x;
      res %= m;
    }
    x *= x;
    x %= m;
    n /= 2;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll a, b, c; cin >> a >> b >> c;
  vll v = {a%10};
  ll now = a%10;
  while(1) {
    now *= a%10;
    now %= 10;
    if(now == a%10) break;
    v.push_back(now);
  }

  ll val = modpow(b, c, SZ(v));

  cout << v[(val+SZ(v)-1)%SZ(v)] << endl;

  return 0;
}


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

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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

const int bm = 200010;
int BIT[bm];
void add(int A) {
	while (A <= bm) {
		BIT[A]++;
		A += A & -A;
	}
}
int query(int A) {
	int ret = 0;
	while (A > 0) {
		ret += BIT[A];
		A -= A & -A;
	}
	return ret;
}

int Q[200001], ne[200001], he[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int H = getint(), W = getint(), M = getint();

	int X[200001], Y[200001];
	rep1(i, H) X[i] = W + 1;
	rep1(i, W) Y[i] = H + 1;
	rep(i, M) {
		int x = getint(), y = getint();
		if (y < X[x]) X[x] = y;
		if (x < Y[y]) Y[y] = x;
	}
	ll kotae = 1;
	int k = 1;
	for (int i = 2; i <= H; i++) {
		if (X[i] == 1) break;
		kotae += X[i] - 1;
		Q[k] = i;
		ne[k] = he[X[i] - 1];
		he[X[i] - 1] = k++;
	}

	int atta = W;
	if (X[1] <= atta) atta = X[1] - 1;
	for (int i = W; i > atta; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
	}
	for (int i = atta; i >= 2; i--) {
		for (int q = he[i]; q; q = ne[q]) {
			add(Q[q]);
		}
		int are = query(Y[i] - 1);
		kotae += Y[i] - 1 - are;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define INF LONG_MAX/3
//#define DIV 1000000007
//#define DIV 998244353

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 dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll N;
ll num;

bool done[25];
ll col[25];

vector<pair<ll, ll> >path;
vector<ll> to[25];

//void dfs1(ll cur) {
//
//	queue<ll> Q;
//	Q.push(cur);
//
//
//	while(!Q.empty()) {
//
//
//
//	}
//	done[cur] = true;
//
//	for(ll next: to[cur]) {
//		if(done[next]) continue;
//		path.push_back(make_pair(cur, next));
//		dfs1(next);
//	}
//	return;
//}

void dfs0(ll cur) {
	queue<pair<ll, ll> > Q;
	Q.push(make_pair(-1, cur));

	while(!Q.empty()) {
		ll f = Q.front().first;
		ll t = Q.front().second;
		Q.pop();

		if(done[t]) continue;
		done[t] = true;
		if(f != -1)
		path.push_back(make_pair(f, t));

		for(ll next: to[t]) {
			if(done[next]) continue;
			Q.push(make_pair(t, next));
		}
	}
	return;
}

bool check() {
	rep(p0, N) {
		for(ll p1: to[p0]) {
			if(col[p0] != -1 && col[p0] == col[p1]) return false;

		}
	}
	return true;
}

void dfs2(ll idx) {
	if(idx == path.size()) {
		if(check()) {
			num++;
		}
		return;
	}

	ll F = path[idx].first;
	ll T = path[idx].second;

	rep(i, 3) {
		if(i == col[F]) continue;
		col[T] = i;
		dfs2(idx+1);
		col[T] = -1;
	}
}

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

	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		a--;b--;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	ll ans = 1;
	rep(i, N) {
		if(done[i]) continue;

		path.clear();
		dfs0(i);
		//cout << "i = " << i << endl;
		//for(auto item: path) cout << item.first << " -> " << item.second << endl;

		num = 0;
		rep(i, N) col[i] = -1;
		col[i] = 0;
		dfs2(0);

		ans *= num * 3;
	}
	cout << ans << endl;
}


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

int main(){
    long a, b, c, d, e;
    cin >> a >> b;
    c = b - a;

    for(int i = c; i > 0; i--){
        d = (a + (i - 1)) / i;
        e = b / i;

        if(e - d >= 1){
            cout << i << endl;
            break;
        }
    }

}

#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<math.h>
using namespace std;
const int INF = 1e9+5;
#define ll long long int
#define vi vector<int>
#define vb vector<bool>
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	int a,b;
	cin>>a>>b;
	int c = a+b;
	if(c>=15 && b>=8)
		cout<<1;
	else if(c>=10 && b>=3)
		cout<<2;
	else if(c>=3)
		cout<<3;
	else
		cout<<4;
}


#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1e9+7;
const double pi = acos(-1);
const ll INF = 1LL<<60;

veci dx = {-1,0,1,0};
veci dy = {0,1,0,-1};
int h,w;

void bfs(P s, vector<string> &G, vecvecl &dist, vector<vector<P>> &tel) {
    queue<P> q;
    q.push(s);
    dist[s.first][s.second] = 0;
    veci seen(26);

    while(!q.empty()) {
        P p = q.front();
        q.pop();
        int y = p.first;
        int x = p.second;

        if('a' <= G[y][x] && G[y][x] <= 'z') {
            if(!seen[G[y][x]-'a']) {
                for(P to : tel[G[y][x]-'a']) {
                    int ny = to.first;
                    int nx = to.second;
                    if(y == ny && x == nx) continue;
                    if(dist[ny][nx] != -1) continue;
                    dist[ny][nx] = dist[y][x]+1;
                    q.push({ny,nx});
                }
                seen[G[y][x]-'a'] = 1;
            }
        }

        for(int dir = 0; dir < 4; dir++) {
            int ny = p.first+dy[dir];
            int nx = p.second+dx[dir];

            if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
            if(G[ny][nx] == '#') continue;
            if(dist[ny][nx] != -1) continue;
            dist[ny][nx] = dist[y][x] + 1;
            q.push({ny,nx});
        }
    }
}

int main() {
    cin >> h >> w;
    vector<string> G(h);
    REP(i,h) cin >> G[i];
    vector<vector<P>> tel(26);

    int sx,sy,gx,gy;
    REP(i,h) REP(j,w) if(G[i][j] == 'S') sx = j, sy = i;
    else if(G[i][j] == 'G') gy = i, gx = j;
    else if('a' <= G[i][j] && G[i][j] <= 'z') tel[G[i][j]-'a'].push_back({i,j});
    vecvecl dist(h,vecl(w,-1));

    bfs({sy,sx}, G , dist, tel);

    cout << dist[gy][gx] << endl;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<climits>
#include<utility>
#include<vector>
#include<queue>
#define int long long
using namespace std;
const int MaxN = 500005;
int n, ans;
char s[MaxN], t[MaxN];
queue<int> pos;

inline int Read(){
	int num = 0, op = 1;
	char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') op = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		num = num * 10 + ch - '0';
		ch = getchar();
	}
	return num * op;
}

signed main(){
	n = Read();
	scanf("%s%s", s+1, t+1);
	for(int i=1; i<=n; i++)
		if(s[i] == '1') pos.push(i);
	for(int i=1; i<=n; i++){
		if(s[i] == t[i]){
			if(s[i] == '1') pos.pop();
			continue;
		}
		else if(s[i] == '1' && t[i] == '0'){
			if(pos.empty()){
				printf("-1");
				return 0;
			}
			int p1 = pos.front();
			pos.pop();
			if(pos.empty()){
				printf("-1");
				return 0;
			}
			int p2 = pos.front();
			pos.pop();
			ans += (p2 - p1);
			s[p1] = s[p2] = '0';
		}
		else if(s[i] == '0' && t[i] == '1'){
			if(pos.empty()){
				printf("-1");
				return 0;
			}
			int p = pos.front();
			pos.pop();
			ans += (p - i);
			s[p] = '0', s[i] = '1';
		}
	}
	printf("%lld", ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 998244353
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int a,b,c;
	cin>>a>>b>>c;
	a=21-a-b-c;
	cout<<a;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pys cout<<"YES"<<endl
#define pyn cout<<"NO"<<endl
#define loop(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define nl cout<<endl
#define s second
typedef vector<int>		vi;
typedef long long ll;

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    int sum=a+b+c;
    cout<<21-sum;
}

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

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

  return 0;
}


#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;
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;

int main(){
    string X;
    cin >> X;
    int size = X.size();
    string ans = "";
    rep(i,0,size){
        if(X[i] == '.'){
            break;
        }else{
            ans += X[i];
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
typedef long long int lli;
typedef pair<lli,lli> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
typedef unsigned long long int ulli;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
  long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
/*

  DONT SUBMIT WITHOUT PROOF

*/

//############################ENDOFTEMPLATE############################
struct FenwickTree {
    vector<int> bit;  // binary indexed tree
    int n;

    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }

    FenwickTree(vector<int> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    int sum(int r) {
        int ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void add(int idx, int delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};

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

  vi a(n);

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

  FenwickTree ft(n);

  lli inv = 0;

  for(int i = n-1;i>=0;i--){
    inv+= (lli)ft.sum(0,a[i]);

    ft.add(a[i],1);
  }

  vlli ans(n);
  ans[0] = inv;

  for(int i = 1;i<n;i++){
    inv-=a[i-1];
    inv+=n-1-a[i-1];
    ans[i] = inv;
  }

  for(int i = 0;i<n;i++){
    cout<<ans[i]<<endl;
  }

}

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

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

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

  for(int zz = 1;zz<=t;zz++){
    //cout<<"Case #"<<zz<<":"<<" ";
    solve();
  }
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;
using Graph = vector<vector<int>>;

int MOD=1000000007;
ll ll_max=9223372036854775807;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int Gcd(int x,int y)              //最大公約数
{
  int large = max(x,y);
  int small = min(x,y);

  while(small!=0){
      int amari =large%small;

      large = small;

      small = amari;
  }
  return large;
}

   vector<bool> seen;
void dfs(const Graph &G, int v)   //深さ優先探索
{   seen[v] = true;
     for (auto next_v : G[v]) {
      if (seen[next_v]) continue;
     dfs(G, next_v); // 再帰的に探索
    }
}

ll combi(ll n, ll r){
  if (r == 0) {
      return 1;
  }
  return (n - r + 1) * combi(n, r - 1) / r;
}

//メイン関数--------------------------------------------

int main(){

int n;
cin>>n;
vector<string> v(n);
for(int i=0;i<n;i++){

string s;
cin>>s;
    if(s[0]=='!'){
        s.erase(0,1);
        s.push_back('A');
    }
    v[i]=s;
}

sort(v.begin(),v.end());
bool x=true;
for(int i=0;i<n-1;i++){
    if(v[i]+'A'==v[i+1]){
        cout<<v[i]<<endl;
        x=false;
        break;
    }
}
if(x) cout<<"satisfiable"<<endl;

}

/*ver 7*/
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : v)
#define reps(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<=b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
	init();
    set<string> st;
    inl(n);
    rep(i,n){
        ins(s);
        st.insert(s);
    }
    for(auto &x:st){
        if(x[0]!='!')continue;
        if(st.count(x.substr(1))==1)die(x.substr(1));
    }
    out("satisfiable");
	return 0;
}


#include<iostream>
#include<array>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
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 n;
int a[2010];
map<int,int> ma;

template<typename T>
vector<T> divisor_list(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if (x%i==0) {
            res.push_back(i);
            if (i*i!=x) res.push_back(x/i);
        }
    }
    return res;
}

int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}

void solve(){
    cin >> n;
    int minA=mod;
    rep(i,n) {
        cin >> a[i];
        chmin(minA,a[i]);
    }
    rep(i,n){
        vector<int> ds=divisor_list(a[i]);
        for(int d:ds){
            ma[d]=gcd(ma[d],a[i]);
        }
    }
    int ans=0;
    for(auto p:ma){
        if(p.first==p.second && p.first<=minA) ans++;
    }
    cout << ans << endl;
}

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

/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define ALL(a) a.begin(), a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define TRAV(x, a) for (auto &x : a)

using namespace std;
using ll = long long; using ld = double;
using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>;
using cd = complex<ld>; using vcd = vector<cd>;

using vi = vector<int>; using vl = vector<ll>;
using vd = vector<ld>; using vs = vector<string>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; // vector<pair>

template<class T> using min_pq = priority_queue<T, vector<T>, greater<T> >;
template<class T> inline int ckmin(T& a, const T& val) { return val < a ? a = val, 1 : 0; }
template<class T> inline int ckmax(T& a, const T& val) { return a < val ? a = val, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sort(ALL(v)); v.erase(unique(ALL(v)), end(v)); }

constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
void setPrec(int x) { cout << fixed << setprecision(x); }

// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(const char* s) { return (string) s; }
string ts(string s) { return s; }
string ts(bool b) { return ts((int)b); }
template<class T> string ts(complex<T> c) { stringstream ss; ss << c; return ss.str(); }
template<class T> using V = vector<T>;
string ts(V<bool> v) {string res = "{"; FOR(i,0,SZ(v)-1) res += char('0'+v[i]); res += "}"; return res; }
template<size_t sz> string ts(bitset<sz> b) { string res = ""; FOR(i,0,SZ(b)-1) res += char('0'+b[i]); return res; }
template<class T, class U> string ts(pair<T,U> p);
template<class T> string ts(T v) { // containers with begin(), end()
    bool fst = 1; string res = "";
    for (const auto& x: v) { if (!fst) res += " "; fst = 0; res += ts(x); }
    return res;
}
template<class T, class U> string ts(pair<T,U> p) { return "("+ts(p.FI)+", "+ts(p.SE)+")"; }

// OUTPUT
template<class T> void pr(T x) { cout << ts(x); }
template<class T, class ...U> void pr(const T& t, const U&... u) { pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
template<class T, class ...U> void ps(const T& t, const U&... u) { pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class T, class ...U> void DBG(const T& t, const U&... u) { cerr << ts(t); if (sizeof...(u)) cerr << ", "; DBG(u...); }
#define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
        << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);

const ld PI = acos(-1.0);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const ld EPS = 1e-9;
const ll MODBASE = 1000000007LL;
const int INF = 0x3f3f3f3f;

const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll r, x, y;
    cin >> r >> x >> y;
    r = r * r;
    ll len = x * x + y * y;

    if (len < r) {
        cout << 2;
        return 0;
    }

    ll res = 1;
    while (r * res * res < len) {
        res++;
    }
    cout << res;
    return 0;
}


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

const int A = 1000000000;

void read(long long &x) {
  double s;
  cin >> s;
  x = round(s * 10000);
}

long long sqrtll(long long x) {
  long long l = 0, r = A;
  while (l < r) {
    long long m = (l + r + 1) / 2;
    if (m * m <= x) {
      l = m;
    } else {
      r = m - 1;
    }
  }
  return r;
}

long long floor_div(long long x, long long y) {
  return x / y - (x % y < 0);
}

long long ceil_div(long long x, long long y) {
  return x / y + (x % y > 0);
}

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

  long long x, y, r;
  read(x), read(y), read(r);

  long long ans = 0;
  for (long long i = -2 * A; i <= 2 * A; i += 10000) {
    long long s = r * r - (x - i) * (x - i);
    if (s < 0) {
      continue;
    }
    s = sqrtll(s);
    ans += floor_div(y + s, 10000) - ceil_div(y - s, 10000) + 1;
  }

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

#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#define inf 1000000000000000000
#define mp make_pair
using namespace std;
int main()
{
    cout.precision(16);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double x,y,r;
    cin>>x>>y>>r;
    lli start=ceil(x-r), rear=floor(x+r), ans=0;
    for(lli i=start; i<=rear; i++)
    {
        long double z=y+sqrt(r*r-(i-x)*(i-x)+1e-9);
        long double l=y-sqrt(r*r-(i-x)*(i-x)+1e-9);
        ans+=(floor(z)-ceil(l)+1);
    }
    cout<<ans;
    return 0;
}


#include"bits/stdc++.h"

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int h,w;cin>>h>>w;
    VS s(h);
    REP(i,h){
        cin>>s[i];
    }

    LL result = 0;
    REP(i,h){
        REP(j,w){
            if(i+1 < h){
                if(s[i][j] == '.' && s[i+1][j] == '.'){
                    result++;
                }
            }
            if(j+1 < w){
                if(s[i][j] == '.' && s[i][j+1] == '.'){
                    result++;
                }
            }
        }
    }
    cout<<result<<endl;

	return;
}

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

#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
ll MOD = 1000000007;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> s(H,(vector<char>(W)));
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>s[i][j];
  vector<vector<ll>> dp(H,(vector<ll>(W)));
  vector<vector<ll>> dpx(H,(vector<ll>(W)));
  vector<vector<ll>> dpy(H,(vector<ll>(W)));
  vector<vector<ll>> dpxy(H,(vector<ll>(W)));
  dp[H-1][W-1] = 1;

  for(int i=H-1;i>=0;i--){
    for(int j=W-1;j>=0;j--){
      if(s[i][j]=='#') continue;
      dp[i][j] += (dpx[i][j]%MOD + dpy[i][j]%MOD + dpxy[i][j]%MOD)%MOD;
      if(j!=0) dpx[i][j-1] = dpx[i][j]+dp[i][j];
      if(i!=0) dpy[i-1][j] = dpy[i][j]+dp[i][j];
      if(i!=0&&j!=0) dpxy[i-1][j-1] = dpxy[i][j]+dp[i][j];
    }
  }
  cout<<dp[0][0]<<"\n";
  /*
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      printf("%11lld",dp[i][j]);
    }
    cout<<"\n";
  }
  */
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int MOD = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007); // ←MOD-1が上限
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

int main() {
    int N, K, M;
    cin >> N >> K >> M;
    int MX = (101) * 100 / 2 * 100;
    MOD = M;
    vector<vector<mint>> dp(101, vector<mint>(MX+1));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        // i個目まで使う
        for (int j = 0; j <= MX; j++) {
            // 合計がjになる個数
            dp[i][j] = dp[i-1][j]; // i個目を使わない場合
            if (j >= i) {
                dp[i][j] += dp[i][j-i];
            }
            if (j >= i * (K+1)) {
                dp[i][j] -= dp[i-1][j - i * (K+1)];
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        mint ans = K;
        int left = i - 1;
        int right = N - i;
        for (int j = 1; j < MX; j++) {
            ans += dp[left][j] * dp[right][j] * (K+1);
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

#define ll long long

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

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  ll x,y; cin >> x >> y;
  ll a = min(x,y);
  ll b = max(x,y);
  if((a+3)>b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;

  }
}

// Author :- Sarvesh Chaudhary
#include<bits/stdc++.h>
using namespace std;
#define w(x) int x; cin>>x; while(x--)
#define ll long long int
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define set_built(x) __builtin_popcountll(x)
#define zero_built(x) __bultin_ctzll(x)
#define pairi pair<int,int>
#define vi vector<int>
#define mod 1000000007
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back
#define po pop_back
#define all(c) c.begin(),c.end()
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Global Variable
map<int,int> m;

//Functions

//Driver Function
int main(){
	io;
	ll a,b;cin>>a>>b;
    if(a>b){
        swap(a,b);
    }
    if((a+3)>b){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll m = 1e9 + 7;
ll mpow(ll a, ll n) {
  ll ret = 1;
  while (n) {
    if (n % 2) {
      ret *= a;
      ret %= m;
    }
    a = (a * a) % m;
    n /= 2;
  }
  return ret;
}
int main () {
  int N, M, K;
  cin >> N >> M >> K;
  if (N - M > K) {
    cout << 0 << endl;
    return 0;
  }
  ll kai[2000004];
  ll fkai[2000002];
  kai[0] = 1;
  for (int i = 1; i <= N + M; i ++) {
    kai[i] = kai[i - 1] * (ll)i;
    kai[i] %= m;
  }
  fkai[N + M] = mpow(kai[N + M], m - 2);
  for (int i = N + M; i > 0; i --) {
    fkai[i - 1] = fkai[i] * (ll)i;
    fkai[i - 1] %= m;
  }
  ll ans = (kai[N + M] * fkai[M]) % m;
  ans *= fkai[N];
  ans %= m;
  if (K >= N) {
    cout << ans << endl;
    return 0;
  }
  ll kj = kai[N + M] * fkai[M + K + 1];
  kj %= m;
  kj *= fkai[N -K - 1];
  kj %= m;
  ans -= kj;
  if (ans < 0) ans += m;
  cout << ans << endl;
}

#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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

typedef long long ll;
int N;
vector<pair<int, ll>> E[301010];
//---------------------------------------------------------------------------------------------------
ll xo[301010];
void dfs(int cu, int pa = -1) {
    fore(p, E[cu]) if (p.first != pa) {
        xo[p.first] = xo[cu] ^ p.second;
        dfs(p.first, cu);
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N - 1) {
        int a, b; ll c; cin >> a >> b >> c;
        a--; b--;
        E[a].push_back({ b, c });
        E[b].push_back({ a, c });
    }

    dfs(0);

    mint ans = 0;
    rep(d, 0, 71) {
        mint a = 1;
        ll mask = 1;
        rep(i, 0, d) a *= 2, mask *= 2;

        mint cnt0 = 0, cnt1 = 0;
        rep(i, 0, N) {
            if (xo[i] & mask) cnt1 += 1;
            else cnt0 += 1;
        }

        mint cnt = 0;
        rep(i, 0, N) {
            if (xo[i] & mask) cnt += cnt0;
            else cnt += cnt1;
        }
        cnt /= 2;
        ans += a * cnt;
    }
    cout << ans << endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(ll i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main(){
    ll n, j = 0;
    cin >> n;
    vector<ll>a;
    ll b = (ll)sqrt(n);
    if(n == 1){
        cout << 1 << endl;
        return 0;
    }else if(n == 2){
        cout << 1 << endl << 2 << endl;
        return 0;
    }else if(n == 3){
        cout << 1 << endl << 3 << endl;
        return 0;
    }else if(n == 4){
        cout << 1 << endl << 2 << endl << 4 << endl;
        return 0;
    }
    rep(i,b){
        if(n % (i+1) == 0){
            a.push_back(i+1);
            if((i+1) * (i+1) != n) a.push_back(n / (i+1));
        }
    }
    sort(a.begin(), a.end());
    rep(i,a.size()) cout << a[i] << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

template<typename T>
vector<T> Divisors(T n) {
	vector<T> ret;
	for(T i = 1; i * i <= n; ++i) {
		if( n % i == 0 ) {
			ret.push_back(i);

			if( i < n / i ) ret.push_back(n / i);
		}
	}

	sort(ret.begin(), ret.end());

	return ret;
}

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

	vector<ll> Div = Divisors(n);

	for(auto& ans : Div) {
		cout << ans << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

const int MOD = 1000000007;

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

	int dgt = (int)log2(N);

	long long ans = 1;

	vector<long long> modulo(40);

	modulo.at(0) = 1;
	modulo.at(1) = P - 2;

	for (int i = 2; i < 40; i++) {
		modulo.at(i) = (modulo.at(i - 1) * modulo.at(i - 1)) % MOD;
	}

	/*for (int i = 0; i < 40; i++) {
		cout << i << " " << modulo.at(i) << endl;
	}*/

	for (int i = 0; i < dgt+1; i++) {
		if (((N-1) >> i) & 1 == 1) {
			ans *= modulo.at(i+1);
			ans %= MOD;
		}
	}

	ans *= P - 1;
	ans %= MOD;

	cout << ans << endl;
}

#include<iostream>
#define mod 1000000007
long long pow(long long x, long long n);

using namespace std;

int main(){
    long long N,P,res;
    cin >> N>>P;
    res=pow(P-2,N-1);
    res*=P-1;
    res%=mod;
    cout << res << endl;
}

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x %mod;
        x = x * x %mod;
        n >>= 1;
    }
    return ret;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define fill(arr,c) memset(arr,c,sizeof(arr))
#define perm(r) next_permutation(all(r))
//it gives bool value ans permute the string lexoggraphically
#define sortdesc greater<int>()
#define ll long long int
//std::setfill('0') << std::setw(5) << 25; it adds leaing zeroes;
#define f(i,a) for(int i=0;i<a;i++)
#define fo(i,a) for(int i=1;i<=a;i++)
#define foo(i,x,n,c) for(ll i=x;i<n;i+=c)
#define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)
#define fauto(i,m) for(auto i:m)
#define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)
#define ld long double
#define in push_back
#define mll map<ll,ll>
#define mcl map<char,ll>
#define msl map<string,ll>
#define vi vector<int >
#define vl vector<ll >
#define vp vector< pair<int,int> >
#define vs vector <string>
#define vc vector <char>
#define o(a) cout<<a
#define os(a) cout<<a<<" "
#define en cout<<"\n";
#define testcase ll t ;cin>>t; while(t--)
#define ff first
#define ss second
#define pl pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a).begin(), (a).end()

#define sz(a)  (a).size()
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
#define bitcount  __builtin_popcountll
#define imin o("imin");en;
using namespace std;
bool comp(const pair<int,int> &a , const pair<int,int> &b){
    if(a.first == b.first)  return a.second < b.second;
     return a.first < b.first;
}
bool comps(const pair<int,int> &a , const pair<int,int> &b){
    if(a.second == b.second)  return a.first< b.first;
     return a.second < b.second;
}
//ll pi=acos(0.0)*2;
void fastio()
{
    	ios::sync_with_stdio(0);
cin.tie(0);

}
void inout()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

     freopen("output.txt", "w", stdout);
     #endif
}

int main()
{
fastio();
vl l;
string s;
cin>>s;
ll sum=0;
ll a[3];
f(i,3)
a[i]=0;
f(i,sz(s))
{
sum+=s[i]-'0';
a[(s[i]-'0')%3]++;
}
ll ans=-1;
if(sum%3==0)
ans=0;
else if(sum%3==1)
{
	if(a[1]>=1)
	ans=1;
	else if(a[2]>=2)
	ans=2;

}
else if(sum%3==2)
{
	if(a[2]>=1)
	ans=1;
	else if(a[1]>=2)
	ans=2;

}
if(ans<sz(s))
o(ans);
else
o(-1);

return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll inv_mod(ll x){
    return pow_mod(x,mod-2);
}

const ll N=(ll)3e5;
ll inv[N];
ll fac[N];

ll ncr(ll n,ll r){
    if(n<r)
    return 0;

    if(n==r||r==0)
    return 1LL;

    ll x=fac[n];
    ll y=inv[n-r];
    ll z=inv[r];

    return ((x*y)%mod*z)%mod;
}

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

    string s[3];

    for(ll i=0;i<3;i++)
    cin>>s[i];

    for(ll i=0;i<3;i++)
    s[i]+=s[i];

    string ans;

    /*
       1
       0101
       0101
       1010
       => ans=010

       01010101
       00110011
       11001100
       => ans=11011

       10011001
       01100110
       => ans=10000

       A binary string of length 2*N can be easily constructed easily
       by taking all the 1's or 0's.

    */

   for(ll i=0;i<n;i++)
   cout<<"0";
   for(ll i=0;i<n;i++)
   cout<<"1";
   cout<<"0";
   cout<<endl;
}
int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

//Start from Here.

  ll t;
  t=1;
  cin>>t;
  while(t--)
  solve();

  fac[0]=1;

  for(ll i=1;i<N;i++)
  fac[i]=(i*fac[i-1])%mod;

  for(ll i=0;i<N;i++)
  inv[i]=inv_mod(fac[i]);
//Good Bye!
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define sz(x) int(x.size())
#define pcnt __builtin_popcountll
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template <typename T> void print(T a) {cout << a << ' ';}
template <typename T> void printe(T a) {cout << a << endl;}
template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;}
template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;}
template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
template <typename T> using vc = vector<T>;
template <typename T> using vv = vc<vc<T>>;
template <typename T> using vvv = vc<vv<T>>;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vvl = vv<ll>;
vi di = {-1, 1,  0, 0, -1, -1,  1, 1};
vi dj = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    vc<string> s(3);
    rep(i, 3) cin >> s[i];
    map<char, ll> Mp; // その文字に割り当てられたものを何倍するか
    set<char> heads; // 先頭の文字
    rep(i, 3) {
        heads.insert(s[i][0]);
        ll scale = 1;
        for (int j = sz(s[i])-1; j >= 0; j--) {
            if (i == 2) {
                Mp[s[i][j]] -= scale;
            }
            else {
                Mp[s[i][j]] += scale;
            }
            scale *= 10;
        }
    }
    if (sz(Mp) > 10) {
        cout << "UNSOLVABLE" << endl;
        return 0;
    }

    map<char, int> Mp2; // 各文字に何の文字入れるか
    vi p(10);
    rep(i, 10) p[i] = i;
    do {
        int now = 0; // 今何番目の要素か
        ll sum = 0;
        for (auto x : Mp) {
            sum += p[now] * x.second;
            if (heads.count(x.first) && p[now] == 0) sum = 1e18; // 先頭は0じゃダメ
            Mp2[x.first] = p[now];
            now++;
        }

        if (sum == 0) {
            rep(i, 3) {
                ll ans = 0;
                rep(j, sz(s[i])) {
                    ans *= 10;
                    ans += Mp2[s[i][j]];
                }
                cout << ans << endl;
            }
            return 0;
        }
      Mp2.clear();
    } while (next_permutation(all(p)));

    cout << "UNSOLVABLE" << endl;

    return 0;
}

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "avx")

#ifdef __APPLE__
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>
#else
# include <bits/stdc++.h>
#endif

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

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

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

const int max_n = 100+10, inf = 1000111222;

int dp[2*max_n];

bool is_start[2*max_n];
bool is_end[2*max_n];
bool is_pair_present[2*max_n][2*max_n];
bool in_some_pair[2*max_n];

void add_start(int a)
{
    if (is_start[a] || is_end[a]){
        cout<<"No"<<"\n";
        exit(0);
    }
    is_start[a]=1;
}

void add_end(int b)
{
    if (is_start[b] || is_end[b]){
        cout<<"No"<<"\n";
        exit(0);
    }
    is_end[b]=1;
}

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

    int n;
    cin>>n;
    for (int i=1;i<=n;i++){
        int a,b;
        cin>>a>>b;
        if (a==-1 && b==-1){

        }
        else if (a==-1){
            add_end(b);
        }
        else if (b==-1){
            add_start(a);
        }
        else{
            if (a>=b){
                cout<<"No"<<"\n";
                exit(0);
            }
            add_start(a);
            add_end(b);
            is_pair_present[a][b]=1;
            in_some_pair[a]=1;
            in_some_pair[b]=1;
        }
    }
    dp[0]=1;
    for (int f=0;f<2*n;f++){
        if (dp[f]){
//            cout<<"dp f :: "<<f<<"\n";
            int l=f+1;
            for (int r=l+1;r + ((r-l)-1)<=2*n;r++){
                bool ok=1;
                for (int i=l;i<r;i++){
                    if (is_pair_present[i][r+(i-l)]){
                        continue;
                    }
//                    cout<<i<<" "<<is_start[i]<<" "<<r+(i-l)<<" "<<is_end[r+(i-l)]<<"\n";
                    if (is_start[i] && is_end[r+(i-l)]){
                        ok=0;
                    }
                }
                for (int i=l;i<r;i++){
                    if (is_pair_present[i][r+(i-l)]){
                        continue;
                    }
                    if (in_some_pair[i]){
                        ok=0;
                    }
                    if (is_end[i]){
                        ok=0;
                    }
                }
                for (int i=r;i<r+(r-l);i++){
                    if (is_pair_present[l+(i-r)][i]){
                        continue;
                    }
                    if (in_some_pair[i]){
                        ok=0;
                    }
                    if (is_start[i]){
                        ok=0;
                    }
                }
//                cout<<r<<" "<<ok<<"\n";
                if (ok){
                    dp[r + ((r-l)-1)]=1;
                }
            }
        }
    }
    cout<<(dp[2*n]?"Yes":"No")<<"\n";
}


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

ll gcd(ll m, ll n) {
  if (n == 0) return m;
  else return gcd(n, m % n);
}

ll extgcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

int main() {
        int T;
    cin >> T;
    ll N, S, K;
    while (T--) {
        cin >> N >> S >> K;
        ll g = gcd(K, N);
        if (g > 1 && (N - S) % g != 0) {
            cout << "-1\n";
        } else {
            ll x, y;
            extgcd(K, N, x, y);
            if (x > 0) {
                x = x - (-x / N + 1) * N;
            }
            //cout << x << "\n";
            x = -x * (S / g);
            N /= g;
            cout << x % N << "\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) int(x.size())
//const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
const ll ll0 = 0 * 1ll;

ll n, s, k;

ll mod;

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

    return gcd(b, a % b);
}

ll euler (ll n) {
    ll d = 2;

    ll ans = n;

    while (d * d <= n) {
        if (n % d == 0) {
            ans /= d;
            ans *= d - 1;
        }
        while (n % d == 0) {
            n /= d;
        }

        d++;
    }

    if (n > 1) {
        ans /= n;
        ans *= n - 1;
    }

    return ans;
}

ll mull(ll a, ll b) {
    return (a * b) % mod;
}

ll binpow (ll a, ll b) {
    if (b == 0) {
        return 1;
    }
    if (b % 2) {
        return mull(a, binpow(a, b - 1));
    }

    ll half = binpow(a, b / 2);
    return mull(half, half);
}

void init () {
}

void input () {
    cin >> n >> s >> k;

    s = n - s;
}

void solve() {
    ll g = gcd(n, k);

    if (s % g) {
        cout << -1 << endl;
        return;
    }

    n /= g;
    s /= g;
    k /= g;

    ll inst = n;
    ll phi = n;

    for (ll d = 2; d * d <= inst; d++) {
        if (inst % d == 0) {
            phi /= d;
            phi *= d - 1;
        }
        while (inst % d == 0) {
            inst /= d;
        }
    }
    if (inst > 1) {
        phi /= inst;
        phi *= inst - 1;
    }

    mod = n;

    ll inv = binpow(k, phi -1);
    cout << mull(s, inv) << endl;
}

void output() {
}

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

    int number_of_testcases = 1;
    cin >> number_of_testcases;
    while (number_of_testcases--) {
        init();

        input();

        solve();

        output();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[15],tot;
int main(){
	int n;
	scanf("%d",&n);
	if(n==0){
		printf("Yes");
		return 0;
	}
	while(n%10==0)n/=10;
	while(n){
		a[++tot]=n%10;
		n/=10;
	}
	int flag=1;
	for(int i=1;i<=tot;i++)if(a[i]!=a[tot+1-i])flag=0;
	printf(flag?"Yes":"No");
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

bool ispelin(const string &s)
{
    int N = s.size();
    bool res=true;
    rep(i,N/2){
        if (s[i]!=s[N-i-1]) res=false;
    }
    return res;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin>>S;
    int N = S.size();
    bool yes=false;
    rep(i,N){
        if (ispelin(S)){
            yes=true;
            break;
        }
        S="0"+S;
    }
    cout<<(yes?"Yes":"No")<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isprime(ll x)
{
    if(x==1) return false;
    if(x==2 || x==3) return true;
    if(x%2==0 || x%3==0) return false;
    for(ll i=5;i*i<=x;i+=6)
    {
        if(x%i==0 || x%(i+2)==0) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
int solve()
{
    int h,w,x,y,i,j,ans=0;
    cin>>h>>w>>x>>y;
    vector<string> v(h);
    for(i=0;i<h;i++)
    {
        cin>>v[i];
    }
    for(i=y-1;i<w;i++)
    {
        if(v[x-1][i]=='#') break;
        ans++;
    }
    for(i=y-2;i>=0;i--)
    {
        if(v[x-1][i]=='#') break;
        ans++;
    }
    for(i=x;i<h;i++)
    {
        if(v[i][y-1]=='#') break;
        ans++;
    }
    for(i=x-2;i>=0;i--)
    {
        if(v[i][y-1]=='#') break;
        ans++;
    }
    cout<<ans;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}

#include <bits/stdc++.h>
#define M 1000000007
#define pii 3.14159265359
#define pb push_back
#define pob pop_back
#define forr(i,n) for(i=0;i<n;i++)
#define fors(i,j,n) for(i=j;i<n;i++)
#define pi pair<int,int>
#define ff first
#define ss second
#define tcase 0
#define all(v) v.begin(),v.end()
typedef long long int ll;
using namespace std;
#define sc(n) scanf("%lld",&n)
#define scn(n) scanf("%d",&n)
#define prt(n) printf("%lld ",n)
#define prtln(n) printf("%lld\n",n)

vector<pi> edges;
vector<vector<int>> v;
vector<int> prt;
vector<ll> val;
vector<ll> ans;

void assign_prt(int node,int p) {
	prt[node] = p;
	for(auto x : v[node]) {
		if(x==prt[node]) continue;
		assign_prt(x,node);
	}
}

void find_ans(int node,int p,ll c) {
	ans[node] += c + val[node];
	for(auto x : v[node]) {
		if(x==prt[node]) continue;
		find_ans(x,node,c+val[node]);
	}
}

void solve() {
    int n,i;
    scn(n);

    v.clear(); edges.clear(); prt.clear(); val.clear(); ans.clear();
    v.resize(n+1); prt.resize(n+1); val.resize(n+1,0ll);
    forr(i,n-1) {
    	int a,b;
    	scn(a); scn(b);
    	edges.pb({a,b});
    	v[a].pb(b); v[b].pb(a);
    }

    assign_prt(1,-1);

    int q;
    scn(q);

    forr(i,q) {
    	int a,b; ll value;
    	scn(a); scn(b); sc(value);

 		int v1,v2;
    	if(a==1) {
    		v1 = edges[b-1].ff;
    		v2 = edges[b-1].ss;
    	}
    	else {
    		v1 = edges[b-1].ss;
    		v2 = edges[b-1].ff;
    	}

    	if(v2==prt[v1]) {
    		val[v1] += value;
    	}
    	else {
    		val[1] += value;
    		val[v2] += -value;
    	}
    }

    ans.resize(n+1,0ll);
    find_ans(1,-1,0);

    fors(i,1,n+1) prtln(ans[i]);
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    int t = 1;
    if(tcase) scn(t);
    while(t--) solve();
    return 0;
}


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

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

    ll ans = 2;
    for (ll i = 3; i <= n; i++)
        ans = (((i * ans)) / (__gcd(i, ans)));
    cout << ans + 1;
}


#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define fo(i,n)         for(int i=0;i<n;i++)
#define fod(i,n)        for(int i=n-1;i>=0;i--)
#define For(i,a,b)      for(int i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
#define SET(x)          memset(x,-1,sizeof(x))
#define si              set<int>
#define pb(i)           emplace_back(i)
#define sll             set<long long>
#define vs              vector<string>
#define yes             cout<<"YES\n"
#define no              cout<<"NO\n"
#define vpii            vector<pair<int,int>>
#define ll              long long int
#define vi              vector<ll>
#define mod             1000000007
#define tc(t)           int t; cin>>t; while(t--)
#define sfm(a,m,n)      ll a[m][n]; fo(i,m) fo(j,n) cin>>a[i][j]
#define sfarr(a,n)      ll a[n]; fo(i,n) cin>>a[i]
#define sfv(v,n)        vi v(n); for(ll &i:v) cin>>i
int f[1000001];
int prime[1000001];
void sieve(){
    prime[0]=prime[1]=0;
    For(i,2,1000000) prime[i]=1;
    for(int i=2;i*i<=1000000;i++){
        if(prime[i]){
            for(ll j=i*i;j<=1000000;j+=i)
            prime[j]=0;
        }
    }
}
int power(int a,int b){
    int r=1;
    while(b){
        if(b&1){
            r=(r*1ll*a)%mod;
            b--;
        }
        else{
            a=(a*1ll*a)%mod;
            b>>=1;
        }
    }
    return r;
}
void factorial(){
    f[0]=f[1]=1;
    For(i,2,1000000) f[i]=(f[i-1]*1ll*i)%mod;
}
int nCr(int a,int b){
     factorial();
     int r=f[a];
     r=(r*1ll*power(f[b],mod-2))%mod;
     r=(r*1ll*power(f[a-b],mod-2))%mod;
     return r;
}
vi z_algo(string s){
    ll n=s.length(),l=0,r=0;
    vi z(n);
    For(i,1,n-1){
        if(i<=r) z[i]=min(r-i+1,z[i-l]);
        while(z[i]+i<n && s[z[i]]==s[i+z[i]]) z[i]++;
        if(i+z[i]-1>r) l=i,r=i+z[i]-1;
    }
    return z;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b; cin>>n>>a>>b;
    cout<<n-a+b;
return 0;
}

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

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 2e5 + 10;

int n;
LL k;
pair<LL, int> p[N];

int main(){
	scanf("%d %lld", &n, &k);
	rep(i, 0, n)	scanf("%lld %d", &p[i].fi, &p[i].se);
	sort(p, p+n);
	LL cur = 0, d;
	rep(i, 0, n){
		if(cur + k < p[i].fi){
			break;
		}
		k = k - (p[i].fi - cur) + p[i].se;
		cur = p[i].fi;
	}

	printf("%lld\n", cur + k);

	return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  vector<int> c(m), d(m);
  for (int i = 0; i < m; i++)
    cin >> c[i] >> d[i];
  vector<vector<int>> grid(h, vector<int>(w, 0));
  for (int i = 0; i < n; i++) {
    --a[i];
    --b[i];
    grid[a[i]][b[i]] = 1;
  }
  for (int i = 0; i < m; i++) {
    --c[i];
    --d[i];
    grid[c[i]][d[i]] = 2;
  }
  vector<vector<bool>> rowp(h, vector<bool>(w));
  vector<vector<bool>> rows(h, vector<bool>(w));
  vector<vector<bool>> colp(h, vector<bool>(w));
  vector<vector<bool>> cols(h, vector<bool>(w));
  for (int i = 0; i < h; i++) {
    bool ok = false;
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == 2) {
        ok = false;
      } else if (grid[i][j] == 1) {
        ok = true;
      }
      rowp[i][j] = ok;
    }
    ok = false;
    for (int j = w - 1; j >= 0; j--) {
      if (grid[i][j] == 2) {
        ok = false;
      } else if (grid[i][j] == 1) {
        ok = true;
      }
      rows[i][j] = ok;
    }
  }
  for (int i = 0; i < w; i++) {
    bool ok = false;
    for (int j = 0; j < h; j++) {
      if (grid[j][i] == 2) {
        ok = false;
      } else if (grid[j][i] == 1) {
        ok = true;
      }
      colp[j][i] = ok;
    }
    ok = false;
    for (int j = h - 1; j >= 0; j--) {
      if (grid[j][i] == 2) {
        ok = false;
      } else if (grid[j][i] == 1) {
        ok = true;
      }
      cols[j][i] = ok;
    }
  }
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == 0 || grid[i][j] == 1) {
        int cur = rowp[i][j] || rows[i][j] || colp[i][j] || cols[i][j];
        res += cur;
      }
    }
  }
  cout << res << '\n';
  return 0;
}

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

vector<vector<int>> graph;
vector<bool> visit(2000);

void  dfs(int now_town){

    if(visit[now_town]){
        return;
    }

    visit[now_town] = true;
    for(auto next_town : graph[now_town]){
        dfs(next_town);
    }
}

int main(void){

    int N, M;
    cin >> N >> M;

    graph.resize(N);
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;

        graph[A-1].push_back(B-1);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){

        for(int j = 0; j < N; j++){
            visit[j] = false;
        }
        dfs(i);

        for(int j = 0; j < N; j++){
            if(visit[j]) ans++;
        }
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using Tuple = tuple<int, int, int, int>;
using V1 = vector<int>;
using V2 = vector<V1>;
using V3 = vector<V2>;
using PQueue = priority_queue<Tuple, vector<Tuple>, greater<Tuple>>;

constexpr int INF = 1e+9;

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

int calc_dist(int idx, V2 &A, V2 &B, int x1, int y1, int z1)
{
    if (idx == 0)
        return A[x1][y1];
    if (idx == 1)
        return A[x1][y1 - 1];
    if (idx == 2)
        return B[x1][y1];
    if (idx == 3)
        return (z1 == 0) ? 2 : 1;
    if (idx == 4)
        return 1;
    assert(false);
    return INF;
}

int main()
{
    int R, C;
    cin >> R >> C;
    V2 A(R, V1(C - 1)), B(R - 1, V1(C));
    for (auto &Ai : A) {
        for (auto &Aij : Ai)
            cin >> Aij;
    }
    for (auto &Bi : B) {
        for (auto &Bij : Bi)
            cin >> Bij;
    }
    V3 cost(R, V2(C, V1(2, INF)));
    cost[0][0][0] = 0;
    PQueue pq;
    pq.push({0, 0, 0, 0});
    int dx[5] = {0, 0, 1, -1, 0};
    int dy[5] = {1, -1, 0, 0, 0};
    while (!pq.empty()) {
        auto [cost1, x1, y1, z1] = pq.top(); pq.pop();
        if (cost[x1][y1][z1] < cost1)
            continue;
        for (int i = 0; i < 5; ++i) {
            auto x = x1 + dx[i], y = y1 + dy[i], z = (i >= 3) ? 1 : 0;
            if (x < 0 || R <= x || y < 0 || C <= y)
                continue;
            if (i == 3 && z1 == 0)
                continue;
            auto d = calc_dist(i, A, B, x1, y1, z1);
            auto cost2 = cost1 + d;
            if (chmin(cost[x][y][z], cost2))
                pq.push({cost2, x, y, z});
        }
    }
    auto &costRC = cost[R - 1][C - 1];
    cout << *min_element(costRC.begin(), costRC.end()) << endl;
}

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vvc d(2000+2,vector<char>(2000+2, '#'));
vector<vvl> dp(4,vvl(2000+2, vl(2000+2,-1)));
//URDL
int dx[4] = {0,1,0,-1};
int dy[4] = {-1,0,1,0};
/*void dfs(int x, int y, int dir){
  if(dp[dir][x][y] != -1) return;
  rep(i,4){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(d.at(nx).at(ny) == '#'){
      dp[i][x][y] = 0;
    }else{
      if(dp[i][nx][ny] != -1){
        dp[i][nx][ny] = dp[i][x][y] + 1;
      }else{
        dfs()
      }
    }

  }

  if(d.at(x).at(y) == '#'){
    dp[dir][x][y] = 0;
    return;
  }

}*/
long dfs(int x, int y, int dir){
  if(d.at(x).at(y) == '#') return 0;
  if(dp[dir][x][y] != -1) return dp[dir][x][y];
  int nx = x + dx[dir];
  int ny = y + dy[dir];
  if(d.at(nx).at(ny) == '#') return dp[dir][x][y] = 0;
  else return dp[dir][x][y] = dfs(nx,ny,dir) + 1;
}

int main(){
  long h,w;
  cin >> h >> w;
  long shiro = 0;
  rep(i,h){
    rep(j,w) {
      cin >> d.at(i+1).at(j+1);
      if(d.at(i+1).at(j+1) == '.') shiro++;
    }
  }

  vl two(5000000, 1);
  REP(i,1,5000000){
    two.at(i) = two.at(i-1)*2%MOD;
  }
  long ans = 0;
  rep(i,h){
    rep(j,w){
      if(d.at(i+1).at(j+1) == '#') continue;
      long cnt = 1;
      rep(k,4){
        cnt += dfs(i+1,j+1,k);
      }
      long tmp = two.at(shiro-cnt) * (two.at(cnt) + MOD - 1) % MOD;
      ans = ( ans + tmp ) % MOD;
    }
  }

  cout << ans << endl;
}


#include<cstdio>
typedef long long ll;
struct SegmentTree {
    int num,rt;
    ll size[2000005],sum[2000005];
    int lson[2000005],rson[2000005];
    SegmentTree() {num=0; rt=0;}
    inline void _change(int &p,int l,int r,int x,int d) {
        if(!p) p=++num;
        size[p]+=d; sum[p]+=x*1ll*d;
        if(l==r) return;
        int mid=l+r>>1;
        if(x<=mid) _change(lson[p],l,mid,x,d);
        else _change(rson[p],mid+1,r,x,d);
    }
    inline void change(int x,int d) {_change(rt,1,100000000,x,d);}
    inline ll _ask(int p,int l,int r,int L,int R,ll *arr) {
        if(L<=l&&r<=R) return arr[p];
        int mid=l+r>>1; ll res=0;
        if(L<=mid&&lson[p]) res+=_ask(lson[p],l,mid,L,R,arr);
        if(R>mid&&rson[p]) res+=_ask(rson[p],mid+1,r,L,R,arr);
        return res;
    }
    inline ll ask(int L,int R,int op) {return op==1? _ask(rt,1,100000000,L,R,size):_ask(rt,1,100000000,L,R,sum);}
}t[2];
int a[200005][2];
inline int read() {
    register int x=0,f=1;register char s=getchar();
    while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
    while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
    return x*f;
}
int main() {
    int n=read(),m=read(),Q=read(); ll ans=0;
    t[0].change(0,n); t[1].change(0,m);
    while(Q--) {
        int op=read()-1,x=read(),val=read();
        t[op].change(a[x][op],-1);
        ans-=t[op^1].ask(1,a[x][op],1)*a[x][op]+t[op^1].ask(a[x][op]+1,1e8,2);
        t[op].change(val,1);
        ans+=t[op^1].ask(1,val,1)*val+t[op^1].ask(val+1,1e8,2);
        a[x][op]=val;
        printf("%lld\n",ans);
    }
    return 0;
}

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

long N, C, x, y, c, cur, pr1, pr2, total;
vector<pair<long, long>> a;

bool sortbc(const pair<int,int> &a,
              const pair<int,int> &b)
{
	if (a.first == b.first)
    	return (a.second > b.second);
    return a.first < b.first;
}

int main() {
	cin>>N>>C;
	for(int i=0; i<N; i++) {
		cin>>x>>y>>c;
		a.push_back(make_pair(x, c));
		a.push_back(make_pair(y, -1*c));
	}
	sort(a.begin(), a.end(), sortbc);

	int i = 0;
	while( i < 2*N ) {
		int day = a[i].first;
		int both = 0;
		while(a[i].first == day && a[i].second > 0) {
			cur += a[i].second;
			i++;
		}
		if( a[i].first == day ) {
			total += min(C, cur);
			both = 1;
		}
		while( a[i].first == day && a[i].second < 0 ) {
			cur += a[i].second;
			i++;
		}
		total += (a[i].first - day - both) * min(C, cur);
	}
	cout<<total;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,a,b;
  cin >> n >> a >> b;
  cout << n - a + b << endl;
  return 0;
}

#include <iostream>
#include<stdio.h>
#include<iostream>
#include <cmath>
using namespace std;

int main(){
  int n,plus,minus;
  cin>>n>>minus>>plus;
  int sum=(n-minus)+plus;
  cout<<sum;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline ll read(){
	ll x=0; char ch=getchar(); bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=2e5+5;
int sum[N][26];
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1),la=n+1;
	ll ans=0;
	Rep(i,n,1){
		For(j,0,25) sum[i][j]=sum[i+1][j];
		sum[i][s[i]-'a']++;
		if(i>n-2) continue;
		if(s[i]==s[i+1]){
			int ssw=la-i-sum[i][s[i]-'a']+sum[la][s[i]-'a'];
			if(s[la]!=s[i]) ssw+=n-la+1;
			la=i; ans+=ssw;
		}
	}
	cout<<ans;
}

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

//UnionFindテンプレ
class UnionFind {
    // まとめる 判定 サイズを知る
    public:
    // Aから見た親の番号を格納する。rootだったら-1*その集合のサイズ。
    vector<int> Parent;

    // 初期化
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    // Aのrootを調べる
    int root(int A) {
        if (Parent[A] < 0) return A;  // マイナスならそれはroot
        return Parent[A] = root(Parent[A]);
    }

    // rootの値をプラスに戻して返す(サイズ)
    int size(int A) {
        return -Parent[root(A)];
    }

    // くっつける関数
    bool connect(int A, int B) {
        // AとBのroot同士をくっつける
        A = root(A);  // ここのAは、"rootの場所"の意味
        B = root(B);
        if (A == B) return false;  // 既にくっついている
        if (size(A) < size(B))
        swap(A, B);            // 大きい方にくっつけるために中身交換
        Parent[A] += Parent[B];  // 中身更新
        Parent[B] = A;
        return true;
    }

    //連結か調べる関数
    bool issame(int A, int B) {
        return root(A) == root(B);
    }
};

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

//aのZ/mZでの逆元
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//累乗a^b
int64_t pow(int a, int b) {
    int64_t ans = (int64_t)1;
    for (int i = 0; i < b; i++) {
        ans *= (int64_t)a;
    }
    return ans;
}

//最大公約数
int gcd(int a, int b) {
    if (a % b == 0) {
        return b;
    }
    return gcd(b, a%b);
}

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

//ここから

int main() {
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    s += s;
    int a = s.size();

    for (int i = 0; i < k; i++) {
        string S;
        for (int j = 0; j < a/2; j++) {
            S += jan(s.at(2*j), s.at(2*j+1));
        }
        s = S+S;
    }

    cout << s.at(0) << endl;
}