// Problem:
// 			B - Reversible Cards
//
//
// Contest: AtCoder - AtCoder Regular Contest 111
// URL: https://atcoder.jp/contests/arc111/tasks/arc111_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

const int N = 4e5+7,M = 2 * N;
vector<int> E[N];
int st[N],in_stk[N],cir;

void dfs(int u,int fa)
{
	in_stk[u] = 1;
	st[u] = 1;
	for(auto& v : E[u])
	{
		if(v == fa)	continue;
		if(in_stk[v])	cir = 1;
		if(st[v])	continue;
		dfs(v,u);
	}
	in_stk[u] = 0;
}

int main()
{
	int n;scanf("%d",&n);
	set<int> col;
	forn(i,1,n)
	{
		int u,v;scanf("%d%d",&u,&v);
		E[u].push_back(v);E[v].push_back(u);
		col.insert(u);col.insert(v);
	}

	int res = col.size();
	// cout << res << endl;
	for(auto& i : col)
		if(!st[i])
		{
			cir = 0;
			dfs(i,-1);
			if(!cir)	--res;
		}
	printf("%d",res);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> using lqueue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using gqueue = priority_queue<T, vector<T>, less<T>>;

constexpr int max_v = 400000;

array<vec<int>, max_v + 1> g;
array<bool, max_v + 1> vis;

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;
    for (int i = 0; i <= max_v; ++i) {
        if (vis[i]) continue;
        vis[i] = true;

        int sum = 0, cnt = 0;
        queue<int> que;
        que.push(i);
        while (!que.empty()) {
            int c = que.front(); que.pop();
            sum += g[c].size(); ++cnt;
            for (auto v : g[c]) {
                if (vis[v]) continue;
                vis[v] = true;
                que.push(v);
            }
        }

        sum /= 2;
        if (cnt <= sum) {
            ans += cnt;
        }
        else {
            ans += cnt - 1;
        }
    }

    cout << ans << endl;
}


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

   ll ans=0;

  // cout<<rr<<endl;

 // cout<<ceil(-5.5)<<endl;

  ll low=(ll)ceil(x-r);
  ll high=(ll)floor(x+r);

  //  cout<<low<<" "<<high<<endl;

   for(ll i=low;i<=high;i++){
       long double x_cor=i;
       long double y_cor=sqrt(r*r-(x-x_cor)*(x-x_cor));

        long double up=y_cor+y+1e-14;
        long double down=y-y_cor-1e-14;

       //  cout<<up<<" "<<down<<endl;

        ll u=(floor)(up);
        ll d=(ceil)(down);

        ans+=(u-d+1);
       //ans+=(2*lim_y+1);
   }

   cout<<ans<<endl;
}
int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

//Start from Here.

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

//Good Bye!
    return 0;
}

#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1000000000;

bool ok(ll x, ll y, ll r){
    return x*x + y*y <= r*r;
}

ll solver(ll x, ll y, ll r, ll lim){
    int L = 0, R = 1;
    ll res = 0;
    for(int i = int(1e9)+50000; i >= lim; i-=10000){
        while(ok(x-L*10000,i-y,r)) --L;
        while(ok(R*10000-x,i-y,r)) ++R;
        res += R - L - 1;
    }
    return res;
}

ll in(){
    double x;
    cin >> x;
    x *= 10000;
    return round(x);
}

int main() {
    ll x = in();
    ll y = in();
    ll r = in();

    x %= 10000;
    y %= 10000;

    ll ans = solver(x, y, r, 10000);
    ans += solver(x, -y, r, 0);

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int s=100;vector<int>v(4);
    for(int i=0;i<4;i++){
        cin>>v[i];
        if(s>v[i])s=v[i];
    }
    cout<<s<<endl;
}

#include<bits/stdc++.h>

#define ll long long
#define eb emplace_back

using namespace std;
const int mx= 1e3 + 10;

void solve(){

	int a, b , c , d;

	cin >> a >> b >> c >> d;

	cout << min(a, min(c , min(b,d)));
}

int main(){

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int t;

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

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long double ld;
#define int long long
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define vii vector<int>
#define pii pair<int,int>
#define piii pair<int, pii>
#define yes cout<<"YES\n";
#define no  cout<<"NO\n";
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define PI 3.1415926535897932384626433832795
#define dec(x) fixed<<setprecision(x)
#define tc int t;cin>>t;while(t--)
#define pr(x) for(auto it : x)cout<<it<<" ";
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a*b/__gcd(a,b))
#define fi(i,n) for(int i=0;i<n;i++)
#define f(i, a, b) for(int i=a;i<b;i++)
#define all(v)  v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define endl cout<<"\n";

map<int,int>mp;

int comp(int a, int b){
    return (a>b);
}

bool prime(int n)
{
   if(n==0 or n==1) return false;
   if(n==2) return true;
   else if(n%2==0) return false;
   for(int i=3;i*i<=n;i+=2)
   {
       if(n%i==0)
       {
           return false;
       }
   }
   return true;
}

int binCo(int n, int r){
    int C[n+1][r+1];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=min(i,r);j++)
        {
            if(j==0 or j==i)
            C[i][j] = 1;
            else
            C[i][j] = C[i-1][j] + C[i-1][j-1];
        }
    }
    return C[n][r];
}

//Modular Exponentiation O(Log y)
int power(int x, int y, int MODL) {
	int res = 1;
	x = x % MODL;
	while (y > 0) {
		if (y & 1)
			res = (res*x) % MODL;
		y = y>>1;
		x = (x*x) % MODL;
	}
	return res;
}

//Fermat's Little theorem, O(Log m)
int modInverse(int a, int m) {
	   return power(a, m-2, m);
}
int binSearch(int arr[], int n, int x)
{
    int l = 0, r=n-1;
    while(l<=r)
    {
        int mid = (l+r)/2;
        if(x==arr[mid])
        return mid;
        if(x>arr[mid])
        {
           l = mid+1;
        }
        else
        if(x<arr[mid])
        {
            r = mid-1;
        }
    }
    return -1;
}

void solve()
{
   int n,k;
   cin>>n>>k;
  string s = "" ;
   while(k--){
       if(n%200==0)
       n/=200;
       else {
           s = to_string(n);
           s+="200";
           n = stoll(s);
       }
   }
   cout<<n;
}
int32_t main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    solve();
    return 0;
}

///*    ***Bismillahir Rahmanir Rahim***   */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double dl;
typedef unsigned long long ull;
#define pb push_back
#define PB pop_back
#define nn "\n"
#define O_O                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define all(p) p.begin(), p.end()
#define zz(v) (ll) v.size()
#define ss ' '
#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(p) memset(p, 0, sizeof(p))
#define precision(a) fixed << setprecision(a)
#define rep(i, b) for (ll i = 0; i < (b); i++)
#define rep1(i, b) for (int i = 1; i <= (b); i++)
//#define rep(s,e)         for(i=s;i<e;i+=1)
//#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i, b, a) for (int i = (b); i >= (a); i--)
#define rep2(i, a, b, c) for (int i = (a); i != (b); i += (c))
#define arrsize(a) (sizeof(a) / sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define S(a) scanf("%lld", &a)
#define SS(a, b) scanf("%lld %lld", &a, &b)
#define SSS(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define pi acos(-1.0)
#define ff first
#define sc second
#define print(v)   \
    for (ll i : v) \
    cout << i << ss
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<ll> vll;
typedef map<string, ll> msl;
typedef map<ll, ll> mll;
#define yes cout << "YES\n"
#define no cout << "NO\n"
bool comp(pair<ll, ll> a, pair<ll, ll> b)
{
    if (a.first != b.first)
        return a.first > b.first;
    else
        return a.second > b.second;
}
//ll minelementindex = min_element(v.begin(),v.end()) - v.begin();
//ll minelement = *min_element(v.begin(), v.end());
//ll maxelementindex = max_element(v.begin(),v.end()) - v.begin();
//ll maxelement = *max_element(v.begin(), v.end());
//memset(ar,-1,sizeof(ar));
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
// string x(w.size(),'1');
//auto s =to_string(42);
//string s = "12345";
// object from the class stringstream
//stringstream geek(s);
// The object has the value 12345 and stream
// it to the integer x
//int x = 0;
//geek >> x;
#define MAX 1000005
#define precision(a) fixed << setprecision(a)
#define mod 1000000007
int main()
{
    //O_O ;
    ll t = 1;
    // cin>>t;
    while (t--)
    {
        ll n, k;
        cin >> n >> k;

        auto s = to_string(n);
        while (k--)
        {
            stringstream geek(s);
            ll x = 0;
            geek >> x;
            //   cout << x << nn;
            if (x % 200 == 0)
            {
                x /= 200;
                auto c = to_string(x);
                s = c;
            }
            else
                s += "200";
        }
        cout << s << nn;
    }

    return 0;
}


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

using lli = long long int;
using ii = pair<int, int>;

const int MAXN = 500;

int r, c;
int a[MAXN+1][MAXN];
int b[MAXN][MAXN+1];

int cost[MAXN+1][MAXN+1];

