#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

using Graph = vector<vector<int>>;

vector<ll> d, sum;
void dfs1(const Graph &G, int v, int p, int D) {
	d[v] = D;
    for (auto nv : G[v]) {
		if (nv == p)continue;
		dfs1(G, nv, v, D+1);
	}
}

void dfs2(const Graph &G, int v, int p){
    for (auto nv : G[v]) {
		if (nv == p)continue;
        sum[nv] += sum[v];
		dfs2(G, nv, v);
	}
}

int main() {
    int n, q;
    cin >> n;
    Graph G(n);
    vector<ll> a(n-1), b(n-1);
    rep(i, n-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    d.resize(n);
    sum.resize(n);
    dfs1(G, 0, -1, 0);
    cin >> q;
    rep(i, q){
        ll t, e, x;
        cin >> t >> e >> x; e--;
        if(t == 1){
            if(d[a[e]] < d[b[e]]){
                sum[0] += x;
                sum[b[e]] -= x;
            }else{
                sum[a[e]] += x;
            }
        }else{
            if(d[b[e]] < d[a[e]]){
                sum[0] += x;
                sum[a[e]] -= x;
            }else{
                sum[b[e]] += x;
            }
        }
    }
    dfs2(G, 0, -1);
    rep(i, n)cout << sum[i] << endl;
}

#include <bits/stdc++.h>
using namespace std;
vector<int> v , T;
void build(int node, int l, int r) {
    if (l == r) {
        T[node] = v[l];
    }
    else {
        int mid = (l + r) / 2;
        build(2 * node, l, mid);
        build(2 * node + 1, mid + 1, r);
        T[node] = T[2 * node] ^ T[2 * node + 1];
    }
}
void update(int node, int start, int end, int pos, int value) {
    if (start == end){
        T[node] = value;
        return;
    }
    int mid = (start + end) / 2;
    if (pos <= mid) {
        update(2 * node, start, mid, pos, value);
    }
    else update(2 * node + 1, mid + 1, end, pos, value);
    T[node] = T[2 * node] ^ T[2 * node + 1];
}

int query(int node, int start, int end, int l, int r){
    if (start > r || end < l) return 0;
    if (start >= l && end <= r) {
        return T[node];
    }
    int mid = (start + end) / 2;
    int ans = query(2 * node, start, mid, l, r);
    int ans2 = query(2 * node + 1, mid + 1, end, l, r);
    return ans ^ ans2;
}

int main(){
    int n , q;
    cin >> n >> q;
    v = vector<int>(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    T = vector<int>(4 * n);
    build(1, 0, n - 1);
    while (q--) {
        int command;
        cin >> command;
        if (command == 1) {
            int x , y;
            cin >> x >> y;
            --x;
            int ans = query(1, 0, n - 1, x, x);
            update(1, 0, n - 1, x, ans ^ y);
        }
        else if (command == 2) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            int ans = query(1, 0, n - 1, x, y);
            cout << ans << endl;
        }
        else assert(false);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;

//#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
//const int mod = 998244353;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

LL N,K;

bool check(LL mid, const VVL& A){
    dump(mid)
    LL half = (K*K+1) / 2;
    VVL acc(N,VL(N));
    REP(i,N) REP(j,N){
        if(i == 0 && j == 0){
            if(A[0][0] <= mid) acc[i][j] = 1;
            else acc[i][j] = 0;
        }else if(i == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i][j-1] + 1;
            }else{
                acc[i][j] = acc[i][j-1];
            }
        }else if(j == 0){
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + 1;
            }else{
                acc[i][j] = acc[i-1][j];
            }

        }else{
            if(A[i][j] <= mid){
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1] + 1;
            }else{
                acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1];
            }

        }
    }

    //REP(i,N){
    //    REP(j,N){
    //        cerr << acc[i][j] << " ";
    //    }
    //    cerr << endl;
    //}

    REP(i,N) REP(j,N){
        if(i-K < -1 or j-K < -1) continue;
        LL tx,ty,tz;
        if(i-K == -1){
            tx = 0;
        }else{
            tx = acc[i-K][j];
        }

        if(j-K == -1){
            ty = 0;
        }else{
            ty = acc[i][j-K];
        }

        if(i-K == -1 or j-K == -1){
            tz = 0;
        }else{
            tz = acc[i-K][j-K];
        }

        //LL cnt = acc[i][j] - acc[i-K][j] - acc[i][j-K] + acc[i-K][j-K];
        LL cnt = acc[i][j] - tx - ty + tz;

        dump(cnt)
            dump(half)
        if(cnt >= half) {
            return true;
        }

    }
    return false;
}

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

    //LL N,K;
    cin >> N >> K;
    vector<VL> A(N,VL(N));

    REP(i,N) REP(j,N){
        cin >> A[i][j];
    }

    LL ok = INF;
    //LL ng = INF;
    LL ng = -1;

    while(abs(ok-ng) > 1){
        LL mid = (ok + ng) / 2;

        if(check(mid,A)){
            dump("ok")
            ok = mid;
        }else{
            dump("ng")
            ng = mid;
        }

    }
    cout << ok << endl;

}

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T>
bool chmin(T& a, const T& b) { return (b < a) ? (a = b, true) : false; }
template<class T>
bool chmax(T& a, const T& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}

int main()
{
    int a, b, w;
    cin >> a >> b >> w;
    w *= 1000;
    auto x = w / b;
    if (x * b < w && w < a * (x + 1))
    {
        return cout << "UNSATISFIABLE" << endl, 0;
    }
    int mi;
    if (w % b == 0) mi = x;
    else mi = x + 1;
    int y = w / a;
    int z = w - y * a;
    if (a <= z) y++;
    cout << mi << " " << y << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxN = 205;
vector <int> v[2];

int dp[maxN][maxN][maxN][2][2];
int a[maxN];
int n;

int rec(int pos = 0, int s1 = 0, int s2 = 0, bool ac1 = 0, bool ac2 = 0) {
	if(pos == n) return (s1 == s2 && ac1 && ac2);

	int &res = dp[pos][s1][s2][ac1][ac2];
	if(~res) return res;

	res = rec(pos + 1, s1, s2, ac1, ac2);
	if(res) return res;

	// Give current pos to s1
	int new_s1 = (s1 + a[pos]) % 200;
	res = rec(pos + 1, new_s1, s2, ac1 || 1, ac2);
	if(res) {
		v[0].push_back(pos + 1);
		return res;
	}

	// Give current pos to s2
	int new_s2 = (s2 + a[pos]) % 200;
	res = rec(pos + 1, s1, new_s2, ac1, ac2 || 1);
	if(res) {
		v[1].push_back(pos + 1);
		return res;
	}

	return res;
}

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

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

	memset(dp, -1, sizeof dp);
	int res = rec();

	if(res) {
		sort(v[0].begin(), v[0].end());
		sort(v[1].begin(), v[1].end());

		cout << "Yes\n";
		cout << v[0].size();
		for(int &x : v[0]) {
			cout << ' ' << x;
		}
		cout << '\n';

		cout << v[1].size();
		for(int &x : v[1]) {
			cout << ' ' << x;
		}
	}
	else {
		cout << "No";
	}
}

#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int MAXN = 55;
const int MOD = 1E9 + 7;
LL n, x, a[MAXN], g[MAXN], lim[MAXN], dp[MAXN][2];

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

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

template <class T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

