#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// clang++ -std=c++11 -stdlib=libc++
//
vi to[200005];
int d[200005];
ll ans[200005];

void add(int v, int from = -1) {
  for (int u : to[v]) {
    if (u == from)
      continue;
    ans[u] += ans[v];
    add(u, v);
  }
}
void dfs(int v, int from = -1) {
  for (int u : to[v]) {
    if (u == from)
      continue;
    chmin(d[u], d[v] + 1);
    dfs(u, v);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n) d[i] = INF;
  d[0] = 0;
  vi a(n - 1);
  vi b(n - 1);
  rep(i, n - 1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    to[a[i]].pb(b[i]);
    to[b[i]].pb(a[i]);
  }
  dfs(0);
  int q;
  cin >> q;
  while (q--) {
    int t, i, x;
    cin >> t >> i >> x;
    i--;
    int avoid;
    int v;
    if (t == 1) {
      avoid = b[i];
      v = a[i];
    } else {
      avoid = a[i];
      v = b[i];
    }
    if (d[avoid] < d[v]) {
      ans[v] += x;
    } else {
      ans[0] += x;
      ans[avoid] -= x;
    }
  }
  add(0);
  rep(i, n) cout << ans[i] << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=400005,INF=1<<30;
vector<pair<int,int>> G[MAX];
ll imo[MAX];
bool seen[MAX];
int s[MAX],g[MAX],timer;
pair<int,int> wh[MAX];

void DFS(int u){
    seen[u]=1;
    s[u]=timer;
    timer++;
    for(auto to:G[u]){
        if(seen[to.fi]) continue;

        wh[to.se]=mp(u,to.fi);
        DFS(to.fi);
    }
    g[u]=timer;
    timer++;
}

int main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;cin>>N;
    vector<pair<int,int>> E(N-1);
    for(int i=0;i<N-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        E[i]=mp(a,b);
        G[a].push_back(mp(b,i));
        G[b].push_back(mp(a,i));
    }

    DFS(0);

    //for(int i=0;i<N;i++) cout<<s[i]<<" "<<g[i]<<endl;

    int Q;cin>>Q;
    while(Q--){
        int t,e,x;cin>>t>>e>>x;
        e--;
        if(t==1){
            if(wh[e].fi==E[e].fi){
                imo[0]+=x;
                imo[s[wh[e].se]]-=x;
                imo[g[wh[e].se]+1]+=x;
                imo[2*N]-=x;
            }else{
                imo[s[wh[e].se]]+=x;
                imo[g[wh[e].se]+1]-=x;
            }
        }else{
            if(wh[e].fi==E[e].se){
                imo[0]+=x;
                imo[s[wh[e].se]]-=x;
                imo[g[wh[e].se]+1]+=x;
                imo[2*N]-=x;
            }else{
                imo[s[wh[e].se]]+=x;
                imo[g[wh[e].se]+1]-=x;
            }
        }
    }

    for(int i=1;i<2*N;i++) imo[i]+=imo[i-1];

    vector<ll> ans(N);

    for(int i=0;i<N;i++){
        cout<<imo[s[i]]<<endl;
    }

}


#include<bits/stdc++.h>
using namespace std ;
int main()
{
	string str ;
	cin>>str ;
	bool f = 1 ;
	for(int i = 0 ; i < str.size() ; i++)
	if(str[i] != str[str.size()-i-1])
	f = 0 ;
	if(f)
	cout<<"Yes"<<endl ;
	else
	{
		int j = str.size()-1 , i = 0 ;
		while( j >= 0 && str[j] == '0' && str[str.size()-j-1] != 0)
		j-- ;
		//int i = 0 ;
		bool f1 = 1 ;
		while(i <= j)
		{
			if(str[i] != str[j])
			{
				f1 = 0 ;
				break ;
			}
			else
			i++,j-- ;
		}
		if(f1)
		cout<<"Yes" ;
		else
		cout<<"No" ;
	}
}

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n % 2) cout << "Black" << endl;
    else
        cout << "White" << endl;
}


#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 0x3f3f3f3f
#define pll pair<long long , long long>
const int MAX=5e6+9;
const ll mod=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<pair<int , int > >adj[MAX];
bool check(int x, int y , int n , int m){
	if(x<0||y<0||x>=n||y>=m)
		return false;
	else
		return true;
}
int dijikstra(int n , int m){
	multiset<pair< int , int > > st;
	int dis[n*m+4];
	bool vis[n*m+4];
	for(int i = 0;i<n*m;i++){
		dis[i]=INF;
		vis[i]=false;
	}
	dis[0]=0;
	st.insert({0 , 0});
	while(!st.empty()){
		pair<int , int > it = *st.begin();
		int from = it.second;
		st.erase(st.begin());
	//	cout<<23;
		if(vis[from])
			continue;
		vis[from]=true;
		//cout<<from<<endl;
		for(auto v:adj[from]){
			if(dis[v.first]>=dis[from]+v.second){
				dis[v.first]=dis[from]+v.second;
				st.insert({dis[v.first],v.first});
			}
		}
	}
	return dis[(n)*m-1];
}
int main()
{
	int n , m;
	cin>>n>>m;
	int a[n+1][m+1] , b[n+1][m+1];
	for(int i = 0;i<n;i++){
		for(int j = 0;j<m-1;j++)
			cin>>a[i][j];
	}
	for(int i = 0;i<n-1;i++){
		for(int j = 0;j<m;j++)
			cin>>b[i][j];
	}
	for(int i = 0;i<n;i++){
		for(int j = 0;j<m;j++){
			if(check(i , j+1, n , m)){
				adj[i*m+j].push_back({i*m+j+1 , a[i][j]});
			}
			if(check(i , j-1, n , m)){
				adj[i*m+j].push_back({i*m+j-1 , a[i][j-1]});
			}
			if(check(i+1 , j ,n , m)){
				adj[i*m+j].push_back({(i+1)*m+j , b[i][j]});
			}
			for(int k = 1;k<=n;k++){
				if(check(i-k , j, n , m)){
				adj[i*m+j].push_back({(i-k)*m+j , 1+k});
			}
			}
		}
	}
	cout<<dijikstra(n , m);

}

#include <bits/stdc++.h>

// #include <atcoder/all>
#define rep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = (int)2e9;
constexpr ll INFll = (ll)1e18;
constexpr int MOD = 1e9 + 7;

struct edge {
  int to, cost;
  edge(int t, int c) : to(t), cost(c) {}
};

vector<vector<edge>> G;
int R, C;

int dijkstra(int s, int t) {
  priority_queue<P, vector<P>, greater<P>> que;
  vector<int> d(2 * R * C, INF);

  que.emplace(s, 0);
  d[s] = 0;

  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    int curd = p.first, curv = p.second;
    if (curd > d[curv]) continue;
    for (auto e : G[curv]) {
      if (curd + e.cost < d[e.to]) {
        d[e.to] = curd + e.cost;
        que.emplace(d[e.to], e.to);
      }
    }
  }
  return d[t];
}

int main() {
  cin >> R >> C;
  G.resize(2 * R * C);
  rep(r, 0, R) rep(c, 0, C - 1) {
    int a;
    cin >> a;
    G[r * C + c].emplace_back(r * C + c + 1, a);
    G[r * C + c + 1].emplace_back(r * C + c, a);
  }
  rep(r, 0, R - 1) rep(c, 0, C) {
    int b;
    cin >> b;
    G[r * C + c].emplace_back((r + 1) * C + c, b);
  }
  rep(r, 0, R) rep(c, 0, C) {
    G[r * C + c].emplace_back(r * C + c + R * C, 1);
    G[r * C + c + R * C].emplace_back(r * C + c, 0);
  }
  rep(r, 0, R - 1) rep(c, 0, C) {
    G[(r + 1) * C + c + R * C].emplace_back(r * C + c + R * C, 1);
  }

  cout << dijkstra(0, R * C - 1) << endl;
}


#include <cstdio>
#include <algorithm>
using namespace std;
long long a[200005],t[200005];
pair<long long,int> x[200005];
long long treemax[800005],treemin[800005],lazy[800005],sum,ans[200005];
bool flazy[800005];
int p;
void build(int p,int l,int r)
{
    if(l==r)
    {
        treemax[p]=treemin[p]=x[l].first;
        return;
    }
    int mid=(l+r)/2;
    build(p<<1,l,mid);
    build(p<<1|1,mid+1,r);
    treemax[p]=max(treemax[p<<1],treemax[p<<1|1]);
    treemin[p]=min(treemin[p<<1],treemin[p<<1|1]);
}
void pushdown(int p,int l,int r)
{
    if(flazy[p])
    {
        treemax[p<<1]=treemin[p<<1]=treemax[p<<1|1]=treemin[p<<1|1]=lazy[p<<1]=lazy[p<<1|1]=lazy[p];
        flazy[p<<1]=flazy[p<<1|1]=true;
        flazy[p]=false;
    }
}
void update(int p,int l,int r,int ql,int qr,long long d)
{
    if(ql==l&&qr==r)
    {
        treemax[p]=treemin[p]=d;
        lazy[p]=d;
        flazy[p]=true;
        return;
    }
    pushdown(p,l,r);
    int mid=(l+r)/2;
    if(qr<=mid)
        update(p<<1,l,mid,ql,qr,d);
    else if(ql>mid)
        update(p<<1|1,mid+1,r,ql,qr,d);
    else
    {
        update(p<<1,l,mid,ql,mid,d);
        update(p<<1|1,mid+1,r,mid+1,qr,d);
    }
    treemax[p]=max(treemax[p<<1],treemax[p<<1|1]);
    treemin[p]=min(treemin[p<<1],treemin[p<<1|1]);
}
int querymin(int p,int l,int r,long long d)
{
    if(l==r)
        return l;
    pushdown(p,l,r);
    int mid=(l+r)/2;
    if(treemin[p<<1|1]<d)
        return querymin(p<<1|1,mid+1,r,d);
    else return querymin(p<<1,l,mid,d);
}
int querymax(int p,int l,int r,long long d)
{
    if(l==r)
        return l;
    pushdown(p,l,r);
    int mid=(l+r)/2;
    if(treemax[p<<1]>d)
        return querymax(p<<1,l,mid,d);
    else return querymax(p<<1|1,mid+1,r,d);
}
long long query(int p,int l,int r,int d)
{
    if(l==r)
        return treemax[p];
    pushdown(p,l,r);
    int mid=(l+r)/2;
    if(d<=mid)
        return query(p<<1,l,mid,d);
    else return query(p<<1|1,mid+1,r,d);
}
int main()
{
    int N,Q;
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
        scanf("%lld%lld",&a[i],&t[i]);
    scanf("%d",&Q);
    for(int i=1;i<=Q;i++)
    {
        scanf("%lld",&x[i].first);
        x[i].second=i;
    }
    sort(x+1,x+Q+1);
    build(1,1,Q);
    for(int i=1;i<=N;i++)
        if(t[i]==1)
            sum+=a[i];
        else if(t[i]==2)
        {
            if(treemin[1]>=a[i]-sum)
                continue;
            p=querymin(1,1,Q,a[i]-sum);
            update(1,1,Q,1,p,a[i]-sum);
        }
        else
        {
            if(treemax[1]<=a[i]-sum)
                continue;
            p=querymax(1,1,Q,a[i]-sum);
            update(1,1,Q,p,Q,a[i]-sum);
        }
    for(int i=1;i<=Q;i++)
        ans[x[i].second]=query(1,1,Q,i);
    for(int i=1;i<=Q;i++)
        printf("%lld\n",ans[i]+sum);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

template<typename T>
void debug(vector<T> item) {

	for (auto i : item) {
		cout << i << " ";
	}

	cout << endl;
}

int main() {
	int N;

	cin >> N;

	int64_t mn = -(int64_t)1e9;
	int64_t mx = 1e9;

	int64_t sum = 0;
	for (int i = 0; i < N; ++i) {
		int64_t a, b;
		cin >> a >> b;

		if (b == 1) {
			sum += a;
			mn += a;
			mx += a;
		} else if (b == 2) {
			mn = max(a, mn);
			mx = max(a, mx);
		} else {
			mn = min(a, mn);
			mx = min(a, mx);
		}
	}

	int Q;

	cin >> Q;

	for (int i = 0; i < Q; ++i) {
		int64_t q;
		cin >> q;

		q += sum;

		if (mn <= q && q <= mx) {
			cout << q << endl;
		} else if (q < mn) {
			cout << mn << endl;
		} else {
			cout << mx << endl;
		}
	}

	return 0;
}


#include <iostream>
using namespace std;
int n, max_ = 1000, min_ = 1;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    int temp;
    for(int i = 0;i < n;++i)
    {
        cin >> temp;
        min_ = max(temp, min_);
    }
    for(int i = 0;i < n;++i)
    {
        cin >> temp;
        max_ = min(temp, max_);
    }
    if(max_ - min_ + 1 <= 0){cout << 0;}
    else{cout << max_ - min_ + 1;}
    return 0;
}