int dijkstra() {
    memset(cost, -1, sizeof(cost));
    priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> pq;

    cost[1][1] = 0;
    pq.push({0, {1, 1}});

    while(!pq.empty()) {
        pair<int, ii> u = pq.top(); pq.pop();
        int curCost = u.first;
        ii pos = u.second;
        // printf("%d %d %d\n", curCost, pos.first, pos.second);

        if(pos.first == r and pos.second == c) {
            return curCost;
        }
        if(curCost > cost[pos.first][pos.second]) {
            continue;
        }

        if(pos.first < r and
        (cost[pos.first+1][pos.second] == -1 or
        curCost+b[pos.first][pos.second] < cost[pos.first+1][pos.second])) {
            cost[pos.first+1][pos.second] = curCost+b[pos.first][pos.second];
            pq.push({cost[pos.first+1][pos.second], {pos.first+1, pos.second}});
        }
        if(pos.second > 1 and
        (cost[pos.first][pos.second-1] == -1 or
        curCost+a[pos.first][pos.second-1] < cost[pos.first][pos.second-1])) {
            cost[pos.first][pos.second-1] = curCost+a[pos.first][pos.second-1];
            pq.push({cost[pos.first][pos.second-1], {pos.first, pos.second-1}});
        }
        if(pos.second < c and
        (cost[pos.first][pos.second+1] == -1 or
        curCost+a[pos.first][pos.second] < cost[pos.first][pos.second+1])) {
            cost[pos.first][pos.second+1] = curCost+a[pos.first][pos.second];
            pq.push({cost[pos.first][pos.second+1], {pos.first, pos.second+1}});
        }
        for(int i=1; i<pos.first; i++) {
            if(cost[pos.first-i][pos.second] == -1 or
            curCost+i+1 < cost[pos.first-i][pos.second]) {
                cost[pos.first-i][pos.second] = curCost+i+1;
                pq.push({cost[pos.first-i][pos.second], {pos.first-i, pos.second}});
            }
            else if(curCost+i+1 == cost[pos.first-i][pos.second]) {
                continue;
            }
            else {
                break;
            }
        }
    }
}

