#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;

const int N = 2e5 + 10;

int n, ans[N], timer;
bool diametr[N];
vector <int> g[N];

pair<int, int> dfs1(int u, int p) {
  pair<int, int> tmp = {0, u}, cur;
  for (int to : g[u]) {
    if (to == p) continue;
    cur = dfs1(to, u);
    tmp = max(tmp, {cur.fi + 1, cur.se});
  }
  return tmp;
}

bool dfs2(int u, int p, int x) {
  diametr[u] = true;
  if (u == x) return true;
  for (int to : g[u]) {
    if (to == p) continue;
    if (dfs2(to, u, x))
      return true;
  }
  return false;
  diametr[u] = false;
}

void dfs3(int u, int p) {
  ans[u] = ++timer;
  for (int to : g[u])
    if (to != p && !diametr[to]) dfs3(to, u);
  for (int to : g[u])
    if (to != p && diametr[to]) dfs3(to, u);
  timer++;
}

main(){
  //freopen("input.txt", "r", stdin);
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].pb(v);
    g[v].pb(u);
  }
  int t1, t2;
  pair<int, int> tmp;
  tmp = dfs1(1, -1); t1 = tmp.se;
  tmp = dfs1(t1, -1); t2 = tmp.se;
  dfs2(t1, -1, t2);
  dfs3(t1, -1);
  for (int i = 1; i <= n; i++)
    printf("%d ", ans[i]);
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n + 1, 1);
  FOR(i, 1, n + 1) for (int j = i * 2; j <= n; j += i) chmax(a[j], a[i] + 1);
  // FOR(i, 1, n + 1) FOR(j, i + 1, n + 1) {
  //   if (j % i == 0) assert(a[i] != a[j]);
  // }
  FOR(i, 1, n + 1) cout << a[i] << " \n"[i == n];
  return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define PB push_back
#define fi first
#define se second
#define MP make_pair
const int P = 1000000007;
const int V = 70;
char s[V];
int a[V];
LL K;

bool check(LL mid, int n) {
    LL v = 0;
    for (int i = 0; i < n; ++i) {
        if (v > K / mid || v * mid > K) return false;
        v = v * mid + a[i];
    }
    return v <= K;
}

int main() {
    while (~scanf("%s%lld", s, &K)) {
        int n = strlen(s);
        for (int i = 0; i < n; ++i) a[i] = s[i] - '0';
        int D = 0;
        for (int i = 0; i < n; ++i) D = max(D, a[i]);
        if (n == 1) {
            if (a[0] <= K) puts("1");
            else puts("0");
            continue;
        }
        if (D > K) {
            puts("0");
            continue;
        }
        LL lo = 1, up = K;
        while (lo != up) {
            LL mid = (lo + up + 1) / 2;
            //printf("%lld %lld %lld\n", lo, up, mid);
            if (check(mid, n)) lo = mid;
            else up = mid - 1;
        }
        printf("%lld\n", max(0LL, up - D));
    }
    return 0;
}

/*
22 10
999 1500
100000000000000000000000000000000000000000000000000000000000 1000000000000000000
*/

