// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(), (v).end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const ll MOD = 1000000007;
// const int MOD = 998244353;

// cout << fixed << setprecision(15) << ans << endl;
// using mint = modint1000000007;

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

int main() {
  int n;cin>>n;
  vector<ll> a(n);
  for(auto&i:a)cin>>i;
  sort(all(a));
  double x = a[n/2]*0.5;
  double ans = 0;
  rep(i, n) ans += x + a[i] - min((double)a[i], 2*x);
  // cout << ans << endl;
  cout << fixed << setprecision(15) << ans / n << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 1000000007
#define inf 1000000000000000000

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

ll power(ll a, ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2!=0)
            res = (res*1ll*a)%mod;
        b/=2;
        a=(a*1ll*a)%mod;
    }

    return res%mod;
}
vector<bool>arr(100000);
void sieve()
{
    for(ll i=2;i<100000;i++)
    {
        if(!arr[i])
        {
            ll temp=i+i;
            while(temp<100000)
            {
                arr[temp]=true;
                temp+=i;
            }
        }
    }
}

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

    m_arr(arr, n);
    loop(i, n)cin>>arr[i];

    map<ll, ll>mp;
    loop(i, n)
    {
        mp[arr[i]%200]++;
    }

    ll res=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        res+=(it->second*1ll*(it->second-1))/2;
    }

    cout<<res<<endl;
    return;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll t;cin>>t;while(t--)
    solve();
    return 0;
}


#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
// #define MOD 998244353
const int INF = (int)1e9 + 10;         // int max > 2*10^9
const long long INFL = (ll)2e18 + 10;  // ll max > 9*10^18

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

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

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

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

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

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

#pragma endregion Region_1
/////////////////////////////////////////////////////////
struct mint {
    ll x;  // typedef long long ll;
    int mod;
    mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % mod), mod(mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    // x^t
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;  // 桁ずらし
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    int n;
    cin >> n;
    VL a(n);
    rep(i, n) {
        cin >> a[i];
    }
    VL s(n + 1, 0);
    VL s2(n + 1, 0);
    rep(i, n) {
        s[i + 1] = s[i] + a[i];
    }
    rep(i, n) {
        s2[i + 1] = s2[i] + s[i + 1];
    }
    ll mv = 0;
    rep(i, n) {
        chmax(mv, a[i]);
        print(mv * (i + 1) + s2[i + 1]);
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//解説見て解きなおし。

int main(){
	long long n;
  cin>>n;
  vector<long long>list(n);
// vector<long long>list2(n);

  for(int i=0;i<n;i++){
   cin>>list.at(i);
 //   list2.at(i)=list.at(i);
 // if(i>0) list2.at(i)+=list2.at(i-1);
  }

  long long total=0;//1+(1+2)+(1+2+3)+...今まで全部の合計
  long long amax =0;
  long long x =0; //1-iの合計をつっこんでおく
	for(int i=0;i<n;i++){
      x += list.at(i);
      total += x;
      amax=max(amax,list.at(i));

     cout<<total+amax*(i+1)<<endl;

    }

}


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

int n;

int main(){
	scanf("%d", &n);
	printf("%d\n", (1 << n) - 1);
	for(int i = 1; i < (1 << n); i++){
		for(int j = 1; j <= (1 << n); j++){
			putchar("BA"[__builtin_popcount(i & j) & 1]);
		}
		puts("");
	}
	return 0;
}

#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=1e5+7;
ll a,b,c,ans,res;
void gao(ll x){
    a=1,b=0,c=0;
    ans=x;
    while(x!=1){
        if(x%2){
            c+=pow(2,b);
            x--;
        }
        b++;
        x/=2;
        a=x;
        ans=min(ans,a+b+c);
    }
}
int main(){
    cin>>res;
    gao(res);
    cout<<ans<<endl;
}


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

int main(){
	int n;
	cin >> n;
	string s1,s2,sm;
	int t1=0,t2=0,tm;
	for(int i=0;i<n;i++){
		string s;
		int t;
		cin >> s >> t;
		if(t > t1){
			sm = s1;
			tm = t1;
			s1 = s;
			t1 = t;
			s2 = sm;
			t2 = tm;

		}
		else if(t > t2 && t < t1){
			s2 = s;
			t2 = t;
		}
	}

	cout << s2 << endl;

}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;

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

    pair<ll, string> p[N];
    string S;
    ll T;
    rep(i, 0, N){
        cin >> S >> T;
        p[i] = make_pair(T, S);
    }
    sort(p, p + N, greater<pair<ll, string>>());

    cout << p[1].second << endl;

    return 0;
}


#include <bits/stdc++.h>

//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int x, y;
    scanf("%d%d", &x, &y);
    puts(abs(x - y) <= 2 ? "Yes" : "No");
}

#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string) s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int) (x).size())
#define endl '\n'

typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> pi;

void solve() {
	//Test case code goes here

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

	for (int i = 0; i < a; ++i)
	{
		int x;
		cin >> x;
		if (x == b) continue;
		cout << x << " ";
	}
	return;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	cout.tie(nullptr);

	// cout << fixed << setprecision(15);
	solve();

	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/* MACROS */
typedef long long int ll;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;
typedef tuple<int,int,int> tup;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 1e5 + 3;

vi node_col(MAX_N),vis(MAX_N , 0),adj[MAX_N];
mii mp;
set<int>ans;

void dfs(int node){
    vis[node] = 1;
    mp[node_col[node]]++;
    if(mp[node_col[node]]==1){
        ans.insert(node);
    }

    for(auto x:adj[node]){
        if(!vis[x]){
            dfs(x);
        }
    }

    mp[node_col[node]]--;
}

void solve(){
    int n; cin >> n;
    rep(i,1,n+1) cin >> node_col[i];

    rep(i,1,n){
        int a,b; cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }

    dfs(1);

    for(auto x:ans) cout << x << "\n";
}

int main(){
    IOS;
    solve();
}

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

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define F first
#define S second
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,greater<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

ll n;
ve<ll> ch(205,-1),val(205,-1),dp(205,-1);

bool com(ll a, ll b)
{
    if(ch[a]==1 || ch[b]==0 || (val[a]!=-1 && val[a]!=b) || (val[b]!=-1 && val[b]!=a) || (ch[a]==0 && ch[b]==1 && val[a]==-1 && val[b]==-1))
        return false;
    return true;
}

void fun(ll x)
{
    if(dp[x]!=-1)
        return;
    ll p=(x+n+n+1)/2;
    bool ans=0;
    for(ll i=x+1;i<=p;i++)
    {
        bool b=1;
        for(ll j=x,k=i;j<i;j++,k++)
            b=(b && com(j,k));
        if(b)
        {
            fun(i+i-x);
            ans=(ans || (dp[i+i-x]==1));
        }
    }
    if(ans)
        dp[x]=1;
    else
        dp[x]=0;
}

int main()
{
    FAST;
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin>>a>>b;
        if(a!=-1)
        {
            if(ch[a]!=-1)
            {
                cout<<"No";
                return 0;
            }
            ch[a]=0;
            val[a]=b;
        }
        if(b!=-1)
        {
            if(ch[b]!=-1)
            {
                cout<<"No";
                return 0;
            }
            ch[b]=1;
            val[b]=a;
        }
    }
    dp[n+n+1]=1;
    fun(1);
    if(dp[1]==1)
        cout<<"Yes";
    else
        cout<<"No";
    subt;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

ll qexp(ll a, ll b, ll m) {
    ll res = 1;
    while (b) {
        if (b % 2) res = res * a % m;
        a = a * a % m;
        b /= 2;
    }
    return res;
}

vector<ll> fact;

void precompute(int n) {
    fact.assign(n + 1, 1);
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
}

ll nCk(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * qexp(fact[k], MOD - 2, MOD) % MOD * qexp(fact[n - k], MOD - 2, MOD) % MOD;
}

// Observation: Counting Diagonal-Avoiding Paths, similar to the method to calculate Catalan number

void solve() {
    ll n, m, k; cin >> n >> m >> k;
    if (n - m > k) {
        cout << 0 << "\n";
        return;
    }
    ll ans = nCk(n + m, n) - nCk(n + m, m + k + 1);
    if (ans < 0) ans += MOD;
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    precompute(2e6);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
}

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

int n,m,t;

void solve()
{
  cin>>n>>m>>t;
  int a[m],b[m],charge=n;
  bool flag=true;
  int time=0;
  for(int i=0;i<=m;++i)
  {
    if(i<m)
      cin>>a[i]>>b[i];
    else
    {a[i]=t;
     b[i]=t;
    }
    charge= charge-(a[i]-time);

    if(charge<=0) flag=false;

    charge=min(n, charge+b[i]-a[i]);

    time=b[i];

  }

  if  (flag) cout<<"Yes";  else cout<<"No";

}

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

      solve();

 return 0;
}


#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);

  int n, t; cin >> n >> t;
  vector<int> a(n);
  for (int &x : a) cin >> x;
  uin(n, 20);
  int m = SZ(a) - n;
  set<i64> b;
  for (int nask = 0; nask < (1 << n); ++nask) {
    i64 sum = 0;
    for (int k = 0; k < n; ++k) {
      if (nask >> k & 1) {
        sum += a[k];
      }
    }
    b.insert(sum);
  }
  i64 ans = 0;
  for (int nask = 0; nask < (1 << m); ++nask) {
    i64 sum = 0;
    for (int k = 0; k < m; ++k) {
      if (nask >> k & 1) {
        sum += a[n + k];
      }
    }
    if (sum <= t) {
      uax(ans, sum + *prev(b.upper_bound(t - sum)));
    }
  }
  kek(ans);
}

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