signed main() {
    // freopen("1.in", "r", stdin);
    read(n, x);
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = n; i >= 1; i--) {
        if (!x) break;
        g[i] = x / a[i], x %= a[i];
    }
    for (int i = n - 1; i >= 1; i--) {
        lim[i] = a[i + 1] / a[i];
        dp[i][0] = (g[i] != 0);
        dp[i][1] = (g[i] != lim[i] - 1);
        if (g[i] == 0) {
            dp[i][0] += dp[i + 1][0];
            dp[i][1] += dp[i + 1][1] + dp[i + 1][0];
        } else if (g[i] == lim[i] - 1) {
            dp[i][0] += dp[i + 1][0] + dp[i + 1][1];
            dp[i][1] += dp[i + 1][1];
        } else {
            dp[i][1] += dp[i + 1][1] + dp[i + 1][0];
            dp[i][0] += dp[i + 1][0] + dp[i + 1][1];
        }
    }
    cout << dp[1][0] + 1;
    return 0;
}


#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<cmath>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

const ll di[] = {-1, 0, 1, 0};
const ll dj[] = {0, -1, 0, 1};

vector<ll> load[100005];

typedef pair<ll,ll> Pair;

int main(){

  	ll N;
	unordered_set<ll> p;

  	cin >> N;

  	ll cnt = 0;

   	for(ll i = 2;i*i <=N;++i){

      for(ll j =i*i;j<=N;j*=i){
        p.insert(j);
      }

    }
  /*
  	for(ll i = 2;i*i <=N;++i){

      ll ok = 1;
      ll ng = 34;

      while(ng-ok != 1){

        ll wj = (ok+ng)/2;

        if(pow(i,wj)<=N){
         ok = wj;
        }
        else{
         ng = wj;
        }

      }

      cout << i <<" " << ok << endl;
      cnt+=(ok-1);
    }

  	cout << N - cnt << endl;
*/
  	cout << N - p.size() << endl;

  return 0;

}

#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool umax(T& a, T b){
    bool ret = a < b;
    if(ret) a = b;
    return ret;
}
template<typename T>
bool umin(T& a, T b){
    bool ret = a > b;
    if(ret) a = b;
    return ret;
}
struct edge{
    int to; ll cost;
    int from;
    edge(){ edge(0,0);}
    edge(int to_, ll cost_) : to(to_), cost(cost_){}
    edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){}
};

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

template<typename... T>
void write(T... a){
    ((cout << a),...);
}

template<typename T>
vector<T> read_array(int sz){
    vector<T> ret(sz);
    for(auto & x : ret) cin >> x;
    return ret;
}

void solve(){
    ll n;
    read(n);
    set<ll> st;
    for(ll k = 2; k * k <= n; k++){
        ll a = k * k;
        while(a <= n){
            st.insert(a);
            a *= k;
        }
    }
    ll ans = n - st.size();
    write(ans, "\n");
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    int T = 1;
    // cin >> T;
    while(T--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define int long long
#define arr(a) new int[a]
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define dbV(arr) cout << #arr << "=[ "; \
for(auto i:arr) cout << i << " "; cout << "]\n";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repF(i,a,n) for(int i = (a); i <= (n); ++i)
#define repB(i,a,n) for(int i = (a); i >= (n); --i)
#define test(t) int t;cin>>t;while(t--)
#define inp(a) int a;cin>>a;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define seti set<int>
#define setl set<ll>
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define all(z) z.begin(),z.end()
using namespace std;

void printArray(int a[],int n)
{
	rep(i,n)
	cout<<a[i]<<" ";
	cout<<"\n";
}

void printVec(vi v)
{
	int s = v.size();
	rep(i,s)
	cout<<v[i]<<" ";
	cout<<"\n";
}
void printBool(bool b)
{
 	if(b) cout<<"YES\n";
 	else cout<<"NO\n";
}
signed main()
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	int t,n;cin>>t>>n;
	int ans = ceil((100.0*n)/(t + 0.0)) + n - 1;
	cout<<ans;
 return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define loopi(n) for(ll i=0;i<n;i++)
#define loopj(n) for(ll j=0;j<n;j++)
#define loopk(n) for(ll k=0;k<n;k++)
#define loopnode(v) for(ll i : v)
#define mod7 1000000007
#define mod9 1000000009
#define mod8 100000000
#define modl 998244353
#define pb push_back
#define mp make_pair
#define fst first
#define scnd second
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vecl;
typedef std::vector<bool> vecb;
typedef std::vector<long double> vecd;
typedef std::vector<string> vecstr;
typedef std::vector<char> vecch;
typedef std::vector< pair<ll,ll> >  vecpair;
typedef unordered_map<ll,ll> umap;
typedef unordered_map<long double,int> umapd;
typedef unordered_map<string,ll> umapstr;
typedef unordered_map<char,ll> umapc;
typedef set< ll,greater<ll>  > st;
typedef priority_queue<ll> q_max;
typedef priority_queue<ll,vector<ll>,greater<ll> > q_min;
typedef map<ll,ll> mapl;

int main()
{

	ll t,N;cin>>t>>N;
	if((N*100)%t == 0)
	cout<<((N*100)/t) + N -1;
	else cout<<((N*100)/t) + N;

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define ch(a) (int(a-'a')+1)
#define mm(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define inf  0x7FFFFFFF
typedef long long ll;
const int Maxx=3*1e5+10;
ll a[Maxx];
int main()
{
    int n;
    IOS;
    cin>>n;
    rep(i,1,n) cin>>a[i];
    ll ans=1LL*(n-1)*n/2;
    sort(a+1,a+n+1);
    ll tmp=1;
    for(int i=1;i<=(n-1);i++)
    {
        if(a[i]==a[i+1])
        {
            ++tmp;
        }
        else
        {
            ans-=1LL*(tmp-1)*tmp/2;tmp=1;
        }
    }
    ans-=1LL*(tmp-1)*tmp/2;
    cout<<ans<<endl;
    return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
using ll = long long;
using P = pair<ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cout << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

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

// 約数列挙
//O(√N)
vector<ll> enumDivisors(ll N) {
    vector<ll> res1, res2;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res1.push_back(i);
            if (N/i != i) res2.push_back(N/i);
        }
    }
    res1.reserve(res1.size()+res2.size());
    copy(res2.rbegin(), res2.rend(), back_inserter(res1));
    return res1;
}

void Main(){
    I(ll, N);
    auto div = enumDivisors(N);
    EACH(v, div){
        cout << v << el;
    }
}


#include <bits/stdc++.h>

#define ll long long
#define X first
#define Y second
#define pii pair<int,int>
#define ld long long double
using namespace std;
int const N = 18;
int x[N], y[N], z[N];
int target;
ll oo = 1e16;
int n;
ll mem[N][1<<18];
ll cal(int i, int j){
    return abs(x[i] - x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]);
}
ll dp(int nd, int mask){
    if((mask&target) == target){
        return cal(nd, 0);
    }
    ll &ret = mem[nd][mask];
    if(~ret)
        return ret;
    ret = oo;
    for(int i=0; i<n; i++){
        if((mask & (1<<i)) == 0){
            ret = min(ret, dp(i, mask | (1<<i)) + cal(nd, i));
        }
    }
    return ret;
}

void test() {
    memset(mem, -1, sizeof(mem));
    cin>>n;
    target = (1<<n) - 1;
    for(int i=0; i<n; i++){
        cin>>x[i]>>y[i]>>z[i];
    }
    cout<<dp(0, 1)<<'\n';
}

int main() {
#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false), cin.tie(0);
#endif
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
//    cin >> t;
    for (int i = 1; i <= t; i++) {
        test();
    }

}

#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
#define endl "\n"
vector<bool>B(100005);
vector<bool>B2(100005);
vector<int>Ans(100005);
struct Edge {
	int to, id;
	Edge(int to, int id) :to(to), id(id) {}
};
vector<Edge>g[100005];
vector<Edge>g2[100005];

void dfs(int v, int p = -1) {
	if (B[v]) {
		return;
	}
	B[v] = true;
	for (Edge e : g[v]) {
		if (p == e.to) {
			continue;
		}
		if (B[e.to]) {
			continue;
		}
		g2[v].emplace_back(e.to, e.id);
		dfs(e.to, v);
	}
	return;
}

void dfs2(int v, int id = -1, int p = -1) {
	Ans[v] = id;
	if (-1 != id) {
		B2[id] = true;
	}
	for (Edge e : g2[v]) {
		if (p == e.to) {
			continue;
		}
		if (Ans[v] != e.id) {
			dfs2(e.to, e.id, v);
		}
		else {
			dfs2(e.to, -1, v);
		}
	}
	return;
}

int main() {
	int N, M;
	cin >> N >> M;
	for (int n = 0; n < M; ++n) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		c--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	for (int i = 0; i < N; ++i) {
		B[i] = false;
		B2[i] = false;
	}
	dfs(0);
	dfs2(0);
	int memo = 0;
	for (; memo < N; ++memo) {
		if (!B2[memo]) {
			break;
		}
	}
	for (int n = 0; n < N; ++n) {
		if (-1 == Ans[n]) {
			Ans[n] = memo;
		}
		cout << Ans[n] + 1 << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    ll n; cin >> n;
    if(n % 100 == 0)
    {
        cout << 100;
        return 0;
    }
    else
    {
        ll p = n / 100;
        p++;
        p = p * 100;
        cout << abs(p - n);
        return 0;

    }

}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <chrono>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,a) rrepi(i,a,0)
#define rrepi(i,a,b) for(ll i=a-1;i>=b;--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
typedef string::const_iterator State;
const ll MAX = 125000;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll x;
    cin >> x;
    PRINT((x/100+1)*100-x);
}