#include <stdio.h>

long long int x[200010];
long long int sum[200010],sum2[200010],max[200010];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=a;i++) sum[i] = sum[i-1] + x[i];
	for(int i=1;i<=a;i++) sum2[i] = sum2[i-1] + sum[i];

	max[1] = x[1];
	for(int i=1;i<=a;i++) max[i] = max[i-1]>x[i]?max[i-1]:x[i];

	for(int i=1;i<=a;i++)
	{
		long long int S = sum[i] + sum2[i-1] + i*max[i];
		printf("%lld\n",S);
	}
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define replr(i, l, r) for (int i = (l); i < (r); ++i)
const int mod = 1e9 + 7;
vector<int> T[202020];
ll ans[202020], C[202020];
void rec(int x, ll c, int par) {
    c += C[x];
    for (int to : T[x]) {
        if (to == par)
            continue;
        rec(to, c, x);
    }
    ans[x] = c;
}

int main() {
    int n, q;
    cin >> n;
    vector<int> A(n), B(n), X(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        A[i] = a;
        B[i] = b;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    queue<P> Q;
    Q.push({1, 0});
    while (!Q.empty()) {
        P p = Q.front();
        Q.pop();
        if (X[p.second] > 0)
            continue;
        X[p.second] = p.first;
        for (int to : T[p.second])
            Q.push({p.first + 1, to});
    }

    cin >> q;
    rep(i, q) {
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        int a = A[e], b = B[e];
        if (X[a] > X[b]) {
            if (t == 1)
                C[a] += x;
            else {
                C[0] += x;
                C[a] -= x;
            }
        } else {
            if (t == 1) {
                C[0] += x;
                C[b] -= x;
            } else
                C[b] += x;
        }
    }
    rec(0, 0, -1);
    rep(i, n) cout << ans[i] << endl;
    return 0;
}

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

typedef long long int ll;
ll n, a, b, q, c[200007], buf, p[200007];
vector<pair<ll, ll>> e;
vector<pair<ll, bool>> op[200007];
vector<ll> adj[200007];

void find_parent(ll x, ll par) {
    p[x] = par;
    for(ll i : adj[x]) {
        if(i != par) {
            find_parent(i, x);
        }
    }
}

void dfs(ll x, ll add) {
    ll cur = add;
    for(pair<ll, bool> i : op[x]) {
        if(i.second) {
            cur += i.first;
        } else {
            cur -= i.first;
            buf += i.first;
        }
    }

    c[x] += cur;
    for(ll i : adj[x]) {
        if(i != p[x]) {
            dfs(i, cur);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(ll i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        e.push_back({a, b});
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    find_parent(1, -1);

    cin >> q;
    for(ll i = 0; i < q; ++i) {
        ll t, k, x;
        cin >> t >> k >> x;
        k--;
        if(t == 1) { //1 - adding to subtree, 0 - subtracting and adding to buffer
            if(p[e[k].first] == e[k].second) op[e[k].first].push_back({x, 1});
            else op[e[k].second].push_back({x, 0});
        } else {
            if(p[e[k].second] == e[k].first) op[e[k].second].push_back({x, 1});
            else op[e[k].first].push_back({x, 0});
        }
    }

    dfs(1, 0);

    for(ll i = 1; i <= n; ++i) cout << c[i] + buf << '\n';
    return 0;
}


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

using namespace std;

ll MOD = (ll)1000000007;
vector<ll> nums;
int occ[26];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t, m, n;
    ll k, ans = 0;
    string s1, s2;
    bool sad = false;
    cin >> s1;
    for(int i = s1.size()-1; i >= 0; i--) {
        occ[s1.at(i)-'a']++;
        if(i != s1.size()-1) {
            if(s1.at(i) == s1.at(i+1)) {
                ans += s1.size() - i - occ[s1.at(i)-'a'];
                for(int j = 0; j < 26; j++) occ[j] = 0;
                occ[s1.at(i)-'a'] = s1.size()-i;
            }
        }
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>
#include <cassert>
#include <functional>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int N;
int main() {
  cin >> N;
  vi p(N);
  rep(i, N) cin >> p[i];
  vector<int> used(200005);
  int mn = 0;
  rep(i, N) {
    int a = p[i];
    used[a] = true;
    while (mn == a || used[mn]) {
      mn++;
    }
    cout << mn << endl;
  }
  return 0;
}


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

void setIO(string s) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen((s + ".in").c_str(), "r", stdin);
//    freopen((s + ".out").c_str(), "w", stdout);
}

int descending(string a)
{
    int arr[a.length()];
    for (int i = 0; i < a.length(); i++)
    {
        arr[i] = a[i] - '0';
    }
    sort(arr, arr + (sizeof(arr) / sizeof(arr[0])), greater<int>());

    for (int i = 0; i < a.length(); i++)
    {
        a[i] = arr[i] + '0';
    }
    int ab = stoi(a);
    return ab;
}

int ascending(string a)
{
    int arr[a.length()];
    for (int i = 0; i < a.length(); i++)
    {
        arr[i] = a[i] - '0';
    }
    sort(arr, arr + (sizeof(arr) / sizeof(arr[0])));

    bool zero = true;
    string s = "";
    for (int i = 0; i < a.length(); i++)
    {
        if (arr[i] != 0) zero = false;
        else continue;

        if (!zero) s.push_back(arr[i] + '0');
    }
    int ab = stoi(s);
    return ab;
}

int main()
{
    setIO("");

    string n; cin >> n;
    int k; cin >> k;
    for (int i = 0; i < k; i++)
    {
        int nDup = descending(n) - ascending(n);
        n = to_string(nDup);
        if (n == "0") break;
    }
    cout << n;
}

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

int ak(int num){
    string n = to_string(num);

    sort(n.begin(), n.end());
    int g2 = stoi(n);

    reverse(n.begin(), n.end());
    int g1 = stoi(n);

    return g1- g2;
}

int main(){
    int n; cin >> n;
    int k; cin >> k;
    for(int i=0;i<k;i++){
        n = ak(n);
    }
    cout << n;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> V;
#define F(N,S,E) for(int N=(int)(S);N<=(int)(E);N++)
#define R(N,S,E) for(int N=(int)(S);N>=(int)(E);N--)
#define D(N,E) for(int N=0;N<(int)(E);N++)
LL read(){LL x;scanf("%lld",&x);return x;}

const int N=2.1e5;
int a[N],b[N];
int st[N];
int main(){
	int n=read();
	F(i,1,n)a[n-i+1]=read();
	F(i,1,n)b[i]=read();
	F(i,1,n)if(a[i]<b[i])swap(a[i],b[i]);
	// F(i,1,n)cerr<<a[i]<<" "<<b[i]<<endl;
	priority_queue<pair<int,int> > q1;
	F(i,1,n){
		if(!q1.empty()&&q1.top().first+b[i]>0){
			pair<int,int> t=q1.top();
			q1.pop();
			if(--st[t.second]==0){
				q1.push(make_pair(-a[t.second],t.second));
			}
			st[i]=1;
			q1.push(make_pair(-b[i],i));
		}
		else{
			q1.push(make_pair(-a[i],i));
		}
	}
	// F(i,1,n)cerr<<i<<" "<<st[i]<<endl;
	LL ans=0;
	F(i,1,n)ans+=st[i]==0?a[i]:st[i]==1?a[i]+b[i]:0;
	printf("%lld\n",ans);
	return 0;
}

// Good Bye rng_58
/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#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++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
    int n; cin >> n;
    for(int i = 0; i < n; ++ i) {
        cout << 2 * i % n + 1 << " " << (2 * i + 1) % n + 1 << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long power(int y) {
   int i; long long power=1;
   if(y == 0)
   return 1;
   for(i=1;i<=y;i++)
   power=power*2;
   return power;
}
int main() {
	int n;
	cin >> n;
	string s[n];
	for(int i = 0; i < n; i++) cin >> s[i];
	long long x = 1;
	for(int i = 0; i < n; i++){
	    if(s[i] == "OR"){
	        x = x + power(i + 1);
	    }
	}
	cout << x;
	return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<long long> dp(2,1);
    for(int i = 0; i < n;++i){
        string s;
        cin >> s;
        vector <long long > p(2,0);
        swap (dp,p);
        for(int j = 0; j < 2;++j){
            for(int x = 0;x < 2; ++x){
                int nj = j;
                if(s == "AND"){
                    nj &= x;
                }
                else nj |= x;
                dp[nj] += p[j];
            }
        }
    }
    cout << dp[1] << endl;
    return 0;
}
/*long long count(string S[],long long n){
    if(n == 0){
        return 1;
    }
    else if(S[n-1] == "OR"){
        return (pow(2,n) + count(S,n-1));
    }
    else return count(S,n-1);
}
/*int main()
{
    long long n;
    cin >> n;
    string S[n];
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    for(long long i = 0; i < n; ++i){
        cin >> S[i];
    }

    cout << count(S,n) << endl;
    return 0;
    /*int cnt = 0;
    for(int bit = 0; bit < (1<<(n+1)); ++bit){
        int bitset[n+1] = {0};
        for(int k = 0; k <= n; ++k){
            int Div = (1 << k);
            bitset[k] = (bit / Div) % 2;
        }
        int y[n+1];
        y[0] = bitset[0];
        for(int i = 1; i <= n; ++i){
            if(S[i-1] == "AND"){
                y[i] = y[i-1] & bitset[i];
            }
            else y[i] = y[i-1] | bitset[i];
        }
        if(y[n] == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
}*/


#include <iostream>

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	char** s = (char**)calloc(h, sizeof(char*));
	for(int i = 0; i < h; i++){
		s[i] = (char*)calloc(w+1, sizeof(char));
		cin >> s[i];
	}
	//→と↓だけ見る
	int count = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '.'){
				if(i == h-1 && j == w-1) break;
				if(i == h-1 && j != w-1){
					if(s[i][j+1] == '.') count++;
				}else if(j == w-1){
					if(s[i+1][j] == '.') count++;
				}
				else{
					if(s[i+1][j] == '.' && s[i][j+1] == '.') count+=2;
					else if(s[i+1][j] == '.' || s[i][j+1] == '.')count++;
				}
			}
		}
	}
	cout << count << endl;

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(),v.end()
#define sz(x) (int)sz.size()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;

#ifdef LOCAL//ONLINE_JUDGE
#include "D:\c_c++\template.h"
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;
			a=a*a%mod;
    }
    return res;
}
int h,w;
bool isval(int x,int y){
	return x>=0 && x<h && y>=0 && y<w;
}
int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
void solve(){
	cin>>h>>w;
	string s[h];
	for(int i=0;i<h;i++)cin>>s[i];

	ll cnt=0;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++){
			if(s[i][j]=='#')continue;
			for(int d=0;d<4;d++){
				int nx=i+dir[d][0],ny=j+dir[d][1];
				if(isval(nx,ny)){
					debug(i,j,nx,ny);
					if(s[nx][ny]=='.')cnt++;
				}
			}
		}
	debug(cnt);
	cout<<(cnt/2LL)<<'\n';

}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
//    #ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)solve();
}