LL n, t, a[45], px, py;
LL x[1100000], y[1100000];

void fx(int p, int ed, LL sum) {
    if (p > ed) {
        x[++px] = sum;
        return;
    }
    fx(p + 1, ed, sum);
    fx(p + 1, ed, sum + a[p]);
    return;
}

void fy(int p, int ed, LL sum) {
    if (p > ed) {
        y[++py] = sum;
        return;
    }
    fy(p + 1, ed, sum);
    fy(p + 1, ed, sum + a[p]);
    return;
}

int main() {
    scanf("%lld%lld", &n, &t);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    fx(1, n / 2, 0LL);
    fy(n / 2 + 1, n, 0LL);
    sort(x + 1, x + px + 1);
    sort(y + 1, y + py + 1);
    LL mx = -1;
    for (int i = 1; i <= px; i++) {
        while (py > 0 && x[i] + y[py] > t) py--;
        if (py == 0) break;
        mx = max(mx, x[i] + y[py]);
    }
    printf("%lld\n", mx);
    return 0;
}


#include <bits/stdc++.h>

#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

using namespace std;
const int Nx = 1e6+10;
class node{
public:
	//variables
	int val;
	node(){
		//initialization
		val = 0;
	}
};
int arr[300001];
node tree[4*Nx];
node merge(node left,node right){
	node temp;
	//merging logic
	temp.val = (left.val ^ right.val);
	return temp;
}
void build(int indx,int start,int end){
	if(start == end){
		//leaf logic
		tree[indx].val = arr[start];
		return ;
	}
	int mid = (start + end) / 2;
	build(2*indx,start,mid);
	build(2*indx+1,mid+1,end);
	tree[indx] = merge(tree[2*indx],tree[2*indx+1]);
}
node query(int indx,int start,int end,int qs,int qe){
	if(qs > end || qe < start){
		node temp;
		return temp;
	}
	if(qs <= start && end <= qe){
		return tree[indx];
	}
	int mid = (start + end) / 2;
	return merge(query(2*indx,start,mid,qs,qe),query(2*indx+1,mid+1,end,qs,qe));
}
void update(int node,int start,int end,int indx,int val = -1){
	if(start == end){
		//update logic
		tree[node].val = (tree[node].val ^ val);
		return ;
	}
	int mid = (start + end)/2;
	if(indx <= mid){
		update(2*node,start,mid,indx,val);
	}else{
		update(2*node+1,mid+1,end,indx,val);
	}
	tree[node] = merge(tree[2*node],tree[2*node+1]);
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,q;
	cin >> n >> q;
	for(int i = 0;i < n;i++){
		cin >> arr[i];
	}
	build(1,0,n - 1);
	while(q--){
		int t,a,b;
		cin >> t >> a >> b;
		if(t == 2){
			a--;
			b--;
			cout << query(1,0,n - 1,a,b).val << "\n";
		}else{
			a--;
			update(1,0,n-1,a,b);
		}
	}
}

#include <bits/stdc++.h>

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

using namespace std;

using graph=vector<vector<int>>;

void add_undirected_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

void add_directed_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
}

int dep[200000];
vector<int> D[200000];

void dfs(int u,int p,const graph& T){
	D[dep[u]].emplace_back(u);
	for(int v:T[u]) if(v!=p) {
		dep[v]=dep[u]+1;
		dfs(v,u,T);
	}
}

class Euler_tour_for_subtrees{
	vector<int> L,R;
	const graph& Tr;
	int idx;
	void dfs(int u,int p){
		L[u]=idx++;
		for(int v:Tr[u]) if(v!=p) dfs(v,u);
		R[u]=idx;
	}
public:
	Euler_tour_for_subtrees(const graph& Tr,int root):L(Tr.size()),R(Tr.size()),Tr(Tr),idx(0){
		dfs(root,-1);
	}
	int get_index(int u)const{ return L[u]; }
	pair<int,int> get_subtree(int u)const{ return {L[u],R[u]}; }
};

int main(){
	int n; scanf("%d",&n);
	graph T(n);
	for(int v=1;v<n;v++){
		int u; scanf("%d",&u); u--;
		add_undirected_edge(T,u,v);
	}

	dfs(0,-1,T);

	Euler_tour_for_subtrees ET(T,0);

	int q; scanf("%d",&q);
	rep(_,q){
		int u,d; scanf("%d%d",&u,&d); u--;
		if(dep[u]>d){
			puts("0");
			continue;
		}

		auto [L,R]=ET.get_subtree(u);
		if(D[d].empty() || R<=ET.get_index(D[d][0]) || ET.get_index(D[d].back())<L){
			puts("0");
			continue;
		}

		int lo=-1,hi=int(D[d].size())-1;
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			int idx=ET.get_index(D[d][mi]);
			if(L<=idx){
				hi=mi;
			}
			else lo=mi;
		}
		int l=hi;

		lo=0; hi=D[d].size();
		while(hi-lo>1){
			int mi=(lo+hi)/2;
			int idx=ET.get_index(D[d][mi]);
			if(idx<R){
				lo=mi;
			}
			else hi=mi;
		}
		int r=hi;

		printf("%d\n",r-l);
	}

	return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll comb(ll n,ll k){
    ll ans = 1;
    REP(i, k)
    {
        ans *= n - i;
        ans /= i + 1;
    }
    return ans;
}

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

    ll N;
    string S;
    cin >> S;
    ll ans = 0;

    REP(i,10){
        REP(j,10){
            REP(k,10){
                REP(l,10){
                    bool flag = true;

                    REP(a,10){
                        if(S.at(a)=='o'){
                            if (a == i || a == j || a == k || a == l)
                            {
                            }
                            else
                            {
                                flag = false;
                                break;
                            }
                        }
                        else if(S.at(a)=='x'){
                            if (a == i || a == j || a == k || a == l){
                                flag = false;
                                break;
                            }
                            else{

                            }
                        }
                    }

                    if(flag){
                        ans++;
                    }
                    flag = true;
                }
            }
        }
    }
    cout << ans << endl;

    /*ll ok = 0, ng = 0, hatena = 0;
    REP(i,10){
        if(S.at(i)=='o'){
            ok++;
        }
        else if(S.at(i)=='x'){
            ng++;
        }
        else{
            hatena++;
        }
    }

    if(ok>=5){
        cout << 0 << endl;
    }
    else if(ng)*/
}

/**
*    author:  shu8Cream
*    created: 15.05.2021 20:32:47
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll n = s.size();
    ll maru = 0, batsu = 0, hate = 0;
    rep(i,n){
        if(s[i]=='o') maru++;
        if(s[i]=='x') batsu++;
        if(s[i]=='?') hate++;
    }
    ll ans = 0;
    rep(i,10)rep(j,10)rep(k,10)rep(l,10){
        string t = "xxxxxxxxxx";
        t[i] = 'o';
        t[j] = 'o';
        t[k] = 'o';
        t[l] = 'o';
        bool f = true;
        rep(_,10){
            if(s[_]=='x' && t[_]=='o') f = false;
            if(s[_]=='o' && t[_]=='x') f = false;
        }
        if(f) ans++;
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int n,flg[200005];string s[200005];char ch[15];
map<string,int>M;
int main(){
	n=read();
	for(int i=1;i<=n;++i){scanf("%s",ch);if(ch[0]=='!')s[i]=ch+1,flg[i]=1;else s[i]=ch;}
	for(int i=1;i<=n;++i)if(!flg[i])M[s[i]]=1;
	for(int i=1;i<=n;++i)if(flg[i]&&M[s[i]])return cout<<s[i],0;
	puts("satisfiable");
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n;
    cin >> n;
    map<string,i64> mp;
    vec<string> s(n);
    rep(i,n){
        cin >> s[i];
        mp[s[i]]++;
    }
    rep(i,n){
        string now = s[i];
        i64 cnt = 0;
        if(mp[now] >= 1){
            cnt++;
        }
        string t = "!";
        t = t + now;
        if(mp[t] >= 1)cnt++;
        if(cnt == 2){
            cout << now << endl;
            return 0;
        }
    }
    cout << "satisfiable" << endl;
}


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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    cin>>t;
    while(t--) {
        ll n,s,k;
        cin>>n>>s>>k;
        ll x,y;
        x=0,y=0;
        ll g=__gcd(n,k);
        if(s%g!=0) {
            cout<<"-1"<<endl;
        }
        else {
            k/=g;
            n/=g;
            s/=g;
            ll a=(-s+n)%n;
            ll kk=gcd(k,n,x,y);
            ll b=x;
            cout<<((a*(b%n))%n+n)%n<<endl;
        }
    }
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
    /******think more code less******/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("Error.txt", "w", stderr);
    #endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
    if(a.ff!=b.ff)
        return a.ff<b.ff;
    else
    {
        if(a.ss>b.ss)
            return b.ss<a.ss;
        else if(a.ss<b.ss)
            return a.ss<b.ss;
    }
    return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        {
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b>>=1;
    }
    return res;
}