#include <iostream>

int main()
{
  int N;
  std::cin>>N;

  int result=1e9+1;

  int A,P,X;
  for(int i=0;i<N;i++)
  {
    std::cin>>A>>P>>X;
    if(X-A>0)if(result>P)result=P;
  }
  if(result==1e9+1)result=-1;

  std::cout<<result<<std::endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i = 0; i < N; i++)cin >> A[i];
    for(int i = 0; i < N; i++)cin >> B[i];
    int mx = 0; int mn = 10000;
    for(int i = 0; i < N; i++){
        mx = max (A[i], mx);
        mn = min(B[i], mn);
    }
    if(mx > mn){
        cout << 0 << endl;
    }
    else{
        cout << mn - mx + 1 << endl;
    }

}


#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

class number {
  public:
    ll a;
    ll b;
    ll other;

    ll num(ll x, ll y) { return x * a + y * b + other; }
};
using p = pair<number, number>;

p op2(number x, number y) {
    number nx, ny;
    nx = {-y.a, -y.b, -y.other};
    ny = x;
    return make_pair(nx, ny);
}

p op1(number x, number y) {
    number nx, ny;
    nx = y;
    ny = {-x.a, -x.b, -x.other};
    return make_pair(nx, ny);
}

p op3(number x, number y, ll axis) {
    number nx;
    nx = {x.a, x.b, x.other - axis};
    nx = {-nx.a, -nx.b, -nx.other};
    nx = {nx.a, nx.b, nx.other + axis};
    return make_pair(nx, y);
}