// Code Written by Pinaki Bhattacharjee (pinakipb2)

#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
// template<typename num_t> using ordered_set = tree<num_t, null_type, less<num_t>, rb_tree_tag, tree_order_statistics_node_update>;

// #define
#define LOCAL
#define endl "\n"
#define PI 2*acos(0.0)
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mpr make_pair
#define all(x) (x).begin(),(x).end()
#define ppc __builtin_popcountll
void pinakipb2() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

// constants
const int MAX = 1e7 + 10;
const int MOD = (int) 1e9 + 7;

ll ans;
vector<ll> parent(MAX),sz(MAX);

void make_set(ll v)
{
    parent[v] = v;
    sz[v] = 1;
}

ll find_set(ll v)
{
    if(v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(ll a, ll b)
{
    a = find_set(a);
    b = find_set(b);
    if(a==b) return;
    ans++;
    if(a!=b)
    {
        if(sz[a]<sz[b])
            swap(a,b);
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main()
{
    pinakipb2();

    ll n;
    cin>>n;
    for(int i=1;i<=MAX-2;i++)
    {
        make_set(i);
    }
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    for(int i=0;i<n;i++)
    {
        union_sets(v[i],v[n-i-1]);
    }
    cout<<ans<<endl;

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;
    template<class t>
    void output(t a){
        if(was_output)cout << " ";
        cout << a;
        was_output = true;
    }
    void outendl(){
        was_output = false;
        cout << endl;
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    void out(t x){
        cout << x;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

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

using namespace templates;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n = in();
    double ans = 0;
    rep(i,1,n){
        ans += 1 / (1 - (n-i) / (double) n);
    }
    printf("%.20lf\n",ans);
    return 0;
}


#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
// #include "atcoder/all"
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,k,n) for (int i = (k); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const ll INF = (ll)1e18;
void chmin(ll &a, ll b) { a = min(a, b); }
void chmax(ll &a, ll b) { a = max(a, b); }

void solve() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int c = a+b;
    if (c >= 15 && b >= 8) ans = 1;
    else if (c >= 10 && b >= 3) ans = 2;
    else if (c >= 3) ans = 3;
    else ans = 4;
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef ptrdiff_t isize;

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef size_t usize;

typedef float f32;
typedef double f64;

#define unordered_set set

auto main() -> i32 {

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

    i64 n;
    string s, x;
    cin >> n >> s >> x;
    unordered_set<i64> need;
    need.insert(0);
    for (i64 i = n - 1; i >= 0; i--) {
        if (x[i] == 'A') {
            unordered_set<i64> next;
            for (i64 d = 0; d < 7; d++) {
                i64 ned = (d * 3) % 7 + 0;
                if (need.find(ned) != need.end()) {
                    i64 ned = ((d * 3) % 7 + s[i] - '0') % 7;
                    if (need.find(ned) != need.end()) {
                        next.insert(d);
                    }
                }

            }
            need = next;
        }
        else {
            unordered_set<i64> next;
            for (auto d : need) {
                i64 nxt = (d - (s[i] - '0')) % 7;
                if (nxt < 0) nxt += 7;
                nxt = (nxt * 5) % 7;
                next.insert(nxt);

                nxt = (d - 0) % 7;
                if (nxt < 0) nxt += 7;
                nxt = (nxt * 5) % 7;
                next.insert(nxt);
            }
            need = next;
        }
    }
    if (need.find(0) != need.end()) {
        cout << "Takahashi";
    }
    else {
        cout << "Aoki";
    }
    cout << "\n";

    return 0;
}

// 問題の URL を書いておく
//

#include <bits/stdc++.h>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = long long;

// 0 なら高橋勝ち
// 1 なら青木勝ち
int calc(int round, int m, string& S, string& T, vector<vector<int>>& state)
{
    Print(round);
    Print(m);
    if(state[round][m] != -1) return state[round][m];

    // 最終ラウンド
    auto n = S[round] - '0';
    if(round == (int)state.size() - 1)
    {
        if(T[round] == 'A')
        {
            if(m != 0 || (m + n) % 7  != 0)
            {
                state[round][m] = 1;
            }
            else state[round][m] = 0;
        }
        else
        {
            if(m == 0 || (m + n) % 7  == 0)
            {
                state[round][m] = 0;
            }
            else state[round][m] = 1;
        }

        Print(state[round][m]);
        return state[round][m];
    }

    if(T[round] == 'A')
    {
        if(calc(round + 1, (m * 10) % 7, S, T, state) == 1 || calc(round + 1, (m + n) * 10 % 7, S, T, state) == 1)
        {
            state[round][m] = 1;
            return 1;
        }
        state[round][m] = 0;
        return 0;
    }
    else
    {
        if(calc(round + 1, (m * 10) % 7, S, T, state) == 0 || calc(round + 1, (m + n) * 10 % 7, S, T, state) == 0)
        {
            state[round][m] = 0;
            return 0;
        }
        state[round][m] = 1;
        return 1;
    }
}

int main(int, const char**)
{
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;

    vector<vector<int>> state(N, vector<int>(7, -1));

    auto ans = calc(0, 0, S, T, state);
    Print(ans);
    cout << (ans == 0 ? "Takahashi" : "Aoki") << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using db = double;
using vdb = std::vector<db>;
using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending
using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending
using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending
using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending
template<class T>
using vv = std::vector<std::vector<T> >;

#define REPL(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FORL(i, 0, n)

#define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- )
#define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
#define INF pow(10, 10)

int main(void)
{
    ll V, T, S, D;
    string Str;
    cin >> V >> T >> S >> D;

    ll vanish_st = V*T;
    ll vanish_end = V*S;
    if(vanish_st <= D && vanish_end >= D)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

#include <bits/stdc++.h>

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

    int v, tstart, tfinish, d;
    std::cin >> v >> tstart >> tfinish >> d;

    if (v * tstart <= d and d <= v * tfinish) {
        printf("No\n");
    }
    else {
        printf("Yes\n");
    }

    return 0;
}


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

const int maxn=400005;
const int logn=21;
const int inf=1ll<<60;

struct Edge {
	int to,next;
	Edge(int to=0,int next=0):to(to),next(next) {}
};

Edge a[maxn*2];
int cnt;
int top;
int Max;
int root;
int s[maxn];
int h[maxn];
int t[maxn];
int ss[maxn];
int lg[maxn*2];
int ans[maxn];
int pre[maxn];
int depth[maxn];
int st[logn][maxn*2];
bool vis[maxn];

void add(int x,int y) {
	a[++cnt]=Edge(y,h[x]);
	h[x]=cnt;
}

void dfs(int x,int fa) {
	st[0][++top]=x;
	pre[x]=top;
//	t[x]=top;
	depth[x]=depth[fa]+1;
	for(int i=h[x]; i; i=a[i].next) {
		if(a[i].to!=fa) {
			dfs(a[i].to,x);
			st[0][++top]=x;
		}
	}
}

void dfs2(int x,int fa) {
	++top;
	t[x]=top;
	for(int i=h[x]; i; i=a[i].next) {
		if(a[i].to!=fa&&!vis[a[i].to]) {
			dfs2(a[i].to,x);
			++top;
		}
	}
}

int getmin(int x,int y) {
	return depth[x]<depth[y]?x:y;
}

int lca(int x,int y) {
	x=pre[x],y=pre[y];
	if(x>y) {
		swap(x,y);
	}
	int k=lg[y-x+1];
	return getmin(st[k][x],st[k][y-(1<<k)+1]);
}

int dist(int x,int y) {
	return depth[x]+depth[y]-2*depth[lca(x,y)];
}
int prt[maxn];

void dfsmax(int x,int dis) {
	s[++top]=x;
	if(dis>Max) {
		Max=dis;
		root=x;
//		memcpy(ss,s,sizeof(ss));
		ss[0]=top;
	}
	vis[x]=1;
	for(int i=h[x]; i; i=a[i].next) {
		if(!vis[a[i].to]) {
			prt[a[i].to]=x;
			dfsmax(a[i].to,dis+1);
		}
	}
	vis[x]=0;
	--top;
}

void prepare() {
	top=0;
	Max=0;
}

void getdis(int x) {
	prepare();
	dfsmax(x,0);
	prepare();
	int tp=root;
	dfsmax(root,0);
	for(int i=root;i!=tp;i=prt[i]) {
		ans[++ans[0]]=i;
	}
	ans[++ans[0]]=tp;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int n;
	cin>>n;
	for(int i=1; i<=n-1; i++) {
		int x,y;
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	dfs(1,0);
//	for(int i=2; i<=top; i++) {
//		lg[i]=lg[i>>1]+1;
//	}
//	for(int i=1; (1<<i)<=top; i++) {
//		for(int j=1; j+(1<<i)-1<=top; j++) {
//			st[i][j]=getmin(st[i-1][j],st[i-1][j+(1<<(i-1))]);
//		}
//	}
	getdis(1);
	top=0;
//	dfs2(root,0);
//	int k=Max;
//	memcpy(ans,ss,sizeof(ans));
	for(int i=1;i<=ans[0];i++) {
		vis[ans[i]]=1;
	}
	t[ans[1]]=1;
	top=1;
	for(int i=2;i<=ans[0]-1;i++) {
		t[ans[i]]=++top;
		for(int j=h[ans[i]];j;j=a[j].next) {
			if(!vis[a[j].to]) {
				dfs2(a[j].to,0);
				++top;
//				p=max(p,Max);
			}
		}
	}
	t[ans[ans[0]]]=++top;
//	int p=-1;
//	for(int i=1;i<=ans[0];i++) {
//		for(int j=h[ans[i]];j;j=a[j].next) {
//			if(!vis[a[j].to]) {
//				getdis(a[j].to);
//				p=max(p,Max);
//			}
//		}
//	}
//	int sum=1+k+2*(p+1);
//	t[ans[1]]=1;
//	t[ans[ans[0]]]=sum;
//	for(int i=1;i<=ans[0];i++) {
//
//		for(int j=h[ans[i]];j;j=a[j].next) {
//			if(!vis[a[j].to]) {
//				getdis(a[j].to);
//				p=max(p,Max);
//			}
//		}
//	}
////	for(int i=1;i<=n;i++) {
////		if(i!=ans[1]&&i!=ans[ans[0]]) {
////			t[i]=dist(ans[1],i)+1;
////		}
////	}
	for(int i=1; i<=n; i++) {
		cout<<t[i]<<" ";
	}
}

#include<algorithm>
#include<cstdio>
#define MaxN 400500
using namespace std;
int f[MaxN],o[MaxN],c[MaxN];
int find(int u)
{return f[u]==u ? u : f[u]=find(f[u]);}
void merge(int u,int v){
  u=find(u);v=find(v);
  if (u!=v){
    o[f[u]=v]+=o[u];
    c[v]+=c[u];
  }o[v]++;
}
bool vis[MaxN];
int n;
int main()
{
  scanf("%d",&n);
  for (int i=1;i<=400000;i++)c[f[i]=i]=1;
  for (int i=1,u,v;i<=n;i++){
    scanf("%d%d",&u,&v);
    merge(u,v);
  }
  int ans=0;
  for (int i=1;i<=400000;i++){
    int u=find(i);
    if (vis[u])continue;
    vis[u]=1;
    ans+=o[u]>=c[u] ? c[u] : c[u]-1;
  }printf("%d",ans);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

int main(){
    int x,y;
    cin>>x>>y;

    int r=min(x,y);
    int m=max(x,y);

    if(r+3>m)cout<<"Yes";
    else{
        cout<<"No";
    }
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#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
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 A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0};
V<int> dy = { 0, 0, -1, 1};

int main () {
    int h, w; cin >> h >> w;
    V<string> a(h); rep(i, h) cin >> a[i];
    V<V<int>> d(h, V<int> (w, -1));
    int sx, sy, gx, gy;
    V<set<P>> st(26);
    rep(i, h) rep(j, w) {
        if (a[i][j] == 'S') {
            sx = i, sy = j;
        }
        if (a[i][j] == 'G') {
            gx = i, gy = j;
        }
        if ('a' <= a[i][j] && a[i][j] <= 'z') {
            st[a[i][j] - 'a'].insert({i, j});
        }
    }
    d[sx][sy] = 0;
    queue<P> que;
    que.push({sx, sy});
    V<bool> checked(26, false);
    while (!que.empty()) {
        auto v = que.front(); que.pop();
        int x = v.first, y = v.second;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (a[nx][ny] == '#') continue;
            if (d[nx][ny] != -1) continue;
            d[nx][ny] = d[x][y] + 1;
            que.push({nx, ny});
        }
        if ('a' <= a[x][y] && a[x][y] <= 'z') {
            int m = a[x][y] - 'a';
            if (checked[m]) continue;
            for (auto p : st[m]) {
                int nx = p.first, ny = p.second;
                if (d[nx][ny] != -1) continue;
                d[nx][ny] = d[x][y] + 1;
                que.push({nx, ny});
            }
            //checked[m] = true;
            st[m] = set<P> ();
        }
    }
    cout << d[gx][gy] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
#define all(a) a.begin(),a.end()
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll INF = LLONG_MAX;
#define N (int)2e5+5

ll base_mat[3][3];
ll mat[N][3][3];

void update(int i)
{
	for(int j=0;j<3;j++)
	{
		for(int k=0;k<3;k++)
		{
			for(int p=0;p<3;p++)
			{
				mat[i][j][k]+=base_mat[j][p]*mat[i-1][p][k];
			}
		}
	}
}

int main()
{
	ios;
	int n;
	cin>>n;
	ll p[n+1][2];
	for(int i=1;i<=n;i++)
	{
		cin>>p[i][0]>>p[i][1];
	}
	int m;
	cin>>m;
	memset(mat,0,sizeof(mat));
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(i==j)mat[0][i][j]=1;
		}
	}
	for(int i=1;i<=m;i++)
	{
		ll t,p;
		cin>>t;
		memset(base_mat,0,sizeof(base_mat));
		if(t==1)
		{
			base_mat[0][1]=1;
			base_mat[1][0]=-1;
			base_mat[2][2]=1;
		}
		else if(t==2)
		{
			base_mat[0][1]=-1;
			base_mat[1][0]=1;
			base_mat[2][2]=1;
		}
		else if(t==3)
		{
			cin>>p;
			base_mat[0][0]=-1;
			base_mat[0][2]=2*p;
			base_mat[1][1]=1;
			base_mat[2][2]=1;
		}
		else if(t==4)
		{
			cin>>p;
			base_mat[0][0]=1;
			base_mat[1][2]=2*p;
			base_mat[1][1]=-1;
			base_mat[2][2]=1;
		}
		update(i);
	}
	int q;
	cin>>q;
	while(q--)
	{
		int after_op,point_num;
		cin>>after_op>>point_num;
		ll x=p[point_num][0],y=p[point_num][1];
		ll ansx=mat[after_op][0][0]*x+mat[after_op][0][1]*y+mat[after_op][0][2];
		ll ansy=mat[after_op][1][0]*x+mat[after_op][1][1]*y+mat[after_op][1][2];
		cout<<ansx<<" "<<ansy<<nl;
	}
}

#include "bits/stdc++.h"
#include <chrono>
#include <random>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000
#define common cout << "Case #" << w+1 << ": "
#define MAXN 200000

int main()
{
    int n;
    cin >> n;
    vector<pair<lli,lli> >v(n);
    for(int i=0;i<n;i++)
        cin >> v[i].first >> v[i].second;
    vector<pair<lli,pair<lli,lli> > >xc,yc;
    lli px=0,py=0,x1=1,y1=0,x2=0,y2=1;
    int m;
    cin >> m;
    lli t,p;
    for(int i=0;i<m;i++)
    {
        cin >> t;
        if(t==1)
        {
            swap(py,px);
            swap(x1,x2);swap(y1,y2);
            py=-py;x2=-x2;y2=-y2;
        }
        else if(t==2)
        {
            swap(py,px);
            swap(x1,x2);swap(y1,y2);
            px=-px;x1=-x1;y1=-y1;
        }
        else if(t==3)
        {
            cin >> p;
            x1=-x1;y1=-y1;
            px=2*p-px;
        }
        else if(t==4)
        {
            cin >> p;
            x2=-x2;y2=-y2;
            py=2*p-py;
        }
        xc.push_back({px,{x1,y1}});
        yc.push_back({py,{x2,y2}});
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++)
    {
        int a,b;
        cin >> a >> b;
        --a;--b;
        if(a==-1)
        {
            cout << v[b].first << " " << v[b].second << endl;
            continue;
        }
        lli x=xc[a].first+xc[a].second.first*v[b].first+xc[a].second.second*v[b].second;
        lli y=yc[a].first+yc[a].second.first*v[b].first+yc[a].second.second*v[b].second;
        cout << x << " " << y << endl;
    }
}


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

int main()
{
  long long int n, k;
  cin >> n >> k;
  while(k--)
  {
    if(n%200)
      n = n*1000+200;
    else
      n /= 200;
  }
  cout << n;
  return 0;
}

#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <ctime>
#include <chrono>
#include <random>
#include <bitset>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>

#define fi first
#define se second
#define il inline
#define Ld double
#define pc putchar
#define rg register
#define ll long long
#define lll __int128
#define pb push_back
#define mp make_pair
#define It ::iterator
#define W(p) while(p--)
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define def(N, K, b) const K N = b;
#define FOR(i, b, s) for(int i = (b); i < (s); ++i)
#define rep(i, b, s) for(int i = (b); i <= (s); ++i)
#define per(i, b, s) for(int i = (b); i >= (s); --i)
#define FOR_(i, b, s) for(int i = (b); i > (s); --i)
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

namespace IO {
    const int SIZE = (1 << 20) + 1;
    char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = obuf + SIZE - 1;
    char _st[55];
    int _qr = 0;
    inline char gc() {
        return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++);
    }
    inline void qread() {}
    template<class T1, class ...T2>
    inline void qread(T1 &IEE, T2&... ls) {
        register T1 __ = 0, ___ = 1;
        register char ch;
        while(!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___;
        do {
            __ = (__ << 1) + (__ << 3) + (ch ^ 48);
        }while(isdigit(ch = gc()));
        __ *= ___;
        IEE = __;
        qread(ls...);
        return ;
    }
    template<class T>
	inline void QreadArr(T Begin, T End) {
		while(Begin != End) {
			qread(*Begin);
			++Begin;
		}
	}
    inline void flush() {
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
        return ;
    }
    inline void putc_(char _x) {
        *oS++ = _x;
        if(oS == oT) flush();
    }
    inline void qwrite() {}
    template<class T1, class ...T2>
    inline void qwrite(T1 IEE, T2... ls) {
        if(!IEE) putc_('0');
        if(IEE < 0) putc_('-'), IEE = -IEE;
        while(IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10;
        while(_qr) putc_(_st[_qr--]);
        qwrite(ls...);
        return ;
    }
    template<class T>
    inline void WriteArr(T Begin, T End) {
    	const char Kg = ' ', Edl = '\n';
    	while(Begin != End) {
    		qwrite(*Begin);
    		++Begin;
    		putc_(Kg);
		}
		putc_(Edl);
	}
    struct Flusher_{ ~Flusher_() { flush(); } } io_flusher;
}

using namespace IO;
using namespace std;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll My_Rand(ll Mod) { return (ull)(rnd()) % Mod; }

template<class T1, class T2>
T1 Min(const T1 x, const T2 y) { return x > y ? y : x; }
template<class T1, class T2>
T1 Max(const T1 x, const T2 y) { return x > y ? x : y; }

template<class T1, class T2>
void To_max(T1 &x, const T2 y) { x < y ? x = y : x = x; }
template<class T1, class T2>
void To_min(T1 &x, const T2 y) { x > y ? x = y : x = x; }

il ll qmul(ll x, ll y, ll p) {
	ll l = x * (y >> 25) % p * (1 << 25) % p;
	ll r = x * (y & ((1 << 25) - 1)) % p;
	return (l + r) % p;
}

il ll qpow(ll n, ll base, ll mod = 1e18) {
	ll ret = 1;
	while(n) {
		if(n & 1) ret = ret * base % mod;
		base = base * base % mod;
		n >>= 1;
	}
	return ret % mod;
}

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

void InitHash(ull &base, int &prime, ull &mod) { base = 131, prime = 233317, mod = 212370440130137957ll; }
//header

int main() {
	ll n, k; qread(n, k);
	W(k) {
		if(n % 200 == 0) n /= 200;
		else n *= 1000, n += 200;
	}
	cout << n << endl;
 	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;

#define vi vector<int>
#define vii vector<vector<int>>
#define ll long long int

void testcase(){
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << setprecision(12) << (a * d + c * b)/(b + d) << "\n";
}

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

#include<bits/stdc++.h>

using namespace std;

#define ll long long int
#define get(a) ll a ; cin >> a ;
#define show(a) cout << a << endl;

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

	get(sx);
	get(sy);

	get(gx);
	get(gy);

	double answer = double( sy*gx + sx*gy ) / double(gy + sy) ;

	cout << answer << endl;

	return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout << (x ? "Yes" : "No") << endl;
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define out(s) cout << s << endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (lli i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
int main()
{
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin >> n;
    map<lli, lli> rec;
    rep(k, n)
    {
        map<long long int, long long int> prime;
        long long int nc = k + 1;
        long long int i = 2;
        while (nc != 1)
        {
            if (i * i > nc)
            {
                if (prime.count(nc))
                    prime.at(nc) += 1;
                else
                {
                    prime[nc] = 1;
                }
                break;
            }
            if (nc % i == 0)
            {
                long long int count = 0;
                while (nc % i == 0)
                {
                    nc /= i;
                    count++;
                }
                if (prime.count(i))
                    prime.at(i) += count;
                else
                {
                    prime[i] = count;
                }
            }
            i++;
        }
        for(auto v: prime){
            if(!rec.count(v.first)||(rec.count(v.first)&&rec[v.first]<v.second)){
                rec[v.first] = v.second;
            }
        }
    }
    lli ans = 1;
    for(auto v: rec){
        ans *= pow(v.first, v.second);
    }
    ans++;
    out(ans);
}

#include <iostream>
using namespace std;
template <class T> T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
template <class T> T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
int main()
{
  long long N;
  cin >> N;
  long long div = 1;
  for (long long i = 2; i <= N; i++) {
    div = lcm(i, div);
  }
  cout << div+1 << endl;
  return 0;
}


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

#define cm (1 << 17)
char cn[cm], *ci = cn + cm, ct;

inline char getcha() {
	if (ci - cn == cm) {
		fread(cn, 1, cm, stdin);
		ci = cn;
	}
	return *ci++;
}

inline int getint() {
	int A = 0;
	while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	return A;
}

static struct FastOutput {
	static constexpr int BUF_SIZE = 1 << 20;
	char buf[BUF_SIZE];
	size_t buf_pos = 0;
	static constexpr int TMP_SIZE = 1 << 20;
	char tmp[TMP_SIZE];
	FILE* out = stdout;

	inline void put_char(char c) {
		buf[buf_pos++] = c;
		if (buf_pos == BUF_SIZE) {
			fwrite(buf, 1, buf_pos, out);
			buf_pos = 0;
		}
	}

	~FastOutput() { fwrite(buf, 1, buf_pos, out); }

	inline FastOutput& operator<<(char c) {
		put_char(c);
		return *this;
	}

	inline FastOutput& operator<<(const char* s) {
		while (*s) {
			put_char(*s++);
		}
		return *this;
	}

	inline FastOutput& operator<<(const string& s) {
		for (int i = 0; i < (int)s.size(); i++) {
			put_char(s[i]);
		}
		return *this;
	}

	template <typename T>
	inline char* integer_to_string(T n) {
		// beware of TMP_SIZE
		char* p = tmp + TMP_SIZE - 1;
		if (n == 0) {
			*--p = '0';
		} else {
			bool is_negative = false;
			if (n < 0) {
				is_negative = true;
				n = -n;
			}
			while (n > 0) {
				*--p = (char)('0' + n % 10);
				n /= 10;
			}
			if (is_negative) {
				*--p = '-';
			}
		}
		return p;
	}

	template <typename T>
	inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
		return integer_to_string(n);
	}

#if !defined(_WIN32) || defined(_WIN64)
	inline char* stringify(__int128 n) { return integer_to_string(n); }
#endif

	template <typename T>
	inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(T n) {
		sprintf(tmp, "%.17f", n);
		return tmp;
	}

	template <typename T>
	inline FastOutput& operator<<(const T& n) {
		auto p = stringify(n);
		for (; *p != 0; p++) {
			put_char(*p);
		}
		return *this;
	}
} fast_output;

#define cout fast_output

vector<int> p;

int get(int x) {
	return p[x] == -1 ? x : p[x] = get(p[x]);
}

int main() {
	int n = getint();
	constexpr int mx = 400010;
	p.resize(mx, -1);
	vector<int> cnt(mx);
	while (n--) {
		int a = getint(), b = getint();
		a = get(a), b = get(b);
		if (a != b) {
			p[b] = a;
			cnt[a] += cnt[b];
		}
		cnt[a]++;
	}
	vector<int> siz(mx);
	for (int i = 0; i < mx; i++) {
		siz[get(i)]++;
	}
	int ans = 0;
	for (int i = 0; i < mx; i++) {
		if (get(i) == i) {
			ans += min(cnt[i], siz[i]);
		}
	}
	cout << ans;
}

#include    <bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define __unique(V) (V).resize(unique((V).begin(),(V).end())-(V).begin())
#define cntbit(X)   __builtin_popcount((X))
#define bit(S,i) (((S)>>(i - 1))&1)
#define PI	acos(-1)
#define fi  first
#define se  second
#define LL  long long
#define ii  pair<int,int>
#define iii pair<int,ii>
#define eb  emplace_back
#define TASK "abc187"
using namespace std;
const int maxn = 20;
int n,m,g[1 << maxn];
bool a[maxn][maxn],dp[1 << maxn];
///--------------------------
void    readf(){
    cin >> n >> m;
    for(int i = 1; i <= m; ++i){
        int u,v;
        cin >> u >> v;
        a[u][v] = 1;
    }
}
///--------------------------
void    solve(){
    for(int mask = 0; mask < (1 << n); ++mask){
        for(int i = 1; i <= n; ++i) if (bit(mask,i))
        for(int j = i + 1; j <= n; ++j) if (bit(mask,j)){
            if (a[i][j] == 0) goto nxt;
        }
        dp[mask] = 1;
        nxt : ;
    }
    memset(g,0x3f,sizeof(g));
    g[0] = 0;
    for(int mask = 1; mask < (1 << n); ++mask)
    for(int i = mask; i > 0; i = (i - 1) & mask) if (dp[i] == 1){
        g[mask] = min(g[mask],g[mask ^ i] + 1);
    }
    cout << g[(1 << n) - 1] << '\n';
}
///--------------------------
int     main(){
	srand(time(NULL));
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    #ifdef TLH2203
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    #endif // TLH2203
    readf();
    solve();
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 1000050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 100000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define counttrailingzeroes(n) __builtin_ctzll(n)
#define countsetbits(n) __builtin_popcountll(n)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

#define loop(i,n)  for (lli i = 0; i < n; i++)
#define FOR(i,a,b) for (lli i = a; i < b; i++)

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)
#define isvowel(v) (0x208222>>(v&0x1f))&1

#define endl '\n'

template <typename Head>
void print(Head&& head)
{
    cout<<head<<endl;
}
template <typename Head, typename... Tail>
void print(Head&& head, Tail... tail)
{
    cout<<head<<" ";
    print(tail...);
}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
*/

lli mceil(lli a,lli b){ return(a/b + (a%b != 0)); }

lli mfloor(lli a,lli b){ return(a/b); }

ll modmul(ll a, ll b,ll MOD = mod) {
    return ((a%MOD) * (b%MOD)) % MOD;
}

ll modadd(ll a, ll b,ll MOD = mod){
    return((a%MOD)+(b%MOD)+MOD)%MOD;
}

ll modsub(ll a, ll b,ll MOD = mod){
    return((a%MOD) - (b%MOD) + MOD)%MOD;
}

lli fastexpo(lli a,lli b ,lli MOD = mod){
    a = a%MOD;
    lli ans=1;
    while(b){
        if(b&1)
            ans=(ans*1ll*a)%MOD;
        a=(a*1ll*a)%MOD;
        b=b/2;
        }
    return ans;
 }

vector<int>all_div[200050];
void alldivisors(){
for(int i=1;i<200050;++i){
        for(int j=i;j<200050;j+=i)
            all_div[j].pb(i);
    }
}

bool ispower2(lli n){
    return(n and (n&(n-1))==0 );
}

bool isp(lli n)
{
    if(n<=1) return 0;
    if(n==2 or n==3) return 1;
    for(lli i=2;i*i<=n;i++)
        if(n%i==0) return 0;
    return 1;
}

int main(){
fastio
lli tt =1;
//cin>>tt;
//alldivisors();
while(tt--)
{
    lli n,x;
    lli a[3];
    scanarr(a,3);
    sort(a,a+3);
    print(a[1]+a[2]);

}
return 0;
}

/* Nikkz99 */
#include <bits/stdc++.h>
#define ll long long
#define s string
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //string w,a; getline(cin,a);
    // stringstream S(a);
   //set<s> d;
  //map<s,ll> F;
    // while(S>>w) { }

    ll A[102];
    for(auto i=0;i<3;i++)
            cin>>A[i];
    sort(A,A+3);
    cout<<A[2]+A[1];
    return 0;
}


#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;
const int N=500005;
int n,q1[N],q2[N];
char s[N],t[N];
ll res;
int main(){
	scanf("%d",&n);
	scanf("%s",s+1);
	scanf("%s",t+1);
	For(i,1,n) if (s[i]=='1') q1[++*q1]=i;
	For(i,1,n) if (t[i]=='1') q2[++*q2]=i;
	int p=1;
	For(i,1,*q2){
		for (;p<=*q1&&q2[i]>q1[p];p+=2)
			res+=q1[p+1]-q1[p];
		if (p>*q1) return puts("-1"),0;
		res+=q1[p]-q2[i]; ++p;
	}
	for (;p<=*q1;p+=2)
		res+=q1[p+1]-q1[p];
	if (p!=(*q1)+1)
		puts("-1");
	else
		printf("%lld\n",res);
}

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
//#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <random>
#include <cassert>
#include <cstring>
#include <sstream>
#include <complex>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_set>
#include <unordered_map>

using namespace std;
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define F first
#define S second
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d\n", n);}
void Print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d\n", n);}
void Print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
int length(long long x){int l = 0;for(long long i=x;i;i/=10)l++;return l;}
int length(string s){return s.size();}
const int M           	= 1e9 + 7;
long long pow(long long a,long long n){ll res = 1;while(n){if(n&1) res = ((res%M)*(a%M))%M;a = ((a%M)*(a%M))%M;n>>=1;}return res%M;}

#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()

const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int NN            = 1e6 + 5;

int solve()
{
	//happy coding

	int a,b;
	cin>>a>>b;
	int x = (a+b)/2;
	cout<<x<<" "<<a - x<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	//readline(test);//(void)getchar();
	while (test--)solve();return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ll I=167167167167167167;
ll Q=1e9+7;

int main(){
	ll N,X;
	cin>>N>>X;
	vector<ll> p(N);
	vector<ll> high(N);
	vector<ll> low(N);
	for(int i=0;i<N;i++){
		cin>>p[i];
		high[i]=((X-1)/p[i]+1)*p[i];
		low[i]=(X/p[i])*p[i];
	}
	vector<ll> dp1(N);
	auto dp2=dp1;
	dp1[0]=1;
	for(int i=0;i<N-1;i++){
		dp1[i+1]=dp1[i];
		dp2[i+1]=dp2[i];
		if((high[i+1]-low[i])%p[i+1]!=0) dp2[i+1]+=dp1[i];
		if((high[i]-low[i+1])%p[i+1]!=0) dp1[i+1]+=dp2[i];
	}
	cout<<dp1[N-1]+dp2[N-1]<<endl;
}

#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 */

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

const int N_MAX = 50;
ll dp[N_MAX][2];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; ll X; cin>>N>>X;
    vll a(N);
    rep(i,N) cin>>a[i];

    if (N==1){
        cout<<"1\n";
        return 0;
    }

    vll cnt(N);
    ll now = X;
    RFOR(i,N-1,0){
        cnt[i]+=now/a[i];
        now%=a[i];
    }
    vll r(N-1);
    rep(i,N-1) r[i] = a[i+1]/a[i];

    dp[0][0] = 1;
    rep(i,N-1)rep(j,2){
        if (dp[i][j]==0) continue;
        ll t = cnt[i]+j;
        if (t%r[i]==0){
            dp[i+1][(t==r[i])] += dp[i][j];
        }else{
            dp[i+1][0] += dp[i][j];
            dp[i+1][1] += dp[i][j];
        }
    }
    cout<<dp[N-1][0]+dp[N-1][1]<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W, X, Y;
    cin >> H >> W >> X >> Y;
    vector<string> data(H);
    for (int i = 0; i < H; i++){
            cin >> data.at(i);
        }
    int answer = 1;

      for (int i = X-2; i >= 0; i--){
        if (data.at(i).at(Y-1) == '#') break;
        else answer += 1;
    }
    for (int i = X; i <= H-1; i++){
        if (data.at(i).at(Y-1) == '#') break;
        else answer += 1;
    }
    for (int i = Y-2; i >= 0; i--){
        if (data.at(X-1).at(i) == '#') break;
        else answer += 1;
    }
    for (int i = Y; i <= W-1; i++){
        if (data.at(X-1).at(i) == '#') break;
        else answer += 1;
    }

    cout << answer << endl;
}

#pragma region

#include <bits/stdc++.h>

#define _GLIBCXX_DEBUG

using namespace std;

using ll = long long;
using ld = long double;
const int INF = INT_MAX;
const ll LLINF = LLONG_MAX;

#define all(x) x.begin(), x.end()

#define rep(i, s, e) for(ll i = s; i < e; ++i)
#define repr(i, s, e) for(ll i = s; i > e; --i)

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

void CIN() {}
template<class T, class ...Ts> void CIN(T &&t, Ts &&...ts){ cin >> t; CIN(ts...); }
void COUT() { cout << endl; }
template<class T, class ...Ts> void COUT(T &&t, Ts &&...ts){ cout << t << " "; COUT(ts...); }

#pragma endregion

int dfs(const vector<string> s, const int h, const int w, const int sy, const int sx)
{
    stack<pair<int, int>> d; //directions(y, x)
    d.push(make_pair(1, 0)); //down
    d.push(make_pair(-1, 0)); //up
    d.push(make_pair(0, 1)); //right
    d.push(make_pair(0, -1)); //left
    int res = 0;
    while (!d.empty()){
        int y = sy - 1, x = sx - 1;
        while(1){
            int dir_y = d.top().first, dir_x = d.top().second; d.pop();
            if ((y + dir_y < 0) || (h <= y + dir_y) || (x + dir_x < 0) || (w <= x + dir_x)) break;
            else {
                if (s[y + dir_y][x + dir_x] == '.') {
                    d.push(make_pair(dir_y, dir_x));
                    x += dir_x;
                    y += dir_y;
                    res ++;
                } else break;
            }
        }
    }
    return res;
}

int main()
{
    cin.tie(nullptr);
    int h, w, sy, sx; CIN(h, w, sy, sx);
    vector<string> s(h);
    for (auto &in :s) cin >> in;
    cout << dfs(s, h, w, sy, sx) + 1 << endl;
    return 0;
}


#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<cstring>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<deque>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<string>
#include<sstream>
#include<chrono>
#include<random>
#include<unordered_map>
#include<ctype.h>
#include<cassert>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll; typedef std::pair<ll, ll> pll; typedef std::pair<int, int> pii; typedef unsigned long long ull; typedef long double ldb; typedef double db;
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
template <class output_type, class input_type>
output_type Convert(const input_type& input) {
	stringstream ss; output_type result;
	ss.clear(); ss << input; ss >> result;
	return result;
}
const double Pi = acos(-1.0); const int inf = 0x3f3f3f3f, Mod = 1e9+7, N = 5e5 + 3; const ll INF = 1ll << 60;
inline ll qpow(ll a, ll b, ll mod = Mod, ll ans = 1) {
	while (b) {
		if (b & 1)ans = ans * a % mod;
		a = a * a % mod; b >>= 1;
	}return ans;
}
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }; ll lcm(ll a, ll b) { return a * b / (gcd(a, b)); }
pii EXgcd(int x, int y) {        //return.first ny
	if (!y) { return { 1,0 }; }pii a = EXgcd(y, (x + y) % y);
	return { a.second, a.first - a.second * (x / y) };
}
inline bool Ezisprime(int n){
	if (n <= 1)return 0;if (n <= 3)return 1;
	vector<int> ezp{ 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	for (int i = 0; i < ezp.size(); i++)if (n == ezp[i])return 1;
	for (int i = 2; i <= sqrt(n); i++)if (n % i == 0)return 0;
	return 1;
}
inline int LIS(const vector<int> Origins, const int n){
	if (!n || !Origins.size()) return 0;
	int len = 0; vector<int> d(n, 0); d[0] = Origins[0];
	for (int i = 1; i < n; i++)
		if (Origins[i] >= d[len])d[++len] = Origins[i];
		else d[upper_bound(d.begin(), d.begin() + len, Origins[i]) - d.begin()] = Origins[i];
	return len + 1;
}
struct edge {ll to, cost, time;}; typedef vector<vector<edge>> Graph;
inline vector<ll> Dijkstra(const Graph& G, ll s)// G为路表，s为起点，结果为各点距离容器
{
	priority_queue<pll, vector<pll>, greater<pll> >q;   //first 为距离，second 为点号
	vector<ll> d(G.size(), INF);
	d[s] = 0;q.push({ 0,s });
	while (!q.empty()){
		pll tp = q.top(); q.pop();
		if (d[tp.second] < tp.first)continue;
		for (auto& e : G[tp.second]){
			if (e.cost + d[tp.second] < d[e.to]){
				d[e.to] = e.cost + d[tp.second];
				q.push({ d[e.to], e.to });
			}
		}
	}
	return d;
}
inline int Alptonum(const char a) { if (a <= 'z')return int(a - 'a'); else return int(a - 'A'); }
inline char Numtoalp(const int n, bool t) { if (!t)return char('a' + n); else return char('A' + n); }
inline bool cmp(pii a, pii b) {  //default more and more larger
	return a.first < b.first;
}
struct cmpstl {           //reverse
	inline bool operator()(pii a, pii b) {
		if (a.second == b.second)return a.first > b.first;
		return a.second < b.second;
	}
};
//partial_sum(begin,end,place,minus<int>()) adjacent_differece(begin,end,place)
//count(begin(),end(),char=='x') count_if(begin(),end(),boolcmp) vector<int> p(n);iota(p.begin(), p.end(), 0);

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| Code follows ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\
//VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV Code follows VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVII
db dp[1001][1001];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
	int n; cin >> n;
//	int ts; cin >> ts;
	double res = 0;
	for (int i = 1; i < n; i++)res += double(n) / i;
	cout << setprecision(11) << fixed << res << '\n';

}
/*

*/

#include<bits/stdc++.h>
using namespace std;
#define I inline int
#define V inline void
#define ll long long int
#define isnum(ch) ('0'<=ch&&ch<='9')
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(u) for(int i=h[u],v;v=e[i].t,i;i=e[i].n)
#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);
I getint(){
	int _s=0,_f=1;char _ch=gc;
	while(!isnum(_ch))(_ch=='-')&&(_f=-1),_ch=gc;
	while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc;
	return _s*_f;
}
const int N=5e5+2,mod=998244353;
V check(int&x){x-=mod,x+=x>>31&mod;}
V cmax(int&x,int y){if(x-y>>31)x=y;}
V cmin(int&x,int y){if(y-x>>31)x=y;}
I Pow(ll t,int x,ll s=1){
	for(;x;x>>=1,t=t*t%mod)if(x&1)s=s*t%mod;
	return s;
}
char a[N];
int n,cnt[26],m,k,ans;
V input(){
	n=getint(),m=getint(),k=getint();
	if(n==1||m==1)ans=Pow(k,n*m);
	else FOR(i,1,k)
		check(ans+=1ll*Pow(i,n)*(Pow(k-i+1,m)-Pow(k-i,m)+mod)%mod);
	cout<<ans;
}
V init(){

}
V work(){

}
int main(){
		input();
		init();
		work();
//	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, w[101], ex[101], sm, dp[2][100 * 101][101];

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

    cin >> n;
    zep(i, 0, n)cin >> w[i];

    ex[0] = 1;
    rep(i, 1, n)ex[i] = i * ex[i - 1] % MOD;

    zep(i, 0, n)sm += w[i];
    if(sm % 2 == 1){print(0) return 0;}

    dp[0][0][0] = 1;
    zep(i, 0, n){
        memset(dp[(i + 1) % 2], 0, sizeof(dp[(i + 1) % 2]));

        rep(j, 0, sm / 2){
            rep(k, 0, i){
                dp[(i + 1) % 2][j][k] += dp[i % 2][j][k];
                dp[(i + 1) % 2][j][k] %= MOD;
                dp[(i + 1) % 2][j + w[i]][k + 1] += dp[i % 2][j][k];
                dp[(i + 1) % 2][j + w[i]][k + 1] %= MOD;
            }
        }
    }

    ll ans = 0;
    zep(k, 1, n){
        ans += dp[n % 2][sm / 2][k] * (ex[k] * ex[n - k] % MOD) % MOD;
        ans %= MOD;
    }
    print(ans)

    return 0;
}

#include <bits/stdc++.h>

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

#ifdef LOCAL
#define log(val) std::cerr << std::setw(3) << __LINE__ << "| " << #val << " = " << (val) << std::endl
#define dbg(proc) proc
#else
#define log(val) 0
#define dbg(proc) 0
#endif

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

using ll = std::int64_t;
using P = std::tuple<int,int>;

constexpr int INF = 1001001001;
int N;
ll X;
int A[110];
int dp[110][110][110];

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

    std::cin >> N >> X;

    for(int i=0;i<N;++i){
        std::cin >> A[i];
    }

    ll res = std::numeric_limits<ll>::max();

    for(int k=1;k<=N;++k){
        std::fill(&dp[0][0][0], &dp[0][0][0] + 110 * 110 * 110, -INF);
        dp[0][0][0] = 0;

        for(int i=0;i<N;++i){
            for(int j=0;j<=k;++j){
                for(int r=0;r<k;++r){
                    dp[i+1][j][r] = std::max(dp[i+1][j][r], dp[i][j][r]);
                    if(j + 1 <= k){
                        dp[i+1][j+1][(r+A[i])%k] = std::max(dp[i+1][j+1][(r+A[i])%k], dp[i][j][r] + A[i]);
                    }
                }
            }
        }

        if(dp[N][k][X%k] < 0){
            continue;
        }

        res = std::min(res, (X - dp[N][k][X%k]) / k);
    }

    std::cout << res << std::endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
using VV = vector<V>;
using SV = vector<string>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1e18
const double PI = acos(-1);
const int dx[] = { -1,0,1,0 }; const int dy[] = { 0,-1,0,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; }

void solve_abc_a() {
	ll l_ans = 0;
	string s_ans;
	double d_ans = 0;

	ll n, m;
	ll x, y;
	ll h, w;
	ll a, b;
	ll c;
	//char c;
	//ll d;
	char yc, ac;
	ll k;
	string s, t;
	//ll s, t;
	ll q, r;

	cin >> a >> b >> c;

	if (a * a + b * b < c * c) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	//cout << l_ans << "\n";
	//cout << s_ans << "\n";
	//cout << d_ans << "\n";
}

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

	solve_abc_a();

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a*a)+(b*b)<(c*c)){
	    cout<<"Yes"<<endl;
	}
	    else
	    cout<<"No";
	return 0;
}


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

int main() {

  long n;
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);

  long ans = 0;

  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    cin >> b.at(i);
    long total = (a.at(i) + b.at(i)) * (b.at(i) - a.at(i) + 1) / 2;
    ans += total;
  }

  cout << ans << endl;

}

#include <bits/stdc++.h>

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

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

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

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

    ll N; cin >> N;
    ll ans = 0;
    REP(i, N)
    {
        ll A, B; cin >> A >> B;
        ans += (A-1)*(B-A+1) + (B-A+1)*(B-A+2)/2;
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
typedef long long int ll ;
#define pb push_back
#define rep(i,k,n) for (i = k; i < n; i++)
#define coy cout<<"YES\n"
#define con cout<<"NO\n"
using namespace std;
//const unsigned long long int M = 1000*100 ;
//ll sieve[M];
//vector<ll>ans;
//const unsigned int n=10000005;

ll ceil_div(ll a, ll b) {
    return (a + b - 1) / b;

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

}

ll dig_sum(ll n)
{
    ll x=n;
    ll cnt=0;

    while(x>0)
    {
        ll a=x%10;
        cnt=cnt+a;

        x=x/10;
    }
    return cnt;

}
ll dig_cnt(ll n)
{
    ll x=n;
    ll cnt=0;

    while(x>0)
    {
        ll a=x%10;
        cnt++;

        x=x/10;
    }
    return cnt;

}
bool dig_check(ll n,ll num,ll len)
{
    ll x=n;
    ll cnt=0;

    while(x>0)
    {
        ll a=x%10;
        if(a==num)
        {
            cnt++;
        }

        x=x/10;
    }
    if(cnt==len)
    {
        return true;
    }
    else
    {
        return false;
    }

}

// void si()
// {
//     ll i,j;
//     rep(i,0,M)
//     {
//         sieve[i]=1;
//     }
//     sieve[0]=sieve[1]=0;
//     for(i=2;i<M;i++)
//     {
//         for(j=i*i;j<M;j=j+i)
//         {
//             sieve[j]=0;
//         }
//     }
//     for(i=2;i<M;i++)
//     {
//         if(sieve[i]==1)
//         {
//             ans.push_back(i);
//         }
//     }
////cout<<ans[ans.size()-1]*ans[ans.size()-2];
////     rep(i,0,100)
////     {
////         cout<<ans[i]<<" ";
////     }
//
// }

ll low(vector<ll>arr,ll l,ll r,ll num)
{
    ll m=0;
    while(l<r)
    {
         m=l+(r-l)/2;
        if(arr[m]<num)
        {
            l=m+1;
        }
        else
        {
            r=m;
        }
    }
//cout<<arr[l]<<" ";
   if(arr[l]>=num)
   {
      return l;
   }
   else
   {
       return arr.size();
   }

//   if(arr[l]<=num)
//   {
//       return true;
//   }
//   else
//   {
//       return false;
//   }
}

void fun()
{

    ll n,m,j,d,l,r,i,x,y,k,z,a,b,c,p,q;
    cin>>n;
    vector<ll>vec(n);
    map<ll,ll>mp;
    rep(i,0,n)
    {
        cin>>vec[i];
        mp[vec[i]]++;
    }
    ll ans=0;
    for(i=n-1;i>=0;i--)
    {
      ans=ans+(i-(mp[vec[i]]-1));
      mp[vec[i]]--;
    }
    cout<<ans;

}

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

//si();

t=1;
//cin>>t;
 while(t--)
 {
     fun();

    }

}

#include<bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  long long sum = 0;
  vector<int>vec(a);
  for(int i = 0;i < a;i++)cin >> vec[i];
  map<int,long long> mp;
  for(int i = 0;i < a;i++){
    mp[vec[i]]++;
  }
  for(int i = 0;i < a;i++){
    sum += a - mp[vec[i]];
  }
  sum /=2;
  cout << sum;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 3e3 + 5;
const int mod = 998244353;

int f[MAXN][MAXN];//use x numbers to get y
int gao(int x,int y)
{
	if(y>x) return 0;
	if(~f[x][y]) return f[x][y];
	if(!x) return f[x][y] = !y;
	if(!y) return f[x][y] = 0;
	return f[x][y] = (gao(x, y*2) + gao(x-1, y-1)) %mod;
}

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

	memset(f,-1,sizeof(f));
	printf("%d",gao(n,d));
	return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first
#define se second
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
#define set20 cout<<fixed<<setprecision(20) ;
// ミント
//int mod ; cin>>mod ;
const ll mod = 1e9+7 ;//924844033;
  //  998244353;
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, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod); //任意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){
    return fact[n]*ifact[n-k] ;
  }
  }  ;

mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }

mint dp[100005][2] ;
mint sum[100005][2] ;

int main(){
  ll n ; cin>>n ;
  vector<ll> A(n) ;
  rep(i,n) cin>>A[i] ;
  dp[1][0]=1ll ;
  //dp[1][1] =1ll ;
  sum[1][0]=A[0] ;
  //sum[1][1]=A[0] ;
  rep(i,n-1){
    dp[2+i][0]=dp[1+i][0]+dp[1+i][1] ;
    dp[2+i][1]=dp[1+i][0] ;
    sum[2+i][0]=sum[1+i][0]+sum[1+i][1]+mint(A[i+1])*(dp[2+i][0]) ;
    sum[2+i][1]=sum[1+i][0]-mint(A[i+1])*(dp[2+i][1]) ;
  }

  mint ans=sum[n][0]+sum[n][1] ;
  cout<<ans<<endl ;
  return 0 ;
  }


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

struct Edge {
    ll to, cost;
    Edge(ll to, ll cost): to(to), cost(cost) {}
};

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

    vl w(n);
    ll maW = 0;
    rep(i, n) {
        cin >> w[i];
        chmax(maW, w[i]);
    }

    vl L(m), v(m);
    rep(i, m) {
        cin >> L[i] >> v[i];
        if(maW > v[i]) {
            out(-1);
            re0;
        }
    }

    vl dist(1<<n);  // dist[S] : ラクダi,j(i < j)間のラクダの集合がSのときのx[j] - x[i]の最小値
    rep(S, 1<<n) {
        ll W = 0;
        rep(i, n) {
            if(S & 1<<i) {
                W += w[i];
            }
        }
        rep(i, m) {
            if(W > v[i]) {
                chmax(dist[S], L[i]);
            }
        }
    }

    vl perm(n);
    rep(i, n) {
        perm[i] = i;
    }

    ll ans = -INF;
    do {
        vector<vector<Edge>> G(n);
        vl indeg(n);  // indeg[v] : 頂点vの入次数
        exrep(i, 0, n-2) {
            ll a = perm[i];
            ll S = 1<<a;
            exrep(j, i+1, n-1) {
                ll b = perm[j];
                S |= 1<<b;
                G[b].emplace_back(a, -dist[S]);
                indeg[a]++;
            }
        }

        ll sv = perm[n-1];
        ll gv = perm[0];

        queue<ll> Q;
        Q.push(sv);

        vl dp(n, INF);  // dp[v] : 頂点svからvへの最短距離
        dp[sv] = 0;
        while(!Q.empty()) {
            ll v = Q.front();  Q.pop();
            for(Edge e : G[v]) {
                ll u = e.to;
                indeg[u]--;
                chmin(dp[u], dp[v] + e.cost);
                if(indeg[u] == 0) {
                    Q.push(u);
                }
            }
        }

        chmax(ans, dp[gv]);
    } while(next_permutation(all(perm)));

    ans *= -1;

    out(ans);
    re0;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define NEXT(i, x) for (int i = h[x]; i; i = e[i].u)