void terminAtor()
{
    ll n;
    cin>>n;
    ll a[n];
    ll ans=0,idx=0;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=2;i<=1000;i++)
    {
        ll op=0;
        for(ll j=0;j<n;j++)
        {
            ll oo=a[j]%i;
            if(oo==0)
                op++;
        }
        if(op>ans)
        {
            ans=op;
            idx=i;
        }
    }
    cout<<idx;
}

int main()
{
    checkpoint1();
/********************************************************/
    auto startrrr = high_resolution_clock::now();
    cout << setprecision(20);
/*******************************************************/

    terminAtor();

/*******************************************************/
    auto stoprrr = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stoprrr - startrrr);
    #ifndef ONLINE_JUDGE
        cerr << "Time: " << duration.count()/1000.0<<"\n";
    #endif
/*******************************************************/
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
string s;
ll ans,raod[200];
int main(){
    ios::sync_with_stdio(false);
    cin >> s;

    for(int i=(int)s.size() - 1; i>=1; i--){
        if(s[i] == s[i - 1]){
            ans += (int)s.size() - i - 1 - raod[s[i] - 'a'];
            for(int j=0; j<26; j++)
                raod[j] = 0;
            raod[s[i] - 'a'] = (int)s.size() - i;
        }
        else {
            raod[s[i] - 'a']++;
        }
    }

    cout << ans << '\n';

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
namespace Flandre_Scarlet
{
    #define N 200005
    #define int long long
    #define mod 1000000007
    #define F(i,l,r) for(int i=l;i<=r;++i)
    #define D(i,r,l) for(int i=r;i>=l;--i)
    #define Fs(i,l,r,c) for(int i=l;i<=r;c)
    #define Ds(i,r,l,c) for(int i=r;i>=l;c)
    #define MEM(x,a) memset(x,a,sizeof(x))
    #define FK(x) MEM(x,0)
    #define Tra(i,u) for(int i=G.st(u),v=G.to(i);~i;i=G.nx(i),v=G.to(i))
    #define p_b push_back
    #define sz(a) ((int)a.size())
    #define all(a) a.begin(),a.end()
    #define iter(a,p) (a.begin()+p)
    int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);}
    template <typename T> void Rd(T& arg){arg=I();}
    template <typename T,typename...Types> void Rd(T& arg,Types&...args){arg=I(); Rd(args...);}
    void RA(int *p,int n) {F(i,1,n) *p=I(),++p;}
    class Graph
    {
        public:
        struct edge{int v,w,nx;} pe[N<<1]; edge*e;
        int ph[N]; int *head; int ecnt;
        void clear()
        {
            MEM(pe,-1); MEM(ph,-1); e=pe+2; head=ph+2; ecnt=-1;
        }
        void add(int u,int v,int w)
        {
            e[++ecnt]=(edge){v,w,head[u]}; head[u]=ecnt;
        }
        void ad2(int u,int v,int w)
        {
            add(u,v,w),add(v,u,w);
        }
        int&st(int u){return head[u];} int&to(int i){return e[i].v;} int&wei(int i){return e[i].w;} int&nx(int i){return e[i].nx;}
    }G;
    int n;
    void Input()
    {
        n=I(); G.clear();
        F(i,1,n-1)
        {
            int u,v,w; Rd(u,v,w);
            G.ad2(u,v,w);
        }
    }
    int xor_s[N];
    void DFS(int u,int f)
    {
        Tra(i,u) if (v!=f)
        {
            xor_s[v]=xor_s[u]^G.wei(i);
            DFS(v,u);
        }
    }
    int suf[N];
    void Sakuya()
    {
        xor_s[1]=0;
        DFS(1,1);
        int ans=0;
        D(k,60,0)
        {
            int have=0;
            F(i,1,n)
            {
                if ((xor_s[i]>>k)&1) ++have;
            }
            int cur=(have*(n-have))%mod*((1ll<<k)%mod)%mod;
            // C(have,2)*(1<<k)
            ans=(ans+cur)%mod;
        }
        printf("%lld\n",ans);
    }
    void IsMyWife()
    {
        Input();
        Sakuya();
    }
}
#undef int //long long
int main()
{
    Flandre_Scarlet::IsMyWife();
    getchar();
    return 0;
}


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

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

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

	int N = getint();
	int k1, k2, x1 = -1e9, x2 = -1e9, y1, y2;
	int k3, k4, x3 = 1e9, x4 = 1e9, y3, y4;
	int k5, k6, x5, x6, y5 = -1e9, y6 = -1e9;
	int k7, k8, x7, x8, y7 = 1e9, y8 = 1e9;
	rep(i, N) {
		int x = getint(), y = getint();
		if (x2 < x) {
			k2 = i;
			x2 = x;
			y2 = y;
			if (x1 < x2) {
				swap(k1, k2);
				swap(x1, x2);
				swap(y1, y2);
			}
		}
		if (x4 > x) {
			k4 = i;
			x4 = x;
			y4 = y;
			if (x3 > x4) {
				swap(k3, k4);
				swap(x3, x4);
				swap(y3, y4);
			}
		}
		if (y6 < y) {
			k6 = i;
			x6 = x;
			y6 = y;
			if (y5 < y6) {
				swap(k5, k6);
				swap(x5, x6);
				swap(y5, y6);
			}
		}
		if (y8 > y) {
			k8 = i;
			x8 = x;
			y8 = y;
			if (y7 > y8) {
				swap(k7, k8);
				swap(x7, x8);
				swap(y7, y8);
			}
		}
	}
	pair<int, ll> list[8];
	list[0] = { -x3 + x1, ll(k3 | k1) << 32 | (k3 & k1) };
	list[1] = { -x4 + x1, ll(k4 | k1) << 32 | (k4 & k1) };
	list[2] = { -x3 + x2, ll(k3 | k2) << 32 | (k3 & k2) };
	list[3] = { -x4 + x2, ll(k4 | k2) << 32 | (k4 & k2) };
	list[4] = { -y7 + y5, ll(k7 | k5) << 32 | (k7 & k5) };
	list[5] = { -y8 + y5, ll(k8 | k5) << 32 | (k8 & k5) };
	list[6] = { -y7 + y6, ll(k7 | k6) << 32 | (k7 & k6) };
	list[7] = { -y8 + y6, ll(k8 | k6) << 32 | (k8 & k6) };
	sort(list, list + 8);

	if (list[7].second == list[6].second) co(list[5].first);
	else co(list[6].first);

	Would you please return 0;
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
#define hmap gp_hash_table<ll, ll>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

  ll n;
  cin>>n;

  pii arr[n];
  rep(n)
        cin>>arr[i].ff>>arr[i].ss;
  map<pii,ll> dis;
  vector<pii> x,y;
  rep(n)
        x.pb(mp(arr[i].ff,i)), y.pb(mp(arr[i].ss,i));
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  for(ll i=0;i<3;i++)
  {
      for(ll j=n-1;j>=n-3;j--)
      {
          if(j != i)
          {
              ll i1 = x[i].ss, i2 = x[j].ss;
              if(i1>i2)
                    swap(i1,i2);
              dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss)));
          }
      }

      for(ll j=0;j<3;j++)
      {
          if(j != i)
          {
              ll i1 = x[i].ss, i2 = x[j].ss;
              if(i1>i2)
                    swap(i1,i2);
              //cout<<max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))<<"\n";
              dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss)));
          }
      }
  }

  for(ll i=0;i<3;i++)
  {
      for(ll j=n-1;j>=n-3;j--)
      {
          if(j != i)
          {
              ll i1 = y[i].ss, i2 = y[j].ss;
              if(i1>i2)
                    swap(i1,i2);
              dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss)));
          }
      }

      for(ll j=0;j<3;j++)
      {
          if(j != i)
          {
              ll i1 = y[i].ss, i2 = y[j].ss;
              if(i1>i2)
                    swap(i1,i2);
              dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss)));
          }
      }
  }

  vector<ll> v;
  autoit(dis,it)
        v.pb(it->ss);// cout<<"for "<<it->ff.ff<<" , "<<it->ff.ss<<" = "<<it->ss<<'\n';
  sort(v.begin(),v.end(),greater<ll>());
  cout<<v[1]<<"\n";

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e3 + 5;
const int modu = 1e9 + 7;
const double inf = 0x3f3f3f3f;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

LL n, m;

int main() {
    // freopen("my.txt", "w", stdout);
    cin >> n >> m;
    LL tmp = 1, a = 10;
    while (n) {
        if (n&1) tmp = tmp*a % (m*m);
        a = (a*a) % (m*m);
        n >>= 1;
    }
    cout << tmp / m << endl;
	return 0;
}

#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iostream>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <vector>
using namespace std;
#ifndef ONLINE_JUDGE
#define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#else
#define File(s)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define mkp make_pair
#define pb push_back
#define SP putchar(' ')
#define EL putchar('\n')

mt19937 rnd(chrono :: steady_clock :: now().time_since_epoch().count());
mt19937_64 rnd64(chrono :: steady_clock :: now().time_since_epoch().count()) ;