int main() {
    scanf("%d %d", &r, &c);
    for(int i=1; i<=r; i++) {
        for(int j=1; j<c; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=1; i<r; i++) {
        for(int j=1; j<=c; j++) {
            scanf("%d", &b[i][j]);
        }
    }

    printf("%d\n", dijkstra());
}

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#define all(v) (v).begin(), (v).end()
#define ar array
#define PB push_back
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1e9 + 7; //998244353
const int N = 2e5 + 1, LOG = 20;
vector<int> adj[N];
unordered_map<int, vector<int>, custom_hash> m1;
int n, dep[N], u, v, d, st[N], en[N], timer = 0;

void dfs(int V, int pV)
{
    st[V] = timer;
    m1[dep[V]].PB(st[V]);
    for (auto &e : adj[V])
    {
        if (e == pV)
            continue;
        timer++;
        dep[e] = dep[V] + 1;
        dfs(e, V);
    }
    en[V] = timer;
}

int search(int U, int D)
{
    if (dep[U] > D)
        return 0LL;
    if (dep[U] == D)
        return 1LL;
    int targ1 = st[U], targ2 = en[U];
    int l = 0, r = (int)m1[D].size() - 1, lbound = -1, rbound = -1;
    while (l <= r)
    {
        int m = l + (r - l) / 2;
        if (m1[D][m] >= targ1)
        {
            lbound = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    if (lbound == -1)
        return 0LL;
    l = 0, r = (int)m1[D].size() - 1;
    while (l <= r)
    {
        int m = l + (r - l) / 2;
        if (m1[D][m] <= targ2)
        {
            rbound = m;
            l = m + 1;
        }
        else
            r = m - 1;
    }
    if (rbound == -1)
        return 0LL;
    return rbound - lbound + 1;
}

void solve()
{
    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        cin >> v;
        adj[v].PB(i);
        adj[i].PB(v);
    }
    dfs(1, 0);
    int q;
    cin >> q;
    while (q--)
    {
        cin >> u >> d;
        cout << search(u, d) << "\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (double)clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


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

int main(){
    ll N;
    cin>>N;
    for(ll i=1;;i++){
        if(stoll(to_string(i)+to_string(i))>N){
            cout<<i-1<<endl;
            return 0;
        }
    }
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif
}
void solver() {
    ll n, cnt = 0;
    cin >> n;
    for(ll i = 1; i <= min((ll)1e6, n); ++i) {
        string s = to_string(i);
        s += s;
        if(stoll(s) <= n) {
            ++cnt;
        }
    }
    cout << cnt << "\n";
    return;
}
int main() {

    localTest();
    fastio;
    int t = 1;
    // cin >> t;
    while(t--) {
        solver();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll H, W;
vector<string> S;
pair<ll,ll> st, en;
map<char,vector<pair<ll,ll>>> T;
map<char,bool> seen;

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

void init() {
    cin >> H >> W;
    S.resize(H);
    rep(i,H) cin >> S[i];
    rep(i,H) rep(j,W) {
        char c = S[i][j];
        pair<ll,ll> p = {i,j};
        if (c=='.' || c=='#') continue;
        if (c=='S') st = p;
        else if (c=='G') en = p;
        else T[c].push_back(p);
    }
}

ll solve() {
    vector<vector<ll>> dist(H,vector<ll>(W,inf));
    dist[st.first][st.second] = 0;
    queue<pair<ll,ll>> que;
    que.push(st);
    while (que.size()) {
        pair<ll,ll> p = que.front();
        que.pop();
        ll x = p.first, y = p.second;
        ll d = dist[x][y];
        rep(i,4) {
            ll nx = x + dx[i], ny = y + dy[i];
            if (nx<0 || nx>=H || ny<0 || ny>=W) continue;
            if (S[nx][ny]=='#') continue;
            ll nd = d + 1;
            if (nd<dist[nx][ny]) {
                dist[nx][ny] = nd;
                que.push({nx,ny});
            }
        }
        char c = S[x][y];
        if (c=='.' || c=='S' || c=='G') continue;
        if (seen[c]) continue;
        seen[c] = true;
        for (auto p : T[c]) {
            ll nx = p.first, ny = p.second;
            ll nd = d + 1;
            if (dist[nx][ny]>nd) {
                dist[nx][ny] = nd;
                que.push(p);
            }
        }
    }
    ll res = dist[en.first][en.second];
    if (res==inf) res = -1;
    return res;
}

int main() {
    init();
    ll ans = solve();
    Cout(ans);
}

///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           nd(a,b,c)                   mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=2e18;
const int mod=1e9+7;
const int M=3005;

inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n;
int a[M],pre[M];

int dp[M][M];

int sum[M],nxt[M];

 main()

{
    fast
    cin>>n;
    f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1];

    rf(k,n,1)
    {
        f(pos,1,n)
        {
            int val=pre[pos-1]%k;

            sum[val]=sub(sum[val],dp[pos][k+1]);

            dp[pos][k]=sum[val];

            int z=pre[n]-pre[pos-1];
            z=z%k;

            if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod;

            if(k!=1){

            val=pre[pos-1]%(k-1);
            nxt[val]=ad(nxt[val],dp[pos][k]);

            }
        }

        f(j,0,k+1)
        {
            sum[j]=nxt[j];
            nxt[j]=0;
        }
    }

    cout<<dp[1][1]<<"\n";
    return 0;

}


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

int main(){
  string s;cin>>s;s+="################";
  int ans=0;
  for(int i=0;s[i]!='#';i++)ans+=s.substr(i,4)=="ZONe";
  cout<<ans<<endl;
}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
using vi64 = vector<i64>;
using vvi64 = vector<vi64>;
using vvvi64 = vector<vvi64>;
using u64 = uint64_t;

#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

// constexpr i64 mod{1000000007};
// constexpr i64 izero{0};
// constexpr i64 ione{1};
// constexpr u64 uone{1};
// constexpr i64 di[]{0, 1, 0, -1}, dj[]{1, 0, -1, 0};

void run() {
  string s;
  cin >> s;
  i64 ret{0};
  rep(i, 0, 4){
    i64 c{0};
    rep(j, i, 9){
      if(s.substr(j, 4) == "ZONe"){
        ++c;
      }
    }
    ret = max(ret, c);
  }
  cout << ret << endl;
}

int main() {
  cin.tie(nullptr);
  cout.precision(std::numeric_limits<double>::max_digits10);
  cerr.precision(std::numeric_limits<double>::max_digits10);
  clog.precision(std::numeric_limits<double>::max_digits10);
  run();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
int main(){
    int R,C;
    cin >> R >> C;
    vector<vector<char>> table(R, vector<char>(C));
    vector<vector<int>> dist(R, vector<int>(C));
    int sy, sx, gy, gx;
    vector<int> alx[26], aly[26];
    bool alf[26]={};
    rep(i, R){
        rep(j, C){
            cin >> table.at(i).at(j);
            if(table.at(i).at(j) == 'S'){sx = j; sy = i;}
            if(table.at(i).at(j) == 'G'){gx = j; gy = i;}
            if(table.at(i).at(j) >= 'a' && table.at(i).at(j) <= 'z'){
                assert(table.at(i).at(j) - 'a' < 26);
                alx[table.at(i).at(j) - 'a'].push_back(j);
                aly[table.at(i).at(j) - 'a'].push_back(i);
                }
            dist.at(i).at(j) = INF;
        }
    }
  //sx--; sy--; gx--; gy--;
    queue<pair<int, int>> Q;
    Q.push(make_pair(sy, sx));
    dist.at(sy).at(sx)=0;

    while(!Q.empty()){
        int cy = Q.front().first, cx = Q.front().second;
        Q.pop();

        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        rep(i, 4){
            int ex = cx + dx[i], ey = cy + dy[i];
            if(ex < 0 || ex >=C || ey < 0 || ey >= R) continue;
            if (table.at(ey).at(ex) == '#' || dist.at(ey).at(ex) != INF) continue;
            Q.push(make_pair(ey, ex));
            dist.at(ey).at(ex) = dist.at(cy).at(cx) + 1;
        }
        if(table.at(cy).at(cx) >= 'a' && table.at(cy).at(cx) <= 'z'){
            if(alf[table.at(cy).at(cx)-'a']) continue;
            int aaa=table.at(cy).at(cx)-'a';
            assert(aaa <= 25);
            assert(alx[aaa].size() <= 2000 * 2000);
            assert(alx[aaa].size() == aly[aaa].size());
            rep(j, alx[aaa].size()){
                if(alx[aaa][j] == cx && aly[aaa][j] == cy) continue;
                if(dist.at(aly[aaa][j]).at(alx[aaa][j]) != INF) continue;
                Q.push(make_pair(aly[aaa][j], alx[aaa][j]));
                dist.at(aly[aaa][j]).at(alx[aaa][j]) = dist.at(cy).at(cx) + 1;
            }
            alf[table.at(cy).at(cx)-'a'] = true;
        }
    }
    if(dist.at(gy).at(gx) == INF){
        cout << -1 << endl;
        return 0;
    }
    cout << dist.at(gy).at(gx) << endl;
}

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int tesuu[2006][2006];
int used[1000];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
string karifie[2006];
char fie[2006][2006];
int main(){
    for(int i=0;i<2006;i++){
        for(int j=0;j<2006;j++){
            tesuu[i][j]=-1;
        }
    }
    int H,W;

    cin>>H>>W;
    for(int i=0;i<H;i++){
        cin>>karifie[i];
    }
    int gy,gx,sy,sx;
    for(int i=0;i<=H+1;i++){
        for(int j=0;j<=W+1;j++){
            if(i==0||j==0||i==H+1||j==W+1)fie[i][j]='#';
            else fie[i][j]=karifie[i-1][j-1];
            if(fie[i][j]=='S'){sy=i;sx=j;};
            if(fie[i][j]=='G'){gy=i;gx=j;};
        }
    }
    queue<int> Qx,Qy;
    Qy.push(sy);
    Qx.push(sx);
    tesuu[sy][sx]=0;
    while(!Qx.empty()){
        int kariy=Qy.front();Qy.pop();
        int karix=Qx.front();Qx.pop();
        for(int i=0;i<4;i++){
            if(fie[kariy+dy[i]][karix+dx[i]]!='#'){
                if(tesuu[kariy+dy[i]][karix+dx[i]]==-1){
                    Qy.push(kariy+dy[i]);Qx.push(karix+dx[i]);
                    tesuu[kariy+dy[i]][karix+dx[i]]=tesuu[kariy][karix]+1;
                }
            }
        }
        if('a'<=fie[kariy][karix]&&fie[kariy][karix]<='z'){
            if(used[fie[kariy][karix]]==0){
                used[fie[kariy][karix]]=1;
                for(int i=1;i<=H;i++){
                    for(int j=1;j<=W;j++){
                        if(i==kariy&&j==karix)continue;
                        if(fie[kariy][karix]==fie[i][j]){
                            if(tesuu[i][j]==-1){
                                Qy.push(i);Qx.push(j);
                                tesuu[i][j]=tesuu[kariy][karix]+1;
                            }
                        }
                    }
                }
            }
        }
    }
    cout<<tesuu[gy][gx]<<endl;
    return 0;
}


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

int N, M, w[10];
int l[101010], v[101010];
ll dp[10][10];
//---------------------------------------------------------------------------------------------------
ll solve() {
	rep(i, 0, N) rep(j, 0, M) if (v[j] < w[i]) return -1;

	map<int, int> pr;
	rep(i, 0, M) {
		if (pr.count(l[i]) == 0) pr[l[i]] = inf;
		chmin(pr[l[i]], v[i]);
	}

	set<pair<ll, int>> lens; // {weight, len}

	int pre = inf;
	for (auto ite = pr.rbegin(); ite != pr.rend(); ite++) if (ite->second < pre) {
		lens.insert({ ite->second, ite->first });
		pre = ite->second;
	}

	vector<int> ord;
	rep(i, 0, N) ord.push_back(i);
	ll ans = infl;
	do {
		rep(i, 0, N) rep(j, 0, N) dp[i][j] = infl;
		rep(i, 0, N) dp[i][i] = 0;

		rep(len, 2, N + 1) rep(l, 0, N) {
			int r = l + len - 1;
			if (N <= r) continue;

			ll weight = 0;
			rep(i, l, r + 1) weight += w[ord[i]];

			auto ite = lens.lower_bound({ weight, -1 });
			if (ite == lens.begin()) {
				dp[l][r] = 0;
			}
			else {
				ite--;
				dp[l][r] = ite->second;
			}

			rep(c, l, r + 1) chmax(dp[l][r], dp[l][c] + dp[c][r]);
		}
		chmin(ans, dp[0][N - 1]);
	} while (next_permutation(all(ord)));

	return ans;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> w[i];
	rep(i, 0, M) cin >> l[i] >> v[i];
	cout << solve() << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mp make_pair
#define fr first
#define sc second

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

	x+=200100.;
	y+=200100.;

	ll X=10000*x+0.5;
	ll Y=10000*y+0.5;
	ll R=10000*rr+0.5;

	ll ret=0;
	for(ll s=x-rr-10;s<x+rr+10;s++){
		ll b,u;
		ll l=y-rr-10,r=y+1;
		//cerr<<l<<" "<<r<<endl;
		while(l<r){
			ll t=(l+r)/2;
			ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y);
			//cerr<<t<<" "<<d<<" "<<R<<endl;
			if(d<=R*R)r=t;
			else l=t+1;
		}
		b=l;
		l=y; r=y+rr+10;
		//cerr<<l<<" "<<r<<endl;
		while(l<r){
			ll t=(l+r+1)/2;
			ll d=(s*10000-X)*(s*10000-X)+(t*10000-Y)*(t*10000-Y);
			if(d<=R*R)l=t;
			else r=t-1;
		}
		u=l;
		if(b<=u)ret+=u-b+1;
		//cout<<s<<" "<<b<<" "<<u<<endl;
	}
	cout<<ret<<endl;
}


#include <bits/stdc++.h>

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

const ll mod = 1000000007;

ll tc, cnt = 0, number, many, total = 0, query, require, length;
int rmove[8] = {1, 0, 0, -1, -1, 1, -1, 1};
int cmove[8] = {0, -1, 1, 0, 1, -1, -1, 1};

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

    return res;
}

int main()
{
    fastio();

    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test
    // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp  -o test

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

    int temp = (a + b) / 2;
    cout << temp << " " << a - temp << '\n';

    //
    return 0;
}

#include <bits/stdc++.h>
#define N 10005
const int mmax = 1e9;
using namespace std;
int a, b;
void process()
{
    cin >> a >> b;
    int x = (a-b)/2;
    int y = (a+b)/2;
    if (x-y == b) cout << x <<" "<<y;
    else cout << y <<" "<< x;
}
int main()
{
    //freopen("test.INP", "r", stdin);
    process();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void center(vector<pair<int, int>>& points) {
  int n = points.size();
  pair<int, int> center(0, 0);
  for (int i = 0; i < n; ++i) {
    center.first += points[i].first;
    center.second += points[i].second;
    points[i].first *= n;
    points[i].second *= n;
  }
  for (int i = 0; i < n; ++i) {
    points[i].first -= center.first;
    points[i].second -= center.second;
  }
}

int get_zero_ind(const vector<pair<int, int>>& points) {
  int n = points.size();
  for (int i = 0; i < n; ++i) {
    if ((points[i].first == 0) && (points[i].second == 0)) {
      return i;
    }
  }
  return -1;
}

vector<pair<int, int>> remove_point(const vector<pair<int, int>>& points, int ind) {
  vector<pair<int, int>> result;
  for (int i = 0; i < int(points.size()); ++i) {
    if (i != ind) {
      result.push_back(points[i]);
    }
  }
  return result;
}

vector<int> get_order(const vector<pair<int, int>>& points) {
  const pair<int, int> origin(0, 0);
  int n = points.size();
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&points, &origin](int i1, int i2) {
      bool ba = points[i1] < origin;
      bool bb = points[i2] < origin;
      if (ba != bb) {
	return (ba < bb);
      }
      int cross = points[i1].first * points[i2].second - points[i2].first * points[i1].second;
      if (cross == 0) {
	auto point_length = [](const pair<int, int>& p) {
	  return p.first * p.first + p.second * p.second;
	};
	return point_length(points[i1]) < point_length(points[i2]);
      }
      return (cross > 0);
    });
  return order;
}

vector<array<int, 3>> make_features(const vector<pair<int, int>>& points, const vector<int>& order) {
  int n = order.size();
  vector<array<int, 3>> features(n);
  for (int i = 0; i < n; ++i) {
    const pair<int, int>& me = points[order[i]];
    const pair<int, int>& he = points[order[(i+1)%n]];
    features[i][0] = me.first * me.first + me.second * me.second;
    features[i][1] = me.first * he.first + me.second * he.second;
    features[i][2] = me.first * he.second - me.second * he.first;
  }
  return features;
}

bool can(vector<pair<int, int>>& S, vector<pair<int, int>>& T) {
  int n = S.size();
  center(S);
  center(T);
  int zero_S = get_zero_ind(S);
  int zero_T = get_zero_ind(T);
  if ((zero_S >= 0) != (zero_T >= 0)) {
    return false;
  }
  if (zero_S >= 0) {
    remove_point(S, zero_S).swap(S);
    remove_point(T, zero_T).swap(T);
  }
  n = S.size();
  if (n < 2) {
    return true;
  }
  vector<int> order_S = get_order(S);
  vector<int> order_T = get_order(T);
  vector<array<int, 3>> features_S = make_features(S, order_S);
  vector<array<int, 3>> features_T = make_features(T, order_T);
  for (int i = 0; i < n; ++i) {
    bool ok = true;
    for (int j = 0; ok && (j < n); ++j) {
      ok = (features_S[j] == features_T[(j+i)%n]);
    }
    if (ok) {
      return true;
    }
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<pair<int, int>> S(N), T(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i].first >> S[i].second;
  }
  for (int i = 0; i < N; ++i) {
    cin >> T[i].first >> T[i].second;
  }
  cout << (can(S, T) ? "Yes" : "No") << endl;
}

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

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
    int k, ans = 0;
    cin >> k;
    vector<int> c(k), d(k);
    for(int i = 0; i < k; i++) cin >> c[i] >> d[i];

    int k2 = 1 << k;
    for(int i = 0; i < k2; i++) {
        vector<int> dish(n+1);
        for(int j = 0; j < k; j++) {
            if((i>>j) & 1) { //iのj桁目が1なら
                dish[d[j]]++;
            } else {
                dish[c[j]]++;
            }
        }
        int now = 0;
        for(int j = 0; j < m; j++) {
            if(dish[a[j]] == 0) continue;
            if(dish[b[j]] == 0) continue;
            now++;
        }
        ans = max(ans, now);
    }
    cout << ans << endl;
    return 0;
}


#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VP = vector<P>;
#define MOD 1000000007
const int INF = 1e9 + 10;

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

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

template <class T> T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////

int main() {
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    int n,k,m;
    cin >> n >> k >> m;
    VI A(n-1);
    ll tot=0;
    rep(i,n-1){
        cin >> A[i];
        tot += A[i];
    }
    if(tot - (n*m)>=0){
        print(0);
    }else if(tot + k <(n*m)){
        print(-1);
    }else{
        print((n*m)-tot);
    }

    return 0;
}

// Problem : D - Snuke Prime
// Contest : AtCoder - AtCoder Beginner Contest 188
// URL : https://atcoder.jp/contests/abc188/tasks/abc188_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define bug(x) cout<<#x<<"="<<x<<endl;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy

void solve()
{
	ll N,C;cin>>N>>C;
	vl pt;
	map<ll,ll> st,en;
	F0R(x,N)
	{
		ll a,b,c;cin>>a>>b>>c;
		st[a]+=c;
		en[b]+=c;
		pt.pb(a);
		pt.pb(b);//?
	}
	sort(all(pt));
	pt.erase(unique(all(pt)),pt.end());
	ll sum=0,ans=0;
	F0R(x,sz(pt))
	{
		if(x!=0)
		{
			ans+=(pt[x]-pt[x-1]-1)*min(C,sum);
		}
		if(st.count(pt[x]))
			sum+=st[pt[x]];
		ans+=min(C,sum);
		if(en.count(pt[x]))
			sum-=en[pt[x]];
	}
	cout<<ans;
}

int main()
{
	// think two times, so you won't have to code three times
	ios_base::sync_with_stdio(0); cin.tie(0);
	int Test_case=1;
	// cin>>Test_case;
	while(Test_case--!=0)
	{
		solve();
	}
	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


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

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

int main(void)
{
    ll a,b,c;

    cin >> a >> b >>c;

    cout << 7-a+7-b+7-c << endl;

    return 0;
}


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

const ll INF = 1LL << 60;
const int MOD = (int)1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));

    ll ans = 0;
    int l = 0, r = n - 1;
    while (r - l >= 1)
    {
        ans += (a[r] - a[l]) * (n - 1);
        n -= 2;
        r--;
        l++;
    }

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

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#ifdef ENABLE_DEBUG
#include <debug.h>
#else
#define DEBUG(...) do {} while (0)
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using lll = __int128;
using ulll = unsigned __int128;

template<typename T, size_t N> using ar = array<T, N>;

template<typename T, typename Cmp = less<T>>
using iset = tree<T, null_type, Cmp, rb_tree_tag,
		  tree_order_statistics_node_update, allocator<T>>;

#define REPSI(name, start, stop, step) for (ll name = start; name < (ll)stop; name += step)
#define REPS(name, start, stop) REPSI(name, start, stop, 1)
#define REP(name, stop) REPS(name, 0, stop)

#define RREPSI(name, start, stop, step) for (ll name = stop-1; name >= (ll)start; name -= step)
#define RREPS(name, start, stop) RREPSI(name, start, stop, 1)
#define RREP(name, stop) RREPS(name, 0, stop)

#define cin fastIO
#define cout fastIO

struct FastIO {
  static const int IBUF_SZ = 2e8, OBUF_SZ = 2e8;
  char IBUF[IBUF_SZ], OBUF[OBUF_SZ];
  int IBUF_I = 0, OBUF_I = 0;

  FastIO() { fread(IBUF, 1, sizeof(IBUF), stdin); }
  ~FastIO() { OBUF[OBUF_I++] = 0; fputs(OBUF, stdout); }

  FastIO &operator>>(char &c) { c = IBUF[IBUF_I++]; return *this; }
  FastIO &operator<<(char c) { OBUF[OBUF_I++] = c; return *this; }

  template<typename Int> FastIO &operator>>(Int &x) {
    x = 0;
    bool neg=false;
    while (IBUF[IBUF_I] < '0' || IBUF[IBUF_I] > '9')
      if (IBUF[++IBUF_I] == '-') neg=true;
    while (IBUF[IBUF_I] >= '0' && IBUF[IBUF_I] <= '9')
      x = 10*x + IBUF[IBUF_I++]-'0';
    if (neg) x = -x;
    return *this;
  }
  template<typename Int> FastIO &operator<<(Int x) {
    static char BUF[40];
    if (x < 0) OBUF[OBUF_I++] = '-', x = -x;
    int i = 40;
    do { BUF[--i] = x%10 + '0'; } while (x /= 10);
    while (i < 40) OBUF[OBUF_I++] = BUF[i++];
    return *this;
  }

  template<typename T> FastIO &operator>>(vector<T> &vec) {
    REP(i, vec.size()) (*this) >> vec[i];
    return *this;
  }
};
FastIO fastIO;

template<typename T> void cins(T &first) { cin >> first; }
template<typename T, typename... Ts> void cins(T &first, T &second, Ts&... rest) {
  cin >> first;
  cins(second, rest...);
}

#define GET(type, ...) type __VA_ARGS__; cins(__VA_ARGS__)
#define GETI(...) GET(int, __VA_ARGS__)
#define GETLL(...) GET(ll, __VA_ARGS__)
#define GETS(...) GET(string, __VA_ARGS__)
#define GETD(...) GET(double, __VA_ARGS__)
#define GETC(...) GET(char, __VA_ARGS__)

template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (T &v : a) is >> v; return is; }
template<typename T, size_t N> istream &operator>>(istream &is, ar<T, N> &a) {
  REP(i, N) is >> a[i];
  return is;
}