const int INF = 2e9;

inline int Max(const int &a, const int &b) { return a > b ? a : b; }
inline ll Min(const ll &a, const ll &b) { return a > b ? b : a; }

inline void read(int &x) {
    x = 0;
    int f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    x *= f;
}

const int N = 2e5 + 7;
int n;
ll s[3][3][3][3];
int sum[3];
ll ans;
bool ff[3];
int pos[3][3];
struct jgt {
    ll x;
    int id, f;
    bool operator<(const jgt &a) const { return x < a.x; }
} a[3][N], tmp[N];

int main() {
    read(n);
    n <<= 1;
    FOR(i, 1, n) {
        ll x;
        char ch;
        scanf(" %lld %c", &x, &ch);
        a[0][i].f = a[1][i].f = a[2][i].f = -1;
        if (ch == 'R') {
            ++sum[0];
            a[0][i] = (jgt){x, i, 0};
        } else if (ch == 'G') {
            ++sum[1];
            a[1][i] = (jgt){x, i, 1};
        } else if (ch == 'B') {
            ++sum[2];
            a[2][i] = (jgt){x, i, 2};
        }
    }
    FOR(i, 0, 2) {
        if (sum[i] & 1) ff[i] = 1;
    }
    if (ff[0] == ff[1] && ff[1] == ff[2] && ff[0] == 0) {
        puts("0");
        return 0;
    }
    FOR(i, 0, 1) {
        FOR(j, i + 1, 2) {
            FOR(k, 1, n) {
                if (a[i][k].f == i)
                    tmp[k] = a[i][k];
                else if (a[j][k].f == j)
                    tmp[k] = a[j][k];
                else {
                    tmp[k].x = (ll)1e18;
                    tmp[k].f = -1;
                }
            }
            std::sort(tmp + 1, tmp + n + 1);
            ll mn = (ll)1e18;
            int P = 0;
            FOR(k, 1, n - 1) {
                if (tmp[k].f != tmp[k + 1].f) {
                    if (tmp[k + 1].x - tmp[k].x < mn) {
                        mn = tmp[k + 1].x - tmp[k].x;
                        P = (tmp[k].f == i ? tmp[k].id : tmp[k + 1].id);
                    }
                }
            }
            s[i][j][0][0] = s[j][i][0][0] = mn;
            pos[i][j] = pos[j][i] = P;
        }
    }
    FOR(i, 0, 2) {
        FOR(j, 0, 2) {
            if (i == j) continue;
            FOR(w1, 0, 2) {
                FOR(w2, 0, 2) {
                    if (w1 == w2) continue;
                    if (w1 == i && w2 == j) continue;
                    if (w1 == j && w2 == i) continue;
                    FOR(k, 1, n) {
                        if (a[i][k].f == i)
                            tmp[k] = a[i][k];
                        else if (a[j][k].f == j)
                            tmp[k] = a[j][k];
                        else {
                            tmp[k].x = (ll)1e18;
                            tmp[k].f = -1;
                        }
                    }
                    tmp[pos[w1][w2]].x = (ll)1e18;
                    tmp[pos[w1][w2]].f = -1;
                    std::sort(tmp + 1, tmp + n + 1);
                    ll mn = (ll)1e18;
                    FOR(k, 1, n - 1) {
                        if (tmp[k].f != tmp[k + 1].f) {
                            mn = Min(mn, tmp[k + 1].x - tmp[k].x);
                        }
                    }
                    s[i][j][w1][w2] = mn;
                }
            }
        }
    }
    int k = 0, kk = 0, kkk = 0;
    if (ff[0] == 0)
        k = 1, kk = 2, kkk = 0;
    else if (ff[1] == 0)
        k = 0, kk = 2, kkk = 1;
    else if (ff[2] == 0)
        k = 0, kk = 1, kkk = 2;
    ans = s[k][kk][0][0];
    ans =
        Min(ans, Min(s[k][kkk][0][0] + s[kkk][kk][k][kkk], s[kkk][k][kk][kkk] + s[kk][kkk][0][0]));
    printf("%lld\n", ans);
    return 0;
}