template<class T> inline void gi(T &x){
  char ch; x = 0;int f = 1;
  while(isspace(ch = getchar()));
  if(ch == '-') ch = getchar(), f = -1;
  do x = x * 10 + ch - '0'; while(isdigit(ch = getchar()));
  x *= f;
}
template<class T> inline void wi(T x){
  static char stk[128]; int top = 0;
  if(x == 0) putchar('0');
  if(x < 0) putchar('-'), x = -x;
  while(x) stk[++top] = x % 10, x /= 10;
  while(top) putchar(stk[top--] + '0');
}
template<class T, class ...Args>
inline void gi(T &x, Args&... args) {gi(x); gi(args...);}
template<class T, class ...Args>
inline void wi(T x, Args... args) {wi(x); SP; wi(args...);}
template<class T> void upmax(T &x, T y) {x = x > y ? x : y;}
template<class T> void upmin(T &x, T y) {x = x < y ? x : y;}

inline int power(ll x, ll y, ll m) {
  ll p = 1;
  for (; y; y >>= 1, x = x * x % m) if (y & 1) p = p * x % m;
  return p;
}

int main() {
  ll n, m;
  gi(n, m);
  printf("%lld\n", power(10, n, m * m) / m % m);
  return 0;
}


//Coded by Abhijay Mitra (AbJ)
#include "bits/stdc++.h"
#define double long double
#define int long long int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = 1e18 + 10;
const int N = 2e6 + 10;
int n, a[N];
void solve(){
	cin >> n;
	rep(i, 1LL, n){
		cin >> a[i];
	}
	vi v;
	if(n == 1LL){
	}
	else if(n == 2LL){
		if(a[1LL] == 2LL){
			v.pb(1LL);
			swap(a[1LL], a[2LL]);
		}
	}
	else{
		rep(i, 1LL, n - 3LL){
			rep(j, i + 1, n){
				if(a[j]==i){
					if((((int)v.size() ) & 1) != (j & 1)){
						if(((int)v.size() & 1) == (n & 1)){
							v.pb(n - 1LL);
							swap(a[n - 1LL], a[n]);
						}
						else{
							v.pb(n - 2LL);
							swap(a[n - 2LL], a[n - 1LL]);
						}
					}
					per(pos, j - 1, i){
						v.pb(pos);
						swap(a[pos], a[pos + 1LL]);
					}
				}
			}
		}
	}
	while(a[n] != n or a[n - 1LL] != n - 1LL or a[n - 2LL] != n - 2LL){
		if(((int)v.size() & 1LL) == (n & 1LL)){
			v.pb(n - 1LL);
			swap(a[n - 1LL], a[n]);
		}
		else{
			v.pb(n - 2LL);
			swap(a[n - 2LL], a[n - 1LL]);
		}
	}
	assert((int)v.size() <= n * n);
	assert(is_sorted(a + 1LL, a + 1LL + n));
	cout << v.size() << "\n";
	for(auto &i: v){
		cout << i << " ";
	}
}
int32_t main(){
	ibs;cti;
	// solve(); return 0;
	int t; cin >> t;
	while (t--){
		solve(); cout << "\n";
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;
void solve();

int main()
{
    srand((unsigned)time(NULL));
    int T;
    cin >> T;
    while(T--)solve();
}

template<class T> ostream& operator<<(ostream& os, const vector<T> arr){ for(int i = 0; i < (int)arr.size(); i++)cout << arr[i] << (i == (int)arr.size() -1 ? "" : " "); return os;}
// #include"debug.hpp"

void solve()
{

    int N; cin >> N;
    vector<int> a(N);
    for(auto &i : a) cin >> i;
    int sel = 0;
    vector<int> ans;
    vector<int> moto = a;

ST:

    while(is_sorted(a.begin(), a.end()) == false) {

        // print(a);
        vector<tuple<int,int,int>> p;
        for(int i = sel; i < N - 1; i += 2) {
            p.push_back({a[i], a[i + 1], i});
        }
        sel = !sel;

        bool ok = false;
        for(auto &[u, v, c] : p) {
            if(u > v) {
                ans.push_back(c + 1);
                swap(a[c], a[c + 1]);
                ok = true;
                break;
            }
        }

        if(ok)continue;
        int v = rand() % (int)p.size();
        ans.push_back(get<2>(p[v]) + 1);
        swap(a[get<2>(p[v])], a[get<2>(p[v]) + 1]);

    }

    if(ans.size() > N * N) {
        a = moto;
        ans.resize(0);
        sel = 0;
        goto ST;
    }
    cout << ans.size() << endl;
    cout << ans << endl;

}

/*
1 10
1
6
9
2
8
5
3
4
10
7
*/


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1000000007LL;

int main(void){
    int N, M;
    cin >> N >> M;
    vector<ll> H(N), W(M);
    for(int i = 0; i < N; i++) cin >> H[i];
    sort(H.begin(), H.end());
    for(int i = 0; i < M; i++) cin >> W[i];
    sort(W.begin(), W.end());
    vector<ll> L(N, 0), R(N, 0);
    for(int i = 1; i < N - 1; i += 2){
        L[i + 1] = L[i - 1] + H[i] - H[i - 1];
    }
    for(int i = N - 2; i > 0; i -= 2){
        R[i - 1] = R[i + 1] + H[i + 1] - H[i];
    }

    // for(int i = 0; i < N; i++) cout << L[i] << "\t";
    // cout << endl;
    // for(int i = 0; i < N; i++) cout << R[i] << "\t";
    // cout << endl;

    ll ans = 1000000000000000000LL;
    for(int i = 0; i < M; i++){
        auto itr = lower_bound(H.begin(), H.end(), W[i]);
        int idx = distance(H.begin(), itr);
        idx = 2 * (idx / 2);
        ll sub = abs(W[i] - H[idx]);
        sub += L[idx] + R[idx];
        ans = min(sub, ans);
        // if(sub == 30) cout << i << endl;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define pll pair<long long, long long>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N >> W;
    if (N > 40)
        return 0;
    vector<ll> v(N), w(N);
    REP(i, N) {
        cin >> v[i]; // >> w[i];
        w[i] = v[i];
    }
    vector<pair<ll, ll>> wv1(1);
    vector<pair<ll, ll>> wv2(1);
    auto merge = [](vector<pll> &wv, pll a) {
        auto [w, v] = a;
        vector<pll> res;
        int y = 0;
        REP(x, wv.size()) {
            while (wv[y].first + w < wv[x].first) {
                res.push_back({wv[y].first + w, wv[y].second + v});
                y++;
            }
            res.push_back(wv[x]);
        }
        FOR(i, y, wv.size()) {
            res.push_back({wv[i].first + w, wv[i].second + v});
        }
        return res;
    };
    REP(i, N) {
        wv1 = merge(wv1, {w[i], v[i]});
        swap(wv1, wv2);
    }

    auto f = [](vector<pll> &wv) {
        ll now = -1;
        vector<pair<ll, ll>> res;
        REP(i, wv.size()) {
            if (chmax(now, wv[i].second)) {
                res.push_back(wv[i]);
            }
        }
        return res;
    };
    wv1 = f(wv1);
    wv2 = f(wv2);
    dump(wv1, wv2);
    int ind = wv2.size() - 1;
    for (auto [w1, v1] : wv1) {
        if (w1 > W)
            break;
        while (w1 + wv2[ind].first > W) {
            ind--;
        }
        chmax(ans, v1 + wv2[ind].second);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
long decimalToOctal(long n) {
    int remainder;
    long octal = 0, i = 1;

    while(n != 0) {
        remainder = n%8;
        n = n/8;
        octal = octal + (remainder*i);
        i = i*10;
    }
    return octal;
}

int main() {

 ll n;
 cin>>n;
 ll ans=0;
 set<ll> s;
 for (ll i = 1; i <= n; i++)
 {
     ans=0;
       int tem=i;
        while (tem!=0)
        {
            ll digit=tem%10;
            if(digit==7){

                ans++;
                  s.insert(i);
              // cout<<i<<endl;
                break;
            }
            tem/=10;
            if(ans!=0){

            }

        }

       ll oc=decimalToOctal(i);

           ans=0;

             while (oc!=0)
           {
            ll digit=oc%10;
            if(digit==7){

                ans++;
                  s.insert(i);
              // cout<<i<<endl;
                break;
            }
            oc/=10;

          }

        //cout<<decimalToOctal(i)<<endl;

 }

 cout<<n-s.size()<<endl;

}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define pf push_front
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll mod=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
ll llpow(ll n,ll i){if(i==0){return 1;}ll cnt=n;for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};
mint f2(ll n) {if (n == 0) return 1;mint x = f2(n/2);x *= x;if (n%2 == 1) x *= 2;return x;}
mint choose(int n,int a){mint x=1,y=1;rep(i,a){x*=n-i;y*=i+1;}return x/y;}
ll xs/*xorsum nまでのxorの和*/(ll n){ll cnt=(n+1)/2;ll ans=cnt%2;if(n%2==0) ans^=n;return ans;}
ll Fa/*Factorial nの階乗*/(ll n){ll ans=1;rrep(i,n){ans*=i;}return ans;}

int main() {
    int n;cin>>n;
    double ans=0.0;
    for(int i=n-1;i>=1;i--){
        ans+=double(n)/double(i);
    }
    printf("%.10f\n",ans);
    return 0;
}


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

int main() {
     long long int a,b;
     cin>>a>>b;
     if(b<a){
         long long sum=0;
         long long bum=0;
     for(int i=1;i<=a;i++){
         cout<<i<<" ";
         sum=sum+i;
     }
     for(int i=1;i<=b-1;i++){
         cout<<(-1)*i<<" ";
         bum=bum+i;
     }
     cout<<bum-sum;
     }
     else{
         long long sum=0;
         long long bum=0;
     for(int i=1000000;i<a+1000000;i++){
         cout<<i<<" ";
         sum=sum+i;
     }
     for(int i=1;i<=b-1;i++){
         cout<<(-1)*i<<" ";
         bum=bum+i;
     }
     cout<<bum-sum;
     }
	return 0;
}

#include <iostream>
using namespace std;
int mtf,mf;
int sum;

int main()
{
    cin>>mtf>>mf;
    sum = mtf+mf;
    if(sum>=15&&mf>=8)
    cout<<1;
    else
    if(sum>=10&&mf>=3)
    cout<<2;
    else
    if(sum>=3)
    cout<<3;
    else
    cout<<4;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> edges[26];
vector<pair<int, int>> states[1024][1024];
int d[1024][1024];

int main()
{
  int N, M;

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

  queue<pair<int, int>> q;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      d[i][j] = 1'000'000'000;
    }
    d[i][i] = 0; q.emplace(i, i);
  }

  for (int i = 0; i < M; i++) {
    int u, v; char c[2];
    scanf("%d %d %s", &u, &v, c);
    if (u > v) swap(u, v);
    edges[c[0] - 'a'].emplace_back(u, v);
    if (u != v) d[u][v] = d[v][u] = 1;
    q.emplace(u, v);
  }

  for (int a = 0; a < 26; a++) {
    int sz = edges[a].size();
    for (int i = 0; i < sz; i++) {
      for (int j = i + 1; j < sz; j++) {
        auto [u, v] = edges[a][i];
        auto [w, x] = edges[a][j];
        states[u][w].emplace_back(v, x); states[w][u].emplace_back(v, x);
        states[u][x].emplace_back(v, w); states[x][u].emplace_back(v, w);
        states[v][w].emplace_back(u, x); states[w][v].emplace_back(u, x);
        states[v][x].emplace_back(u, w); states[x][v].emplace_back(u, w);
      }
    }
  }

  while (q.size()) {
    auto [u, v] = q.front(); q.pop();
    if (u > v) swap(u, v);
    if (u == 1 && v == N) {
      printf("%d\n", d[u][v]); return 0;
    }
    for (auto [u2, v2] : states[u][v]) {
      if (d[u2][v2] == 1'000'000'000) {
        d[u2][v2] = d[v2][u2] = d[u][v] + 2;
        q.emplace(u2, v2);
      }
    }
  }

  printf("-1\n");

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
/*
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
*/
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}
ll mod_pow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

const int mod = 1e9 + 7;

bool check(vector<vector<int>> &A, int K, int c) {
    int N = A.size();
    vector<vector<int>> B(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            B[i][j] = (A[i][j] <= c);
        }
    }
    vector<vector<int>> acc(N + 1, vector<int>(N + 1));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            acc[i][j] = acc[i - 1][j] + acc[i][j - 1] - acc[i - 1][j - 1] + B[i - 1][j - 1];
        }
    }
    for (int i = 0; i <= N - K; i++) {
        for (int j = 0; j <= N - K; j++) {
            int sum = acc[i + K][j + K] - acc[i][j + K] - acc[i + K][j] + acc[i][j];
            if (sum >= (K * K + 1) / 2) return true;
        }
    }
    return false;
}

void solve() {
    int N, K;
    cin >> N >> K;
    vector<vector<int>> A(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }
    int ok = 1e9 + 1, ng = -1;
    while(ok - ng > 1) {
        int c = (ok + ng) / 2;
        if (check(A, K, c)) {
            ok = c;
        } else {
            ng = c;
        }
    }
    cout << ok << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}


#include<bits/stdc++.h>
#define endl '\n'
#define QAQ(m, n) for(ll i = m;i <= n;i++)
#define QWQ(m, n) for(ll j = m;j <= n;j++)
#define FOR(k, m, n) for(ll k = m;k <= n;k++)
#define uQAQ(n, m) for(ll i = n;i >= m;--i)
#define uQWQ(n, m) for(ll j = n;j >= m;--j)
#define uFOR(k, n, m) for(ll k = n;k >= m;--k)
#define ALL(a) a.begin(), a.end()
#define all(a, n) a + 1, a + n + 1
#define fin(a) freopen(a, "r", stdin)
#define fout(a) freopen(a, "w", stdout)
#define pb push_back
#define mkp std::make_pair
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
ll n, m;
string s[801];
int main ()
{
	std::cin.tie (0);
	std::ios::sync_with_stdio (false);
	cin >> n >> m;
	QAQ (1, m)
		cin >> s[i];
	sort (all (s, n), [](string a, string b) { return a.size () > b.size (); });
	ll now = 1;
	QAQ (1, n)
	{
		ll t = n;
		while (t > (ll) s[now].size ())
			cout << s[now], t -= s[now++].size ();
		while (t > 0)
			cout << '.', --t;
		cout << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
#define pow(n,m) powl(n,m)
#define sqrt(n) sqrtl(n)
const ll MAX = 5000000000000000000;
const ll MOD = 0;
random_device rd;
mt19937 mt(rd());
int main(){
    ll N,M;
    cin >> N >> M;
    vector<string> S(M),ans(N),T;
    set<string> ss;
    ll m = MAX;
    for(ll i = 0;i < M;i++) cin >> S[i];
    for(ll i = 0;i < M;i++) ss.insert(S[i]);
    for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size());
    for(ll t = 0;t < 35000;t++){
        string a = S[mt() % M];
        for(ll i = 0;i < 10;i++){
            string b = S[mt() % M];
            if(a.size() + b.size() <= N){
                a += b;
            }
        }
        while(a.size() < N) a += (char)('A' + (mt() % 8));
        T.emplace_back(a);
    }
    vector<ll> aaaa;
    do{
        for(ll j = 0;j < T.size();j++){
            set<string> c;
            for(ll k = 0;k < N;k++){
                string p = "";
                for(ll l = 0;l < m;l++){
                    p += T[j][(k + l) % N];
                }
                for(ll l = m;l < m + 5;l++){
                    p += T[j][(k + l) % N];
                    if(ss.count(p) != 0) c.insert(p);
                }
            }
            aaaa.emplace_back(c.size());
        }
    } while(false);
    sort(aaaa.begin(),aaaa.end(),greater<ll>());
    for(ll i = 0;i < N;i++){
        ll C = 0;
        string A = "____________________";
        for(ll j = 0;j < T.size();j++){
            set<string> c;
            for(ll k = 0;k < N;k++){
                string p = "";
                for(ll l = 0;l < m;l++){
                    p += T[j][(k + l) % N];
                }
                for(ll l = m;l < m + 5;l++){
                    p += T[j][(k + l) % N];
                    if(ss.count(p) != 0) c.insert(p);
                }
            }
            if(C < c.size()){
                C = c.size();
                A = T[j];
            }
            if(i == 0 && aaaa[1000] > c.size()){
                T.erase(T.begin() + j);
                j--;
            }
        }
        for(ll k = 0;k < N;k++){
            string p = "";
            for(ll l = 0;l < m;l++){
                p += A[(k + l) % N];
            }
            for(ll l = m;l < m + 5;l++){
                p += A[(k + l) % N];
                if(ss.count(p) != 0) ss.erase(p);
            }
        }
        ans[i] = A;
    }
    ll C = 0;
    vector<string> ansans = ans,ansansans = ans;
    if(m < 5){
        for(ll t = 0;t < 1000;t++){
            swap(ans[mt() % N],ans[mt() % N]);
            for(ll i = 0;i < N;i++){
                ll qqq = mt() % N;
                for(ll j = 0;j < N;j++) ansans[j][i] = ans[i][(j + qqq) % N];
            }
            set<string> c;
            for(ll i = 0;i < N;i++){
                for(ll k = 0;k < N;k++){
                    string p = "";
                    for(ll l = 0;l < m;l++){
                        p += ansans[i][(k + l) % N];
                    }
                    for(ll l = m;l < m + 5;l++){
                        p += ansans[i][(k + l) % N];
                        if(ss.count(p) != 0) c.insert(p);
                    }
                }
            }
            if(C < c.size()){
                C = c.size();
                ansansans = ansans;
            }
        }
    }
    //cout<<C<<endl;
    for(ll i = 0;i < N;i++) cout << ansansans[i] << endl;
}


//---------------------------------------------------------JAI HIND------------------------------------------------------------------------

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define Summon_Tourist ios::sync_with_stdio(false); cin.tie(0);
ll inf = 998244353;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll extgcd(ll a, ll b, ll *x, ll *y) { if (b == 0){*x = 0;*y = 1;return a;}ll x1, y1;ll g = extgcd(b, a % b, &x1, &y1);*x = y1 - (a / b) * x1;*y = x1;return g; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modexp(ll base, ll power){if (power == 0)return 1;if (power & 1)return base * modexp(base, power - 1) % inf;return modexp(base * base % inf, power / 2); }
ll modinv(ll a, ll mod){ ll x, y;ll g = extgcd(a, mod, &x, &y); if (g != 1) return 0; return (y + mod) % mod; }

//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int main()
{
    Summon_Tourist
    ll t = 1;
    //cin>>t;
    while (t--)
    {

        int a,b; cin>>a>>b;
        int which = 1;
        if( b<a ){
            int z = b;
            b = a,a = z;
            which = 0;
        }

        int avg = b/a,rem = b%a;
        rem = a - rem;

        vector<int> av,bv;
        int count = 1;
        for( int i = 0 ; i<a; i++ ){
            int correspond = 0;
            for( int j = 0 ; j<avg; j++ ){
                bv.emplace_back(count);
                correspond += count;
                ++count;

            }
            if( rem-- <= 0 ){
                bv.emplace_back(count);
                correspond += count;
                ++count;
            }

            av.emplace_back(correspond);

            correspond = 0;
        }

        for( int i = 0 ; i<a; i++ ){
            if( which == 1 ) cout<<av[i]<<" ";
            else cout<<-av[i]<<" ";
        }
        for( int i = 0 ; i<b; i++ ){
            if( which == 1 ) cout<<-bv[i]<<" ";
            else cout<<bv[i]<<" ";
        }

    }
    return 0;
}

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

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 2005

ll A,B;
ll table[SIZE];

int main(){

	scanf("%lld %lld",&A,&B);

	ll sum = 0;

	for(ll i = 0; i < A; i++){

		table[i] = i+1;
		sum += table[i];
	}

	for(ll i = 0; i < B; i++){

		table[A+i] = -(i+1);
		sum += table[A+i];
	}

	if(sum > 0){

		table[A+B-1] -= sum;

	}else if(sum < 0){

		table[A-1] += abs(sum);
	}

	printf("%lld",table[0]);

	for(ll i = 1; i < A+B; i++){

		printf(" %lld",table[i]);
	}
	printf("\n");

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define Bs binary_search
#define In insert
#define Mp make_pair
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second

const int mx1 = 20;
const int mx2 = 505;
const int mx3 = 1005;
const int mx4 = 30005;
const int mx5 = 100005;
const int mx6 = 1000005;

typedef vector<int> Vi;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vi> VVi;
typedef pair<int, int> Pii;
typedef pair<DD, DD> Pdd;
typedef vector<Pii> Vpi;
typedef vector<Pdd> Vpd;
typedef queue<int> Qi;
typedef stack<int> Si;
typedef deque<int> Di;

int _toggle(int N, int pos) {return N = N ^ (1 << pos);}
int _set(int N, int pos) {return N = N | (1 << pos);}
int _reset(int N, int pos) {return N = N & ~(1 << pos);}
bool _check(int N, int pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///******************************************************///

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

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    int ans = 1e9;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j){
                ans = min(ans, a[i] + b[j]);
            }
            else{
                ans = min(ans, max(a[i], b[j]));
            }
        }
    }
    cout << ans << '\n';
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int tc = 1;
    //cin >> tc;
    while(tc--){
        solve();
    }
}

#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define pie  3.14159265
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)