p op4(number x, number y, ll axis) {
    number ny;
    ny = {y.a, y.b, y.other - axis};
    ny = {-ny.a, -ny.b, -ny.other};
    ny = {ny.a, ny.b, ny.other + axis};
    return make_pair(x, ny);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> x(n), y(n);
    rep(i, n) { cin >> x[i] >> y[i]; }
    ll m;
    cin >> m;
    vector<p> v(m + 1);
    v[0] = {{1, 0, 0}, {0, 1, 0}};
    rep(i, m) {
        number bx = v[i].first;
        number by = v[i].second;
        ll num;
        cin >> num;
        if (num <= 2) {
            if (num == 1) {
                v[i + 1] = op1(bx, by);
            } else {
                v[i + 1] = op2(bx, by);
            }
        } else {
            ll axis;
            cin >> axis;
            if (num == 3) {
                v[i + 1] = op3(bx, by, axis);
            } else {
                v[i + 1] = op4(bx, by, axis);
            }
        }
    }

    ll q;
    cin >> q;
    vector<ll> a(q), b(q);
    rep(i, q) {
        cin >> a[i] >> b[i];
        b[i]--;
    }

    rep(i, q) {
        number nx, ny;
        nx = v[a[i]].first;
        ny = v[a[i]].second;
        ll ans_x = nx.num(x[b[i]], y[b[i]]);
        ll ans_y = ny.num(x[b[i]], y[b[i]]);
        cout << ans_x << " " << ans_y << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef pair<llint, llint> P;

llint h, w, n, m;
llint a[1505][1505];
bool r[1505][1505];

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

	cin >> h >> w >> n >> m;
	llint y, x;
	rep(i, 1, n){
		cin >> y >> x;
		a[x][y] = 1;
	}
	rep(i, 1, m){
		cin >> y >> x;
		a[x][y] = -1;
	}

	rep(y, 1, h){
		llint b = 0;
		rep(x, 1, w){
			if(a[x][y]) b = a[x][y];
			if(b > 0) r[x][y] = true;
		}
		b = 0;
		for(int x = w; x >= 1; x--){
			if(a[x][y]) b = a[x][y];
			if(b > 0) r[x][y] = true;
		}
	}
	rep(x, 1, w){
		llint b = 0;
		rep(y, 1, h){
			if(a[x][y]) b = a[x][y];
			if(b > 0) r[x][y] = true;
		}
		b = 0;
		for(int y = h; y >= 1; y--){
			if(a[x][y]) b = a[x][y];
			if(b > 0) r[x][y] = true;
		}
	}

	llint ans = 0;
	rep(y, 1, h){
		rep(x, 1, w){
			if(r[x][y]) ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
//#define int long long
const int N=1505;
int h,w,n,m,a[N][N],cnt[N][N];
int32_t main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m>>h>>w;
    for(int i=1;i<=h;i++){
        int r,c;cin>>r>>c;
        a[r][c]=1;
    }
    for(int i=1;i<=w;i++){
        int r,c;cin>>r>>c;
        a[r][c]=-1;
    }

    for(int i=1;i<=n;i++){
        for(int j=1,flg=0;j<=m;j++){
            if(a[i][j]==1)flg=1;
            else if(a[i][j]==-1)flg=0;
            cnt[i][j]|=flg;
        }
        for(int j=m,flg=0;j>=1;j--){
            if(a[i][j]==1)flg=1;
            else if(a[i][j]==-1)flg=0;
            cnt[i][j]|=flg;
        }
    }

    for(int j=1;j<=m;j++){
        for(int i=1,flg=0;i<=n;i++){
            if(a[i][j]==1)flg=1;
            else if(a[i][j]==-1)flg=0;
            cnt[i][j]|=flg;
        }
        for(int i=n,flg=0;i>=1;i--){
            if(a[i][j]==1)flg=1;
            else if(a[i][j]==-1)flg=0;
            cnt[i][j]|=flg;
        }
    }

    int ans = 0;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans+=cnt[i][j];
    cout<<ans;

}


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

const int MOD = 1000000007;

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

    rep(i, T) {
        ll N, A, B;
        cin >> N >> A >> B;

        ll d = max(0LL, N - A - B + 1) % MOD;
        ll ans = 2 * d % MOD * (d + 1) % MOD * (N - A + 1) % MOD * (N - B + 1) %
                     MOD -
                 d * d % MOD * (d + 1) % MOD * (d + 1) % MOD;
        if (ans < 0) ans += MOD;
        cout << ans << endl;
    }
}

// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b;
	cin>>a>>b;
	int sign = 1;
	if(b > a){
		sign = -1;
	}
	vi v(a+b);
	int sum = 0;
	rep(i,max(a,b)){
		v[i] = sign*(i+1);
		sum += (i+1);
	}
	sign *= (-1);
	int j = 1;
	repa(i,max(a,b),a+b-1){
		v[i] = sign*(j);
		sum -= j;
		j++;
	}
	v[a+b-1] = sign*sum;
	rep(i,a+b){
		cout<<v[i]<<" ";
	}
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

int main(){
   int n,k;
   cin>>n>>k;
   using P=pair<ll,ll>;
   vector<P> ps(n);
   rep(i,0,n)cin>>ps[i].first>>ps[i].second;
   sort(ALL(ps));
   vector<ll> a(n+1),b(n+1);
   rep(i,1,n+1){
      a[i]=ps[i-1].first;
      b[i]=ps[i-1].second;
   }
   ll cur=k;
   rep(i,1,n+1){
      if(cur<a[i]-a[i-1]){
         cout<<cur+a[i-1]<<'\n';
         return 0;
      }
      else{
         cur-=a[i]-a[i-1];
         cur+=b[i];
      }
   }
   cout<<cur+a.back()<<'\n';
   return 0;
}

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

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

    vector<pair<ll,ll>>a(n);

    for(ll i=0;i<n;i++)cin>>a[i].first>>a[i].second;

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

    ll now=0;

    for(ll i=0;i<n;i++){
        if(k-(a[i].first-now)<0){
            cout<<now+k<<endl;
            return 0;
        }

        k-=(a[i].first-now);
        k+=a[i].second;
        now=a[i].first;
    }

    cout<<now+k<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define pb push_back
#define F first
#define S second
typedef long long ll;
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
//cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる
//vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言

int main(){
   int a,b,c;
   cin>>a>>b>>c;
int ans=a+b+c-min({a,b,c});
   cout<<ans;
}

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

int main() {
    int arr[3];
    for(int i=0;i<3;i++){
        cin>>arr[i];
    }
    sort(arr,arr+3);
    cout<<(arr[1]+arr[2]);
	return 0;
}


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

int main(){
    int t;
    cin >> t;
    rep(i, t){
        string s;
        cin >> s;
        int ans = 0;
        if(string(s.size(), 'a') == s) ans = -1;
        else if(s > "atcoder") ans = 0;
        else{
            int k;
            rep(j, s.size()){
                if(s[j] != 'a'){
                    k = j;
                    break;
                }
            }
            if(s[k] > 't') ans = k - 1;
            else ans = k;
        }
        cout << ans << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert
#define mp make_pair
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

#ifndef ONLINE_JUDGE
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl;
#else
#define deb(x)
#endif

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18;
const ld pie = acos((ld)-1);

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void __print(int x) {cerr<<x;}
void __print(char x) {cerr<<x;}
void __print(string x) {cerr<<x;}
void __print(float x) {cerr<<x;}
void __print(double x) {cerr<<x;}
void __print(bool x) {cerr<<x;}
void __print(ll x) {cerr<<x;}

template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

int main(){

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

	string s,t;
	cin >> s >> t;

	int cs0 = 0, ct0 = 0;
	rep(i, 0, N) {
		if(s[i] == '0') {
			cs0++;
		}
		if(t[i] == '0') {
			ct0++;
		}
	}

	if(cs0 != ct0) {
		puts("-1");
		return 0;
	}

	int cs = 0, ct = 0;
	int ans = cs0;

	rep(i, 0, N) {
		if(s[i] == '0') {
			cs++;
		}
		if(t[i] == '0') {
			ct++;
		}

		if(s[i] == t[i] && t[i] == '0' && cs == ct) {
			ans--;
		}
	}

	printf("%d\n", ans);

	return 0;

	/*STUFF TO LOOK:
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int x;
    cin>>x;
    cout<<max(x,0ll)<<endl;
}

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

int main() {
  int x;
  cin >> x;
  if(x < 0) cout << "0" << endl;
  else cout << x << endl;
    }


#pragma GCC optimize("O3")
#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;
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k):    It returns to an iterator to the kth element (counting from zero) in the set
// order_of_key(k) :    It returns to the number of items that are strictly smaller than our item k
#define fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb              push_back
#define f               first
#define s               second
#define F(i,a,b)        for(i=a;i<b;i++)
#define nl              "\n"
#define sp              " "
#define all(c)          (c).begin(),(c).end()
#define rev(i,b,a)      for(int i=b;i>=a;i--)
#define iota            cout<<-1<<nl
#define cty             cout<<"YES"<<nl
#define ctn             cout<<"NO"<<nl
#define lmax            LLONG_MAX
#define lmin            LLONG_MIN
#define sz(v)           (v).size()
#define deci(n)         fixed<<setprecision(n)
#define c(x)            cout<<(x)
#define csp(x)          cout<<(x)<<" "
#define c1(x)           cout<<(x)<<nl
#define c2(x,y)         cout<<(x)<<" "<<(y)<<nl
#define c3(x,y,z)       cout<<(x)<<" "<<(y)<<" "<<(z)<<nl
#define c4(a,b,c,d)     cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<nl
#define c5(a,b,c,d,e)   cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<nl
#define c6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<nl
typedef long double     ld;
typedef long long       ll;
typedef vector<ll>      vll;
typedef pair<ll,ll>     pll;
typedef vector<pll>     vpll;
const int mod=998244353;
const double pi=3.14159265358979323846264338327950288419716939937510582097494459230;
// priority_queue<t>

ll poww(ll a, ll b) { ll res=1; while(b) { if(b&1)	res=(res*a); a=(a*a); b>>=1; } return res; }
ll modI(ll a, ll m=mod) { ll m0=m,y=0,x=1;  if(m==1) return 0;  while(a>1)  { ll q=a/m; ll t=m;  m=a%m;  a=t; t=y; y=x-q*y;  x=t; } if(x<0) x+=m0; return x;}
ll powm(ll a, ll b,ll m=mod) {ll res=1;	while(b) {	if(b&1)	res=(res*a)%m;	a=(a*a)%m; b>>=1;	}	return res;}
//*******************************************************************************************************************************************//
void iamzeus()
{ ll i,j,x=0,y,ans=0,n,m,d,cnt=0,z,c=2,k;

 char a[3];
 cin>>a[0]>>a[1]>>a[2];
 cout<<a[1]<<a[2]<<a[0];

};
int main()
{fast;
    int t;
  t=1;
//cin >>t;
 while(t--)
     iamzeus();
}

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define pii pair<ll,ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n+1)

signed main()
{
    FIO;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(min(a,b),min(c,d));
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef priority_queue<pll, vpll, function<bool(pll,pll)> > pqpll;
typedef priority_queue<ll, vll, function<bool(pll,pll)> > pqll;

// struct triplet{ ll fs,sc,td; triplet(ll a,ll b,ll c): fs(a), sc(b), td(c){} };
// typedef priority_queue<triplet, vector<triplet>, function<bool(triplet, triplet)> > pqtri;
// typedef vector<triplet> vtri;
// typedef vector<vtri> vvtri;

struct edge{ ll from,to,cost; edge(ll e_from,ll e_to,ll e_cost): from(e_from), to(e_to), cost(e_cost){} };
typedef vector<vector<edge>> Graph;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (1LL << 60)
#define INF (1 << 30)
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()
#define tcheck(a) if((clock() - start)/(ld)CLOCKS_PER_SEC >= a) break

template<typename T> ll sz(vector<T> &pos){ return (ll)pos.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); }

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

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

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

bool endflag;

void rec(ll k, vector<string> &s, vb &is_used, vll &num, vector<string> &ans, vb &temp){
    if(26 <= k){
        bool flag = false;
        vll tempnum(3,0);
        rep(i,0,3){
            bool check = true;
            rep(j,0,sz(s[i])){
                if(check && num[s[i][j] - 'a'] == 0){
                    return;
                }
                else check = false;
                tempnum[i] *= 10;
                tempnum[i] += num[s[i][j] - 'a'];
            }
        }
        if(tempnum[0] + tempnum[1] == tempnum[2]){
            endflag = true;
            cout << tempnum[0] << endl;
            cout << tempnum[1] << endl;
            cout << tempnum[2] << endl;
        }
        return;
    }
    else if(!temp[k]){
        rec(k+1,s,is_used,num,ans,temp);
        return;
    }

    if(endflag) return;

    rep(i,0,10){
        if(!is_used[i]){
            is_used[i] = true;
            num[k] = i;
            rec(k+1,s,is_used,num,ans,temp);
            is_used[i] = false;
            num[k] = -1;
        }
    }
    return;
}

int main(){
    vector<string> s(3),ans(3);
    vb temp(26,false);
    ll cnt = 0;
    rep(i,0,3){
        cin >> s[i];
        rep(j,0,sz(s[i])){
            if(temp[s[i][j] - 'a']) cnt++;
            temp[s[i][j] - 'a'] = true;
        }
    }

    vb is_used(10,false);
    vll num(26,-1);
    rep(i,0,3) rep(j,0,sz(s[i])) ans[i].push_back('X');
    rec(0,s,is_used,num,ans,temp);

    if(!endflag) cout << "UNSOLVABLE" << endl;
}

#include <bits/stdc++.h>
using namespace std;
// clang-format off
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353

using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template<typename T>
istream& operator>>(istream &is, complex<T>& c) {
    double x, y;
    is >> x >> y;
    c.real(x);
    c.imag(y);
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
#define GET_NAME(_1,_2,_3,_4,NAME,...) NAME
#define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;

// cout << fixed << setprecision(15);
void solve();
int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    vector<string> S(3);
    cin >> S;

    set<char> heads;
    map<char, ll> mp;
    rep(i, 3) {
        ll co = 1;
        if (i == 2) co = -1;
        for_each(rall(S[i]), [&](char c) {
            mp[c] += co;
            co *= 10;
        });
        heads.insert(S[i][0]);
    }
    veci d(10);
    iota(all(d), 0);
    do {
        int i = 0;
        ll tot = 0;
        for (auto [c, co] : mp) {
            if (d[i] == 0 && heads.count(c)) {
                tot = 1;
                break;
            }
            tot += co * d[i++];
        }
        if (tot == 0) {
            i = 0;
            for (auto& [c, co] : mp) co = d[i++];
            rep(j, 3) {
                ll x = 0;
                for (char c : S[j]) x = x * 10 + mp[c];
                cout << x << endl;
            }
            return;
        }
    } while (next_permutation(all(d)));
    cout << "UNSOLVABLE" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i64 i=0; i<n; i++)
#define all(v) v.begin(),v.end()
#define pp pair<int,int>
using Graph=vector<vector<int>>;
using i64=int64_t;

int main() {
    int si,sj;cin>>si>>sj;
    vector<vector<int>> t(50,vector<int>(50));
    rep(i,50) {
        rep(j,50) {
            cin>>t[i][j];
        }
    }
    vector<vector<int>> p(50,vector<int>(50));
    rep(i,50) {
        rep(j,50) {
            cin>>p[i][j];
        }
    }
    vector<char>ans;
    if(si<=48) {
        if(t[si][sj]!=t[si+1][sj]) {
            ans.push_back('D');
            if(si<=47 && t[si+1][sj]!=t[si+2][sj]) {
                ans.push_back('D');
                if(si<=46 && t[si+2][sj]!=t[si+3][sj]) {
                    ans.push_back('D');
                }
            }
        } else {
            ans.push_back('U');
        }
    } else {
        if(sj<=48) {
            if(t[si][sj]!=t[si][sj+1]) {
                ans.push_back('R');
                if(sj<=47 && t[si][sj+1]!=t[si][sj+2]) {
                    ans.push_back('R');
                }
            } else {
                ans.push_back('L');
            }
        } else {
            if(t[si][sj]!=t[si][sj-1]) {
                ans.push_back('L');
            } else {
                ans.push_back('U');
            }
        }
    }
    rep(i,ans.size()) {
        cout << ans[i];
    }
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

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

	int ans=0;
	rep(x,1,a+1) rep(y,1,b+1){
		ans+=x*100+y;
	}

	cout<<ans<<endl;
}


#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>

// 最大公約数
template<typename T> T gcd(T a, T b)
{
	if (a < b) {
		return gcd(b, a);
	}
	else {
		const T mod = a % b;
		if (mod == 0) {
			return b;
		}
		else {
			return gcd(b, mod);
		}
	}
}

int main()
{
	int N;
	std::cin >> N;
	double m = 0;
	double y = 0;
	double c = 0;
	for (int64_t i = 0; i < N; ++i) {
		double x;
		std::cin >> x;
		m += abs(x);
		y += x * x;
		c = std::max<double>(c, abs(x));
	}
	y = sqrt(y);
	std::cout << std::setprecision(15)  << m << "\n" << y << "\n" << c << std::endl;

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {int N;cin>>N;
            vector<long long>A(N),B(N);
            for(int i=0;i<N;i++)
              cin>>A.at(i);
            for(int i=0;i<N;i++)
              cin>>B.at(i);
            long long c=0;
            int d=0;
            for(int i=0;i<N;i++)
              {d=max<long long>(d,A.at(i));
               c=max(c,d*B.at(i));
              cout<<c<<endl;}

}


        // Rakib (CSE'19)

        #include<bits/stdc++.h>

        #define               boost_                 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
        #define               pb                     push_back
        #define               read(i,n,a)            for(i=0;i<n;++i) cin>>a[i]
        #define               print(i,a)             for(auto i:a) cout<<i<< " " ; cout<<endl ;
        #define               dpoint(n)              cout<<showpoint<<fixed<<setprecision(n)
        #define               MOD                    1000003
        #define               llmax                  LONG_LONG_MAX
        #define               llmin                  LONG_LONG_MIN
        #define               read_grid(i,j,n,m,a)   for(i=0;i<n;++i) for(j=0;j<m;++j) cin >> a[i][j];
        #define               all(a)                 a.begin(),a.end()
        #define               vl                     vector<ll>

        typedef               long long              ll;
        typedef               unsigned long long     ull;

         using namespace std;

        int gcd(int x,int y){
                if(!y) return x;
                return gcd(y,x%y);
        }
        ll MX=100001;

        vector<ll>check(MX,1), divisor(MX,2);
         //vector<ll>primes,divisor;

        void prime(){

                ll i,j;
                //check[1]=0;
                //check[2]=1;
                //primes.pb(2);
                for(i=3;i<MX;i+=2){
                        if(check[i]){
                                //primes.pb(i);
                                divisor[i]=i;
                                for(j=i*i;j<MX;j+=2*i) divisor[j]=i, check[j]=0;
                        }
                }
        }

        void task(ll case_no){

            ll n,m;
            cin >> n >> m;
            ll i,j;
            ll a[n][m];

            ll x=llmax;
            for(i=0;i<n;++i){
                    for(j=0;j<m;++j){
                            cin >> a[i][j];
                            x=min(x,a[i][j]);
                    }
            }

            ll ans=0;

            for(i=0;i<n;++i){
                    for(j=0;j<m;++j){
                            ans+=a[i][j]-x;
                    }
            }

            cout << ans << "\n";

        }

        int main(){

                boost_;
                //prime();
                ll t=1,i=0;
                //cin >> t;

                while(t--){

                        task(++i);

                }

                return 0;
        }

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
//#define ld long double
#define mod  998244353
//define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
//#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define repr(x,n,j)for(ll x=n;x>j;x--)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;
typedef long double ld;

mt19937 myrand(time(0));

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    a-=b;
    if(a<0)a+=mod;
    return a%mod;
}

struct CustomCompare
{
    bool operator()(pi a,pi b)
    {
        return a.fi<b.fi;
    }
};
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

const int mxn = 2e5 +10;

vi arr(mxn);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);

ll n,w; cin>>n>>w;

rep(i,0,n)
{
    ll l,r,p; cin>>l>>r>>p;
    arr[l]+=p;
    arr[r]-=p;
}

bool flag = true;
ll curr = 0;
rep(i,0,mxn)
{
    curr+=arr[i];
    if(curr>w)flag = false;
}
if(flag)cout<<"Yes\n";
else cout<<"No\n";
return 0;
}
/*

*/


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

int main() {
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  if (r1 == r2 && c1 == c2)
    cout << 0 << endl;
  else if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 ||
           abs(r1 - r2) + abs(c1 - c2) <= 3)
    cout << 1 << endl;
  else if (abs(r1 + c1 + r2 + c2) % 2LL == 0)
    cout << 2 << endl;
  else {
    if (abs(r1 - c1 - r2 + c2) <= 5 || abs(r1 + c1 - r2 - c2) <= 5)
      cout << 2 << endl;
    else
      cout << 3 << endl;
  }
  return 0;
}

#line 1 "C.cpp"
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);

	int ans;
	if(std::abs(a + b) % 2 == std::abs(c + d) % 2) ans = 2;
	else ans = 3;
	if(a == c and b == d) ans = 0;
	if(a + b == c + d) ans = std::min(ans, 1);
	if(a - b == c - d) ans = std::min(ans, 1);

	for(int i = a - 2; i <= a + 2; i++) {
		for(int j = b - 2; j <= b + 2; j++) {
			if(i == c and j == d) ans = std::min(ans, 1);
			if(i + j == c + d) ans = std::min(ans, 2);
			if(i - j == c - d) ans = std::min(ans, 2);
			if(std::abs(i - c) + std::abs(j - d) <= 3) ans = std::min(ans, 2);
		}
	}

	std::vector<std::pair<int, int>> v = {{a - 3, b}, {a + 3, b}, {a, b - 3}, {a, b + 3}};
	for(auto [i, j]: v) {
		if(i == c and j == d) ans = std::min(ans, 1);
		if(i + j == c + d) ans = std::min(ans, 2);
		if(i - j == c - d) ans = std::min(ans, 2);
		if(std::abs(i - c) + std::abs(j - d) <= 3) ans = std::min(ans, 2);
	}

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