int main() {
  GETLL(n);
  vector<ll> a(n); cin >> a;

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

  ll ans = 0;
  ll cur = 0;

  REP(i, n) cur += a[i]-a[0];
  ans += cur;

  REPS(i, 1, n) {
    ll smaller = i-1;
    ll larger = n-i-1;

    ll diff = a[i]-a[i-1];

    cur += diff*smaller;
    cur -= diff*larger;

    ans += cur;
  }

  cout << ans/2 << '\n';
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;

#define debug(x) cout << #x << " is " << x << endl
#define inc(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;
const int INF = 0x3f3f3f3f, N = 2005;
const int MOD = 1e9 + 7;

int n, m;

ll qpow(ll x, ll y) {
	ll ans = 1;
	for (; y; y >>= 1, x = x * x % MOD)
		if (y & 1) ans = ans * x % MOD;
	return ans;
}

int main()
{
	scanf("%d%d", &n, &m);
	int a = n + m, b = n, x, y;
	for (int i = 1; i <= n; ++i) scanf("%d", &x), b += x;
	if (a < b) { puts("0"); return 0; }
	x = 1, y = 1;
	for (int i = 1; i <= b; ++i) {
		x = (ll)x * (a - i + 1) % MOD;
		y = (ll)y * i % MOD;
	}
	printf("%lld\n", (ll)x * qpow(y, MOD - 2) % MOD);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll MOD = 998244353;

int main(void) {
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n); F(n) cin >> a[i];
    sort(all(a));
    ll ret = 0; ll p = 0;
    F(n) {
        ret += a[i]*a[i];
        ret %= MOD;
        ret += (p*a[i])%MOD;
        ret %= MOD;
        p *= 2; p += a[i]; p %= MOD;
    }
    cout << ret << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20);
    #endif
    int n, L;
    cin >> n >> L;
    vector <int> a(n + 2), b(n + 1);
    a[n + 1] = L + 1;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i)
        cin >> b[i];

    map <int, int> l, r;
    for (int i = 0; i <= n + 1; ++i) {
        if (!l.count(a[i] - i)) {
            l[a[i] - i] = i;
        }
        r[a[i] - i] = i;
    }

    vector <int> link(n + 1);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] == b[i]) {
            link[i] = -1;
        }
        else if (b[i] < a[i]) {
            if (!r.count(b[i] - i)) {
                cout << -1 << endl;
                exit(0);
            }

            link[i] = r[b[i] - i];
        }
        else {
            if (!l.count(b[i] - i)) {
                cout << -1 << endl;
                exit(0);
            }

            link[i] = l[b[i] - i];
        }
    }

    #ifdef HOME
    for (int i = 1; i <= n; ++i) {
        cout << link[i] << ' ';
    }
    cout << endl;
    #endif

    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        if (link[i] != -1 && link[i] > i) {
            if (link[i] < mx) {
                cout << -1 << endl;
                exit(0);
            }
            if (link[i] > mx) {
                ans += link[i] - i;
                mx = link[i];
            }
        }
    }

    #ifdef HOME
    cout << "right ok" << endl;
    debug(ans);
    #endif

    const int INF = 1e18;
    int mn = INF;
    for (int i = n; i; --i) {
        if (link[i] != -1 && link[i] < i) {
            if (link[i] > mn) {
                cout << -1 << endl;
                exit(0);
            }
            if (link[i] < mn) {
                ans += i - link[i];
                mn = link[i];
            }
        }
    }

    cout << ans << endl;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