void solve()
{
	ll n;
	cin >> n;
	vi a(n);
	ll s = 0;
	fr(i, 0, n)
	{
		cin >> a[i];
		s += a[i];
	}
	vi dp(s + 1, 0);
	dp[0] = 1;
	ll ans = 1e9;
	fr (i, 0, n)
	{
		for (ll j = s - a[i]; j >= 0; j--)
		{
			if (dp[j] == 1)
			{
				dp[j + a[i]] = 1;
				ll x = s - (j + a[i]);
				ans = min(ans, max(x, j + a[i]));
			}
		}
	}
	cout << ans << endl;

}

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


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 5050;
int n, m;
int pw[N][N];

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

	for (int x = 0; x < N; x++) {
		pw[x][0] = 1;
		for (int i = 1; i < N; i++)
			pw[x][i] = mult(pw[x][i - 1], x);
	}
	scanf("%d%d", &n, &m);
	int ans = 0;
	for (int i = 0; i < n; i++)
		for (int x = 1; x <= m; x++) {
			ans = add(ans, mult(pw[m - x][i], pw[m][n - 1 - i]));
		}
	for (int d = 1; d < n; d++)
		for (int x = 1; x <= m; x++) {
			ans = add(ans, mult(mult(n - d, x - 1), mult(pw[m - x][d - 1], pw[m][n - 1 - d])));
		}
	printf("%d\n", ans);

	return 0;
}