/* Hardwork allways pays off */
//You never know how close to the solution you are ,so keep practicing
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long

#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define endl '\n'
#define REP(i,n) for(int i=1;i<=n;i++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
#define all(x) (x).begin(), (x).end()
#define mod1 998244353
#define mod 1000000007
#define pie 3.141592653589793238
#define printv(x) for(i=0;i<x.size();i++) cout<<x[i]<<" ";
#define printA(x,n) for(i=0;i<n;i++) cout<<x[i]<<" ";
#define F first
#define S second
#define vi vector<int>
void debb(int x) {cerr << x;}
void debb(double x) {cerr << x;}
void debb(long double    x) {cerr << x;}
void debb(char x) {cerr << '\'' << x << '\'';}
void debb(const char *x) {cerr << '\"' << x << '\"';}
void debb(const string &x) {cerr << '\"' << x << '\"';}
void debb(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void debb(const pair<T, V> &x) {cerr << '{'; debb(x.ff); cerr << ','; debb(x.ss); cerr << '}';}
template<typename T>
void debb(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), debb(i); cerr << "}";}
void _debb() {cerr << "]\n";}
template <typename T, typename... V>
void _debb(T t, V... v) {debb(t); if (sizeof...(v)) cerr << ", "; _debb(v...);}
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