int n, L, a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N];
ll solve() {
	for (int i = 1;i <= n;++i) {
		c[i] = a[i] - a[i-1] - 1;
		d[i] = b[i] - b[i-1] - 1;
	}
	ll res = 0;
	for (int i = 1, j = 1;i <= n;++i) {
		if (d[i] == 0) continue;
		while (!c[j])
			++j;
		int k = j, sum = 0;
		while (sum < d[i]) {
			assert(k <= n);
			sum += c[k++];
		}
		if (sum != d[i])
			return -1;

		res += max(0, k-i-1) + max(0, i-j);
		j = k;
	}
	return res;
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> L;
	for (int i = 1;i <= n;++i)
		cin >> a[i];
	for (int i = 1;i <= n;++i)
		cin >> b[i];
	a[n+1] = b[n+1] = L+1, ++n;
	cout << solve() << '\n';
}


#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#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) - 1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int 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(){
    int n; cin >> n;
    rep(i,n) cout << i/2+1 << " " << (i+n)/2+1 << "\n";
}

#include <bits/stdc++.h>
#define For(i,l,r) for (register int i=l; i<=r; i++)
using namespace std;
typedef unsigned long long LL;
typedef signed long long ll;
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}

ll n, k;
signed main() {
	read(n); read(k);
	for (register int i=1; i<=k; ++i) {
		if (n % 200 == 0) {
			n /= 200;
		}
		else n = n*1000+200;
	}
	cout << n;
	getchar();
	return 0;
}


//Keep calm and carry on..

/*  Problem :
    URL :
    Memory Limit: 1024 MB
	Time Limit: 2000 ms
	Powered by CP Editor (https://github.com/cpeditor/cpeditor)
*/

#include<bits/stdc++.h>
//#include <boost/math/common_factor.hpp>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

# define fast           ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
# define pi             3.1415926535897932384626
# define mod            1000000007
# define pb             push_back
# define all(v)			v.begin(), v.end()
# define rall(v)		v.rbegin(), v.rend()
# define F              first
# define S              second
# define mk             make_pair
# define loop1(i,a,b)   for(ll i = a; i<b; i++)
# define loop2(i,a,b)   for(ll i = b-1; i>=a; i--)
# define endl          '\n'
# define DEBUG          false
# define sz(x) 			(int)x.size()
# define mem(a, val) 	memset(a, val, sizeof(a))
# define deci(x) 		cout << fixed << setprecision(x);
# define bitcount(x) 	__builtin_popcountll(x)
# pragma GCC optimize "trapv"

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

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

const long double EPS = 1e-12;
const int N = 1e5 + 20;

int countDigit(ll n) {
	return floor(log10(n) + 1);
}
int sumDigits(int no) {
	return no == 0 ? 0 : no % 10 + sumDigits(no / 10) ;
}

//
//
void reverse(int n, int &rev)
{
    // base case
    if (n == 0) {
        return;
    }

    rev = rev * 10 + (n % 10);
    reverse(n / 10, rev);
}

int isPalindrome(int num)
{
    int rev = 0;

    // reverse `num` and store it in `rev`
    reverse(num, rev);

    // if the given number is equal to its reverse,
    // then the number is a palindrome
    return (num == rev);
}
//
//
void soln() {

	//cout << "Case #" << ks << ": " << abs(k - cnt);
}

int main() {

	fast;
	ll n;	cin >> n;
	if (n < 12){ cout << "Yes"; return 0; }
	while (n % 10 == 0){
	    n /= 10;
	}

	if (n < 12) cout << "Yes";
	else if (isPalindrome(n)) cout << "Yes";
	else cout << "No";

	return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
using ll= long long;
int main()
{
    string t;
    cin>>t;
    int count=0;
    int n=t.length();
    int k=stoi(t);
    int flag=1;

    for(int i=0;i<n;i++)
    {
       if(k%10==0)
       {
           count++;
           k=k/10;
       }
       else
       {
           break;
       }
    }
    for(int i=0;i<n-count;i++)
    {
        if(t[i]!=t[n-i-1-count])
        {
            flag=0;
            break;
        }
        else
        {
            flag++;
        }
    }
    if(flag!=0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }

}


#include<iostream>
#include<cstdio>
using namespace std;
const int N=200005;
int n,m,Q;
int a[N],b[N];
struct Segment_Tree
{
	struct Node
	{
		int ls,rs;
		int cnt;
		long long sum;
	}tree[N*20];
	int rt,tot;
	void modifycnt(int &i,int l,int r,int pos,int val)
	{
		if(!i) i=++tot;
		if(l==r)
		{
			tree[i].cnt+=val;
			return;
		}
		int mid=(l+r)/2;
		if(pos<=mid) modifycnt(tree[i].ls,l,mid,pos,val);
		else modifycnt(tree[i].rs,mid+1,r,pos,val);
		tree[i].cnt=tree[tree[i].ls].cnt+tree[tree[i].rs].cnt;
		return;
	}
	void modifysum(int &i,int l,int r,int pos,int val)
	{
		if(!i) i=++tot;
		if(l==r)
		{
			tree[i].sum+=val;
			return;
		}
		int mid=(l+r)/2;
		if(pos<=mid) modifysum(tree[i].ls,l,mid,pos,val);
		else modifysum(tree[i].rs,mid+1,r,pos,val);
		tree[i].sum=tree[tree[i].ls].sum+tree[tree[i].rs].sum;
		return;
	}
	int querycnt(int i,int l,int r,int L,int R)
	{
		if(!i) return 0;
		if(L<=l&&r<=R) return tree[i].cnt;
		int mid=(l+r)/2;
		int res=0;
		if(L<=r) res+=querycnt(tree[i].ls,l,mid,L,R);
		if(R>=l) res+=querycnt(tree[i].rs,mid+1,r,L,R);
		return res;
	}
	long long querysum(int i,int l,int r,int L,int R)
	{
		if(!i) return 0;
		if(L<=l&&r<=R) return tree[i].sum;
		int mid=(l+r)/2;
		long long res=0;
		if(L<=r) res+=querysum(tree[i].ls,l,mid,L,R);
		if(R>=l) res+=querysum(tree[i].rs,mid+1,r,L,R);
		return res;
	}
}TA,TB;
int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	TA.modifycnt(TA.rt,1,1e8,0,n);
	TB.modifycnt(TB.rt,1,1e8,0,m);
	long long ans=0;
	while(Q--)
	{
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t==1)
		{
			TA.modifycnt(TA.rt,1,1e8,a[x],-1);
			TA.modifysum(TA.rt,1,1e8,a[x],-a[x]);
			TA.modifycnt(TA.rt,1,1e8,y,1);
			TA.modifysum(TA.rt,1,1e8,y,y);
			ans-=1LL*TB.querycnt(TB.rt,1,1e8,1,a[x])*a[x]+TB.querysum(TB.rt,1,1e8,a[x]+1,1e8);
			ans+=1LL*TB.querycnt(TB.rt,1,1e8,1,y)*y+TB.querysum(TB.rt,1,1e8,y+1,1e8);
			a[x]=y;
		}
		else if(t==2)
		{
			TB.modifycnt(TB.rt,1,1e8,b[x],-1);
			TB.modifysum(TB.rt,1,1e8,b[x],-b[x]);
			TB.modifycnt(TB.rt,1,1e8,y,1);
			TB.modifysum(TB.rt,1,1e8,y,y);
//			cerr<<"del"<<ans<<" "<<1LL*TA.querycnt(TA.rt,1,1e8,1,b[x])*b[x]-TA.querysum(TA.rt,1,1e8,b[x]+1,1e8)<<" "<<1LL*TA.querycnt(TA.rt,1,1e8,1,y)*y-TA.querysum(TA.rt,1,1e8,y+1,1e8)<<"\n";
			ans-=1LL*TA.querycnt(TA.rt,1,1e8,1,b[x])*b[x]+TA.querysum(TA.rt,1,1e8,b[x]+1,1e8);
			ans+=1LL*TA.querycnt(TA.rt,1,1e8,1,y)*y+TA.querysum(TA.rt,1,1e8,y+1,1e8);
			b[x]=y;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

//#define ACL
#ifdef ACL
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#if __has_include("acl-all.h")
#include "acl-all.h" //on Wandbox
using namespace atcoder;
#endif
#endif //#ifdef ACL

typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;
typedef pair<ll, ll> pll;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)

#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define Ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())

int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll fact_mod(ll n, ll mod) {
    ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

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

ll modncr(ll n, ll r, ll mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    ll a = 1;
    rep(i, r) a = a * ((n-i) % mod) % mod;
    ll b = modpow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

signed main() {
	ll a, b, c;
    cin >> a >> b >> c;

	mes(21-a-b-c);

}


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);

	int N;
	int ans = 0;
	vector<int> A;
	map<int,int> mp;

	cin>>N;

	A.resize(N);

	for(int i = 0; i < N; i++){
		cin>>A[i];
		if(i%2 == 0) A[i] *= -1;
	}

	mp[0] = 1;
	for(int i = 0, sum = 0; i < N; i++){
		sum += A[i];
		ans += mp[sum];
		// cout<<"sum = "<<sum<<" += "<<A[i]<<" "<<mp[sum]<<endl;

		mp[sum]++;
	}

	cout<<ans<<endl;

	return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n + 1);
	map<ll, int> wys;
	ll suma = 0;
	ll res = 0;
	wys[0] = 1;
	rep(i, 0, n) {
		cin >> a[i];
		if ((i&1) == 0) {
			suma += a[i];
		} else {
			suma -= a[i];
		}
		// printf("suma is :%d, adding: %d\n", suma, wys[suma]);
		res += wys[suma];
		++wys[suma];
	}
	cout << res << endl;
}