#include<bits/stdc++.h>
using namespace std;
namespace Sakurajima_Mai{
    #define ms(a) memset(a,0,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=2e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
    inline int qi(){
        int f=0,fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline ll ql(){
        ll f=0;int fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline db qd(){
        char c=getchar();int flag=1;double ans=0;
        while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
        if(c=='-') flag=-1,c=getchar();
        while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
        if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
        return ans*flag;
    }
}
namespace Read{
    #define si(a) scanf("%d",&a)
    #define sl(a) scanf("%lld",&a)
    #define sd(a) scanf("%lf",&a)
    #define ss(a) scanf("%s",a)
    #define rai(x,a,b) repi(i,a,b) x[i]=qi()
    #define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
    #define pi(x) printf("%d",x)
    #define pl(x) printf("%lld",x)
    #define ps(x) printf("%s",x)
    #define pc(x) printf("%c",x)
    #define pe() puts("")
}
namespace DeBug{
    #define MARK false
    #define DB if(MARK)
    #define pr(x) cout<<#x<<": "<<x<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
namespace INT128{
    inline void print(__int128 x)
    {
        if(!x) return;
        if(x<0) putchar('-'),x=-x;
        print(x/10),putchar(x%10+'0');
    }
    inline void read(__int128 &X)
    {
        int w=0; char ch=0; X=0;
        while(!isdigit(ch)) w|=ch=='-',ch=getchar();
        while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
        if(w) X=-X;
    }
}
using namespace INT128;
const int MAX_N=1e5+5;
char s[MAX_N];
int x[MAX_N],len;
__int128 m;
bool check(ll base)
{
    __int128 now=1,res=0;
    repd(i,len,1){
        if(res>m-now*x[i]) return false;
        res+=now*x[i];
        if(i!=1&&now>m/base) return false;
        now*=base;
        if(i!=1&&now>m) return false;
    }
    return true;
}
int main()
{
    ss(s+1); read(m);
    len=strlen(s+1);
    int mx=0;
    repi(i,1,len) x[i]=(s[i]-'0'),gmx(mx,x[i]);
    if(!check(1ll*mx+1)) return puts("0"),0;
    if(len==1) return puts("1"),0;
    ll l=mx+1,r=1000000000000000000,ans;
    while(l<=r){
        ll mid=(l+r)>>1;
        if(check(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    pl(ans-(mx+1)+1),pe();
    return 0;
}


/*

  AUTHOR:    nit1n
  CREATED:   23.01.2021 22:00:57

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

const int N = 65 ;
vector<string> a(N) ;
int dp[N][2][2] ,n ;

int solve(int idx , bool flag){

	if(idx > n){
		return ((flag)?1 : 0) ;
	}
	if(dp[idx][flag][0] != -1 && dp[idx][flag][1] != -1){
		return dp[idx][flag][0]  + dp[idx][flag][1]  ;
	}

	if(a[idx] == "AND"){
		dp[idx][flag][0] = solve(idx +1 , flag&0) ;
		dp[idx][flag][1] = solve(idx +1 , flag&1) ;
	}else{
		dp[idx][flag][0] = solve(idx +1 , flag|0) ;
		dp[idx][flag][1] = solve(idx +1 , flag|1) ;
	}
	return dp[idx][flag][1] + dp[idx][flag][0] ;
}

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

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

	memset(dp , -1 , sizeof(dp)) ;
	int ans = solve(1 , true) + solve(1 ,false ) ;
	cout << ans ;

}

#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 1e5 + 5;

int n;
int a[maxn], b[maxn];

void read_input()
{
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int i = 1; i <= n; ++i)
        cin >> b[i];
}

void solve()
{
    lli ans = 0;
    multiset<int> odd, even;
    for(int i = 1; i <= n; ++i)
    {
        ans += b[i];
        if(i & 1) odd.insert(b[i] - a[i]);
        else even.insert(b[i] - a[i]);
    }
    int remain = n / 2;
    while(remain)
    {
        int val_odd = *odd.begin(); odd.erase(odd.begin());
        int val_even = *even.begin(); even.erase(even.begin());
        --remain;
        if(val_odd + val_even < 0)
            ans -= val_odd + val_even;
        else break;
    }
    cout << ans << '\n';
}

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


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
vector<int>v[200005];
int sm[200005];
int c[200005];
signed main()
{
	int n,m;
	cin>>n>>m;
	rep(i,n) cin>>c[i],sm[i]=1000000000000000;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		v[b-1].pb(a-1);
	}
	int ans=-1000000000000000;
	rep(i,n){
		rep(j,sz(v[i])){
			sm[i]=min(sm[i],sm[v[i][j]]);
			sm[i]=min(sm[i],c[v[i][j]]);
		}
	//	cout<<sm[i]<<' ';
		ans=max(ans,c[i]-sm[i]);
	}
	cout<<ans;
	re 0;
}


#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <iostream>
#include <iomanip>

constexpr int HeighestDim = 505000;

int n, m, k;
long long int res[101];
int dim_a = 0, dim_b = 0;
int A[HeighestDim + 1], B[HeighestDim];

void mult_a(int v){
    for(int i = dim_a, j = i - v; j >= 0; --i, --j){ A[i] -= A[j]; if(A[i] < 0) A[i] += m; }
}
void div_a(int v){
    for(int i = v, j = 0; i <= dim_a; ++i, ++j){
        A[i] += A[j]; if(A[i] >= m) A[i] -= m;
    }
}

void mult_b(int v){
    dim_b += v;
    for(int i = dim_b, j = i - v; j >= 0; --i, --j){
        B[i] -= B[j]; if(B[i] < 0) B[i] += m;
    }
}
void div_b(int v){
    for(int i = v, j = 0; i <= dim_b; ++i, ++j){
        B[i] += B[j]; if(B[i] >= m) B[i] -= m;
    }
}

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);
    A[0] = 1; B[0] = 1;
    std::cin >> n >> k >> m; ++k;
    for(int i = 1, j = k; i < n; ++i, j += k){ dim_a += j; mult_a(j); div_a(i); }
    for(int i = 0, j = n, I = k, J = k * (n - 1); ; I += k, J -= k){
        long long int res_v = 0;
        for(int d = 0; d <= dim_b; ++d) res_v += static_cast<long long int>(A[d]) * B[d] % m;
        if(res_v) res_v = (k * res_v - 1) % m; else res_v = m - 1;
        res[i++] = res_v; res[--j] = res_v;
        if(i > j) break;
        mult_a(j); div_a(J);
        mult_b(I); div_b(i);
    }

    for(int i = 0; i < n; ++i) std::cout << res[i] << '\n';
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vi a(n + 1);
    rep(i, 0, n + 1) cin >> a[i];
    int ans = INT_MAX;
    rep(i, 0, n) ans = min(ans, abs(a[i] - a[i + 1]));
    vector<vi> b(n + 1, vi(ans, 0));
    int k = 0;
    rep(i, 0, n + 1) {
        rep(j, 0, ans) b[i][j] = a[i] / ans;
        int dif = a[i] - (a[i] / ans) * ans;
        if(i % 2 == 0) {
            rep(j, 0, dif) {
                b[i][k]++;
                k = (k + 1) % ans;
            }
        }else {
            rep(j, 0, dif) {
                k = (k + ans - 1) % ans;
                b[i][k]++;
            }
        }
    }

    cout << ans << '\n';
    rep(j, 0, ans) {
        rep(i, 0, n + 1) {
            cout << b[i][j] << ' ';
        }
        cout << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define mod 1000000007
#define rep(i,be,en) for(int i=be;i<=en;i++)
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
//const double pi=acos(-1);
using namespace std;
const int N=2e5+7;
const int M=1e6+7;

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

inline ll readl(){
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}

int T,n,m,fl;
string s;
int p;//模数
int ksm(int a,int k){
    int res=1;
    a%=p;
    while(k){
        if(k&1)  res=1ll*res*a%p;
        k>>=1;
        a=1ll*a*a%p;
    }
    return res;
}
int C(int a,int b){
    if(a<b) return 0;
    int up=1,down=1;
    for(int i=a,j=1;j<=b;i--,j++){
        up=1ll*up*i%p;
        down=1ll*down*j%p;
    }
    return 1ll*up*ksm(down,p-2)%p;
}
int Lucas(ll a,ll b){
    if(a<p&&b<p) return C(a,b);
    else return 1ll*C(a%p,b%p)*Lucas(a/p,b/p)%p;
}
map<char,int> mp;
signed main(){
	n=read();
	cin>>s;
	p=3;
	mp['B']=0;mp['W']=1;mp['R']=2;
	int ans=0;
	rep(i,0,n-1){
		ans=(ans+Lucas(n-1,i)*mp[s[i]])%3;
	}
	if(n%2==0) ans=(3-ans)%3;
	if(ans==0) puts("B");
	else if(ans==1) puts("W");
	else puts("R");
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using ll = long long;

int main() {
  int n;
  cin >> n;
  cout << (n % 2 == 0 ? "White" : "Black") << endl;
  return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll s, p;
    cin >> s >> p;
    for(ll i = 1; i * i <= p; i++){
        if(p % i == 0 && i + p / i == s){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

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

    cout << n / w << endl;
    return 0;
}


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

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

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

	int N;
	cin >> N;

	ll kotae = 0;
	int A[100000];
	rep(i, N) {
		cin >> A[i];
		kotae += A[i];
	}
	priority_queue<int> p, q;
	rep(i, N) {
		int b;
		cin >> b;

		if (i & 1) p.push(b - A[i]);
		else q.push(b - A[i]);
	}

	while (p.size()) {
		int a = p.top();
		int b = q.top();
		if (a + b <= 0) break;
		kotae += a + b;
		p.pop();
		q.pop();
	}

	co(kotae);

	Would you please return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
using ll=long long;
using P = pair<int,int>;
int main(){
    int N;
    cin >> N;
    int vec[N];
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }
    int x,X;
    while(1){
        sort(vec,vec+N);
        x=vec[0],X=vec[N-1];
        if(vec[0]==vec[N-1]){
            cout << vec[0] << endl;
            break;
        }
        for(int i=0;i<N;i++){
            if(vec[i]%x==0)vec[i]=x;
            else vec[i]=vec[i]%x;
        }
    }
}


#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

double r, x, y;
double p;

inline bool check()
{
	double c = p / r;
	if(int(c) * r == p) return 0;
	return 1;
}

int main()
{
	scanf("%lf%lf%lf", &r, &x, &y);
	p = 1.0 * sqrt(x * x + y * y);
	if (check()) printf("%d\n", int((p - r) / r) + 2);
	else printf("%d\n",int(p / r));
	return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int R; cin>>R;
    int X, Y; cin>>X>>Y;

    int dist2 = X*X + Y*Y;
    if(dist2==R*R){
        cout<<1<<endl;
    }else if(dist2<R*R){
        cout<<2<<endl;
    }else{
        // int N2 = dist2/(R*R);
        for(int i=2;i<=1000000;i++){
            if(i*i*R*R>=dist2){
                cout<<i<<endl;
                return 0;
            }
        }

    }

    return 0;

}


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

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args)
{cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

void solve(){
  int n,k; cin >> n >> k;
  int cnt=0;
  for(int i=2;i<=2*n;i++){
    int num=k+i;
    if(num>2*n||num<=1)continue;
    if(num%2==0&&i%2){
      int m=min(num,n);
      int combs=(m-(m==num?1:0)-(num)/2)*2+1;
      int m2=min(n,i);
      int combs2=(m2-(m2==i?1:0)-(i-1)/2)*2;
      cnt+=combs*combs2;
    }
    else if(num%2==0&&i%2==0){
      int m=min(num,n);
      int combs=(m-(m==num?1:0)-(num)/2)*2+1;
      int m2=min(n,i);
      int combs2=(m2-(m2==i?1:0)-i/2)*2+1;
      cnt+=combs*combs2;
    }
    else if(num%2&&i%2){
      int m=min(num,n);
      int combs=(m+(m==num?-1:0)-(num-1)/2)*2;
      int m2=min(n,i);
      int combs2=(m2-(m2==i?1:0)-(i-1)/2)*2;
      cnt+=combs*combs2;
    }
    else if(num%2&&i%2==0){
      int m=min(num,n);
      int combs=(m+(m==num?-1:0)-(num-1)/2)*2;
      int m2=min(n,i);
      int combs2=(m2+(m2==i?-1:0)-i/2)*2+1;
      cnt+=combs*combs2;
    }
  }
  cout << cnt << endl;
}

int32_t main(){
  ios_base:: sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  for(int tt=1;tt<=t;tt++){
    solve();
  }
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
const ll SZ = 3100, INF = 1e9;

template<int MOD>
struct Mint {
	int val;

	Mint() : val(0) {}
	Mint(int x) : val(x) {}
	Mint(long long x) : val((x % MOD + MOD) % MOD) {}

	Mint<MOD> operator + (Mint<MOD> a) const {
		int x = val + a.val;
		return Mint<MOD>(x - MOD * (x >= MOD));
	}

	Mint<MOD> operator - (Mint<MOD> a) const {
		int x = val - a.val;
		return Mint<MOD>(x + MOD * (x < 0));
	}

	Mint<MOD> operator * (Mint<MOD> a) const {
		return Mint<MOD>((long long)val * a.val % MOD);
	}

	static Mint<MOD> power(Mint<MOD> a, long long b) {
		if (b == 0) return Mint<MOD>(1);
		if (b % 2) return a * power(a, b - 1);
		return power(a * a, b / 2);
	}

	Mint<MOD> rev() const {
		return power(*this, MOD - 2);
	}

	Mint<MOD> operator / (Mint<MOD> a) const {
		return Mint<MOD>((long long)val * a.rev().val % MOD);
	}

	Mint<MOD>& operator += (Mint<MOD> a) {
		return *this = *this + a;
	}

	Mint<MOD>& operator -= (Mint<MOD> a) {
		return *this = *this - a;
	}

	Mint<MOD>& operator *= (Mint<MOD> a) {
		return *this = *this * a;
	}

	Mint<MOD>& operator /= (Mint<MOD> a) {
		return *this = *this / a;
	}

	Mint<MOD>& operator = (long long x) {
		return *this = Mint<MOD>(x);
	}

	friend istream& operator >> (istream &in, Mint<MOD> &x) {
		long long val;
		in >> val;
		x = Mint<MOD>(val);
		return in;
	}

	friend ostream& operator << (ostream &out, Mint<MOD> x) {
		return out << x.val;
	}
};

constexpr int MOD = 998244353;
using mint = Mint<MOD>;

ll n, k;

mint dp[SZ + 3][SZ + 3], ones[SZ + 3][2];

int main() {
	fastInp;

	cin >> n >> k;

	dp[0][0] = 1;

	for (int i = 0; i <= SZ; i++) {
		for (int j = SZ; j >= 0; j--) {
			if (i > 0 && j > 0) dp[i][j] += dp[i - 1][j - 1];
			if (j != 0 && 2 * j < SZ) dp[i][j] += dp[i][2 * j];
		}
	}

	cout << dp[n][k];

	return 0;
}


#include "bits/stdc++.h"
#include <iomanip>

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++)
#define REP(i,n) for(int i = 0;i < (n) ; i++)
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
const int MOD = 1000000007;
/*----------------------------------------------------------------*/
bool dp[200100][10] = {};
/*----------------------------------------------------------------*/
signed main(){

	int n;
	string s,x;
	cin >> n >> s >> x;

	dp[n][0] = 1;
	for(int i = n-1;i >= 0;i--){
		int cnt = 0;
		rep(j,10){
			bool a = dp[i+1][10*j%7];
			bool b = dp[i+1][(10*j+(s[i]-'0'))%7];
			if(x[i] == 'T' && (a||b)){
				dp[i][j] = true;
				cnt++;
			}
			if(x[i] == 'A' && (a&&b)){
				dp[i][j] = true;
				cnt++;
			}
		}
		if(cnt == 0){
			cout << "Aoki" << endl;
			return 0;
		}
	}
	if(dp[0][0])cout << "Takahashi" << endl;
	else cout << "Aoki" << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://atcoder.jp/contests/agc048/tasks/agc048_a
// rm -r -f test;oj d https://atcoder.jp/contests/abc195/tasks/abc195_a

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

vector<map<int,int>> mp(MAX);

class Union_Find{
  vector<int> par; vector<int> rank; vector<int> num;
public:
  Union_Find(int n) {
    par = vector<int>(n); rank = vector<int>(n,0); num = vector<int>(n,1);
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if(par[x] == x) return x;
    else  return par[x] = find(par[x]);
  }
  int number(int x) {
    return num[find(x)];
  }
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    if (rank[x] == rank[y]) rank[x]++;
    par[y] = x;
    num[x] += num[y];
    for(auto s : mp[y]) mp[x][s.first] += s.second;
    mp[y].clear();
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main(){
  int n, q;
  cin >> n >> q;
  int c[n];
  rep(i,n) {
    cin >> c[i];
    c[i]--;
    mp[i][c[i]]++;
  }
  Union_Find uf(n);
  vector<int> ans;
  rep(i,q) {
    int t, x, y;
    cin >> t >> x >> y;
    x--; y--;
    if(t == 1) uf.unite(x,y);
    else ans.push_back(mp[uf.find(x)][y]);
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


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

using P = pair<int,int>;
using Edge = struct { int to; int cost; };
const int INF = 1e9;

vector<int> a,b,c;
int n,m;

// s: スタート位置, g: 隣接リストグラフ
vector<int> dijkstra(int s, vector<vector<Edge>> g) {
  vector<int> dist(g.size(), INF);
  dist[s] = 0;

  priority_queue<P, vector<P>, greater<P>> q;
  q.emplace(0, s); // [現在位置のコスト, 位置位置]

  while (!q.empty()) {
    P p = q.top(); q.pop();
    auto d = p.first, v = p.second;
    if (dist[v] < d) continue;

    for (Edge e: g[v]) {
      if (dist[v]+e.cost < dist[e.to]) {
        dist[e.to] = dist[v] + e.cost;
        q.emplace(dist[e.to], e.to);
      }
    }
  }

  return dist;
}

void solve() {
  vector<vector<Edge>> g(n);
  REP(i,m) {
    Edge e = { b[i], c[i] };
    g[a[i]].emplace_back(e);
  }

  REP(i,n) {
    vector<int> d = dijkstra(i, g);

    int ans = INF;
    REP(j,n) {
      for(Edge e: g[j]) {
        if (e.to == i) ans = min(ans, d[j]+e.cost);
      }
    }

    cout << (ans == INF ? -1 : ans) << endl;
  }
}

int main() {
  cin >> n >> m;
  a.resize(m); b.resize(m); c.resize(m);
  REP(i,m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
  }

  solve();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF          = numeric_limits<long long>::max();
const long long DP_INF       = 1 << 29;
template <class T> using arr = vector<vector<T>>;
using vint                   = vector<int>;
using vll                    = vector<ll>;
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#define STRACE(var) cout << #var << "=" << var << endl;
#define SMAPTRACE(var)  \
    cout << #var << "=" \
         << "{" << var.first << "," << var.second << "}" << endl;
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#define STRACE(var) \
    {}
#define SMAPTRACE(var) \
    {}
#endif
template <class T> void dump(const vector<T>& vec) {
#ifdef SOURCE_TEST
    for (ll i = 0; i < vec.size(); ++i) {
        cout << vec[i] << ",";
    }
    cout << endl;
#endif
}
struct Item {
    ll to;
    ll minutes;

    friend ostream& operator<<(ostream& os, const Item& pos) {
#ifdef SOURCE_TEST
        os << "{" << pos.to << "," << pos.minutes << "}";
#endif
        return os;
    }
};

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

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

    vector<vector<Item>> routes(N);

    for (ll i = 0; i < M; ++i) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        routes[a].push_back(Item{b, c});
    }

    for (const auto& v : routes) {
        dump(v);
    }

    for (ll n = 0; n < N; ++n) {
        priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
        vll dist(N, INF);
        dist[n] = 0;
        que.push({dist[n], n});
        ll ans = INF;
        while (!que.empty()) {
            ll index = que.top().second;
            ll d     = que.top().first;
            que.pop();

            if (d > dist[index]) continue;
            STRACE(index);

            for (const auto& route : routes[index]) {
                if (chmin(dist[route.to], dist[index] + route.minutes)) {
                    que.push({dist[route.to], route.to});
                }
                if (route.to == n) {
                    chmin(ans, dist[index] + route.minutes);
                }
            }
            STRACE(ans);
            dump(dist);
        }

        if (ans == INF) {
            PR(-1);
        } else {
            PR(ans);
        }
    }

    return 0;
}


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

ll n,x,man=0,che=0;
double eu=0;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x;
    man+=abs(x);
    eu+=abs(x*x);
    che=max(che,abs(x));
  }
  eu=sqrt(eu);
  printf("%ld",man);
  cout<<endl;
  printf("%.15lf",eu);
  cout<<endl;
  printf("%ld",che);
}

#include<bits/stdc++.h>
#define ll long long int
const ll MOD = 1e9+7;
const ll inf = 1e18+5;
using namespace std;
#define debug() for(ll l=0;l<50;l++){}
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
ll bs(ll arr[], ll l, ll r, ll x){
	ll mid=0;
    if (r >= l){
		if (arr[mid] == x) return mid;
        if (arr[mid] > x) return bs(arr, l, mid - 1, x);
        return bs(arr, mid + 1, r, x);
    }
    return -1;
}
ll power(ll x,ll y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}
const int max1=500001;
pair<int,int>st[4*max1];
int arr[max1],arr1[max1];
void buildtree(int si,int ss,int se){
	if(ss==se){
        st[si].first=arr1[ss];
        st[si].second=arr1[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	buildtree(2*si,ss,mid);
	buildtree(2*si+1,mid+1,se);
	if(arr1[mid]>arr1[mid+1]) st[si].first=st[2*si].first+st[2*si+1].first;
    else st[si].second=st[2*si].second+st[2*si+1].second;

}
int query(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return inf;
	if(ss>=qs && se<=qe)
		return st[si].first;
	int mid=ss+(se-ss)/2;
	int l=query(2*si,ss,mid,qs,qe);
	int r=query(2*si+1,mid+1,se,qs,qe);
	return min(l,r);
}
int geteven(int si,int ss,int se,int qs,int qe){
	if(ss>qe || se<qs) //completely outside
		return 0;
	if(ss>=qs && se<=qe)
		return st[si].second;
	int mid=ss+(se-ss)/2;
	int l=geteven(2*si,ss,mid,qs,qe);
	int r=geteven(2*si+1,mid+1,se,qs,qe);
	return l+r;
}
int getodd(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return 0;
	if(ss>=qs && se<=qe)
		return st[si].first;
	int mid=ss+(se-ss)/2;
	int l=getodd(2*si,ss,mid,qs,qe);
	int r=getodd(2*si+1,mid+1,se,qs,qe);
	return l+r;
}

void update(int si,int ss,int se,int qi,int newval){
	if(ss==se){
        if(arr[ss]%2==1) st[si]={0,1};
        else st[si]={1,0};
		arr[ss]=newval;
		return;
	}
	int mid=ss+(se-ss)/2;
	if(qi<=mid) update(2*si,ss,mid,qi,newval);
	else update(2*si+1,mid+1,se,qi,newval);
	st[si].first=st[2*si].first+st[2*si+1].first;
    st[si].second=st[2*si].second+st[2*si+1].second;
}
ll bin_exp(ll x, ll n){	// binary exponention
	ll res = 1;
	while(n){
		if(n&1)
			res = (res*x)%MOD;
		n /= 2;
		x = (x*x)%MOD;
	}

	return res;
}
ll fermi(ll a, ll b){	// inverse mod
	return (a%MOD*(bin_exp(b, MOD-2)%MOD))%MOD;
}
ll nCr(ll n, ll r){	// calc nCr
	ll ans = 1;
	ll k = min(r, n-r);
	for(ll i=0;i<k;i++){
		ans = (ans%MOD *(n-i)%MOD)%MOD;
		ans = fermi(ans, i+1);
	}

	return ans%MOD;
}
bool isPrime(ll n){
	ll flag=1;
	for (ll i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            flag = 0;
            break;
        }
    }
    if(n<=1)
    flag=0;
    else if(n==2)
    flag=1;

    if (flag == 1) return true;
    else return false;
}
void solve(){
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++) cin>>a[i];
	ll a1=0,a2=0,a3=0;
	for(ll i=0;i<n;i++){
		a1+=abs(a[i]);
		a2+=abs(a[i]*a[i]);
		a3=max(a3,abs(a[i]));
	}
	printf("%lld\n",a1);
	printf("%.15lf\n",sqrt(a2));
	printf("%lld\n",a3);
}
int main(){
	fast;
	ll t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)
#define dec() cout << fixed << setprecision(15)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }

struct UnionFind {
    vi p;
    UnionFind(int n): p(n, -1) { }
    int root(int x) { if (p[x] < 0) return x; else return p[x] = root(p[x]); }
    int size(int x) { return -p[root(x)]; }
    void unite(int x, int y) {
        int rx = root(x), ry = root(y);
        if (rx == ry) return; if (p[rx] > p[ry]) swap(rx, ry);
        p[rx] += p[ry]; p[ry] = rx;
    }
};

ll MOD = 1e9 + 7;
//ll MOD = 998244353;

struct mint {
    ll x;
    mint(ll a = 0): x((a + MOD) % MOD) { }
    mint operator+(mint a) { return mint(*this) += a; }
    mint operator-(mint a) { return mint(*this) -= a; }
    mint operator*(mint a) { return mint(*this) *= a; }
    mint operator/(mint a) { return mint(*this) /= a; }
    mint& operator+=(mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; }
    mint& operator-=(mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; }
    mint& operator*=(mint a) { (x *= a.x) %= MOD; return *this; }
    mint& operator/=(mint a) { return *this *= a.inv(); }
    mint pow(ll t) { mint a = x, ret = 1; while (t) { if (t & 1) ret *= a; a *= a; t >>= 1; } return ret; }
    mint inv() { return pow(MOD - 2); }
    friend istream& operator>>(istream& is, mint& a) { return is >> a.x; }
    friend ostream& operator<<(ostream& os, mint& a) { return os << a.x; }
};

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

    prt(n - (ll)((sqrtl(8 * (n + 1) + 1) - 1) / 2) + 1);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define show(a) for(auto e:a)cout<<e<<" ";cout<<endl
#define size(a) static_cast<int>((a).size())

int main(){
  const long long mod = 1e9 + 7;
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; ++i) cin >> a.at(i);
  vector<vector<long long>> dp(4, vector<long long>(n, 0));
  dp.at(0).at(0) = a.at(0);
  dp.at(1).at(0) = 1;
  for(int i = 1; i < n; ++i){
    dp.at(0).at(i) = (dp.at(0).at(i - 1) + a.at(i) * dp.at(1).at(i - 1) % mod) % mod;
    dp.at(0).at(i) += (dp.at(2).at(i - 1) + a.at(i) * dp.at(3).at(i - 1) % mod) % mod;
    dp.at(1).at(i) = (dp.at(1).at(i - 1) + dp.at(3).at(i - 1)) % mod;
    dp.at(2).at(i) = (dp.at(0).at(i - 1) + mod - a.at(i) * dp.at(1).at(i - 1) % mod) % mod;
    dp.at(3).at(i) = dp.at(1).at(i - 1) % mod;
  }
  /*
	for(int i = 0; i < 4; ++i){
		show(dp.at(i));
	}
*/
  cout << (dp.at(0).at(n - 1) + dp.at(2).at(n - 1)) % mod << endl;
  return 0;
}


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

typedef long long ll;

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

int popcount(int x) {
    int ret = 0;
    while (x > 0) {
        ret += x % 2;
        x /= 2;
    }
    return ret;
}

int main() {
    ll N;
    cin >> N;
    cout << (1 << N) - 1 << "\n";
    for (int i = 1; i < (1 << N); i++) {
        rep(j, (1 << N)) {
            if (popcount(i & j) % 2) cout << "A";
            else cout << "B";
        }
        cout << "\n";
    }
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<int> A(N, 0);
    REP(i, 0, N) {
        int a; cin >> a;
        A[--a] = 1;
    }

    if (accumulate(ALL(A), 0) == N) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	string s[n];
	map< string , int > mp;
	for(int i = 0 ;i < n ;i++){
		cin >> s[i];
		if(s[i][0] == '!') mp[s[i].substr(1)]++;
	}
	for(int i = 0 ; i < n ; i++){
		if(s[i][0] != '!' && mp.find(s[i]) != mp.end()){
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << "satisfiable" << endl;

	return 0;
}

//-- In the name of ALLAH --
// We're nothing and you're everything.
// Ya Ali!
#include<bits/stdc++.h>
using namespace std;

#define      pai              acos(-1)
#define      ff               first
#define      ss               second
#define      ll               long long
#define      pb               push_back
#define      mp               make_pair
#define      pll              pair<ll,ll>
#define      sz(a)            (ll)a.size()
#define      endl             "\n"
#define      gcd(a, b)        __gcd(a, b)
#define      lcm(a, b)        ((a*b)/gcd(a,b))
#define      all(vec)         vec.begin(),vec.end()
#define      ms(a, b)         memset(a,b,sizeof(a))
#define      rep(i,n)         for(int i= 0; i < int(n); i++)
#define      rep1(i,n)        for(int i= 1; i <= n; i++)
#define      TEST_CASE(t)     for(int zz=1;zz<=t;zz++)
#define      PRINT_CASE       printf("Case %d: ",zz)
#define      fii              freopen("input.txt","r",stdin);
#define      foo              freopen("output.txt","w",stdout);
#define      boom             ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

const ll M   = 1e9+7;
const ll mxn = 1e5+7;

int  main()
{
    ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v;
    string s1,s2,ans;
    set<string>st;
    map<string,bool>vis;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s1;
        vis[s1]=true;
        if(s1[0]!='!')
        {
            st.insert(s1);
        }
    }
    bool flag=true;
    for(auto s:st)
    {
        s2="!"+s;
        if(vis[s2])
        {
            ans=s;
            flag=false;
            break;
        }
    }
    if(flag)
    {
        cout<<"satisfiable"<<endl;
    }
    else
    {
        cout<<ans<<endl;
    }
    return 0;
}


#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 dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
template<typename T> bool chmax(T &a, T b) {if(a<b){a=b; return 1; } return 0; }
template<typename T> bool chmin(T &a, T b) {if(a>b){a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll mpow(ll x, ll p) {
	if (p==0) return 1;
	ll res=mpow(x,p/2); res=res*res%MOD;
	return p%2?res*x%MOD:res;
}
ll lpow(ll x, ll p) {
	if (p==0) return 1;
	ll res=lpow(x,p/2); res*=res;
	return p%2?res*x:res;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	ll ans = 0;
	for (ll i = 0; i <= 10000000; ++i) {
		if (b*c > i * a) ans = max(ans, i);
	}
	cout << ans << endl;
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int b, c, d;
    sort(a, a+3);
    cout << a[1] + a[2] << endl;
}


//void __(){
//    _(int,n);
//    rep(i,1,n){
//        print (i*2-1)%n+1, (i*2+1-1)%n+1;
//    }
//}
//
//
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = (l); i <= (r); ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }

    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
    _(int,n);
    rep(i,1,n){
        print (i*2-1)%n+1, (i*2+1-1)%n+1;
    }
}

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

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }

void Solve()
{
	ll N, M, T;
	cin >> N >> M >> T;
	ll maxN = N;
	VL A(M), B(M);
	REP(i, M) cin >> A[i] >> B[i];

	string ans = "Yes";
	ll stTime = 0;
	REP(i, M) {
		N -= (A[i] - stTime);
		if (N <= 0) {
			ans = "No";
			break;
		}
		N += (B[i] - A[i]);
		N = min(maxN, N);
		stTime = B[i];
	}

	N -= (T - stTime);
	if (N <= 0) {
		ans = "No";
	}

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(6);
	Solve();
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll ans=LLONG_MAX;
    for(ll bit=0; bit<(1<<n); bit++){
        ll tmp_ans=0;
        vector<ll> v;
        ll tmp=0;
        for(int i=0; i<n; i++){
            tmp|=a[i];
            if(bit&(1<<i) || i==n-1){
                v.emplace_back(tmp);
                tmp=0;
            }
        }
        for(auto t : v){
            tmp_ans ^= t;
        }
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
    os << "[";
    for (ll i=0; i < v.size(); ++i) {
        os << v[i];
        if (i != v.size() - 1)
            os << ", ";
    }
    os << "]";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
    os << "{";
    for (auto it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v){
    os<<"{";
    for (auto it : v){
        os << it.first << " : "
           << it.second ;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}";
    return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v){
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    return os;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector<ll> arr(n);
        REP(i,n){
            cin>>arr[i];
            arr[i]--;
        }
       // cout<<arr<<endl;
        if(n==2){
            if(arr[0]==0){
                cout<<0<<endl;
            }
            else{
                cout<<1<<endl;
                cout<<1<<endl;
            }
            continue;
        }
        ll turn=0;
        vector<ll> ans;
        for(ll elem=n-1;elem>2;elem--){
            ll pos;
            for(ll i=0;i<=elem;i++){
                if(arr[i]==elem){
                    pos=i;
                    break;
                }
            }
            if(pos==elem) continue;
            if((pos & 1)==turn){
                for(ll i=pos;i<elem;i++){
                    ans.pb(i);
                    swap(arr[i],arr[i+1]);
                    turn^=1;
                }
            }
            else{
                ll ideal=-1;
                for(ll j=0;j<elem;j++){
                    if((j & 1)==turn){
                        if(j+1!=pos){
                            ideal=j;
                            break;
                        }
                    }
                }
                if(ideal!=-1){
                    ans.pb(ideal);
                    swap(arr[ideal],arr[ideal+1]);
                    turn^=1;
                    for(ll i=pos;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
                else{
                    ans.pb(pos-1);
                    swap(arr[pos-1],arr[pos]);
                    turn^=1;
                    ans.pb(pos);
                    swap(arr[pos],arr[pos+1]);
                    turn^=1;
                    for(ll i=pos-1;i<elem;i++){
                        ans.pb(i);
                        swap(arr[i],arr[i+1]);
                        turn^=1;
                    }
                }
            }
        }
       // cout<<arr<<endl;
       // cout<<turn<<endl;
        vector<ll> aux(arr.begin(),arr.begin()+3);
        vector<ll> tar{0,1,2};
        while(aux!=tar){
            if(turn & 1){
                ans.pb(1);
                swap(aux[1],aux[2]);
                turn^=1;
            }
            else{
                ans.pb(0);
                swap(aux[0],aux[1]);
                turn^=1;
            }
        }
        cout<<ans.size()<<endl;
        for(auto & x:ans){
            cout<<x+1<<" ";
        }
        cout<<endl;

    }

}


#include <bits/stdc++.h>
using namespace std;
int a,b=105;

int main()
{
	cin>>b;
	for(int i=1;i<=3;i++)
		cin>>a,b=min(b,a);
	cout<<b<<endl;
	return 0;
}

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

int main() {

  		long long N ,S,T,U,U2,T2,V;
  		cin >> N ;
  		U = 0;
  		V = 0;
  		T2 = 0;
  		vector<long long> vec1(N);

  		for (long long i = 0 ; i < N ; i++){
          cin >> vec1.at(i);
          T = vec1.at(i) * vec1.at(i) * (N - 1 - i);
          T2 = T2 + T;
        }

  		for (long long j = 1; j < N ; j++){
          S = vec1.at(j) * vec1.at(j);

          U2 = 0;
          U = U + vec1.at(j-1);

          U2 = ( -2 ) * U * vec1.at(j);
          V = V + (S * j) + U2;
      	}

  		V = V + T2;

        cout << V << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
const ll mod = 998244353;
ll func(ll n) { return (n * (n + 1) / 2) % mod; }
int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    ll ans = ((func(A) * func(B)) % mod) * func(C);
    cout << ans % mod << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false),cin.tie(NULL);
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define irep(i,a,b) for(int i=a;i>=b;i--)
#define ip(V,n) vector<float> V(n); for(int _i=0;_i<n;_i++) cin>>V[_i]
#define op(V,sep) for(int _i=0;_i<V.size();_i++) cout<<V[_i]<<sep
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define int long long int
#define MOD 998244353
#define MAX 100005
#define INF 1e18
//.............. User: zero_bug   (Not to touch) ....................

void solve() {
    int a,b,c;
    cin>>a>>b>>c;
    int ans=1;
    ans=((a*(a+1))/2)%MOD;
    ans=ans*(((b*(b+1))/2)%MOD);
    ans%=MOD;
    ans=ans*(((c*(c+1))/2)%MOD);
    cout<<(ans%MOD)<<endl;
}

int32_t main() {
    FastIO
    // int t;
    // cin>>t;
    // rep(tt,1,t) {
    //     cout<<"Case #"<<tt<<":"<<" ";
        solve();
    // }
}


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

using namespace std;

inline int read () {
	int ret = 0, t = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	if (c == '-') t = -1, c = getchar();
	while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
	return ret * t;
}

const int mod = 1e9 + 7;
int n, a[100100];

int main () {
	n = read(); int i, j, ans = 1;
	for (i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + n + 1); n = unique(a + 1, a + n + 1) - a - 1;
	for (i = 1; i <= n; i++) ans = 1ll * ans * (a[i] - a[i - 1] + 1) % mod;
	printf("%d\n", ans);
	return 0;
}

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

#ifdef _DEBUG
#include "_DEBUG.hpp"
#endif
#define int long long
const long long inf = 2e18;
const int mod = 1e9 + 7;

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &in : v) is >> in;
  return is;
}

template <class T>
vector<T> make_vec(size_t a) {
  return vector<T>(a);
}

template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template <class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
  t = v;
}

template <class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) {
  for (auto &e : t) fill(e, v);
}

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

  int ans = 0;
  map<int, int> mp;
  mp[0] = 1;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += (i % 2 == 0 ? a[i] : -a[i]);
    ans += mp[sum];
    mp[sum]++;
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF (int)1e9
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
//
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<pii> vpii;
typedef vector<vint> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
#define mk make_pair
#define pb push_back
#define ff first
#define ss second
//
#define por(i, a, b, in) for (int i=a ; i<(b) ; i+=in)
#define rpor(i, a, b, in) for (int i=a-1 ; i>=(b) ; i-=in)
#define rep(i, a, b) por(i, a, b, 1)
#define rrep(i, a, b) rpor(i, a, b, 1)
#define each(it, mp) for (auto it = mp.begin(); it != mp.end(); it++)
#define all(c) c.begin(), c.end()
#define allg(c) all(c), greater<> ()
#define len(v) (int) v.size()
#define notin(c, x) ((c).find(x) == (c).end())
//
#define show(x) cout << x << "\n";
#define showp(x, y) cout << x << " " << y << "\n";
#define showv(v, n) rep(i, 0, n) {cout << v[i] << " ";} cout << "\n";
#define showvp(v, n) rep(i, 0, n) {showp(v[i].ff, v[i].ss);}
#define showvv(vv, n, m) rep(i, 0, n) {showv(vv[i], m);}
#define showset(it, st) each(it, st) {cout << *it << " ";} cout << "\n";
#define showmap(it, mp) each(it, mp) {cout << it->ff << " " << it->ss << "\n";} cout << "\n";
#define precision(d) cout << setprecision(d) << fixed;

void solve () {
	string s;
	cin >> s;
	int n = len(s);
	rrep (i, n, 0) {
		if (s[i] == '6') {
			cout << 9;
		} else if (s[i] == '9') {
			cout << 6;
		} else
		cout << s[i];
	}
	cout << "\n";
}

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

	//int t; cin >> t; while (t--)

	solve();

	return 0;
}

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

#define ll long long int

void get(int n, vector<int>& oct) {
    vector<int> vec1(100);
    int k = 0;
    while (n != 0) {
        vec1[k] = n % 8;
        n = n / 8;
        k++;
    }
    for (int j = k - 1; j >= 0; j--) oct.push_back(vec1[j]);
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    int cnt = 0;

    for (int i = 1; i <= n; i++) {
        bool t = true;
        string cur = to_string(i);
        for (int j = 0; j < cur.length(); j++) {
            if (cur[j] - '0' == 7) {
                t = false;
                break;
            }
        }

        if (t) {
            vector<int> vec;
            get(i, vec);

            for (int j = 0; j < vec.size(); j++) {
                //cout << vec[j] << endl;
                if (vec[j] == 7) {
                    t = false;
                    break;
                }
            }
        }

        if (t) cnt ++;

    }
    cout << cnt << endl;

    return 0;

}


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

const int N=2e5+1e3+7;

int T,n,fa[N];

int find(int x)
{
    return x==fa[x]?x:fa[x]=find(fa[x]);
}

signed main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        fa[find(x)]=find(i);
    }
    int cnt=1;
    for(int i=1;i<=n;i++)
        if(fa[i]==i)
            cnt=cnt*2%998244353;
    cnt=(cnt-1+998244353)%998244353;
    printf("%d\n",cnt);
}

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

//累乗 aのb乗、正しmを法として求める
long long pw(long long a,int b,int m){
    if(b==0) return 1;
    else if(b%2==0){
        long long x = pw(a,b/2,m);
        return (x*x)%m;
    }
    else{
        long long x = pw(a,b-1,m);
        return (a*x)%m;
    }
}

int main(){
    int N; cin >> N;
    int f[N+1]; bool remain[N+1];
    int vis1[N+1];
    rep(i,N){
        cin >> f[i+1];
        remain[i+1] = true;
        vis1[i+1] = 0;
    }
    int loop = 0;
    rep(i,N){
        if(!remain[i+1]) continue;
        int st = i+1;
        while(vis1[st]==0){
            vis1[st] = i+1;
            remain[i+1] = false;
            st = f[st];
        }
        if(vis1[st]==i+1) loop++;
    }
    int m = 998244353;
    cout << (pw(2LL,loop,m) - 1+m)%m << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
//const ll MOD = 1000000007;
const ll MOD = 998244353;

void solve() {
    int h, w, a, b; cin >> h >> w >> a >> b;
    Graph c(h * (w - 1) + (h - 1) * w, vector<int>(4));
    int ind = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w-1; j++){
            c[ind][0] = i;
            c[ind][1] = j;
            c[ind][2] = i;
            c[ind][3] = j + 1;
            ind++;
        }
    }
    for(int i=0; i<h-1; i++){
        for(int j=0; j<w; j++){
            c[ind][0] = i;
            c[ind][1] = j;
            c[ind][2] = i + 1;
            c[ind][3] = j;
            ind++;
        }
    }
    int ans = 0;
    for(int i=0; i<pow(2, ind); i++){
        int tmp = i;
        int cnt = 0;
        for(int j=0; j<ind; j++) if(i & (1<<j)) cnt++;
        if(cnt == a){
            Graph g(h, vector<int>(w, 0));
            for(int j=0; j<ind; j++) if(i & (1<<j)){
                g[c[j][0]][c[j][1]]++;
                g[c[j][2]][c[j][3]]++;
            }
            bool p = true;
            for(int ii=0; ii<h; ii++) for(int jj=0; jj<w; jj++) if(g[ii][jj] > 1) p = false;
            if(p) ans++;
        }
    }
    print(ans);
    return;
}

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

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

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

using namespace std;

#pragma GCC optimize ("Ofast")

#define all(x) x.begin() , x.end()
#define mp make_pair
#define gcd __gcd
typedef long long int ll;
typedef pair<ll , ll> pll;
typedef pair<int , int> pii;
typedef long double db;
typedef pair<ll , pll> plll;
typedef pair<pii , int> piii;
typedef pair<pll , pll> pllll;

const ll MAXN = 32 , MASK = 1 << 16 , md = 1e9 + 7 , inf = 2e9;

ll tav(ll n , ll k){
	ll res = 1;
	while(k > 0){
		if(k & 1){
			res *= n; res %= md;
		}
		n *= n; n %= md;
		k >>= 1;
	}
	return res;
}

ll dp[MASK][MAXN] , t[MAXN];

int main(){ // check MAXN
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	t[0] = 1;
	for(ll i = 1 ; i < 20 ; i++){
		t[i] = t[i - 1] << 1;
	}
	memset(dp , 0 , sizeof(dp));
	ll h , w , a , b , q;
	cin>>h>>w>>a>>b; q = h * w;
	ll lm = 1 << (h * w);
	dp[0][0] = 1;
	for(ll mask = 1 ; mask < lm ; mask++){
		ll av;
		for(ll j = 0 ; j < q ; j++){
			if(mask & t[j]){
				av = j;
				break;
			}
		}
		ll h = mask - t[av];
		for(ll j = 1 ; j <= b ; j++){
			dp[mask][j] += dp[h][j - 1];
		}
		if(av % w != w - 1 && (mask & t[av + 1])){
			h -= t[av + 1];
			for(ll j = 0 ; j <= b ; j++){
				dp[mask][j] += dp[h][j];
			}
			h += t[av + 1];
		}
		if(av + w < q && (mask & t[av + w])){
			h -= t[av + w];
			for(ll j = 0 ; j <= b ; j++){
				dp[mask][j] += dp[h][j];
			}
			h += t[av + w];
		}
	}
	cout<<dp[lm - 1][b]<<'\n';
	return 0;
}

/*

*/


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

int n;
int calc(int x, int m){
    if (x >= (m << 1)) x -= m << 1;
    if (x >= n) x -= m;
    return x + 1;
}
int main(){
    scanf("%d", &n);
    int m;
    for (m = 1; (m << 1) <= n; m <<= 1);
    for (int i = 0; i < n; i++)
        printf("%d %d\n", calc(i << 1, m), calc(i << 1 | 1, m));
    return 0;
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
//#define int long long
//const int N = ;

inline int read()
{
	int X=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){X=(X<<1)+(X<<3)+ch-'0';ch=getchar();}
	if(flag)return X;
	return ~(X-1);
}

inline void write(int X)
{
	if(X<0){X=~(X-1);putchar('-');}
	if(X>9){write(X/10);}
	putchar(X%10+'0');
}

signed main()
{
	int n=read();
	int ans=n/100;
	if(n%100!=0)ans+=1;
	cout<<ans;
	return 0;
}


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

int main(){
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    int Q, R, S;
    Q = x * 2;
    //同じ階の場合
    if(a == b) cout << x << endl;
    //下りの場合
    else if(a > b){
        R = a - b - 1;
        cout << min(R * y + x, R * Q + x) << endl;
    }
    //上りの場合
    else{
        S = b - a;
        cout << min(S * y + x, S * Q + x) << endl;
    }

}

#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

long long power(long long base, long long val)
{
    int ans = 1;
    for (long long i = 0; i < val; ++i) {
        ans *= base;
    }
    return ans;
}

long long count_point(long long n1, long long n2, long long n3, long long n4, long long n5)
{
    vector<long long> counts(9, 0);
    counts[n1 - 1]++;
    counts[n2 - 1]++;
    counts[n3 - 1]++;
    counts[n4 - 1]++;
    counts[n5 - 1]++;

    long long cnt = 0;
    for (long long i = 0; i < 10; ++i) {
        cnt += (i + 1) * power(10, counts[i]);
    }
    return cnt;
}

int main()
{
    long long K;
    string S, T;
    cin >> K;
    cin >> S;
    cin >> T;
    unordered_map<int, long long> num_cards;
    vector<long long> Snumbers;
    vector<long long> Tnumbers;
    for (long long i = 1; i <= 9; ++i)
        num_cards[i] = K;

    for (long long i = 0; i < 4; ++i) {
        long long Snumber = S[i] - '0';
        long long Tnumber = T[i] - '0';
        num_cards[Snumber]--;
        num_cards[Tnumber]--;
        Snumbers.push_back(Snumber);
        Tnumbers.push_back(Tnumber);
    }

    long double win_rate = 0;

    for (long long i = 1; i <= 9; ++i) {
        if (num_cards[i] <= 0)
            continue;
        for (long long j = 1; j <= 9; ++j) {
            if (num_cards[j] <= 0)
                continue;
            if (num_cards[j] == 1 && i == j)
                continue;
            long long Spoint = count_point(Snumbers[0], Snumbers[1], Snumbers[2], Snumbers[3], i);
            long long Tpoint = count_point(Tnumbers[0], Tnumbers[1], Tnumbers[2], Tnumbers[3], j);
            // cout << Spoint << endl;
            // cout << Tpoint << endl;
            if (Spoint > Tpoint) {
                if (i == j)
                    win_rate += num_cards[i] * (num_cards[i] - 1);
                else
                    win_rate += num_cards[i] * num_cards[j];
            }
        }
    }

    cout << setprecision(16) << win_rate / ((9 * K - 8) * (9 * K - 9)) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 15e5 + 5;
map<int,int> mp;
int a[N];

int main()
{
	int n,m;
	cin >> n >> m;
	int minn = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i <= m){
			mp[a[i]]++;
		}
	}
	for(int i = 0; i <= m+1; i++){
		if(!mp[i]){
			minn = i;
			break;
		}
	}
	for(int i = m+1; i <= n; i++){
		mp[a[i]]++;
		mp[a[i-m]]--;
		if(!mp[a[i-m]]){
			minn = min(a[i-m],minn);
		}
	}
	cout << minn << endl;
    return 0;
}