void make_unique(vector<int> vec)
{
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}

bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int cceil(int x, int y){
    return (x+y-1)/y;
}
struct Cmp
{
        bool operater(const pair<int,int> &a,const pair<int,int> &b)
       {
               return (a.first)<(b.first);
       }

};
bool cmp(const pair<int,int> &a,const pair<int,int> &b)
{
       return (a.second)<(b.second);
}
int bpower(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n&1) res*=a,n--;
        else   a*=a,n/=2;
    }
    return res;
}
void solve(){
    int i,j,k;
    int n;
    cin>>n;
    if(n==1){
        cout<<1<<endl;
        return;
    }
    int sum=1e18;

    int b=log2(n)+1;
    while(b>0){

            int num=bpower(2,b);
            int a=n/num;
            int c=n%num;
            sum=min(sum,a+b+c);
            b--;
    }
    cout<<sum<<endl;

}

signed main()
 {
    ios;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    // init();
    while(t--){
        int k,n,i,j,m;
        solve();
    }

    printclock;
    return 0;

}

// Powered by CP Editor (https://cpeditor.org)

//a+b = (a^b) + 2*(a&b)
//b^c = (a^b)^(a^c)
//gcd(x,y) = gcd(x-y,y)
//if n = 5000 then complexity cannot be (n^2*log(n)) means no map ,no sets
//check for long long overflow if input is large
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define mod 1000000007
// #define mod 998244353
#define pb push_back
#define ll long long
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define loop(i,n) for(int i=0;i<n;i++)
#define pp  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fil(a,b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()