// 三手以下
// 2 手判断
// パリティ同じ -> 曲がって行ける
// 異なる -> 四角内で動いてからななめ
// 1 手判断
// もとから


// Problem : B - DNA Sequence
// Contest : AtCoder - AtCoder Regular Contest 104
// URL : https://atcoder.jp/contests/arc104/tasks/arc104_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// $%U%$
// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n;
	string s;
	cin >> n >> s;
	map<pair<int,int>,int> mp;
	int A,G,C,T;
	A = G = C = T = 0;
	int ans=0;
	mp[{0,0}]++;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='A')
		A++;
		else if(s[i]=='G')
		G++;
		else if(s[i]=='C')
		C++;
		else
		T++;
		if(mp[{A-T,C-G}]!=0)
		ans+=mp[{A-T,C-G}];
		mp[{A-T,C-G}]++;
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define M 1000000007
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

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

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

    while (t--)
    {
        string s;
        cin >> s;
        //cout << s;
        for (int i = 0; i < s.length() && s[i] != '.'; i++)
        {
            cout << s[i];
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)
		printf("%d %d\n",(2*i)%n+1,(2*i-1)%n+1);
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
#pragma GCC target ("avx2,fma")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define rank fewfewf
#define double long double

using namespace std;
using namespace __gnu_pbds;
//using namespace atcoder;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 705000;
const int K = 20;
const int mod = 1e9 + 7;
int x, y;
map<int,int> m;
int solve(int z){
    if (m.find(z) != m.end()) return m[z];
    m[z] = abs(z - x);
    for (int i = -1; i <= 1; i++){
        if ((z + i) % 2 == 0) m[z] = min(m[z], 1 + abs(i) + solve((z + i) / 2));
    }
    return m[z];
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);
    cin >> x >> y;
    cout << solve(y);
}

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