#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 998244353;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s, t;
  cin>>s>>t;
  if(s[0]=='N')cout<<t<<endl;
  else {
    cout<<char(t[0] - 'a' + 'A')<<endl;
  }
  return 0;
}

#include <bits/stdc++.h>

int main() {
  std::string S, Y;
  std::cin >> S >> Y;
  if (S == "Y") {
    Y[0] = std::toupper(Y[0]);
  }
  std::cout << Y << std::endl;
}


#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(int i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).begin(), (x).end()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX =  100;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error

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

int main(){
    int t;
    cin>>t;
    vl res;
    rep(i,t){
        ll l,r;
        cin>>l>>r;

        ll ans=max((ll)0,(r-2*l+1)*(r-2*l+2)/2);
        if(r-2*l+1<0)ans=0;
        res.push_back(ans);
    }
    for(auto x:res)cout<<x<<endl;
    return 0;
}


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

#define fore(i, l, r) for(int i = int(l); i < int(r); i++) //Python style baby
#define sz(a) int((a).size())
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vpi vector<pair<int, int>>
#define vl vector<long long>
#define vpl vector<pair<long long, long long>>

using namespace std;
using ll = long long;
int mode, t;

const int N = 101;

int total(vpi &queries, vpi &choices, int k, int code) {
  int hits[N] = {};
  fore (i, 0, k) {
    if (code & 1) {
      hits[choices[i].first]++;
    } else {
      hits[choices[i].second]++;
    }
    code /= 2;
  }

  int ans = 0;
  for (auto ab : queries) {
    if (hits[ab.first] > 0 && hits[ab.second] > 0) {
     ans++;
    }
  }
  return ans;
}