// Problem: C - Sequence Scores
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

//愿神 zhoukangyang 指引我。
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int p=998244353;
int Q[5003][5003];
int qp(int x,int y)
{
	return Q[x][y];
}
signed main()
{
	for(int i=1; i<=5000; i++)
	{
		Q[i][0]=1;
		for(int j=1; j<=5000; j++) Q[i][j]=Q[i][j-1]*i%p;
	}
	int n=read(),m=read(),ans=0;
	for(int i=1; i<=n-2; i++) for(int j=1; j<=m; j++)
		ans+=(j-1)*(j-1)*(n-i-1)%p*(p+qp(m-j+1,i)-qp(m-j,i))%p*qp(m,n-i-2)%p,ans%=p;
	for(int r=1; r<=n; r++) for(int i=1; i<=m; i++)
	{
		int t=1,k=n-r;
		if(r^n) t=1ll*t*(i-1)%p,k--;
		ans+=1ll*t*(p+qp(m-i+1,r)-qp(m-i,r))%p*qp(m,k)%p,
		ans%=p;
	}
	for(int l=2;l<=n;l++) for(int i=1;i<=m;i++)
	{
		ans+=1ll*(i-1)*(p+qp(m-i+1,n-l+1)-qp(m-i,n-l+1))%p*qp(m,l-2)%p,
		ans%=p;
	}
	printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int n,di1,di2,di;
long long t,ans;
long long a[50];
long long sum1[100000006],s,sum2[100000006],sum[10000006];

void ready()
{
    ios::sync_with_stdio(false),cin.tie(0);
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }

}

void work()
{
    for(int i=1;i<=n/2;i++)
    {
        sum1[++di1]=a[i];
        for(int j=di1-1;j>=1;j--)
            if(a[i]+sum1[j]<=t)
              sum1[++di1]=a[i]+sum1[j];
    }
    sort(sum1+1,sum1+di1+1);
    for(int i=n/2+1;i<=n;i++)
    {
    	sum2[++di2]=a[i];
        for(int j=di2-1;j>=1;j--)
            if(a[i]+sum2[j]<=t)
              sum2[++di2]=a[i]+sum2[j];
	}

	for(int i=1;i<=di2;i++)
	{
		int l=0,r=di1,mid=(l+r)/2;
		while(l<=r)
		{
			mid=(l+r)/2;
			if(sum2[i]+sum1[mid]<=t)
			  l=mid+1;
			else
			  r=mid-1;
		}
		if(sum1[(l+r)/2]+sum2[i]<=t)
			ans=max(ans,sum1[(l+r)/2]+sum2[i]);
	}
	cout<<ans;

}

void work1()
{
    if(s<=t)
    {
        cout<<s;
        return ;
    }
    for(int i=1;i<=n;i++)
    {
        sum[++di]=a[i];
        for(int j=di-1;j>=1;j--)
            if(a[i]+sum[j]<=t)
              sum[++di]=a[i]+sum[j];
    }
    sort(sum+1,sum+di+1);
    for(int i=di;i>=0;i--)
        if(sum[i]<=t)
    {

        cout<<sum[i];
        return ;
    }

}

int main()
{
    ready();
    if(n>20)
      work();
    else
      work1();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MOD = 1e9+7;

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

	ll n, t; cin >> n >> t;
	vi v(n); FOR(i, n) cin >> v[i];
	vector<ll> v1, v2;

	for(int i = 0; i < (1<<(n/2)); i++){
		ll aux = 0;
		for(int j = 0; j < n/2; j++){
			if(i&(1<<j)){
				aux += v[j];
			}
		}
		v1.PB(aux);
	}

	for(int i = 0; i < (1<<((n+1)/2)); i++){
		ll aux = 0;
		for(int j = 0; j < (n+1)/2; j++){
			if(i&(1<<j)){
				aux += v[j+n/2];
			}
		}
		v2.PB(aux);
	}

	sort(all(v2));

	ll ans = 0;
	FOR(i, v1.size()){
		int p = distance(v2.begin(),
						 lower_bound(all(v2), t-v1[i]));
		if(p == (int) v2.size() || v2[p] > t-v1[i]) p--;
		if(p >= 0) ans = max(ans, v1[i] + v2[p]);
	}

	cout << ans << '\n';

	return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

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

typedef pair<ll, ll> P;
typedef pair<string, int> Psi;

ll index_max[1234567];
ll A[1234567];
ll ruiseki[1234567];
ll ruiseki_sum[1234567];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin>>n;

	vector<pair<ll,ll>> A,B;
	vector<pair<ll,pair<ll,ll>>> C;

	for(ll i=0; i<n;i++){
		ll a,b;cin>>a>>b;

		A.push_back(P(a,i));
		B.push_back(P(b,i));
	}

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());

	C.push_back(make_pair(abs(A[0].first-A[n-1].first),P(A[0].second,A[n-1].second)));
	C.push_back(make_pair(abs(A[1].first-A[n-1].first),P(A[1].second,A[n-1].second)));
	C.push_back(make_pair(abs(A[0].first-A[n-2].first),P(A[0].second,A[n-2].second)));
	C.push_back(make_pair(abs(B[0].first-B[n-1].first),P(B[0].second,B[n-1].second)));
	C.push_back(make_pair(abs(B[1].first-B[n-1].first),P(B[1].second,B[n-1].second)));
	C.push_back(make_pair(abs(B[0].first-B[n-2].first),P(B[0].second,B[n-2].second)));

	sort(C.rbegin(), C.rend());

	if(C[0].second.first == C[1].second.first && C[0].second.second == C[1].second.second){
		cout<<C[2].first<<endl;
	}else{
		cout<<C[1].first<<endl;
	}