#define en cout<<"\n"

#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl

using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
const long long INF = 2000000000000000000;

long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
}

void solve()
{
	int n;
	cin>>n;
	int ar[n];
	loop(i,n) cin>>ar[i];
	int dp[n][2];
	if(n<=2)
	{
		cout<<(n*ar[0])%mod;return;
	}
	for(int i=0;i<n;i++) for(int j=0;j<2;j++) dp[i][j]=0;
	dp[0][0]=1;
	dp[1][0]=1;
	dp[1][1]=1;
	for(int i=2;i<n;i++)
	{
		dp[i][0] = (dp[i-1][0] + dp[i-1][1])%mod;
		dp[i][1] = dp[i-1][0];
	}
	int total = dp[n-1][0] + dp[n-1][1];
	total%=mod;
	int ans=0;
	// trace(total);
	for(int i=0;i<n;i++)
	{
		int pos = (dp[i][0]*(dp[n-i-1][0] + dp[n-i-1][1])%mod)%mod;
		pos%=mod;
		pos = (pos - (total - pos) + mod)%mod;
		// trace2(i,pos);
		ans += (pos*ar[i])%mod;
		ans%=mod;
	}
	cout<<ans;
}

int32_t main()
{
pp;
int test=1;
// cin>>test;
while(test--)
{
	solve();
	en;
}
return 0 ;
}