void solve() {
  int n, m;
  cin >> n >> m;
  vpi queries;
  int a, b;
  fore (i, 0, m) {
    cin >> a >> b;
    queries.pb(mp(a,b));
  }

  int k;
  cin >> k;
  vpi choices;
  fore (i, 0, k) {
    cin >> a >> b;
    choices.pb(mp(a,b));
  }

  int ans = 0;
  fore (i, 0, 1<<k) {
    ans = max(ans, total(queries, choices, k, i));
  }

  cout << ans << endl;

}

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

  mode = 0;
  if (mode == 0) {
    solve();
  } else {
    cin >> t;
    while (t--) {
      solve();
    }
  }
}

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

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

    string s;
    int n;
    int q;
    cin >> n;
    cin >> s;
    cin >> q;
    int t, a, b;
    int start = 0;
    while(q--){
        cin >> t >> a >> b;
        --a;
        --b;
        if(t == 1){
            if(start){
                a += (start);
                b += (start);
            }
                swap(s[a % (2*n)], s[b % (2*n)]);
        } else {
            start = (start == n) ? 0 : n;
        }
    }

    if(!start){
        cout << s;
        return 0;
    }

    for(int i = start; i < s.size(); ++i){
        cout << s[i];
    }
    for(int i = 0; i < start; ++i){
        cout << s[i];
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
namespace IO{
  inline char ch(){
    static char s[1<<16],*S,*T;
    return (S == T)&&(T = (S = s)+
      fread(s,1,1<<16,stdin),S == T)?EOF:*S++;
  }
  template<typename T> void read(T &x){
    x = 0; int f(1); char c = ch();
    for(;!isdigit(c);c = ch()) if(c == '-') f = -1;
    for(;isdigit(c);c = ch()) x = x*10+c-'0';
    x *= f;
  }
  template<typename T,typename... Args>
  inline void read(T &x,Args&... args){
    read(x); read(args...);
  }
  template<typename T> void write(T x,char f = '\n'){
    if(x < 0) putchar('-'),x = -x;
    if(x > 9) write(x/10,'\0');
    putchar('0'+x%10);
    if(f != '\0') putchar(f);
  }
}
using namespace IO;
const int maxn = 103;
int n; ll A[maxn],X;
ll dp[2][maxn][maxn];
int main(){
#ifdef LZX_CAI
  freopen("test.in","r",stdin);
  freopen("test.out","w",stdout);
#endif
  read(n,X);
  for(int i(1);i <= n;++i) read(A[i]);
  ll Ans = 1e18;
  for(int d(1);d <= n;++d){
    int x = X%d;
    for(int i(0);i <= d;++i)
      for(int j(0);j < d;++j)
        dp[0][i][j] = -1e14;
    dp[0][0][0] = 0;
    for(int i(1);i <= n;++i){
      int nw = (i&1);
      for(int i(0);i <= min(i,d);++i)
        for(int j(0);j < d;++j)
          dp[nw][i][j] = -1e14;
      for(int j(0);j <= min(i,d);++j)
        for(int k(0);k < d;++k){
          int x = A[i]%d;
          if(j > 0) dp[nw][j][k] = max(dp[nw][j][k],dp[nw^1][j-1][(k-x+d)%d]+A[i]);
          dp[nw][j][k] = max(dp[nw][j][k],dp[nw^1][j][k]);
        }
    }
    if(dp[n&1][d][x] > 0){
      ll tm = (X-dp[n&1][d][x])/d;
      Ans = min(Ans,tm);
    }
  }
  cout << Ans << endl;
  return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << '\n'; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

template<ll MOD = 1000000007>
class ModInt {
    ll n;
    ModInt constexpr inverse() const {
        return ModInt::pow(*this, MOD - 2);
    }

public:
    ModInt() : n(0) {}
    ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {}
    ModInt operator+=(const ModInt &m) {
        n += m.n;
        if (n >= MOD) n -= MOD;
        return *this;
    }
    ModInt operator-=(const ModInt &m) {
        n -= m.n;
        if (n < 0) n += MOD;
        return *this;
    }
    ModInt operator*=(const ModInt &m) {
        n *= m.n;
        if (n >= MOD) n %= MOD;
        return *this;
    }
    ModInt operator/=(const ModInt &m) {
        (*this) *= m.inverse();
        return *this;
    }
    friend ModInt operator+(ModInt t, const ModInt &m) {
        return t += m;
    }
    friend ModInt operator-(ModInt t, const ModInt &m) {
        return t -= m;
    }
    friend ModInt operator*(ModInt t, const ModInt &m) {
        return t *= m;
    }
    friend ModInt operator/(ModInt t, const ModInt &m) {
        return t /= m;
    }
    ModInt operator=(const ll l) {
        n = l % MOD;
        if (n < 0) n += MOD;
        return *this;
    }
    friend ostream &operator<<(ostream &out, const ModInt &m) {
        out << m.n;
        return out;
    }
    friend istream &operator>>(istream &in, ModInt &m) {
        ll l;
        in >> l;
        m = l;
        return in;
    }
    static constexpr ModInt pow(const ModInt x, ll p) {
        ModInt<MOD> ans = 1;
        for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) {
            if (p % 2) ans *= m;
        }
        return ans;
    }
};
using mint = ModInt<998244353>;
mint operator"" _m(unsigned long long m) {
    return mint(m);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin, n, m, k;
    mint ans = 0;
    if (n == 1 || m == 1) {
        print(mint::pow(k, m * n));
        return 0;
    }
    rep(i, 0, k) {
        mint a = mint::pow(k - i, m) - mint::pow(k - i - 1, m);
        ans += a * mint::pow(i + 1, n);
        // dump(ans, a);
    }
    print(ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sz(a) a.size()
#define all(v) (v.begin(),v.end());
#define pb push_back
#define int long long
void solve() {
	int n;
	cin >> n;
	vi v(n);
	map<int, int> m;
	rep(i, 0, n) {
		cin >> v[i];
		m[v[i]]++;
	}

	int tot = n * (n - 1) / 2;
	for (auto x : m) {
		int temp = x.second;
		if (temp > 1) {
			tot -= (temp * (temp - 1) / 2);
		}
	}
	cout << tot << endl;
}
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();

}

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

#define sz(v) int (v.size())
#define ff first
#define ss second
#define pb push_back
#define int long long
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MOD = 1000000009;
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());

double GetTime() { return clock() / (double) CLOCKS_PER_SEC; };
/// Actual code starts here
int n;
const int N = 100005;

void solve() {
    cin >> n;
    int res = 0;
    vector<int> v(n);
    for (auto &i : v) cin >> i;
    map<int, int> cnt;
    for (int i = 0; i < n; i++) {
        cnt[v[i]]++;
        res += i - cnt[v[i]] + 1;
    }
    cout << res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int tt = 1;
    //cin >> tt;
    while (tt--)
        solve();
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*

*/
vector<vector<ll>> G(100010);
bool used[100010];
ll C[100010];
ll D[100010];
vector<ll> ans;

void dfs(ll v){
  used[v] = true;
  ll col = C[v];
  if (!D[col]) ans.push_back(v+1);
  D[col]++;
  for(auto nv: G[v]){
    if (used[nv]) continue;
    dfs(nv);
  }
  D[col]--;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  rep(i, N) cin >> C[i];
  rep(i, N-1){
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0);
  sort(all(ans));
  for(auto v: ans)
    cout << v << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int M=1e5+5,P=1e9+7,base=269;
const long double e=1e-10;
inline int rd(){
	int x=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}
int K,n,m,p[M],ans[M];
long double A[M],B[M],C[M];
bool cmp(int x,int y){
	return C[x]>C[y]+e;
}
int main(){
	K=rd(),n=rd(),m=rd();
	int t=m;
	for(int i=1;i<=K;++i){
		A[i]=rd();p[i]=i;
		B[i]=A[i]/n*m;
		int tmp=B[i];
		t-=tmp;
		C[i]=B[i]-tmp;
		ans[i]=tmp;
	}
	sort(p+1,p+K+1,cmp);
	for(int i=1;i<=t;++i){
		ans[p[i]]++;
	}
	for(int i=1;i<=K;++i){
		printf("%d ",ans[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
namespace math{
    const int MOD = 1e9+7;
    const int MN = 10'100;
    int fact[MN], inv_fact[MN];
    int power(int a, int n) {
        int res = 1;
        for (;n; n >>= 1, a = (a * a) % MOD) if (n & 1) res = (res * a) % MOD;
        return res;
    }
    int inv(int a) { return inv_fact[a]*fact[a-1]%MOD; }
    void init_fact() {
        fact[0]=1;
        for (int i=1;i<MN;++i) fact[i] = fact[i-1]*i%MOD;
        inv_fact[MN-1] = power(fact[MN-1], MOD - 2);
        for (int i=MN-1; i>0;--i) inv_fact[i-1]=inv_fact[i]*i%MOD;
    }
    struct mint {
        int n;
        mint(int n): n(n){}
        mint(): n(0){}
        mint operator+(mint o){return (n + o.n) % MOD;}
        mint operator-(mint o){return (n - o.n % MOD + MOD) % MOD;}
        mint operator*(mint o){return (n * o.n) % MOD;}
        mint operator/(mint o){return o.n >= MN ? n * power(o.n, MOD - 2) % MOD : n * inv(o.n) % MOD;}
    };
};
using namespace math;
using mat = vector<vector<mint>>;
int n, m, k;
vector<int> g[100];
mat M;
mat operator*(mat A, mat B)
{
    mat ret(A.size(), vector<mint>(B[0].size()));
    for (int i = 0; i < A.size(); ++i)
    {
        for (int j = 0; j < B[0].size(); ++j)
        {
            for (int k = 0; k < B.size(); ++k)
                ret[i][j] = ret[i][j] + A[i][k] * B[k][j];
        }
    }
    return ret;
}
mat power(mat A, int n)
{
    mat ret(A.size(), vector<mint>(A.size()));
    for (int i = 0;  i < A.size(); ++i)
        ret[i][i] = 1;
    for (; n; A = A * A, n >>= 1)
    {
        if (n & 1) ret = ret * A;
    }
    return ret;
}
signed main()
{
    cin.tie(0)->sync_with_stdio(false);
    cin>>n>>m>>k;
    M.resize(n, vector<mint>(n));

    mat A(1, vector<mint>(n));
    for (int i = 0; i< n;++i)
        cin>>A[0][i].n;

    for (int i = 0; i<m;++i)
    {
        int u, v; cin>>u>>v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    init_fact();

    for (int i = 0; i < n;++i)
    {
        M[i][i] = mint(1) - mint(g[i].size()) / m / 2;
        for (int it: g[i])
        {
            M[it][i] = mint(1) / m / 2;

        }
    }

    mat Ans = A * power(M, k);
    for (int i = 0; i<n;++i)
        cout << Ans[0][i].n << '\n';
    return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

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

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A,mat &B){
  mat C(A.size(),vec(B[0].size()));
  for(int i=0;i<A.size();i++){
    for(int k=0;k<B.size();k++){
      for(int j=0;j<B[0].size();j++){
        C[i][j]=(C[i][j]+(A[i][k]*B[k][j])%MOD)%MOD;
      }
    }
  }
  return C;
}

// C=pow(A,n)
mat pow(mat A,ll n){
  mat B(A.size(),vec(A.size()));
  for(int i=0;i<A.size();i++){
    B[i][i]=1;
  }
  while(n>0){
    if(n&1) B=mul(B,A);
    A=mul(A,A);
    n=(n>>1);
  }
  return B;
}

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

  int N,M,K;
  cin>>N>>M>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  vector<int> X(M),Y(M);
  rep(i,M) cin>>X[i]>>Y[i];

  rep(i,M) X[i]--,Y[i]--;

  vector<vector<int>> g(N);
  rep(i,M){
    g[X[i]].push_back(Y[i]);
    g[Y[i]].push_back(X[i]);
  }

  mat P(N,vec(N,0));
  for(int i=0;i<N;i++){
    int deg=g[i].size();
    ll inv=mod_inverse(M);
    {
      ll coef=M-deg;
      mul(coef,inv);
      add(P[i][i],coef);
    }

    {
      ll coef=deg;
      mul(coef,inv);
      mul(coef,mod_inverse(2));
      add(P[i][i],coef);

      mul(coef,mod_inverse(deg));
      for(auto n:g[i]){
        add(P[i][n],coef);
      }
    }
  }

  mat C=pow(P,K);
  mat B(N,vec(1,0));
  rep(i,N) B[i][0]=A[i];

  B=mul(C,B);

  rep(i,N) cout<<B[i][0]<<"\n";

  return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using P = pair<int,int>;
#define INF 1001001001
#define LINF (1LL<<60)
#define F first
#define S second
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  bool ans = true;
  rep(i, n) {
    if (a[i] != i+1) ans = false;
  }
  if (ans) puts("Yes");
  else puts("No");
}

/**
 * \author KienNguyen246
 * \date 01/06/2021
 */

///😭😢😞☹🙁😐🙂☺😊😁😀😆😂🤣

///----------------🤔🤔🤔 -----------------///

/**< 🤣🤣🤣 */
#include <bits/stdc++.h>

///TLE (in case of emergency)
#define TLE 0
#if TLE
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif // TLE

#define NOT_INTERACTIVE 1

using namespace std;

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

//const int maxn = 5005;
const int maxn = 5e5 + 7;
const int mod =  1e9 + 7;
const int infi = (2e9 + 69);
const ll infy = (2e16 + 69);
const int base = 311;
const ll MM = 7ll * mod * mod;
const int addition = 1e5;
const double eps = 1e-8;
const string numd[10] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const double pi = 3.14159265358980;
const string P1 = "ALICE";
const string P2 = "BOB";
const string spmcode = "My power does not end. Ask for aid and you will receive it.\n";

template <typename Num> void maximize (Num &x, Num y) {x = mx (x, y);}
template <typename Num> void minimize (Num &x, Num y) {x = min (x, y);}
void exit_with_runtime() {double x = 1.0 * clock() / CLOCKS_PER_SEC; cerr << "\n\n---------------------\nTime elapsed: " << x << " s.\n\n"; exit (0);}
void decorate() {cerr << "KienNguyen246\n"; chrono:: system_clock::time_point today = chrono::system_clock::now(); time_t tt = chrono::system_clock::to_time_t (today); cerr << ctime (&tt); cerr << "\nProcessing...\n\n";}

///Multiple tests?
#define MUL_TEST 0

/**< 🤣🤣🤣 */

//bool Palin(string s) {string r = s; reverse(whole(r)); return (r == s);}

/* 🙃🙃🙃 */
int n, a[maxn], cnt[maxn];

//My power does not end. Ask for aid and you will receive it.
void Main_Process()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        cnt[a[i]] ++;
        if (cnt[a[i]] == 2)
        {
            cout << "No";
            return;
        }
    }
    cout << "Yes";

}

/**< 😂😂😂 */
int main()
{
    /**< Main preprocessing begin */
    ios_base::sync_with_stdio (0);

#if NOT_INTERACTIVE
    cin.tie(0); cout.tie(0);
    decorate();

#ifndef ONLINE_JUDGE
    freopen(".inp", "r", stdin);
//    freopen(".out", "w", stdout);
#endif
#endif
    /**< Main preprocessing end */
    /*😍😍😍*/
    int test = 1;

//    Prepare();

#if MUL_TEST
    cin >> test;
#endif

    while (test --)
    {
        Main_Process();
    }
    exit_with_runtime();
}
/**< 😂😂😂 */
///😂😂😂😂😂😂😂😂🌚🔥😂😂😂😂🌚🔥😂😂🔥😂😂😂🔥😂😂😂🔥😂💯💯💯💯💩🐸🔥😂🔥😂🔥💩🔥🔥😂🌚💯🐸💯💩🐸🔥🔥💞🔥💩💩💩💞😂😂😂😂😂😂😂💞💞😂😂😂💞🔥🔥💞💯💩💞💯💞😂😂😂💞💩💩💩💩💩💩💞💩💩💩💩💩💩💩💩💞🔥🔥😂💞🔥😂😂💞


/*
			Saturday 29 May 2021 05:32:07 PM IST
					@uthor::astrainL3gi0N
*/

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

typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<ll> vl;

#define pb push_back
#define mp make_pair
#define debg(x)	std::cerr<<(#x)<<" => "<<x<<'\n';
#define debgg(x,y)	std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n';
#define len(a) (int)(a).size()
#define all(x) x.begin(),x.end()
const int mod = 1000000007;
//const int mod = 998244353;

bool comp (ii x, ii y) {
    if (x.second == y.second)
        return x.first < y.first;
    return x.second < y.second;
}
template < typename T> void  printv (T &a) {
    cout<<'\n';
    for (auto it = a.begin(); it != a.end(); ++it)
        cout<<it->first<<' '<<it->second<<'\n';
}
int gint() {
    int n;  cin>>n;
    return n;
}
//int t[510][510];
ll ans;

void solve () {
    map <ii,int> hmp;
    int n = gint();
    vii vpr;
    vii arr;
    for (int i = 0; i < n;++i) {
        int x = gint();
        int y = gint();
        vpr.pb(mp(x,y));
        hmp[mp(x,y)] = i+1;
    }
    for (auto v:vpr) {
        arr.pb(mp(v.first,v.second));
    }
    vi vr;
    set <int> hsh;

    sort(all(vpr));
    hsh.insert(hmp[vpr[0]]);
    hsh.insert(hmp[vpr[1]]);
    hsh.insert(hmp[vpr[n-1]]);
    hsh.insert(hmp[vpr[n-2]]);
    for (auto &v: vpr) {
        swap(v.first,v.second);
    }
    sort(all(vpr));

    hsh.insert(hmp[mp(vpr[0].second,vpr[0].first)]);
    hsh.insert(hmp[mp(vpr[1].second,vpr[1].first)]);
    hsh.insert(hmp[mp(vpr[n-1].second,vpr[n-1].first)]);
    hsh.insert(hmp[mp(vpr[n-2].second,vpr[n-2].first)]);
    for (auto &v: vpr) {
        swap(v.first,v.second);
    }
    vii vrr;
    for (auto v: arr) {
        if (hsh.count(hmp[v]))
        vrr.pb(v);
    }

    for (int i = 0; i < len(vrr); ++i) {
        for (int j = i+1; j < len(vrr); ++j) {
            vr.pb(max(abs(vrr[i].first-vrr[j].first),
                    abs(vrr[i].second-vrr[j].second)));
        }
    }
    sort(all(vr));
    cout<<vr[len(vr)-2];

}
void sol () {
    //test
    //cout << setprecision(15) << fixed;
}

int main () {
    int testcases = 1;
    for (int t = 0; t < testcases; ++t) {
        solve();
    }

    return 0;
}

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

using ll = long long;
#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++)

template <typename T>
vector<vector<T> > binomial_table(int N) {
  vector<vector<T> > mat(N + 1, vector<T>(N + 1));
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      if (j == 0 || j == i)
        mat[i][j] = 1;
      else
        mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}

int main() {
  auto c = binomial_table<ll>(61);
  ll a, b;
  cin >> a >> b;
  ll k;
  cin >> k;
  string ans;
  ll n = a + b;
  rep(i, 0, n) {
    if (a > 0 && c[a + b - 1][b] >= k) {
      ans += 'a';
      a--;
    } else {
      k -= c[a + b - 1][b];
      ans += 'b';
      b--;
    }
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int MOD = 998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

int modpow(int x, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) {  // nが奇数のとき
            res *= x;
            res %= mod;
        }
        x *= x;
        x %= mod;
        n >>= 1;
    }
    return res;
}

signed main() {
    int N, M, K;
    cin >> N >> M >> K;
    if(N==1 && M==1){
        cout << K << endl;
        return 0;
    }
    if(N==1){
        cout << modpow(K,M,MOD) << endl;
        return 0;
    }
    if(M==1){
        cout << modpow(K,N,MOD) << endl;
        return 0;
    }
    int ans = 0;
    int mi[K+2]{}, ma[K+2]{};
    int mis[K+2]{}, mas[K+2]{};
    for(int i=1;i<=K;i++){
        int miZ = modpow(i,N,MOD);
        mi[i] = (miZ + MOD - mi[i-1]) % MOD;
    }
    for(int i=K;i>=1;i--){
        int maZ = modpow((K-i+1), M, MOD);
        ma[i] = (maZ + MOD - ma[i+1]) % MOD;
    }
    for(int i=1;i<=K;i++){
        ans += (modpow(i,N,MOD) - modpow(i-1,N,MOD) + MOD) * modpow((K-i+1), M, MOD);
        ans %= MOD;
    }
    cout << ans << endl;
    /*
    for(auto c : mi) cout << c << " ";
    for(auto c : ma) cout << c << " ";
    */
}

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

#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define pb push_back
#define ppb pop_back
#define ff first
#define ss second
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define fillc(a,b) memset(a,b,sizeof(a))
#define MOD 1000000007
#define INF 1e17
void check(ll a,ll b,ll c)
{
	double la,lb;
	if(a==0)
		la=-INF;
	else
		la=c*log(a);
	if(b==0)
		lb=-INF;
	else
		lb=c*log(b);
	//cout<<setprecision(10)<<la<<" "<<lb<<endl;
	if(la<lb)
		cout<<"<"<<endl;
	else if(la>lb)
		cout<<">"<<endl;
	else
		cout<<"="<<endl;
}

void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b)
	{
		cout<<"="<<endl;
		return;
	}
	if(c%2)
	{
		if(a<0 && b>=0)
		{
			cout<<"<"<<endl;
			return;
		}
		else if(a>=0 && b<0)
		{
			cout<<">"<<endl;
			return;
		}
		else if(a<0 && b<0)
		{
			check(abs(b),abs(a),c);
			return;
		}
	}
	a=abs(a);
	b=abs(b);
	check(a,b,c);
}

int main()
{
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
        solve();
}


#include <ctime>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define inf 100010
#define INF 0x7fffffff
#define ll long long

template <class I>
inline void read(I &num){
    num = 0; char c = getchar(), up = c;
    while(!isdigit(c)) up = c, c = getchar();
    while(isdigit(c)) num = (num << 1) + (num << 3) + (c ^ '0'), c = getchar();
    up == '-' ? num = -num : 0; return;
}
template <class I>
inline void read(I &a, I &b) {read(a); read(b);}
template <class I>
inline void read(I &a, I &b, I &c) {read(a); read(b); read(c);}

int n, x;

signed main(){
    read(n, x);
    double cnt = 0;
    for(int i = 1; i <= n; i++) {
        int a, b; read(a, b);
        cnt += a * (b / 100.0);
        if(cnt - x > 1e-8) {
            printf("%d\n", i);
            return 0;
        }
    }
    puts("-1");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n, x;
  cin>>n>>x;
  x *= 100;

  int res = 0;
  int count = 1;
  int ans = -1;
  bool ok = false;
  while(n--){
    int a, b;
    cin>>a>>b;
    res += a * b;
    if(res > x and !ok)ok = true, ans = count;
    count++;
  }
  cout<<ans<<endl;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    if (a == b) {
        for (int i=0; i<a; i++) {
            int e_i = i+1;
            cout << e_i << " " << -1*e_i ;
            if (i != a-1) cout << " ";

        }
    } else {
        int s = a > b ? 1 : -1;

        int sum = 0;
        for (int i=0; i<max(a,b); i++) {
            cout << s*(i+1) << " ";
            sum = sum + i+1;
        }
        int n = min(a,b);
        // cout << sum << endl;
        int k = sum/n;
        int w = n/2;
        int r = sum%n;
        // cout << k << " "<< w <<" "<< r << endl;
        for (int i=k+w; i>=k-w; i--) {
            // cout << i << endl;
            if (n%2==0 && i == k) continue;
            int e_i = i;
            if (r>0) {
                e_i++;
                r--;
            }
            e_i = -1 * s * e_i;
            cout << e_i;
            if (i != k-w)
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int a, b, suma = 0;
    cin >> a >> b;
    for (int i = 0; i < a; i++)
    {
        cout << 1000000 - i << " ";
        suma += 1000000 - i;
    }
    for (int i = 1; i < b; i++)
    {
        cout << -i << " ";
        suma -= i;
    }
    cout << -suma << endl;
}