//
//	for(auto x: A){
//		cout<<x.second<<":"<<x.first<<" ";
//	}
//	cout<<endl;
//	for(auto x: B){
//		cout<<x.second<<":"<<x.first<<" ";
//	}
//	cout<<endl;
//	for(auto x: C){
//			cout<<x.second.first<<" "<<x.second.second<<":"<<x.first<<" ";
//	}
//	cout<<endl;

}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define SIZE 200005

struct LOC{

	ll x,y;
};

typedef vector<ll> V;
typedef vector<V> MATRIX;

int N = 3;
int num_P;
LOC loc[SIZE];
ll table[SIZE][3][3];

MATRIX calc(MATRIX left,MATRIX right){

	MATRIX ret(N,V(N));

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)ret[i][k] = 0;
	}

	for(int row = 0; row < N; row++){
		for(int col = 0; col < N; col++){
			for(int a = 0; a < N; a++){
				ret[row][col] += left[row][a]*right[a][col];
			}
		}
	}

	return ret;

}

int main(){

	scanf("%d",&num_P);

	for(int i = 1; i <= num_P; i++){

		scanf("%lld %lld",&loc[i].x,&loc[i].y);
	}

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

	MATRIX A1(N,V(N));
	A1[0][1] = 1;
	A1[1][0] = -1;
	A1[2][2] = 1;

	MATRIX A2(N,V(N));
	A2[0][1] = -1;
	A2[1][0] = 1;
	A2[2][2] = 1;

	MATRIX AX(N,V(N));
	AX[0][0] = -1,AX[0][1] = 0;
	AX[1][0] = 0,AX[1][1] = 1;
	AX[2][2] = 1;

	MATRIX AY(N,V(N));
	AY[0][0] = 1,AY[0][1] = 0;
	AY[1][0] = 0,AY[1][1] = -1;
	AY[2][2] = 1;

	MATRIX MULT(N,V(N));
	MULT[0][0] = 1,MULT[1][1] = 1,MULT[2][2] = 1;

	int command;
	ll p;

	for(int row = 0; row < 3; row++){
		for(int col = 0; col < 3; col++){

			table[0][row][col] = MULT[row][col];
		}
	}

	for(int i = 1; i <= M; i++){

		scanf("%d",&command);

		MATRIX work(N,V(N));

		switch(command){
		case 1:

			MULT = calc(A1,MULT);
			break;
		case 2:
			MULT = calc(A2,MULT);
			break;
		case 3:

			scanf("%lld",&p);
			for(int row = 0; row < 3; row++){
				for(int col = 0; col < 3; col++){

					work[row][col] = AX[row][col];
				}
			}
			work[0][2] = 2*p;

			MULT = calc(work,MULT);

			break;

		case 4:

			scanf("%lld",&p);
			for(int row = 0; row < 3; row++){
				for(int col = 0; col < 3; col++){

					work[row][col] = AY[row][col];
				}
			}
			work[1][2] = 2*p;
			MULT = calc(work,MULT);

			break;
		}

		for(int row = 0; row < 3; row++){
			for(int col = 0; col < 3; col++){

				table[i][row][col] = MULT[row][col];
			}
		}
	}

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

	int count,index;

	for(int loop = 0; loop < Q; loop++){

		scanf("%d %d",&count,&index);

		ll x = loc[index].x;
		ll y = loc[index].y;

		ll ans_x = table[count][0][0]*x+table[count][0][1]*y+table[count][0][2];
		ll ans_y = table[count][1][0]*x+table[count][1][1]*y+table[count][1][2];

		/*printf("\n");
		for(int row = 0; row < 3; row++){
			for(int col = 0; col < 3; col++){

				printf(" %lld",table[count][row][col]);
			}
			printf("\n");
		}*/

		printf("%lld %lld\n",ans_x,ans_y);
	}

	return 0;
}


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

int nt[200009], id[200009], ds[200009];
bool rm[200009];
queue<int> q;

int uf(int n)
{
	if (ds[n] == n) return n;
	return ds[n] = uf(ds[n]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> nt[i];
		id[nt[i]]++;
		ds[i] = i;
	}
	for (int i = 1; i <= n; i++)
		if (!id[i]) {
			rm[i] = true;
			q.push(i);
		}
	while (!q.empty()) {
		int hn = q.front(); q.pop();
		id[nt[hn]]--;
		if (!id[nt[hn]]) {
			rm[nt[hn]] = true;
			q.push(nt[hn]);
		}
	}
	for (int i = 1; i <= n; i++)
		if (!rm[i]) {
			int ua = uf(i), ub = uf(nt[i]);
			if (ua != ub)
				ds[ua] = ub;
		}
	int c = 0;
	for (int i = 1; i <= n; i++)
		if (!rm[i] && ds[i] == i)
			c++;
	long long ans = 1, md = 998244353;
	for (int i = 0; i < c; i++)
		ans = (ans * 2) % md;
	ans = (ans - 1 + md) % md;
	cout << ans << '\n';
	return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
#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

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if ((ct = *ci++) >= '0') {
				tmp = tmp * 10 + ct - '0';
				ci++;
			}
		}
	}
	return tmp;
}
ll tmp[400010];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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

	int N = getint(), M = getint();
	ll XY[200000];
	rep(i, M) {
		int x = getint();
		XY[i] = x | (ll)getint() << 32;
	}
	pakuri_sort(M, XY);

	auto ST = tmp + 200000;
	ST[0] = -1;
	const ll ma = (1ll << 32) - 1;
	int m = 0;
	while (m < M) {
		int m0 = m;
		int x = (XY[m] & ma);
		while (m < M && (XY[m] & ma) == x) {
			int y = (XY[m] >> 32) - N;
			if (y < -M || y > M) XY[m] = 0;
			else if (ST[y - 1] < 0 | ST[y + 1] < 0) XY[m] |= 1ll;
			else if (ST[y] < 0) XY[m] &= (~1ll);
			else XY[m] = 0;
			m++;
		}
		for (int p = m0; p < m; p++) {
			int y = (XY[p] >> 32) - N;
			if (XY[p] & 1) ST[y] = -1;
			else if (XY[p]) ST[y] = 0;

		}
	}
	int kotae = 0;
	for (int i = -M; i <= M; i++) kotae += (ST[i] < 0);
	co(kotae);

	Would you please return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
const int kMod = 1e9 + 7;
const int kInf = (~(1<<31)) / 2 - 500;
const ll kInfL = (~(1LL<<63)) / 2 - 2000;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  vector<int> idx(N);
  for (int i = 0; i < N; ++i) {
    int tmp;
    cin >> tmp;
    --tmp;
    ++idx[tmp];
  }
  map<int, int> cnt;
  for (int i = 0; i < N; ++i) {
    cnt[B[i]] += idx[i];
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    ans += cnt[A[i]];
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
const int modu = 998244353;
const double eps = 1e-5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

typedef long long LL;

int n;
LL sum[maxn];

int main() {
    // freopen("my.txt", "w", stdout);
	cin >> n;
    sum[0] = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &sum[i]);
        sum[i] += sum[i-1];
    }
    LL ss = 0, ans = 0, incr = sum[1];
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, ss+incr);
        ss += sum[i];
        if (i+1 <= n)
            incr = max(incr, sum[i+1]);
    }
    cout << ans << endl;
	return 0;
}


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

int main(){
    double X,Y,Z,ans;
    double price_per_gram;
    cin >> X >> Y >> Z;
    ans = 1000001.0;
    price_per_gram = (double) (Y/X);
    while (1){
        if((double)(ans/Z)>=price_per_gram){
            ans-=1.0;
        }
        else{
            break;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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

//グラフ関連
struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, ll _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (int)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (int)G[from].size() - 1));
}

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1)
                ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt<MOD>;
void solve() {
    ll n, p;
    cin >> n >> p;
    cout << mint(p - 1) * mint(p - 2).pow(n - 1) << en;
}

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

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}