const int DEPTH = 19;
class SegTree {
public:
	int val[1 << (DEPTH + 1)];
	SegTree() {
		for (int i = 0; i < (1 << (DEPTH + 1)); i++) {
			val[i] = 0;
		}
	}
	void update(int pos, int x) {
		pos += (1 << DEPTH) - 1;
		val[pos] ^= x;
		while (pos > 0) {
			pos = (pos - 1) / 2;
			val[pos] = val[2 * pos + 1] ^ val[2 * pos + 2];
		}
	}
	int query(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return 0;
		if (l <= a && b <= r) return val[id];
		int res1 = query(l, r, a, (a + b) / 2, id * 2 + 1);
		int res2 = query(l, r, (a + b) / 2, b, id * 2 + 2);
		return res1 ^ res2;
	}
};

SegTree seg;
int n, q;
int a[300000];
int t, x, y;

signed main() {
	int i;

	cin >> n >> q;
	rep(i, n) cin >> a[i];
	rep(i, n) seg.update(i, a[i]);
	rep(i, q) {
		cin >> t >> x >> y;
		x--;
		if (t == 1) { seg.update(x, y); }
		else { cout << seg.query(x, y) << endl; }
	}
	return 0;
}


/*************************BALIGA***************************************/
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define lld long double
#define MP make_pair
#define PB push_back
#define MT make_tuple
#define rep0(i,n) for(lli i=0;i<n;i++)
#define rep1(i,n) for(lli i=1;i<=n;i++)
#define rep(i,x,y) for(lli i=x;i<=y;i++)
#define per1(i,n) for(lli i=n;i>0;i--)
#define per0(i,n) for(lli i=n-1;i>=0;i--)
#define per(i,x,y) for(lli i=x;i>=y;i--)
#define ff first
#define ss second
#define pli pair <lli,lli>
#define plli pair <pli,lli>
#define vi vector<int>
#define vli vector<long long int>
#define vs vector<string>
#define vc vector<char>
#define vipair vector<pair<int,int>>
#define vlipair vector<pair<lli,lli>>
#define all(c) c.begin(),c.end()
#define print(c) for(lli i=0;i<c.size();i++) cout<<c[i]<<' '
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define sz(a) a.size()
#define INF64 1e18
#define INF32 1e9
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const lli mod = INF64;
const lld eps = 1e-9;
const lli maxn = 1000;
const lli max_nodes=15;
const lli alpha=26;
const lli max_log=19;
lli fact[maxn+3];
template <typename T> void add(T &a, T b){a += b;if(a >= mod)a -= mod;}
template <typename T> void sub(T &a, T b){a -= b;if(a < 0)a += mod;}
template <typename T> void mul(T &a, T b){a *= b;if(a >= mod)a %= mod;}
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void calcfac() {fact[0]=1;fact[1]=1;rep(i,2,maxn) fact[i] = (fact[i-1]*i)%mod;}
lli gcd(lli a,lli b) {if(b==0) return a; return gcd(b,a%b);}
lli gcdext(lli a,lli b,lli &x,lli &y){if(a==0){x=0;y=1;return b;}lli x1,y1;lli g=gcdext(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return g;}
lli fastexp(lli a,lli b) {a%=mod;lli res=1;while(b>0){if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1;}return res;}
lli inverse(lli n) {return fastexp(n,mod-2);}
lli ncr(lli n , lli r){if(n < r|| (n < 0) || (r < 0)) return 0 ; if(r==0) return 1; return (((fact[n] * inverse(fact[r]))%mod)*inverse(fact[n-r]))%mod;}
int pct(int x) { return __builtin_popcount(x);} //number of set bits
int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
// TRIE
// int triex[max_nodes][alpha],globcount=1;
// void build_triex(string s) {int i = 0, v = 0;while(i < s.size()){if(triex[v][s[i]-'a'] == -1)v = triex[v][s[i++]-'a'] = globcount++ ;else v = triex[v][s[i++]-'a'];}}
// SPARSE TABLE
// lli logarithm[maxn+1];
// void calclog() {logarithm[1]=0;for(lli i=2;i<=maxn;i++)logarithm[i]=logarithm[i/2]+1;}
// lli sp_table[maxn][max_log+1];
// void build_sp(vli &nums) {calclog();lli n=nums.size();rep0(i,n)sp_table[i][0]=nums[i];for(lli j=1;j<=max_log;j++){for(lli i=0;i+(1<<j)<=n;i++){sp_table[i][j]=min(sp_table[i][j-1],sp_table[i+(1<<(j-1))][j-1]);}}}
// lli query_sp(lli l,lli r) {lli j=logarithm[r-l+1];return min(sp_table[l][j],sp_table[r-(1<<j)+1][j]);}

void solve() {
	lli n;
	cin>>n;
	lli ncpy = n;
	lli ans = 0;
	if(n<1000) {
		cout<<'0';
		return;
	}
	lli digs=0;
	while(ncpy>0) {
		digs++;
		ncpy/=10;
	}
	lli d = 3*(digs/3);
	if(d == digs) d-=3;
	// cout<<digs<<' '<<d<<'\n';
	for(int i=d;i>=3;i-=3) {
		// cout << n - fastexp(10,i) + 1<<'\n';
		ans += n - fastexp(10,i) + 1;
	}
	cout<<ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC;
    TC=1;
    // cin>>TC;
    for(int t=0;t<TC;t++) solve();
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

vector<ll> get_moebius_function(ll m){
	vector<ll> is_prime(m+1, 1);
    vector<ll> meb(m+1, -1);
    meb[0] = 0;
    meb[1] = 0;
    is_prime[0] = 0;
    is_prime[1] = 0;
    REP(i, m+1){
    	if(is_prime[i] == 0) continue;
    	for(int j=2;j*i<=m;j++){
    		is_prime[i*j] = 0;
    	}
    	for(int j=1;j*i<=m;j++){
    		meb[i*j] *= -1;
    		if(j%i == 0) meb[i*j] = 0;
    	}
    }

    // 普通のメビウス関数の定義に戻すための処理
    meb[1] = 1;
    // REP(i, m+1) if(i>1) meb[i] *= -1;
    return meb;
}

int main(){

    ll L, R;
    cin >> L >> R;

    ll MA = 1010101;
    // ll MA = 30;
    auto meb = get_moebius_function(MA);
    // dump(meb)

    ll res = 0;
    for(ll i=2;i<=R;i++){
        ll kosu = R/i - (L-1)/i;
        ll tmp = kosu * kosu * meb[i];
        res += tmp;
    }

    for(ll i=L;i<=R;i++){
        ll kosu = R/i - (L-1)/i;
        ll tmp = 2*kosu-1;
        res -= tmp;
    }

    if(L == 1){
        res += 2*R-1;
    }

    cout << res << endl;

    return 0;
}


#include <bits/stdc++.h>
//#include <chrono>
#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N;
    rep(i, N){
        cout<<(i*2)%N + 1 <<' '<<(i*2 + 1)%N + 1<<endl;
    }
}

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <array>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define dump(x) // // cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template < typename T >
ostream& operator<<(ostream& os, vector< T >& v) {
    os << "{";
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i < v.size() - 1 ? ", " : "");
    }
    os << "}";
    return os;
}
// pair出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const pair< T, U >& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const map< T, U >& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template < typename T >
ostream& operator<<(ostream& os, const set< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// multiset 出力
template < typename T >
ostream& operator<<(ostream& os, const multiset< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#pragma endregion

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

int main() {
    string s;cin >> s;
    string ans;
    for (int i = s.size()-1; i >= 0; i--) {
        if (s[i] == '6') {
            ans.push_back('9');
        }
        else if (s[i] == '9') {
            ans.push_back('6');
        }
        else {
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int main() {

	int n, t; cin >> n >> t;
	vector<int> left, right;

	for (int i = 0; i <= n - 1; i++) {
		int a; cin >> a;
		if (i <= n / 2) left.emplace_back(a);
		else right.emplace_back(a);
	}

	auto subseq = [&](const vector<int>& v) -> vector<long long> {
		vector<long long> res;
		for (int mask = 0; mask < 1 << (int)v.size(); mask++) {
			long long curr = 0;
			for (int j = 0; j < v.size(); j++) {
				if (mask & (1 << j)) curr += v[j];
			}
			res.emplace_back(curr);
		}
		sort(res.begin(), res.end());
		return res;
	};

	vector<long long> ff = subseq(left);
	vector<long long> ss = subseq(right);

	long long ans = 0;
	for (auto i : ff) {
		auto it = upper_bound(ss.begin(), ss.end(), t - i);
		if (it == ss.begin()) continue;
		ans = max(ans, i + *prev(it));
	}

	cout << ans;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,-1,1};
ll dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,t; cin >> n >> t;
    vl a(n); rep(i,n) cin >> a[i];
    vl ls1, ls2;
    int N = n/2;
    rep(bit,1<<N){
        ll s = 0;
        rep(i,N) if(bit>>i & 1) s += a[i];
        ls1.push_back(s);
    }
    rep(bit,1<<(n-N)){
        ll s = 0;
        rep(i,n-N) if(bit>>i & 1) s += a[i+N];
        ls2.push_back(s);
    }
    sort(rall(ls1));
    sort(all(ls2));
    ll ans = 0;
    int id = 0;
    int m = ls2.size();
    for(auto x : ls1){
        if(x > t) continue;
        while(id < m-1 && ls2[id+1] + x <= t) id++;
        if(id < m) chmax(ans, ls2[id] + x);
    }
    cout << ans << "\n";
}


/*input
helloAtZoner

*/
#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 tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key #of elements less than x
// find_by_order kth element
using ll=long long;
using ld=long double;
using pii=pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=3;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
inline ll mult(ll a,ll b){
    if(a>=MOD) a%=MOD;
    if(b>=MOD) b%=MOD;
    return (a*b)%MOD;
}
inline ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const int maxn=1e5+5;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    string s;
    cin>>s;
    int ans=0;
    REP(i,sz(s)){
        string x="";
        REP(j,4) x.pb(s[i+j]);
        if(x=="ZONe"){
            ++ans;
        }
    }
    cout<<ans;
}

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

const ll mod = 1e9 + 7;

int run_test(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i <= 8; i++){
    if(s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3] =='e'){
      ans++;
    }
  }
  cout << ans;
  return 0;
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int tt;
  tt = 1;
  while(tt--){
    run_test();
  }
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
	int n,x;
	cin>>n;
	int l=1,r=2e9;
	while(r-l>1)
	{
		int m=l+r>>1;
		if(m*(m+1)/2<=n+1)
			l=m;
		else
			r=m;
	}
	cout<<n-l+1<<endl;
	return 0;
}

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

typedef long long ll;

int main()
{
    int K;
    cin >> K;
    ll ans = 0;
    for (int i = 1; i <= K; i++)
    {
        int jEnd = K / i;
        for (int j = i; j <= jEnd; j++)
        {
            int p = K / (i * j);
            if (p < j)
                break;
            if (i == j)
                ans += 1 + (p - i) * 3;
            else
                ans += 3 + (p - j) * 6;
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n;
    cin>>n; n*=2;
    vector<ll> a(n), b;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    multiset<ll> s;
    ll ans=0, val=0;
    for(ll i=0;i<n/2;i++){
        if(a[i]<a[n-i-1]) swap(a[i],a[n-i-1]);
        if(s.size()>0 && *s.rbegin()>a[i]){
            ans+=*s.rbegin();
            s.erase(--s.end());
            s.insert(a[i]);
            s.insert(a[n-i-1]);
        }
        else{
            ans+=a[i];
            s.insert(a[n-i-1]);
        }
    }
    cout<<ans;

    cerr<<"\n\nTIME: "<<(long double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

#include <bits/stdc++.h>
#define N 400005
#define ll long long
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int T;
int n;
int a[N];
int main()
{
    n = read();
    ll ans = 0;
    for(int i=1;i<=2*n;i++) a[i] = read(), ans += a[i];
    priority_queue<int> q;
    for (int i = 1 ; i <= n; i += 1) {
        q.push(-a[n - i + 1]);
        q.push(-a[n + i]);
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}
// 1 2 3 4 5 6 7 8
//


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

class BIT{
    public:
    int size;
    vector<long long> tree;

    BIT(int n){
        size = n;
        tree = vector<long long>(n, 0);
        return;
    }

    void add(int n, long long a) {
        assert(n < size);
        int x = n;
        while (x < size){
            tree[x] += a;
            x |= x+1;
        }
        return;
    }

    long long getsum(int n) {
        assert(n < size);
        int x = n+1;
        long long sum = 0;
        while (x > 0) {
            sum += tree[x-1];
            x &= x-1;
        }
        return sum;
    }

};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] += i;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        B[i] += i;
    }
    {
        vector<ll> C = A, D = B;
        sort(C.begin(), C.end());
        sort(D.begin(), D.end());
        if (C != D) {
            cout << -1 << endl;
            return 0;
        }
    }
    map<ll, ll> mp;
    set<ll> st;
    map<ll, ll> cnt;
    for (int i = 0; i < N; i++) {
        st.insert(A[i]);
        cnt[A[i]]++;
    }
    ll t = 0;
    for (ll n : st) {
        mp[n] = t;
        t += cnt[n];
    }
    map<ll, ll> cnt2;
    for (int i = 0; i < N; i++) {
        ll pre = A[i];
        A[i] = mp[A[i]]+cnt2[A[i]];
        cnt2[pre]++;
    }
    cnt2.clear();
    for (int i = 0; i < N; i++) {
        ll pre = B[i];
        B[i] = mp[B[i]]+cnt2[B[i]];
        cnt2[pre]++;
    }
    {
        vector<ll> tmp(N);
        for (int i = 0; i < N; i++) {
            tmp[B[i]] = i;
        }
        for (int i = 0; i < N; i++) {
            A[i] = tmp[A[i]];
        }
    }
    ll ans = 0;
    BIT bit(N);
    for (ll i = 0; i < N; i++) {
        ans += i - bit.getsum(A[i]);
        bit.add(A[i], 1);
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/modint.hpp>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
const int mod2=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using Vd=vector<ld>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;
//using mint=atcoder::modint1000000007;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >>n;
    ll m;cin >>m;
    ll r=m;
    ll x=0;
    for (int i = 0; i < n; ++i) {
        int a;cin >>a;
        x+=(a+1);
        r-=a;
    }
    x++;
//    cout <<x<<" "<<r<<"\n";
    //((x,r))を求めたい　つまり(x+r-1,x-1)を求めたい
    mint ans=1;
    for (int i = 1; i <=x-1; ++i) {
//        cout<<x+r-i<<" "<<i<<"\n";
        ans*=(x+r-i);
        ans/=i;
    }
    cout <<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define F0R(i, n) FOR(i, 0, n)
#define FOR1(i, n) FOR(i, 1, n+1)
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;

int a, b, c;

signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a >> b >> c;
    a += c;
    if(b >= a) cout << "Aoki\n";
    else cout << "Takahashi\n";
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;
  cin >>A>>B>>C;
  if(A>B){
    cout <<"Takahashi"<<endl;
  }
  if(A<B){
    cout <<"Aoki"<<endl;
  }
  if(A==B){
    if(C==0){
      cout <<"Aoki"<<endl;
    }
    if(C==1){
      cout <<"Takahashi"<<endl;
    }
  }
}


#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scanf("%c",&a)
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(int i=a;i<=b;++i)
#define repd(i, a, b) for(int i=a;i>=b;--i)
#define reps(s) for(int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

const int N = 105;
int head[N], ver[N * N << 1], Next[N * N << 1], tot;
int siz[N], n;
bool v[N];
char a[N];

inline void add(int x, int y) {
    ver[++tot] = y;
    Next[tot] = head[x];
    head[x] = tot;
}

void dfs(int x) {
    siz[x]++, v[x] = true;
    reps(x)if (!v[ver[i]])
            dfs(ver[i]);
}

int main() {
    n = qr();
    repi(i, 1, n) {
        ss(a + 1);
        repi(j, 1, n)if (a[j] == '1')add(i, j);
    }
    repi(i, 1, n) {
        memset(v, false, sizeof(bool) * (n + 1));
        dfs(i);
    }
    double ans = 0;
    repi(i, 1, n)ans += 1.0 / siz[i];
    printf("%.9lf", ans);
    return 0;
}

#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

vi adj[101], vis;
int cnt = 0;

void dfs (int cur)
{
    cnt++;
    vis[cur] = 1;
    for (int i: adj[cur])
        if (!vis[i]) dfs(i);
}

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

	read(n);
	FOR (i, 1, n)
	{
	    reads(s);
	    FOR (j, 1, n)
	        if (s[j - 1] == '1') adj[j].pb(i);
	}

	ld ans = 0;
	FOR (i, 1, n)
	{
	    vis.assign(n + 1, 0);
	    cnt = 0;
	    dfs(i);
	    ans += 1/(ld)(cnt);
	}

	setprec;
	print(ans);
}


#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
// #define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

double distance(pii a, pii b) {
    return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second));
}

signed main() {
    fio();

    int n;
    cin >> n;
    vector<pii> yx(n);
    rep (i, n) cin >> yx[i].second >> yx[i].first;
    sort(all(yx));

    double ok = 0, ng = 100;
    rep (_, 200) {
        double r = (ok + ng) / 2;
        bool update_flag = true;
        vector<bool> dp(n);
        while (update_flag) {
            update_flag = false;
            rep (i, n) {
                if (yx[i].first + 100 < 2 * r) {
                    if (not dp[i]) {
                        dp[i] = true;
                        update_flag = true;
                    }
                }
                rep (j, n) {
                    if (dp[j]) {
                        double dist = distance(yx[i], yx[j]);
                        if (dist < 2 * r) {
                            if (not dp[i]) {
                                dp[i] = true;
                              	update_flag = true;
                            }
                        }
                    }
                }
            }
        }
        bool flag = true;
        rep (i, n) {
            if (dp[i]) {
                if (100 - yx[i].first < 2 * r) {
                    flag = false;
                }
            }
        }
        (flag ? ok : ng) = r;
    }
    Sp(ok);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void pv(vector<int> v) {
    if (v.empty()) return;
    cout << v[0];
    for (int i = 1; i < sz(v); i++) {
        cout << " " << v[i];
    }
    cout << endl;
}

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, m;
    cin >> m >> h;
    if (h % m == 0)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}