#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const double pi = 3.14159265358979;

int si,sj;
vector<vector<int>> tile(50, vector<int>(50));
vector<vector<int>> profit(50, vector<int>(50));
vector<bool> seen(2500,false);
string ans;

void all_resize(){
    return;
}

void all_input(){
    cin >> si >> sj;

    all_resize();

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> tile[i][j];
        }
    }

    for (int i = 0; i < 50; i++){
        for (int j = 0; j < 50; j++){
            cin >> profit[i][j];
        }
    }

    return;
}

void all_output(){

    cout << ans << endl;

    return;
}

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

    all_input();

    all_output();
}

//


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<vector<ll>> memo(31, vector<ll>(31, -1));
ll f(int a, int b) {
	if (memo[a][b] != -1) return memo[a][b];
	if (a == 0) {
		return 1;
	}
	if (b == 0) {
		return 1;
	}
	ll va = f(a - 1, b);
	ll vb = f(a, b - 1);
	memo[a][b] = va + vb;
	return va + vb;
}
#ifdef _DEBUG
#define show(x)          \
	cerr << #x << " : "; \
	showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
	for (const T &v : a) cerr << v << " ";
	cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
	cerr << endl;
	for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
int main() {
	ll k;
	int a, b;
	cin >> a >> b >> k;
	f(a, b);
	string ans;
	int sz = a + b;
	for (int i = 0; i < sz; i++) {
		if (a > 0 && f(a - 1, b) >= k) {
			ans += 'a';
			a--;
		} else {
			if (a > 0) k -= f(a - 1, b);
			b--;
			ans += 'b';
		}
		show(k);
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<pi, int> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, vis[105], coun;
ld x[105], y[105], r;

inline ld sqr(ld t) {
	return t*t;
}

void dfs(int node) {
	vis[node] = coun;
	FOR(i, 1, n) if (sqr(x[i] - x[node]) + sqr(y[i] - y[node]) < sqr(2*r) and vis[i] == -1) dfs(i);
}

bool check(ld g) {
	memset(vis, -1, sizeof vis);
	coun = 0;
	r = g;
	FOR(i, 1, n) if (100 - y[i] < 2*r and vis[i] == -1) ++coun, dfs(i);
	FOR(i, 1, n) if (y[i] + 100 < 2*r and vis[i] != -1) return 0;
	return 1;
}

int main() {
	fastio; cout << fixed << setprecision(4);
	cin >> n;
	FOR(i, 1, n) cin >> x[i] >> y[i];
	ld lower = 0, upper = 100.0001;
	while (upper - lower > (ld) 0.0001) {
		ld mid = (upper + lower)/2;
		if (check(mid)) lower = mid;
		else upper = mid;
	}
	cout << lower;
}


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

signed main(){
	int N;
	scanf("%d", &N);
	if(N % 2 == 0){
		printf("White\n");
	}
	else{
		printf("Black\n");
	}
	return 0;
}

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

int main(){
  long long l;
  cin >> l;

  long long ans =1;
  for(int i = 1; i<=11; i++){
    ans *= l-i;
    ans /= i;
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
char gap = 32;
#define ll long long
#define lll __int128_t
#define pb push_back
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
ll status[200000];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    ll i,j,k,l;
    cin >> n;
    vector <ll> res;
    res.pb(6);
    res.pb(10);
    res.pb(15);
    ll cnt = 0;
    ll curr = 6;
    status[6] = status[10] = status[15] = 1;
    for(i = 1 ; i <= n - 3 ; ){
        while(curr <= 10000 and status[curr] == 1){
            if(cnt == 0)
                curr = curr + 6;
            else if(cnt == 1)
                curr = curr + 10;
            else
                curr = curr + 15;
        }
        if(curr > 10000){
            if(cnt == 0){
                cnt = 1;
                curr = 10;
            }
            else if(cnt == 1){
                cnt = 2;
                curr = 15;
            }
        }
        if(status[curr] == 0){
            status[curr] = 1;
            res.pb(curr);
            i++;
        }
    }
    for(i = 0 ; i < n;i++){
        cout << res[i] << " ";
    }
    cout << "\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

  int n;
  cin >> n;

  double ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += 1.0 / i;
  }
  ans = n * ans - 1;

  cout << fixed << setprecision(12) << ans << '\n';

  return 0;
}


//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,k,m,ans[105],f[240005],a[105];
int main(){
	srand(time(0));
	scanf("%d%d%d",&n,&k,&m);
	for(int i=1;i*2-1<=n;++i){
		memset(f,0,sizeof(f));
		f[120000]=1;
		for(int j=1;j<=n;++j)a[j]=j-i;
		random_shuffle(a+1,a+n+1);
		for(int j=1;j<=n;++j){
			int t=a[j];
			if(!t) continue;
			if(t>0){
				int T=t*k;
				for(int s=230000;s>230000-t;--s){
					int o=0;
					for(int I=0;I<k;++I){
						o+=f[s-I*t];
						if(o>=m)o-=m;
					}
					for(int q=s;q>=10000;q-=t){
						o+=f[q-T]-f[q];
						if(o<0)o+=m;
						else if(o>=m)o-=m;
						f[q]+=o;
						if(f[q]>=m)f[q]-=m;
					}
				}
			}
			else{
				t=-t;
				int T=t*k;
				for(int s=10000;s<10000+t;++s){
					int o=0;
					for(int I=0;I<k;++I){
						o+=f[s+I*t];
						if(o>=m)o-=m;
					}
					for(int q=s;q<=230000;q+=t){
						o+=f[q+T]-f[q];
						if(o<0)o+=m;
						else if(o>=m)o-=m;
						f[q]+=o;
						if(f[q]>=m)f[q]-=m;
					}
				}
			}
		}
		ans[i]=ans[n+1-i]=(f[120000]*1ll*(k+1ll)-1ll)%m;
	}
	for(int i=1;i<=n;++i)printf("%d\n",ans[i]);
    return 0;
}

#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>
#include<random>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;

ll dp[101][250001];

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

	ll n, k, m;
	cin >> n >> k >> m;
	dp[0][0] = 1 ;
	REP(i, n) {
		Array tmp(i + 1, 0);
		REP(j, 250001) {
			(tmp[j % (i + 1)] += dp[i][j]) %= m;
			if (j / (i + 1) > k)(tmp[j % (i + 1)] += m - dp[i][j - (i + 1) * (k + 1)]) %= m;
			(dp[i + 1][j] += tmp[j % (i + 1)]) %= m;
		}
	}
	auto solve = [&](ll x) {
		ll ret = 0;
		REP(i, 250001)(ret += dp[x - 1][i] * dp[n - x][i] % m) %= m;
		(ret *= k + 1) %= m;
		return (ret + m - 1) % m;
	};
	REP(i, n)cout << solve(i + 1) << "\n";

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define all(v) v.begin(),v.end()
#define mp make_pair
#define space ' '
#define INF (1LL<<60)
#define graph vector<vector<edge>>
template<class T>int chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
struct edge{int to;int cst;edge(int to,int cst):to(to),cst(cst){}};

void dijkstra()
{
	int n,m;cin>>n>>m;
	graph g(n*2);
	for(int i=0;i<m;i++){
		int a,b,cst;cin>>a>>b>>cst;a--;b--;
		g[a].push_back(edge(b,cst));
		g[a+n].push_back(edge(b,cst));
		g[a].push_back(edge(b+n,cst));
	}
	for(int s=0;s<n;s++){
		int t=s+n;
		//ここからdijkstra
		vector<int>dist(n*2,INF);dist[s]=0;
		vector<int>prev(n*2,-1);
		//pair(d[v],[v])が要素のプラキューを作る
		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;
		pq.push(mp(dist[s],s));
		//反復
		while(!pq.empty()){
			//v : 使用済みでない頂点の最小がd[v]になる
			//d : vに対するkey値
			int v=pq.top().second;
			int d=pq.top().first;
			pq.pop();

			if(d>dist[v])continue;

			for(auto e:g[v]){
				if(chmin(dist[e.to],dist[v]+e.cst)){
					prev[e.to]=v;
					pq.push(mp(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF) cout<<-1<<endl;
		else{cout<<dist[t]<<endl;}
	}
}
main(){
	dijkstra();
}

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

/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair

/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__);
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__);
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__);
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__);
#define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__);

/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;

/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

void IN() {}

template <class Head, class... Tail>
void IN(Head &head, Tail &... tail) {
  cin >> head;
  IN(tail...);
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  LL(n);
  set<ll> div;

  rep2(i, 1, sqrt(n)) {
    if (n % i == 0) {
      div.em(i);
      div.em(n/i);
    }
  }

  for (auto e : div) cout << e << endl;
}


#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
ll  n ,  m , cnt, ans , sum;
ll x , y , z;
ll a , b , c;
string s , s1;
char ch;
vector<string>v;
int main(){
    ll arr[4];
    for( int i = 0;i < 4;i ++ )
        cin >> arr[i];
    sort( arr , arr + 4 );
    cout <<arr[0];
}

// 2020-12-13 21:00:20
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
void answer() {
  vector<int> a(4);
  rep(i, 4) cin >> a[i];
  sort(ALL(a));
  cout << a[0] << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int read() {
	char c=getchar(); int x=0,f=1;
	while (c<'0' || c>'9') {
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
vector<pair<int,int> > odd[100005],even[100005];
vector<int> G[100005];
int a[100005],b[100005],siz[100005];
bool cmp(pair<int,int> x,pair<int,int> y) {
	int dx=x.first-x.second;
	int dy=y.first-y.second;
	return dx>dy;
}
void dfs(int x) {
	siz[x]=1;
	for (int i=0; i<G[x].size(); i++) {
		int v=G[x][i];
		dfs(v);
		if (siz[v]&1) odd[x].push_back(make_pair(a[v],b[v]));
		else even[x].push_back(make_pair(a[v],b[v]));
		siz[x]+=siz[v];
	}
	sort(odd[x].begin(),odd[x].end(),cmp);
	sort(even[x].begin(),even[x].end(),cmp);
	a[x]=0; b[x]=1;
	int i;
	for (i=0; i<even[x].size(); i++) {
		if (even[x][i].first>even[x][i].second) {
			a[x]+=even[x][i].first;
			b[x]+=even[x][i].second;
		}
		else break;
	}
	for (int j=0; j<odd[x].size(); j++) {
		if (j&1) {
			b[x]+=odd[x][j].first;
			a[x]+=odd[x][j].second;
		}
		else {
			a[x]+=odd[x][j].first;
			b[x]+=odd[x][j].second;
		}
	}
	for (; i<even[x].size(); i++) {
		if (odd[x].size()&1) {
			b[x]+=even[x][i].first;
			a[x]+=even[x][i].second;
		}
		else {
			a[x]+=even[x][i].first;
			b[x]+=even[x][i].second;
		}
	}
}
int main() {
	int n=read();
	for (int i=2; i<=n; i++) {
		int p=read();
		G[p].push_back(i);
	}
	dfs(1);
	cout<<b[1]<<endl;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;

struct Tree
{
    int n;
    int r;
    int l;
    std::vector<std::vector<int>> prit;
    std::vector<std::vector<int>> t;
    std::vector<int> par;
    std::vector<int> dpt;
    std::vector<int> tour;
    std::vector<std::vector<int>> appear_on_tour;
    std::vector<std::vector<int>> anc;

    Tree(){}

    Tree(int n, int r) : n(n), r(r){
        prit.resize(n);
        t.resize(n);
        par.resize(n);
        dpt.resize(n);
    }

    void add_edge(int u, int v){
        prit[u].push_back(v);
        prit[v].push_back(u);
    }

    void build(){
        for(int i = 0; i < n; i++) dpt[i] = -1;
        std::queue<int> que;
        par[r] = -1;
        dpt[r] = 0;
        que.push(r);
        while(que.size()){
            int u = que.front();
            que.pop();
            for(int v : prit[u]){
                if(dpt[v] == -1){
                    t[u].push_back(v);
                    par[v] = u;
                    dpt[v] = dpt[u] + 1;
                    que.push(v);
                }
            }
        }
    }

/*    std::vector<int> toposort(){
        std::vector<std::pair<int, int>> p(n);
        for(int i = 0; i < n; i++) p[i] = std::pair<int, int>(dpt[i], i);
        sort(p.begin(), p.end(), std::greater<std::pair<int, int>>());
        std::vector<int> res(n);
        for(int i = 0; i < n; i++) res[i] = p[i].second;
        return res;
    }*/

    void dfs(int u, int &k){
        appear_on_tour[u].push_back(k);
        tour[k++] = u;
        for(int v : t[u]){
            dfs(v, k);
            appear_on_tour[u].push_back(k);
            tour[k++] = u;
        }
    }

    void build_euler_tour(){
        tour.resize(n * 2 - 1);
        appear_on_tour.resize(n);
        int k = 0;
        dfs(0, k);
    }

    void build_lca(){
        for(l = 1; l <= n; l++){
            if((1 << (l - 1)) >= n) break;
        }
        anc.resize(l);
        for(int j = 0; j < l; j++) anc[j].resize(n);
        for(int i = 0; i < n; i++) anc[0][i] = par[i];
        for(int j = 1; j < l; j++){
            for(int i = 0; i < n; i++){
                if(anc[j - 1][i] == -1) anc[j][i] = -1;
                else anc[j][i] = anc[j - 1][anc[j - 1][i]];
            }
        }
    }

    int lca(int u, int v){
        if(dpt[u] < dpt[v]) std::swap(u, v);
        int dpt_diff = dpt[u] - dpt[v];
        for(int j = l - 1; j >= 0; j--){
            if((dpt_diff >> j) & 1) u = anc[j][u];
        }
        if(u == v) return u;
        for(int j = l - 1; j >= 0; j--){
            if(anc[j][u] != anc[j][v]){
                u = anc[j][u];
                v = anc[j][v];
            }
        }
        return anc[0][u];
    }
};

int size(int u, Tree &t, int *d){
    if(d[u]) return d[u];
    d[u]++;
    for(int v : t.t[u]) d[u] += size(v, t, d);
    return d[u];
}

int dfs(int u, Tree &t, int *d, int *dp){
    if(dp[u]) return dp[u];
    dp[u]--;
    vector<int> p, q;
    for(int v : t.t[u]){
        if(d[v] % 2) p.push_back(dfs(v, t, d, dp));
        else q.push_back(dfs(v, t, d, dp));
    }
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    for(int i = 0; i < (int)p.size(); i++){
        if(i % 2) dp[u] -= p[i];
        else dp[u] += p[i];
    }
    for(int i = 0; i < (int)q.size(); i++){
        if(q[i] > 0 || !((int)p.size() % 2)) dp[u] += q[i];
        else dp[u] -= q[i];
    }
    return dp[u];
}

int main()
{
    int n;
    cin >> n;
    Tree t(n, 0);
    for(int i = 1; i < n; i++){
        int p;
        cin >> p;
        t.add_edge(i, --p);
    }
    t.build();
    int d[100005]{0}, dp[100005]{0};
    size(0, t, d);
    cout << (n - dfs(0, t, d, dp)) / 2 << endl;
}


#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define LL long long
using namespace std;

template <class I>
inline void read(I &z)
{
    z=0;
    char c=getchar();int base=1;
    while (!isdigit(c) && c!='-') c=getchar();
    if (c=='-') c=getchar(),base=-1;
    while (isdigit(c)) z=z*10+c-'0',c=getchar();
    z*=base;
}

struct node
{
    int h,x;
};

node a[1010];
int n,h;

char s[1010][20];

bool comp(node x,node y)
{
    return x.h>y.h;
}

int main(int argc, char const *argv[])
{
    read(n);
    for (int i=1;i<=n;++i)
    {
        scanf("%s",s[i]+1);
        read(h);
        a[i]=(node){h,i};

    }
    sort(a+1,a+n+1,comp);
    printf("%s",s[a[2].x]+1);
    return 0;
}

#include<bits/stdc++.h>
#define int         int64_t
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mi        map<int,int>
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
void solve(){
    int n; cin>>n;
    pair<int,string> arr[n];
    rep(i,0,n){
        string s; int p;
        cin>>s>>p;
        arr[i].first=p;
        arr[i].second=s;
    }
    sort(arr,arr+n);
    cout<<arr[n-2].second;
}
signed main(){
    ios

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


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

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

    int n;
    cin>>n;
    set<string> yes,no;
    while(n--)
    {
        string s;
        cin>>s;
        if(s.front()=='!')
        {
            s.erase(s.begin());
            no.insert(s);
        }
        else
            yes.insert(s);
        if(yes.count(s)&&no.count(s))
            cout<<s,exit(0);
    }
    cout<<"satisfiable";
}

#include<bits/stdc++.h>
using namespace std;
#define vec vector<int>
#define vecp vector<pair<int,int>>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fr first
#define sc second
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define fr2(i,a,b) for(int i=a;i>=b;i--)
#define fr3(i,a,b) for(int i=a;i<=b;i++)
#define umap unordered_map<int,int>
#define omap map<int,int>
#define uset unordered_set<int>
#define oset set<int>
#define pr pair<int,int>
#define endl "\n"
#define mod 1000000007
#define mp make_pair
#define all(v) v.begin(),v.end()

void solve()
{
  int n;
  cin>>n;
  vector<string> s(n);
  fr1(i,0,n)
  {
    cin>>s[i];
  }
  unordered_set<string> s1;
  fr1(i,0,n)
  {
    s1.insert(s[i]);
  }
  for(auto i=s1.begin();i!=s1.end();i++)
  {
    string S=*i;
    if(s1.count('!'+S)==1)
    {
      cout<<S<<endl;
      return;
    }
  }
  cout<<"satisfiable"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    fr3(i,1,t){
        solve();
    }
   return 0;
}


#ifdef _DEBUG
#include "../../../library/src/debug_template.hpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <variant>
#include <array>

using namespace std;
using lint = long long;
constexpr int INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
    init() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} init_;

template<class T, class F>
T bisearch(T OK, T NG, F f) {
    T ok = OK;
    T ng = NG;

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

        if (f(mid)) ok = mid;
        else ng = mid;
    }

    return ok;
}

template<class T>
vector<T> make_vec(size_t s, T val) { return vector<T>(s, val); }
template<class... Size>
auto make_vec(size_t s, Size... tail) {
    return vector<decltype(make_vec(tail...))>(s, make_vec(tail...));
}

int main() {

    int N;
    cin >> N;

    vector<array<int, 5>> ability(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            cin >> ability[i][j];
        }
    }

    auto judge = [&](int now) -> bool {
        auto dp = make_vec((1 << 5), 3, 0);
        for (int i = 0; i < N; i++) {
            int bit = 0;
            for (int j = 0; j < 5; j++) {
                if (now <= ability[i][j]) bit += (1 << j);
            }
            dp[bit][0] = 1;
            for (int j = 0; j < (1 << 5); j++) {
                for (int k = 0; k < 2; k++) {
                    dp[j | bit][k + 1] |= dp[j][k];
                }
            }
        }
        DMP(dp);
        return dp[(1 << 5) - 1][2];
    };

    cout << bisearch(0, INF, judge);

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

class Graph{
    int V;
    list<int> *adj;
    int *exist;
public:

    Graph(int N){
        V=N;
        adj=new list<int> [N];
        exist= new int [N];
        memset(exist,0,sizeof(exist));
    }

    void AddEdge(int x,int y){
        adj[x].push_back(y);
        adj[y].push_back(x);
        exist[x]=1;
        exist[y]=1;
    }

    void dfs(int src,int visited[]){
        visited[src]=1;
        for(auto ngb: adj[src]){
            if(!visited[ngb]){
                dfs(ngb,visited);
            }
        }
    }

    int Ans(){
        int visited[V];
        int comp=0;
        memset(visited,0,sizeof(visited));
        for(int i=0;i<V;i++){
            if((!visited[i]) and exist[i]){
                dfs(i,visited);
                comp++;
            }
        }

        return comp;
    }

};

void solve(){
    Graph G(200005);
    int n;
    cin>>n;
    vector<int> v(n);
    unordered_map<int,int> m;
    int uniq=0;
    for(auto &x:v){
        cin>>x;
        if(m.count(x)){
            m[x]++;
        }
        else{
            m[x]=1;
            uniq++;
        }
    }

    int i=0,j=n-1;
    while(i<=j){
        G.AddEdge(v[i],v[j]);
        i++;
        j--;
    }

    //cout<<"Here"<<endl;

    int comp= G.Ans();
    cout<<uniq-comp<<endl;

    return;
}

int main(){
    int t;
    //cin>>t;
    t=1;
    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}


///****In the name of ALLAH, most Gracious, most Compassionate****//

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

typedef long long ll;
typedef pair <ll, ll> pii;

const int N=2e5+5;

pii x[N];

#define func(xi) (2*xi.first + xi.second)

inline bool cmp( pii x, pii  y)
{
    return func(x) < func(y);
}

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

    while(n>=N) ;

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

    sort(x,x+n, cmp);

    ll a = 0, b = 0;
    for(int i=0; i<n; i++)
        b+=x[i].first;

    int tot =0;
    for(int i=n-1; i>=0; i--)
    {
        a+=x[i].first;
        a+=x[i].second;
        b-=x[i].first;
        tot++;
        if(a>b)
        {
            cout<<tot<<"\n";
            return 0;
        }
    }
    cout<<n<<"\n";
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll, ll>> d(n);

    ll a, b;
    ll all_a = 0;
    rep(i, n) {
        cin >> a >> b;
        all_a += a;
        d[i] = {a + b + a, a};
    }
    sort(d.begin(), d.end(), greater<pair<ll, ll>>());
    ll all_b = 0;
    ll res = 0;
    rep(i, n) {
        auto p = d[i];
        all_a -= p.second;
        all_b += p.first - p.second;
        res++;
        if (all_b > all_a) break;
    }
    cout << res << endl;
    return 0;
}


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

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

    int a = 0;

    while (x*a < y*z) {
        ++a;
    }
    --a;

    cout << a << endl;
    return 0;
}

#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll n, k;
string s;
char dp[200][200];
ll pow2[200];

char winner(char a, char b){
    if(a == 'R') return (b == 'S' ? a : b);
    else if(a == 'P') return (b == 'R' ? a : b);
    else return (b == 'P' ? a : b);
}

char dfs(ll pos, ll len){
    if(dp[pos][len]) return dp[pos][len];
    if(len == 0) return s[pos];
    return dp[pos][len] = winner(dfs(pos, len - 1), dfs((pos + pow2[len - 1]) % n, len - 1));
}

signed main(){
    cin >> n >> k >> s;
    pow2[0] = 1;
    REP(i, n) pow2[i + 1] = (pow2[i] * 2) % n;
    PRINT(dfs(0, k));
    return 0;
}


/// hhoangcpascal

#include <iostream>
#include <algorithm>
#define llong long long

using namespace std;

const llong mod = 1e9+7;
llong prefix[3006], dp[3006][3006], tmp[3006];
int n;

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

    cin >> n;
    for(int i = 1; i <= n; ++i) {
        llong a; cin >> a;
        prefix[i] = prefix[i-1] + a;
    }

    for(int i = 1; i <= n; ++i) dp[1][i] = 1;

    for(int i = 2; i <= n; ++i) {
        fill(tmp, tmp+i, 0LL);

        tmp[prefix[i-1] % i] = dp[i-1][i-1];
        for(int j = i; j <= n; ++j) {
            (dp[i][j] += tmp[prefix[j] % i]) %= mod;
            (tmp[prefix[j] % i] += dp[i-1][j]) %= mod;
        }
    }

    llong ans = 0;
    for(int i = 1; i <= n; ++i) (ans += dp[i][n]) %= mod;

    cout << ans;

    return 0;
}

//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
      I ♥ CLARICE STARLING...
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
vector<int>d[10];
void precompute()
{
    d[0].pb(0);
    ll i;
    foe(i,1,9)
    {
        unordered_set<ll>x;
        ll now=i;
        while(true)
        {
            if(x.count(now%10))break;
            d[i].pb(now%10);
            x.insert(now%10);
            now*=i;
        }
    }
}
ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1ll;
    while(n>0)
    {
        if(n % 2 ==1)
        result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return (result-1+M)%M;
}
void solve()
{
   ll A,B,C;cin>>A>>B>>C;
   A=A%10;
   ll p=modularExponentiation(B,C,sz(d[A]));
   cout<<d[A][p]<<"\n";

}
int main()
{
   fastio
   precompute();
   //Test_cases
   solve();
  return 0;
}