//In the name of Allah (swt)
/*

 T sort / plano ax
 == [g o t c p]
// 我爱雨，花，食物，空气，水，都赞美真主   由 埃姆兰 制造

 upper_bound = find the last positon where n could be inserted
 lower_boudn = find the first position where n could be inserted
 lambda = [](int x){return x<10;}

 STL Algorithm Non- modifying----
--------------------------------

 vector<int> vec = {9,60,90,8,45,87,90,69,55,7};

    --- 1 counting
 int n = count(vec.begin(),vec.end(),69); // 2
 int m = count_if(vec.begin(),vec.end(),[](int x){return x<10;});//3 ->9,7,8

    --- 2 Min and Max
 itr = max_element(vec.begin(),vec.end()); // 90
//it returns the first max value

 itr = max_element(vec.begin(),vec.end(),[](int x,int y){return (x%10)<(y%10);});// 9
// which number has the biggest last digit---
...Most Algorithms have a simple form and a generalized form

itr = min_element(vec.begin(),vec.end()); // 7
// generalized form : min_element()

pair_of_itr = minmax_element(vec.begin(),vec.end(),[](int x,int y){return (x%10)<(y%10);}); //60 69

    ...3 linear search (used when the data is not sorted
// return the first match
 itr = find(vec.begin(),v.end(),

 itr = find_if(vec.begin(),vec.end(),[](int x){return x>80;});

 itr = find_if_not(vec.begin(),vec.end(),[](int x){return x>80;});

 itr = search_n(vec.begin(),vec.end(),2,69);
//Generalized form: search_n();

//search subrange
 vector<int> sub = {45,87,90};

 itr = search(vec.begin(),vec.end(),sub.begin(),sub.end());
        // search first subrange
 itr = find_end(vec.begin(),vec.end(),sub.begin(),sub.end());
........// search last subrange
//     generalized form: search(), fidn_end()

....Search any_of
 vector<int> items = {87,69};
 itr = find_first_of(vec.begin(),vec.end(),items.begin(),items.end());
      // Search any one of the item in items
 itr = find_first_of(vec.begin(),vec.end(),items.begin(),items.end(),[](int x,int y){return x==y*4});
 //     search any item in items that satisfy: x==y*4

// Search Adjacent
itr = adjacent_find(vec.begin(),vec.end()); // find two adjacent that are same
itr = adjacent_find(vec.begin(),vec.end(),[](int x,int y){return x==y*4}); // find two adjacent that are same
//           find two adjacent items that satisfy : s==y*4

//    4

//    5 check Attributes
is_sorted(vec.begin(),vec.end());//check if vec is sorted

itr = is_sorted_until(vec.begin(),vec.end());
// itr points to first place to where elements are no longer sorted
// generalizedforms: is_sorted(), is_sorted_until()

is_partitioned(vec.begin(),vec.end())[](int x){return x>80;});
// check if vec is partitioned according to the condition of (x>80)

if_heap(vec.begin(),vec.end()); // check if vec is a heap
itr = is_heap_until(vec.begin(),vec.end());
// find the first place where it is no longer a heap
//

//    All Any None
all_of(vec.begin(),vec.end(),[](int x){return x>80;});
// If any of vec is bigger than 80

any_of(vec.begin(),vec.end(),[](int x){return x>80});
//if any of vec is bigger than 80

none_of(vec.begin(),vec.end(),[](int x){return x>80;});
// if none of vec is bigger than 80

*/

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int temp[2005]={0};
vector<vector<int>>G;
void dfs(int v)
{
    if(temp[v]==1)return;
    temp[v]=1;
    for(auto vv:G[v]){
        dfs(vv);
    }
}

void kick()
{
    int n,m;
    cin>>n>>m;
    G.resize(n);

    for (int i=0; i<m ; i++)
    {
        int x,y;
        cin>>x>>y;
       G[x-1].pb(y-1);
    }
    int ans = 0;

    for (int i=0; i<n ; i++)
    {
        for(int j=0; j<n; j++)temp[j]=0;

        //temp[i]=1;
        dfs(i);
        for (int j=0; j<n ; j++)
        {
            if(temp[j]==1)ans++;
        }

    }

    cout<<ans<<endl;

}
int32_t main()

{

        kick();

    }

#include<bits/stdc++.h>
#define int long long
#define ll int
#define itn int
#define ld long double
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define rep(i, n) for(int  i = 0 ; i < n ; i++ )
#define repu(i, a, b) for(int i = a; i <=b; ++i)
#define repd(i, a, b) for(int i = a; i >=b; --i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

using namespace std;

const long long MOD = 1000000007;
void dfs(int root, vvi &adj, vi& vis){
    if(vis[root]) return;
    vis[root]=1;
    trav(x,adj[root]){
        if(!vis[x]) dfs(x,adj,vis);
    }
}

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

    vvi adj(n+1);
    rep(i,m){
        int x,y;
        cin >> x >> y;
        adj[x].pb(y);
    }
    int ans = 0;
    repu(i,1,n){
        vi vis(n+1,0);
        dfs(i,adj,vis);
        int tmp  = 0;
        trav(x, vis){
            tmp+=x;
        }
        ans += tmp;
    }
    cout << ans << endl;
}

signed main(){

    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    rep(z,t){
        solve();
    }

    cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";

    return 0;
}


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

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

  long long A[N],P[N],X[N];
  for (long i = 0; i < N; i++) {
      cin >> A[i] >> P[i] >> X[i];
  }

  long long price = 2000000000;

  for (long i = 0; i < N; i++) {
      if (X[i] > A[i]) {
          price = min(price,P[i]);
      }
  }

  if (price == 2000000000) {
    cout << -1 <<endl;
  }else{
      cout << price <<endl;
  }
}

// Author : Chinmay JHa @chinmayajha
//
// Problem: B - Play Snuke
// Contest: AtCoder - Caddi Programming Contest 2021(AtCoder Beginner Contest 193)
// URL: https://atcoder.jp/contests/abc193/tasks/abc193_b
// Date / Time: 02-04-2021 18:58:24

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int t = 1;
	// cin >> t;
	while (t--) {
        lli n;cin>>n;
        vector<vector<lli>> a(n);
        // vector<lli> d(n);
        lli minn = 1e11;
        for(lli i = 0;i<n;++i){
            vector<lli> temp(3);
            cin >> temp[0]>>temp[1]>>temp[2];
            a[i] = temp;
        }
        sort(a.begin(),a.end());
        for(lli i = 0;i < n;++i){
            // minutes = a[i][0];
            // price = a[i][1];
            // stock = minutes*i + 0.5;

            float stock = a[i][2] - a[i][0];
            if(stock>=1){
                minn = min(minn, a[i][1]);
                // cout << a[i][1] << " ";
            } else {
                continue;
            }
        }
        if(minn == 1e11){
            cout << "-1\n";
        } else {
            cout << minn << "\n";
        }
	}

}


#include <bits/stdc++.h>

using namespace std;

int main(){
    vector<string> S(3);
    for (auto &s: S)
        cin >> s;

    string C = "";
    for (const auto &s: S)
        C += s;

    sort(C.begin(), C.end());
    C.erase(unique(C.begin(), C.end()), C.end());

    if (C.size() > 10){
        puts("UNSOLVABLE");
        return 0;
    }

    vector<char> A;
    for (int i = 0; i < 10; i++)
        A.push_back('0' + i);

    do {
        vector<string> T = S;
        map<char, char> f;
        for (int i = 0; i < C.size(); i++)
            f[C[i]] = A[i];

        for (int i = 0; i < 3; i++){
            for (auto &t: T[i])
                t = f[t];
        }

        vector<int64_t> B(3);
        bool flag = true;
        for (int i = 0; i < 3; i++){
            B[i] = stoll(T[i]);
            flag &= T[i] == to_string(B[i]);
            flag &= B[i] > 0;
        }

        if (!flag)
            continue;

        if (B[0] + B[1] == B[2]){
            for (const auto &b: B)
                cout << b << endl;
            return 0;
        }
    } while (next_permutation(A.begin(), A.end()));

    puts("UNSOLVABLE");
}

#include "bits/stdc++.h"
#pragma region header
#define loop(n) for ([[maybe_unused]] size_t lpcnt_ = 0; lpcnt_ < (n); ++lpcnt_)

using i32 = int;
using i64 = long long int;
using u32 = unsigned int;
using u64 = unsigned long long int;
using isize = ptrdiff_t;
using usize = size_t;

template <class T, T Div = 2>
constexpr T infty = std::numeric_limits<T>::max() / Div;
constexpr i32 infi32 = infty<i32, 2>;
constexpr u32 infu32 = infty<u32, 2>;
constexpr i64 infi64 = infty<i64, 4>;
constexpr u64 infu64 = infty<u64, 4>;

constexpr usize operator"" _uz(u64 v) { return usize(v); }
inline u64 popcount(const u64 v) {
#ifdef _MSC_VER
  return u64(__popcnt64(v));
#else
  return u64(__builtin_popcount(v));
#endif
}

template <class T>
constexpr T difference(const T a, const T b) {
  return a > b ? a - b : b - a;
}
template <class T>
constexpr T ceildiv(const T a, const T b) {
  return (a + b - 1) / b;
}

class range {
  struct range_iterator {
    usize itr;
    constexpr range_iterator(const usize pos) noexcept : itr(pos) {}
    constexpr void operator++() noexcept { ++itr; }
    constexpr bool operator!=(const range_iterator& other) const noexcept {
      return itr != other.itr;
    }
    constexpr usize operator*() const noexcept { return itr; }
  };
  const range_iterator first, last;

 public:
  constexpr range(const usize first_, const usize last_) noexcept
      : first(first_), last(last_) {}
  constexpr range_iterator begin() const noexcept { return first; }
  constexpr range_iterator end() const noexcept { return last; }
};

template <class F>
class rec_lambda {
  F f;

 public:
  constexpr rec_lambda(F&& f_) : f(std::forward<F>(f_)) {}
  template <class... Args>
  constexpr auto operator()(Args&&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
#pragma endregion

void main_() {
  std::array<i32, 3> A;
  std::cin >> A[0] >> A[1] >> A[2];
  std::sort(A.begin(), A.end());
  if (A[1] - A[0] == A[2] - A[1])
    std::cout << "Yes" << '\n';
  else
    std::cout << "No" << '\n';
  // AtCoder Beginner Contest 201
}

int main() { main_(); }