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

int main(){
  string S;
  cin >> S;
  int o=0,x=0,q=0;
  for(int i=0;i<10;i++){
    if(S[i]=='o') o++;
    if(S[i]=='x') x++;
    if(S[i]=='?') q++;
  }

  int ans = 0;
  for(int i=0;i<10000;i++){
    vector<int> V(10,0);
    int now = i;
    for(int j=0;j<4;j++){
      V[now%10]++;
      now /= 10;
    }

    bool ok = true;
    for(int j=0;j<o;j++){
      if(V[j]==0) ok = false;
    }
    for(int j=o;j<o+x;j++){
      if(V[j]!=0) ok = false;
    }
    if(ok) ans++;
  }

  cout << ans << endl;
  return 0;
}

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

using namespace std;
int main()
{
    string s;
    cin >> s;
    int ans_o = 0, ans_p = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'o') ans_o++;
        if(s[i] == '?') ans_p++;
    }
    if(ans_o > 4) {
        cout << 0 << endl;
    }
    else if(ans_o == 4){
        cout << 24 << endl;
    }
    else if(ans_o == 3){
        cout << ans_p*24+36<<endl;
    }
    else if(ans_o == 2){
        cout << 14+ans_p*36+ans_p*(max(0,ans_p-1))*12<<endl;
    }
    else if(ans_o == 1){
        cout << 1+ans_p*14+ans_p*(max(0,ans_p-1))*18+ans_p*(max(0, ans_p-1))*(max(0,ans_p-2))*4<<endl;
    }
    else{
        cout << ans_p+ans_p*(max(0,ans_p-1))*7+ans_p*(max(0, ans_p-1))*(max(0,ans_p-2))*6+ans_p*(max(0, ans_p-1))*(max(0,ans_p-2))*(max(0,ans_p-3))<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
char dp[105][105];
string s;
ll Mod;
ll mypow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%Mod;
        a=a*a%Mod;
        b>>=1;
    }
    return ans;
}
char chos(char s1,char s2){
    if(s1==s2)return s1;
    if(s1=='P'&&s2=='R')return s1;
    if(s1=='P'&&s2=='S')return s2;
    if(s1=='R'&&s2=='P')return s2;
    if(s1=='R'&&s2=='S')return s1;
    if(s1=='S'&&s2=='P')return s1;
    if(s1=='S'&&s2=='R')return s2;
}
int main(){
    int n,k;
    cin>>n>>k;
    cin>>s;
    s='='+s;
    Mod=n;
    for(int i=1;i<=n;++i)dp[i][0]=s[i];
    for(int j=1;j<=k;++j){
        ll f=mypow(2,j-1);
        for(int i=1;i<=n;++i){
            int a=(i+f)%Mod;
            if(a==0)a=n;
            dp[i][j]=chos(dp[i][j-1],dp[a][j-1]);
        }
    }
    cout<<dp[1][k];
	return 0;
}

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

int n, k;
string s;

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

int main() {
    //ifstream fin("date.in.txt");

    /*
    R beats S;
    P beats R;
    S beats P.
    */
    cin >> n >> k >> s;

    for (int i = 0; i < k; ++i) {
        s += s;
        string new_s;

        for (int j = 0; j < n; ++j) {
            new_s += winner(s[2*j], s[2*j+1]);
        }
        s = new_s;
    }
    cout << s.front() << '\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

template<typename T_vector>
void output_vector(const T_vector &v, bool addOne = false, int start = -1, int end = -1) {
	if (start < 0) start = 0;
	if (end < 0) end = (int) v.size();
	for(int i = start; i < end; i++)
		cout<< v[i] + (addOne ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

void solve() {
	int n;
	cin>>n;
	vector<int> v(n);
	rep(i,0,n) {
		cin>>v[i];
	}

	int sum = 0;

  sort(all(v));

	for(int i = sz(v) - 1; i >=  0; i--){
	sum += (v[i]*(i)- v[i]*(n-i-1));
	}

	cout<<sum<<"\n";
}

signed main() {
	fast
	#ifndef ONLINE_JUDGE

    // For getting input from input.txt file
    freopen("input.txt", "r", stdin);

    // Printing the Output to output.txt file
    freopen("output.txt", "w", stdout);

	cout<<setprecision(12);
	cout<<fixed;

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

#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    int n; cin >>n;
    double x1,y1,x2,y2,x3,y3;
    double x[n];
    double y[n];
    bool result=false;
    for(int i=0;i <n; i++){
        cin >> x[i];
        cin >> y[i];
    }
    for(int i=0; i<n ;i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                x1=x[i];x2=x[j];x3=x[k];y1=y[i];y2=y[j];y3=y[k];
                if(x3-x2==0&& x3-x1==0){
                    result=true;}
                else{
                    if((y3-y2)/(x3-x2)==(y3-y1)/(x3-x1)){
                        result=true;
                        break;
                    }

                }
            }
        }
    }
    if(result)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int V,T,S,D;
  cin>>V>>T>>S>>D;
  if (D<V*T || D>V*S){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
#define all(v) ((v).begin()), ((v).end())
#define sz(v) v.size()
#define endl "\n"
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
constexpr auto EPS = 1e-7;
const int mod = (int)1e9 + 7;
int dxn[] = { -1,-2,-2,-1,1,2,2,1 };

int dyn[] = { -2,-1,1,2,2,1,-1,-2 };
int dx[] = { -1 , -1 , -1 , 0 , 0 , 1 , 1 , 1 , 0 };
int dy[] = { -1 , 0 , 1 , -1 , 1 , -1 , 0 , 1 , 0 };
ll gcd(ll a, ll b) { return (a) ? gcd(b % a, a) : b; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
void COME_BACK()
{
    std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);
#endif
}

   int main()
   {
       COME_BACK();
       int a, b, c, d;
       cin >> a >> b >> c >> d;
       cout <<( a * d) - (c * b) << endl;

   }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

int main()
{
    ll N, X;
    INX(N, X);
    X *= 100;

    bool yotta = false;
    ll suma = 0;
    for (ll i = 1; i <= N; i++)
    {
        ll v,p;
        INX(v,p);

        suma += v * p;
        if(suma > X)
        {
            yotta = true;
            OUTX(i);
            break;
        }
    }

    if(!yotta)
    {
        OUTX(-1);
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

int main()
{
  string str;
  cin >> str;
  int ans = 0;
  rep(i,12){
    if(str.compare(i,4,"ZONe")==0){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

// using mint = long double;
// using mint = modint998244353;
// using mint = modint1000000007;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;
typedef pair<ll, vector<ll>> Pd;

const ll INF = 1e18;
const ll fact_table = 320000;

priority_queue<ll> pql;
priority_queue<P> pqp;
// big priority queue
priority_queue<ll, vector<ll>, greater<ll>> pqls;
priority_queue<P, vector<P>, greater<P>> pqps;

// small priority queue
// top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1};
//↓,→,↑,←

#define p(x) cout << x << "\n";
#define el cout << "\n";
#define pe(x) cout << x << " ";
#define ps(x) cout << fixed << setprecision(25) << x << endl;
#define pu(x) cout << (x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = a; i <= (b); i++)
#define rep3(i, a, b) for (ll i = a; i >= (b); i--)
#define all(c) begin(c), end(c)
#define sorti(v) sort(all(v))
#define sortd(v)                                                               \
    sort(all(v));                                                              \
    reverse(all(v));
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

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

// vec v(n) -> 長さnのベクトルを宣言
// mat dp(h, vec(w)) -> h * w の行列を宣言

// const ll mod = 1000000007ll;
const ll mod = 998244353ll;

ll mypow(ll a, ll b, ll m = mod) {
    ll x = 1;
    while (b) {
        while (!(b & 1)) {
            (a *= a) %= m;
            b >>= 1;
        }
        (x *= a) %= m;
        b--;
    }
    return x;
}
vec rv(ll read) {
    vec res(read);
    for (int i = 0; i < read; i++) {
        cin >> res[i];
    }
    return res;
}
/*
ll fact[fact_table + 5], rfact[fact_table + 5];

void c3_init() {
    fact[0] = rfact[0] = 1;
    for (ll i = 1; i <= fact_table; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod);
    for (ll i = fact_table; i >= 1; i--) {
        rfact[i - 1] = rfact[i] * i;
        rfact[i - 1] %= mod;
    }
    return;
}

ll c3(ll n, ll r) {
    return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
}
*/

bool icpc = false;
bool multicase = false;

ll n;
bool used[400005];
map<ll, vec> mp;

bool solve() {
    cin >> n;
    n *= 2;
    vector<P> table;
    for (int i = 0; i < n; i++) {
        int value;
        cin >> value;
        table.pb({value, i});
    }
    sortd(table);
    for (int i = 0; i < n / 2; i++) {
        int idx = table[i].second;
        used[idx] = true;
    }
    vec v;
    for (int i = 0; i < n; i++) {
        int now = (used[i]) ? 1 : 0;
        bool push = false;
        if (v.size() == 0) {
            push = true;
        } else if (v.back() == now) {
            push = true;
        } else {
            push = false;
        }
        if (push) {
            pu("(");
            v.pb(now);
        } else {
            pu(")");
            v.pop_back();
        }
    }
    el;

    return true;
}

/*

*/

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    if (icpc) {
        while (solve())
            ;
        return 0;
    }
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // cout << "Case #" << testcase << ": ";
        solve();
        testcase++;
    }

    // solve();
    return 0;
}

    #include <bits/stdc++.h>
    using namespace std;
    #define rep(i,a,b) for(int i=(a);i<=(b);++i)
    #define FI freopen("/home/empathy/in.txt", "r", stdin)
    #define FO freopen("/home/empathy/out.txt", "w", stdout)
    template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
    template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
    void dbg_out() { cerr << endl; }
    template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
    #ifdef QUICKRUN
    #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
    #else
    #define dbg(...)
    #endif
    typedef long long ll;
    typedef pair<int, int> ii;

    bool check(vector<int> arr, ll base, ll M) {
        __int128_t res = 0;
        for (int i = 0; i < arr.size(); ++i) {
            if (res > (M - arr[i]) / base) return true;
            res = res * base + arr[i];
            if (res > M || res < 0) return true;
        }
        return false;
    }

    __int128_t binarySearch(vector<int> arr, ll l, ll M) {
        ll r = M + 1;
        while (r - l > 1) {
            ll mid = l + (r - l) / 2;
            if (check(arr, mid, M)) r = mid;
            else l = mid;
            dbg(r);
        }
        return r;
    }

    void solve() {
        string X;
        cin >> X;
        ll M;
        cin >> M;
        int ma = 0;
        int n = int(X.length());
        vector<int> arr(n);
        for (int i = 0; i < n; ++i) {
            arr[i] = X.at(i) - '0';
            if (arr[i] > ma) ma = arr[i];
        }
        ll cnt = 0;
        if (n != 1) {
            cnt = binarySearch(arr, 1, M);
            dbg(cnt);
            cnt -= ma + 1;
            if (cnt < 0) cnt = 0;
        }
        else {
            if (arr[0] > M) cnt = 0;
            else cnt = 1;
        }
        cout << cnt << '\n';
    }

    int main() {
        ios::sync_with_stdio(false);
    #ifndef QUICKRUN
        cin.tie(nullptr);
    #endif
    #ifdef QUICKRUN
        FI;
        // FO;
    #endif
        solve();
        return 0;
    }


// AUTHOR:- Saumya Rangani

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<pair<int,int>>
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define it(a) for(auto &i:a)
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define read(v) for(auto &i:v)cin>>i;
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define in cin>>
#define out cout<<
#define default(a,n,b) for(int i=0;i<n;i++)a[i]=b;
#define YNans(poss) cout << (poss ? "YES" : "NO" ) << endl;
#define inarray(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define fast ios_base :: sync_with_stdio(false),cin.tie(NULL);
#define MAXN 2005

int gcd(int a, int b){return (b?gcd(b,a%b):a);}
bool isPrime(int n){if(n==1) return false;if(n==2) return true;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int power(long long x, unsigned int y, int p=mod){int res = 1;x = x % p; if (x == 0) return 0;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int digit(int n){int ans=0;while(n){ans++;n/=10;}return ans;}
int lcm(int a,int b){return a*b/gcd(a,b);}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}

vector<vector<int>> grp(MAXN);
bool vis[MAXN];
int  dfs(int node){
    int ans=1;
    if(vis[node]){
        return 0;
    }
    vis[node]=1;
    // cout<<node<<endl;
    for(auto i:grp[node]){
        ans+=dfs(i);
    }
    return ans;
}

void solve(){
    int n;in n;
    int m;in m;
    for(int i=0;i<m;i++){
        int x,y;in x>>y;
        grp[x].pb(y);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        ans+=dfs(i);
    }
    cout<<ans<<endl;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
int n, m, q, l, r, h, mn, imn;
array<int, 51> bx, kt;
pair<int, int> bg[51];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m >> q;
    f(i,1,n) cin >> bg[i].second >> bg[i].first;
    sort(bg+1, bg+n+1, greater<pair<int, int>>());
    f(i,1,m) cin >> kt[i];
    while(q--) {
        cin >> l >> r;
        h = 0, bx = kt;
        f(i,1,n) {
            imn = 0, mn = 1e9;
            f(j,1,m) if(j < l || j > r) {
                if(bx[j] >= bg[i].second && bx[j] < mn) {
                    mn = bx[j], imn = j;
                }
            }
            if(imn) h += bg[i].first, bx[imn] = 0;
        }
        cout << h << '\n';
    }
}


/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com
	> Blog: https://blog.csdn.net/Pig_cfbsl
	> Created Time: 2020/10/11 22:45:26
 ************************************************************************/
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define pb push_back
#define pr pair<int,int>
#define fi first
#define se second
#define LL long long
#define mk(a,b) make_pair(a,b)
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
const int maxx=1e5+10;
int n,m,sum=0,cnt=0,mx;
int w[10],tmp[10],s[10],dis[10],v[maxx],l[maxx];
int p[10]={0,1,2,3,4,5,6,7,8};
pr a[maxx];
bool cmp(pr x,pr y){
	if(x.fi!=y.fi) return x.fi<y.fi;
	return x.se>y.se;
}
int iso(int x){
	x=lower_bound(v+1,v+cnt+1,x)-v-1;
	return l[x];
}
int solve(){
	s[0]=0;
	For(i,1,n){ tmp[i]=w[p[i]]; s[i]=s[i-1]+tmp[i];  dis[i]=0;}
	For(i,2,n) For(j,1,i-1) dis[i]=max(dis[i],dis[j]+iso(s[i]-s[j-1]));
//	cout<<dis[3]<<endl;
	return dis[n];
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	int u1,u2;
	n=read(); m=read();
	For(i,1,n){ w[i]=read(); mx=max(w[i],mx);}
	For(i,1,m){
		u1=read(); u2=read();
		a[i]=mk(u2,u1);
		if(u2<mx){ printf("-1\n"); return 0; }
	}
	sort(a+1,a+m+1,cmp);
	v[++cnt]=a[1].fi; l[cnt]=a[1].se;
	For(i,2,m)
		if(a[i].se>l[cnt]){
			v[++cnt]=a[i].fi;
			l[cnt]=a[i].se;
		}
	int ans=1e9;
	do{
		ans=min(ans,solve());
//		return 0;
	}while(next_permutation(p+1,p+n+1));
	printf("%d\n",ans);
	return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<int>>;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first
#define se second
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
#define set20 cout<<fixed<<setprecision(20) ;
// ミント
//int mod ; cin>>mod ;
const ll mod = //1e9+7 ;//924844033;
    998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod); //任意modではここ消す
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ; //kは個数
  }
  }  c(1000005);

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

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

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

mint dp[105][10005] ;
mint ep[105][10005] ;

int main(){
  ios::sync_with_stdio(false) ;
  cin.tie(nullptr) ;
  ll n ; cin>>n ;
  vector<ll> A(n) ;
  rep(i,n) cin>>A[i] ;
  ll sum=0 ;
  rep(i,n){
    sum+=A[i] ;
  }
  if(sum%2!=0){
    cout<<0<<endl ;
    return 0 ;
  }
  ll g=sum/2 ;

  dp[0][0]=1ll ;

  rep(i,n){
    ll now=A[i] ;
    //mint ep[105][10005] ;
    rep(x,105)rep(y,10005) ep[x][y]=0ll ;

    rep(k,i+1){
    rep(j,10005){
     if(j+now<=g) ep[k+1][j+now]+=dp[k][j] ;
     else break ;
    }
    }

    rep(x,105)rep(y,10005) dp[x][y]+=ep[x][y] ;

  }

  vector<mint> p(n+5) ;
  p[0]=1ll ;
  rep(i,n+4) p[i+1]=p[i]*(i+1);
  mint ans=0 ;
  rep(i,n+1){ // cout<<dp[i][g]<<endl ;
    ans+=dp[i][g]*p[i]*p[n-i] ;
  }

  cout<<ans<<endl ;
  return 0 ;
  }


#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<=n;i++)
#define RIP(i,a,b) for(int i=a;i<b;i++)
#define all(V) V.begin(),V.end()
#define sec  setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
const ll MOD = 998244353;
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 * b / gcd(a, b);
}
ll pow(ll a, ll b) {
	ll ans = 1;
	if (b < 0)return 1;
	else if (b % 2 == 0)return(pow(a * a, b / 2));
	else return (a * pow(a, b - 1));
}
ll modpow(ll x, ll n, ll mod) {
	x %= mod;
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return (modpow((x * x) % mod, n / 2, mod) % mod);
	else
		return (x * modpow(x, n - 1, mod)) % mod;
}
template<typename T>
vector<T> primes(T n) {//primes[i]でiを割り切る最初の素数を返す
	vector<T> spf(n + 1);
	for (int i = 0; i <= n; i++) spf[i] = i;
	for (T i = 2; i * i <= n; i++) {
		if (spf[i] == i) {
			for (T j = i * i; j <= n; j += i) {
				if (spf[j] == j) {
					spf[j] = i;
				}
			}
		}
	}
	return spf;
}
void solveA() {
	int a, b, c; cin >> a >> b >> c;
	if (c == 0) {
		if (b >= a)cout << "Aoki" << endl;
		else cout << "Takahashi" << endl;
	}
	else {
		if (b > a)cout << "Aoki" << endl;
		else cout << "Takahashi" << endl;
	}
}
void solveB() {
	int n, s, d; cin >> n >> s >> d;
	vector<int>x(n);
	vector<int>y(n);
	rip(i, n)cin >> x[i] >> y[i];
	ll sum = 0;
	rip(i, n) {
		if (x[i]<s && y[i]>d)sum += y[i];
	}
	if (sum > 0)cout << "Yes" << endl;
	else cout << "No" << endl;
}
void solveC() {
	int n, m; cin >> n >> m;
	vector<int>a(m);
	vector<int>b(m);
	rip(i, m)cin >> a[i] >> b[i], a[i]--, b[i]--;
	int k; cin >> k;
	vector<int>c(k);
	vector<int>d(k);
	rip(i, k)cin >> c[i] >> d[i], c[i]--, d[i]--;
	int ans = 0;
	for (int i = 0; i < pow(2, k); i++) {
		vector<bool>e(n, false);
		for (int j = 0; j < k; j++) {
			int m = i / (pow(2, j));
			if (m % 2 == 1) {
				//d[j]を使う
				e[d[j]] = true;
			}
			else {
				//c[j]を使う
				e[c[j]] = true;
			}
		}
		int count = 0;
		for (int r = 0; r < m; r++) {
			if (e[a[r]] && e[b[r]])count++;
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
}
void solveD() {
	ll n; cin >> n;
	//正のみで考えて弐倍すればok
	int count = 0;
	for (int i = 1; (ll)i * i + i <= 2 * n; i++) {
		if ((2 * n) % i == 0 && ((2 * n / i) + 1 - i) % 2 == 0) {
			count += 2;
		}
	}
	cout << count << endl;
}
void solveE() {
	int n, m; cin >> n >> m;
	vector<int>a(m); vector<int>b(m);
	rip(i, m)cin >> a[i] >> b[i];
	int k; cin >> k;
	vector<int>c(k);
	rip(i, k)cin >> c[i];

}
int main() {
	int n;cin>>n;
  cout<<max(0,n)<<endl;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

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

#define null NULL

typedef long double ld;

#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

#define vc vector
#define pb push_back
#define um unordered_map
#define us unordered_set
#define inf LONG_LONG_MAX
#define MOD (int)((1e9)+7)

vc<int>primes;
vc<int>spf;

void generatePrimes(int n){

    vc<bool>isPrime(n+1, true);
    isPrime[1] = false;
    isPrime[0] = false;

    for(int i = 2; i<= n; i++){
        if(isPrime[i]){
            primes.push_back(i);
            spf[i] = i;
        }
        for(int j = 0; j<primes.size() &&
                        i*primes[j]<n && primes[j]<=spf[i];
                        j++){

            isPrime[i*primes[j]] = false;
            spf[i*primes[j]] = primes[j];

        }
    }

}

bool myComp(pair<string, int>a, pair<string, int>b){
    return a.second < b.second;
}

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

int mod(int a, int m){
    return (a%m + m) % m;
}

int power(int x, int n, int m){

    int res = 1;

    x = x%m;
    if(x==0){
        return 0;
    }

    while(n){
        if(n%2 == 1){
            res = (res*x)%m;
        }
        x = (x*x)%m;
        n /= 2;
    }
    return res;

}
int nCr(int n, int r){

    int p=1, k=1;

    if(n-r < r){
        r = n-r;
    }

    if(r != 0){

        while(r){

            p *= n;
            k *= r;

            int m = gcd(p, k);

            p /= m;
            k /= m;
            n--;
            r--;

        }

    }
    else{
        p=1;
    }
    return p;

}

void testcase(){

    int n;
    cin >> n;
    vc<int>arr(n);
    rep(i, 0, n){
        cin >> arr[i];
    }

    sort(all(arr));
    ld x;
    ld res = 0;
    if(n%2){
        x = (ld)arr[n/2]/2;
    }
    else{
        x = (ld)(arr[n/2] + arr[(n/2)-1])/4;
    }

    for(auto i: arr){
        res += (x + i - min((ld)i, 2*x));
    }
    cout <<fixed <<res/n;
    cout << '\n';

}

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(null);
    //cout.tie(null);
    //generatePrimes(1000001);

    int t;

    //cin >> t;

    //while(t--){

        testcase();

    //}

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

#define endl "\n"

#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
	fast;
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif

ll n,x;
cin>>n>>x;

vector<ll> v(n,0),p(n,0);

for(ll i=0;i<n;i++)
{
	cin>>v[i]>>p[i];
}

ll a=-1;
ll k=0;

for(ll i=0;i<n;i++)
{
	k+=v[i]*p[i];

	if(k>x*100)
	{
		a=i+1;
		break;
	}

}

cout<<a;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
#define ERASE(a)  (a).erase(unique((a).begin(), (a).end()), (a).end()); // sortしてから
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<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;

#define pu(x) cout << (x) << endl
int main()
{
	int n, x; cin >> n >> x;
	int v, p;
	x *= 100;
	rep(i, n)
	{
		cin >> v >> p;
		x = x - v * p;
		if (x < 0)
		{
			pu(i + 1);
			return (0);
		}
	}
	pu(-1);
}


#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, x, n) for(int i = x; i < (n); i++)
using namespace std;
using ll = long long;
//const double PI = 3.14159265358979323846;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    if(c % 2 == 0) {
        a = a * a;
        b = b * b;
        if(a > b)
            cout << ">" << endl;
        else if(a < b)
            cout << "<" << endl;
        else
            cout << "=" << endl;

    } else {
        if(a >= 0 && b >= 0) {
            if(a > b)
                cout << ">" << endl;
            else if(a < b)
                cout << "<" << endl;
            else
                cout << "=" << endl;

        } else if(a >= 0 && b < 0) {
            cout << ">" << endl;
        } else if(a < 0 && b >= 0) {
            cout << "<" << endl;
        } else if(a < 0 && b < 0) {
            if(a > b)
                cout << ">" << endl;
            else if(a < b)
                cout << "<" << endl;
            else
                cout << "=" << endl;
        }
    }

    return 0;
}

#include <iostream>

using namespace std;

typedef long long ll;

ll abso(ll a){
    if(a < 0){
        return -a;
    }else{
        return a;
    }
}

int main(){
    ll A, B, C;
    cin >> A >> B >> C;

    if(A == B){
        cout << "=";
    }else if(C%2 == 0){
        if(abso(A) == abso(B)){
            cout << "=";
            goto end;
        }
        cout << ((abso(A) < abso(B)) ? "<" : ">");
    }else{
        cout << ((A < B) ? "<" : ">");
    }

    end:

    return 0;

}


	#include<bits/stdc++.h>
	using namespace std;
	#define N 200005
	char s[N];int l,i,st[N],hd;
	int main(){
		scanf("%d%s",&l,s+1);
		for(i=1;i<=l;++i){
			st[++hd]=s[i];
			while(hd>2&&st[hd-2]=='f'&&st[hd-1]=='o'&&st[hd]=='x')hd-=3;
		}
		cout<<hd;
	}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::string s){
    if (s.size() < 3) {
        cout << s.size() << endl;
        return;
    }
    deque<char> queue;
    rep(i,0,N) queue.push_back(s[i]);
    auto itr = queue.begin();
    int cnt = 0;
    while (!queue.empty() && itr != queue.end()) {
        auto itr2 = itr+1;
        if (itr2 == queue.end()) break;
        auto itr3 = itr+2;
        if (itr3 == queue.end()) break;
        if (*itr == 'f' && *itr2 == 'o' && *itr3 == 'x') {
            ++cnt;
            itr = queue.erase(itr);
            itr = queue.erase(itr);
            auto tmp = queue.erase(itr);
            if (queue.size() < 3) break;
            if (tmp == queue.end()) {
                itr = queue.end() - 3;
            } else if (tmp == queue.begin() || (tmp-1) == queue.begin() || (tmp-2) == queue.begin()) {
                itr = queue.begin();
            } else {
                itr = tmp-2;
            }
        } else {
            itr++;
        }
    }
    cout << s.size() - 3 * cnt << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::string s;
    std::cin >> s;
    solve(N, s);
    return 0;
}


#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

struct Edge {
  int to;
  long long weight;
  Edge() : to(0), weight(0) {}
  Edge(int to, long long weight) : to(to), weight(weight) {}
  Edge(const Edge& e) {
    to = e.to;
    weight = e.weight;
  }
  bool operator>(const Edge &e) const { return weight > e.weight; }
  bool operator<(const Edge &e) const { return weight < e.weight; }
  bool operator==(const Edge &e) const { return weight == e.weight; }
  bool operator<=(const Edge &e) const { return weight <= e.weight; }
  bool operator>=(const Edge &e) const { return weight >= e.weight; }
};

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
using weightedGraph = vector<vector<Edge>>;
using heap = priority_queue<int, vector<int>, greater<int>>;

const ll BIL = 1e9;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 29;
const ld PI = 3.141592653589793238462643383;

struct mint {
  ll val;
  constexpr mint(ll val=0) : val((val%MOD + MOD) % MOD) {}
  constexpr mint(const mint &m) : val(m.val) {}
  constexpr mint operator-() const {return mint(-val);}
  constexpr mint operator+(const mint &m) const noexcept {return mint(*this) += m;}
  constexpr mint operator-(const mint &m) const noexcept {return mint(*this) -= m;}
  constexpr mint operator*(const mint &m) const noexcept {return mint(*this) *= m;}
  constexpr mint operator/(const mint &m) const noexcept {return mint(*this) /= m;}
  constexpr mint &operator+=(const mint &a) noexcept {if((val += a.val) >= MOD) val -= MOD; return *this;}
  constexpr mint &operator-=(const mint &a) noexcept {if((val -= a.val) < 0) val += MOD; return *this;}
  constexpr mint &operator*=(const mint &a) noexcept {val = val * a.val % MOD; return *this;}
  constexpr mint &operator/=(mint m) noexcept {
    ll exp = MOD - 2;
    while(exp) {
      if(exp % 2 != 0) *this *= m;
      m *= m;
      exp /= 2;
    }
    return *this;
  }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= (*this);
    return a;
  }
  bool operator==(const mint &m) {return val == m.val;}
  bool operator<(const mint &m) {return val < m.val;}
  bool operator>(const mint &m) {return val > m.val;}
  bool operator<=(const mint &m) {return val <= m.val;}
  bool operator>=(const mint &m) {return val >= m.val;}
  bool operator!=(const mint &m) {return val != m.val;}
  friend ostream &operator<<(ostream &os, const mint &m) {os << m.val; return os;}
  friend istream &operator>>(istream & is, mint &m) {is >> m.val; return is;}
};

int main(int argc,char* argv[]){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  ll n;
  mint p;
  cin >> n >> p;
  mint ans = p-1;
  mint nn = p-2;
  nn = nn.pow(n-1);
  ans *= nn;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

long long powl(long long x, long long n) {
  long long ret = 1;
  while (n > 0) {
    if (n&1) ret = ret * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

int main() {
  long long N, P;
  cin >> N >> P;
  long long ans = P-1;
  ans *= powl(P-2, N-1);
  ans %= MOD;
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
ll Modpow(ll k,ll n,ll m){
    if(n==0){
        return 1;
    }else if(n%2==0){
        ll t=Modpow(k,n/2,m);
        return (t*t)%m;
    }else{
        return (Modpow(k,n-1,m)*k)%m;
    }
}
int main() {
    ll n,m;
    cin >> n >> m;
    ll ans=(Modpow(10,n,m*m)/m)%m;
    cout << ans << endl;
}

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

long long n, m;
vector<long long> ten;
vector<vector<long long>> memo, sum;

int main() {
  cin >> n >> m;
  ten.push_back(10 % m);
  for (int i = 0; i < 62; ++i) {
    long long now = ten.back() * ten.back() % m;
    ten.push_back(now);
  }
  memo.assign(62, vector<long long>(m, 0));
  sum.assign(62, vector<long long>(m, 0));
  for (int i = 0; i < m; ++i) memo[0][i] = (i * 10) % m;
  for (int i = 0; i < m; ++i) sum[0][i] = (i * 10) / m % m;
  for (int i = 0; i < 60; ++i)
    for (int j = 0; j < m; ++j) {
      memo[i + 1][j] = memo[i][memo[i][j]];
      sum[i + 1][j] = (sum[i][j] * ten[i] + sum[i][memo[i][j]]) % m;
    }
  long long res = 0, now = 1;
  for (int i = 0; i < 60; ++i)
    if (n >> i & 1) {
      res = (res * ten[i] + sum[i][now]) % m;
      now = memo[i][now];
    }
  cout << res << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
    string S;
    cin >> S;
    char S1 = S[0];
    char S2 = S[1];
    char S3 = S[2];
    cout << S2 << S3 << S1<< endl;
}

//
// Created by Abhishek Bansal on 3/28/2021
//
//#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
/*------------------------------------------------IO_OPERATORS---------------------------------------------*/
template<typename T, typename U> inline ostream &operator << (ostream &_out, const pair<T, U> &_p) { _out << _p.first << " " << _p.second; return _out; }
template<typename T, typename U> inline istream &operator >> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const vector<T> &_v) { if (_v.empty()) return _out; _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline istream &operator >> (istream &_in, vector<T> &_v) { for (auto &_i : _v) _in >> _i; return _in; }
template<typename T> inline ostream &operator << (ostream &_out, const set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T> inline ostream &operator << (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) return _out; _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const map<T, U> &_m) { if (_m.empty()) return _out; _out << "{\"" << _m.begin()->first << "\", \"" << _m.begin()->second << "\"}"; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", { \"" << _it->first << "\", \"" << _it->second << "\"}"; return _out; }
template<typename T, typename U> inline ostream &operator << (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) return _out; _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) _out << ", (" << _it->first << ": " << _it->second << ')'; return _out; }
//For 1 based indexing
template<typename T>
void out(const vector<T> &a, int n) {
    for (int i = 1; i <= n; ++i) {cout << a[i] << ' ';} cout << "\n";
}
template<typename T>
void out(const vector<vector<T>> &a, int n, int m) {
    for (int i = 1; i <= n; ++i) {for (int j = 1; j <= m; ++j) {cout << a[i][j] << ' ';}cout << '\n';}
}

void solve() {
    string s;cin >> s;
    cout << s[1] << s[2] << s[0];
}

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

    startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    int T = 1;
    while (T--) {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll MAX = 1000000000000000000LL;
const ll md = 998244353;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)

ll pw(ll a, ll n)
{
	ll result = 1;
	while (n)
	{
		if (n&1) result = (result*a)%md;
		a = (a*a)%md;
		n >>= 1;
	}
	return result;
}

int main()
{
	FAST_IO;

	int n;
	cin >> n;

	vl a(n);

	for (auto &i : a)
		cin >> i;

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

	ll result = 0, run = 0;
	for (int i=0; i<n; ++i)
	{
		result += (a[i] * (run + a[i]))%md;
		run = (2*run)%md + a[i];
		run %= md;
		result %= md;
	}
	cout << result << "\n";
	return 0;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
int N;
int A[SIZE];
void solve() {
    FOR(i,1,N){
        R(A[i]);
    }
    sort(A+1,A+1+N);
    LL an=0;
    LL now=0;
    FOR(i,1,N){
        ADD(an,(LL)A[i]*A[i]);
        ADD(an,A[i]*now);
        ADD(now,now);
        ADD(now,A[i]);
    }
    W(an);
}
void input() {
    R(N);
}
int main(){
    MOD=998244353;
    input();
    solve();
    return 0;
}


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

using ll = int64_t;

using vl = vector<ll>;

#define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i))
#define fire(i, a, b) for (int (i) = (b) - 1; (i) >= (a); --(i))

ll n;

ll get(vl& w, ll idx) {
    ll s = 0;
    while (idx > 0) {
        s += w[idx];
        idx -= idx & (-idx);
    }
    return s;
}

void upd(vl& w, ll idx, ll val) {
    while (idx <= n) {
        w[idx] += val;
        idx += idx & (-idx);
    }
}

ll cnt(vl v) {
    ll ans = 0;
    vl w(n + 1, 0);
    fire(i, 0, n) {
        ans += get(w, v[i]);
        upd(w, v[i] + 1, 1);
    }
    return ans;
}

void solve() {
    cin >> n;
    vl v(n);
    ice(i, 0, n) {
        cin >> v[i];
    }
    ll ans = cnt(v);
    cout << ans << '\n';
    ice(i, 0, n - 1) {
        ans += ((n - 1) - 2 * v[i]);
        cout << ans << '\n';
    }
}

int main() {
    int tc = 1;
    ice(i, 0, tc) {
        solve();
    }
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (n);i++)
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
const ll MOD = 1000000007;
const ll MOD3 = 998244353;
const ll INFl = 10000000000000000;
const int INFi = 1000000000;

int main() {
    int n;cin >> n;
    int sum = 0;
    vector<int> t(n);
    rep(i, n) {

        cin >> t[i];
        sum += t[i];
    }

    int ans = 10000000;

    vector<vector<bool>> dp(n + 1,  vector<bool>(100010, false));

    // rep(i, 100001) dp[0][i] = 0;
    dp[0][0] = 1;

    rep(i, n + 1) {
        // cout << i << endl;
        rep(j, 100001) {
            if(i == 0) break;
            dp[i][j] = dp[i - 1][j];
            if(j - t[i - 1] < 0) continue;
            // dp[i][j] = max(dp[i][j], dp[i - 1][j - t[i]]);
            if(dp[i][j - t[i - 1]]) dp[i][j] = dp[i - 1][j - t[i - 1]];
        }
    }

    for(int i = (sum + 1) / 2;i <= sum;i++) {
        if(dp[n][i]) {
            cout << i << endl;
            return 0;
        }
    }

    // rep(i, 1 << n) {
    //     int a1 = 0, a2 =0;

    //     rep(j, n) {
    //         if(i  & 1 << j) {
    //             a1 += t[j];
    //         }
    //         else a2 += t[j];
    //     }

    //     ans = min(max(a1, a2), ans);
    // }

    // // cout << ans << endl
    // cout << sum / n << endl;
    // // cout << sum << endl;
    // // int ave = sum / n;

    // // int a1 = t[0] - ave;
    // // int a2 = 0;

    // // rep(i, n) {

    // //     rep(j, n) {

    // //     }

    // // }
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

const int nax = 5e5 + 5;
char a[nax];

ll f[nax];
ll inv[nax];

ll nk(ll n, ll k){
    if(n < k) return 0;
    return f[n] / (f[k] * f[n - k]);
}

void prep(){
    f[0] = 1;
    for(int i=1;i<5;i++) f[i] = f[i - 1] * i;
}

vector<int> trojki(int n){
    vector<int> ans;

    while(ans.size() < 15){
        ans.pb(n % 3);
        n /= 3;
    }
    return ans;
}

void solve(){
    int n; cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    int sum = 0;
    int h = n - 1;
    for(int i=0;i<=h;i++){
        int w = 0;
        if(a[i + 1] == 'B') w = 1;
        if(a[i + 1] == 'W') w = 2;
        vector<int> one = trojki(h);
        vector<int> two = trojki(i);
        int c = 1;
        for(int j=0;j<15;j++){
            c *= nk(one[j], two[j]);
            c %= 3;
        }
        sum += c * w;
    }
    sum %= 3;
    if(n % 2 == 0) sum = 3 - sum;
    sum %= 3;
    if(sum == 0) cout <<"R";
    if(sum == 1) cout <<"B";
    if(sum == 2) cout<<"W";

}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    prep();
    int tt = 1;
    // cin >> tt;
    while(tt--) solve();

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=4e5;
const int inf=1e9;
int fact[siz+1];
int three_count(int n){
	int ret = 0;
	while(n > 0){
		n /= 3;
		ret += n;
	}
	return ret;
}
int modcomb(int n, int r){
	if(three_count(n) > three_count(r) + three_count(n-r)) return 0;
	return (fact[n] * fact[n-r] * fact[r]) % 3;
}
int main(){
	fact[0] = 1;
	rep(i,1,siz+1){
        int j = i;
        while(j % 3 == 0) j /= 3;
		fact[i] = (fact[i-1] * j) % 3;
        //cout<<fact[i]<<endl;
	}
	int N; string s; cin>>N>>s;
	map<char,int> mp1; map<int,char> mp2;
	mp1['B'] = 0; mp1['W'] = 1; mp1['R'] = 2;
	mp2[0] = 'B'; mp2[1] = 'W'; mp2[2] = 'R';
	int ans = 0;
	rep(i,0,N){
        (ans += modcomb(N-1, i) * mp1[s[i]]) %= 3;
        //cout<<modcomb(N-1, i)<<endl;
    }
	if(N % 2 == 0) ans = (3 - ans) % 3;
	cout<<mp2[ans]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define ALL(v) v.begin(), v.end()
using ll = long long;
const int LIGHT = 1;
const int BLOCK = -1;
const int BLANK = 0;
const int LIT = 2;

int main()
{
    int H, W, N, M;
    cin >> H >> W >> N >> M;
    //light A:x, B:y   block C:x, D:y
    //vector<int> A(N), B(N), C(M), D(M);
    //REP(i, N) cin >> A.at(i) >> B.at(i);
    //REP(i, M) cin >> C.at(i) >> D.at(i);
    vector<vector<int>> S(H, vector<int>(W, BLANK));
    //1:light, -1:block, 0:blank
    int A, B, C, D;
    REP(i, N)
    {
        cin >> A >> B;
        S.at(A - 1).at(B - 1) = LIGHT;
    }
    REP(i, M)
    {
        cin >> C >> D;
        S.at(C - 1).at(D - 1) = BLOCK;
    }

    int b;

    //scan from left to right

    REP(i, H)
    {
        bool lit = false;
        int left = 0, right;
        REP(j, W)
        {
            int z = S.at(i).at(j);
            if (z == LIGHT)
            {
                lit = true;
            }

            if (z == BLOCK || (z != BLOCK && j == W - 1))
            {
                right = j + 1;
                if (lit)
                {
                    FOR(k, left, right)
                    {
                        if (S.at(i).at(k) == BLANK)
                        {
                            S.at(i).at(k) = LIT;
                        }
                    }
                    lit = false;
                }
                left = j + 1;
            }
        }
    }

    //scan from top to bottom

    REP(j, W)
    {
        bool lit = false;
        int top = 0, bottom;
        REP(i, H)
        {
            int z = S.at(i).at(j);
            if (z == LIGHT)
            {
                lit = true;
            }

            if (z == BLOCK || (z != BLOCK && i == H - 1))
            {
                bottom = i + 1;
                if (lit)
                {
                    FOR(k, top, bottom)
                    {
                        if (S.at(k).at(j) == BLANK)
                        {
                            S.at(k).at(j) = LIT;
                        }
                    }
                    lit = false;
                }
                top = i + 1;
            }
        }
    }

    int count = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            if(S.at(i).at(j) > 0) count += (S.at(i).at(j) > 0) ? 1 : 0;
        }
    }

    cout << count << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()

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

  vector<vector<ll>> vec(H,vector<ll> (W,0));

  for(ll i=0;i<N;i++) {
ll A,B;
    cin>>A>>B;
 A--;
    B--;
    vec[A][B]=1;
  }

  for(ll i=0;i<M;i++) {
ll C,D;
    cin>>C>>D;
    C--;
    D--;
    vec[C][D]=2;
  }

  vector<vector<bool>> note(H,vector<bool> (W,false));
  ll ans=0;

  for(ll i=0;i<W;i++) {
ll count=0;

    for(ll j=0;j<H;j++) {
      if(vec[j][i]==0) {
        if(count<=0) {
count--;
        }
        else {
count++;
      }
      }

      else if(vec[j][i]==1) {
        if(count<=0) {
count*=-1;
        }
        count++;
      }

        else {
if(count<=0) {
count=0;
}
          else {
            ans+=count;
            for(ll h=j-count;h<j;h++) {
              note[h][i]=true;
            }
            count=0;
          }
        }

       if(j==H-1&&count>0) {
         ans+=count;
for(ll h=j-count+1;h<=j;h++) {
note[h][i]=true;
}
       }

      }

  }

      for(ll i=0;i<H;i++) {
ll count=0;
        for(ll j=0;j<W;j++) {

  if(vec[i][j]==0) {
if(count<=0) {
count--;
}
    else {
count++;
    }
  }
          else if(vec[i][j]==1) {
if(count<=0) {
count*=-1;
}
            count++;
          }

          else {
if(count<=0) {
count=0;
}
            else {
ans+=count;
              for(ll h=j-count;h<j;h++) {
if(note[i][h]) {
ans--;
}
              }
              count=0;
            }
          }

            if(count>0&&j==W-1) {
ans+=count;
              for(ll h=j-count+1;h<=j;h++) {
if(note[i][h]) {
ans--;
}
              }

            }

          }
        }

        cout<<ans<<endl;
      }


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

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using pll = pair<ll, ll>;
using vpl = vector<pll>;

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define mkt make_tuple
#define rep2(i, m, n) for (ll i = (m); i < (ll) (n); i++)
#define rep(i, n) rep2(i, 0LL, n)
#define per2(i, n, m) for (ll i = n - 1; i >= m; i--)
#define per(i, n) per2(i, n, 0LL)
#define repit(itr, t) for (auto itr = (t).begin(); itr != (t).end(); ++itr)
#define all(c) begin(c), end(c)
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define biti(bit, i) ( (bit >> i) & 1 )
#define _GLIBCXX_DEBUG

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U> p) {
  os << "(" << p.fi << " " << p.se << ")" << endl;
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T> v) {
  os << "{ ";
  for (auto e: v) os << e << " ";
  os << "}";
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<vector<T>> vv) {
  os << "{" << endl;
  for (auto v: vv) {
    for (auto e: v) os << e << " ";
    os << endl;
  }
  os << "}";
  return os;
}

const ll VLMAX = 200010;
const ll MOD = 1000000007;
const ll INF = LONG_MAX;

int main() {
  ll a, b;
  cin >> a >> b;

  if (15 <= a + b && 8 <= b) cout << 1 << endl;
  else if (10 <= a + b && 3 <= b) cout << 2 << endl;
  else if (3 <= a + b) cout << 3 << endl;
  else cout << 4 << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;

    if (a + b >= 15 && b >= 8) cout << 1 << endl;
    else if (a + b >= 10 && b >= 3) cout << 2 << endl;
    else if (a + b >= 3) cout << 3 << endl;
    else cout << 4 << endl;

    return 0;
}


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

void chmax(int& a, int b){
    a = max(a, b);
}

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0; i<H; i++) cin >> S[i];

    vector<vector<int>> dp(H, vector<int>(W, -1e9));
    dp[H-1][W-1] = 0;
    for(int i=H-1; i>=0; i--) for(int j=W-1; j>=0; j--){
        int v = (S[i][j] == '+' ? 1 : -1);
        if(i) chmax(dp[i-1][j], -dp[i][j] + v);
        if(j) chmax(dp[i][j-1], -dp[i][j] + v);
    }
    int v = dp[0][0];
    string ans = "Draw";
    if(v > 0) ans = "Takahashi";
    if(v < 0) ans = "Aoki";
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int N=2010;
int f[N][N];
int n,m;
int opt[N][N];
int main(){
	scanf("%d%d",&n,&m);
	char s;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		cin>>s;
		if(s=='+')f[i][j]=1;
		else f[i][j]=-1;
	}
	for(int i=n;i>=1;i--)
	for(int j=m;j>=1;j--){
		if(i+1>n&&j+1>m)continue;
		else if(i+1>n&&j+1<=m){
			if(i+j&1)opt[i][j]=opt[i][j+1]-f[i][j+1];
			else opt[i][j]=opt[i][j+1]+f[i][j+1];
		}
		else if(i+1<=n&&j+1>m){
			if(i+j&1)opt[i][j]=opt[i+1][j]-f[i+1][j];
			else opt[i][j]=opt[i+1][j]+f[i+1][j];
		}
		else if(i+j&1)opt[i][j]=min(opt[i+1][j]-f[i+1][j],opt[i][j+1]-f[i][j+1]);
		else opt[i][j]=max(opt[i+1][j]+f[i+1][j],opt[i][j+1]+f[i][j+1]);
	}
	if(opt[1][1]>0)puts("Takahashi");
	else if(opt[1][1]==0)puts("Draw");
	else puts("Aoki");
	return 0;
}


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

const int mod = 998244353;

int main()
{
    int n ,ans = 0;
    scanf("%d",&n);
    vector <int> a(n);
    for(int&i : a){
        scanf("%d",&i);
        ans = (ans + 1LL*i*i%mod)%mod;
    }
    sort(a.begin() ,a.end());
    int bef = a[0];
    for(int i=1; i<n; i++){
        ans = (ans + 1LL*a[i]*bef%mod)%mod;
        bef = (2LL*bef + a[i])%mod;
    }
    printf("%d\n",ans);
}


#include<ctime>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=2e5+7;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
ll n,x,c,las,l[N],r[N],f[N][2];
int main() {
	#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	for(ll i=1;i<=n;++i){
		l[i]=1e18;
		r[i]=-1e18;
	}
	for(ll i=1;i<=n;++i){
		x=read();
		c=read();
		l[c]=min(l[c],x);
		r[c]=max(r[c],x);
	}
	++n;
	l[n]=r[n]=0;
	for(ll i=1;i<=n;++i){
		if(l[i]>r[i])
			continue;
		f[i][0]=1e18;
		f[i][1]=1e18;
		if(l[las]<=l[i])
			f[i][1]=min(f[i][1],f[las][0]+r[i]-l[las]);
		else
			f[i][1]=min(f[i][1],f[las][0]+l[las]-l[i]*2+r[i]);
		if(r[las]<=l[i])
			f[i][1]=min(f[i][1],f[las][1]+r[i]-r[las]);
		else
			f[i][1]=min(f[i][1],f[las][1]+r[las]-l[i]*2+r[i]);
		if(l[las]>=r[i])
			f[i][0]=min(f[i][0],f[las][0]+l[las]-l[i]);
		else
			f[i][0]=min(f[i][0],f[las][0]+r[i]*2-l[las]-l[i]);
		if(r[las]>=r[i])
			f[i][0]=min(f[i][0],f[las][1]+r[las]-l[i]);
		else
			f[i][0]=min(f[i][0],f[las][1]+r[i]*2-r[las]-l[i]);
		las=i;
	}
	printf("%lld",min(f[n][0],f[n][1]));
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<P> cx;
    vector<ll> L = {0},R = {0};
    rep(i,n)
    {
        int c,x;
        cin >> x >> c;
        cx.emplace_back(c,x);
    }
    sort(cx.begin(),cx.end());
    map<ll,bool> used;
    for(auto cxi:cx)
    {
        ll ci,xi;
        tie(ci,xi) = cxi;

        if(!used[ci])
        {
            L.emplace_back(xi);
            R.emplace_back(xi);
            used[ci] = true;
        }
        else
        {
            int idx = L.size()-1;
            L[idx] = min(L[idx],xi);
            R[idx] = max(R[idx],xi);
        }
    }
    int s = L.size()-1;
    vector<vector<ll>> dp(s+5, vector<ll> (2));
    dp[0][0] = 0;

    rep(i,s)
    {
        dp[i+1][0] = min(dp[i][0] + abs(L[i] - R[i+1]),
                         dp[i][1] + abs(R[i] - R[i+1]))
                         + abs(R[i+1]-L[i+1]);
        dp[i+1][1] = min(dp[i][0] + abs(L[i] - L[i+1]),
                         dp[i][1] + abs(R[i] - L[i+1]))
                         + abs(R[i+1]-L[i+1]);

    }
    ll ans = min(dp[s][0]+abs(L[s]),dp[s][1]+abs(R[s]));
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> dp(n+1,0.0);
  for(int i = n-1; i >= 1; i--) dp[i] = dp[i+1] + (double)n/(double)(n-i);
  printf("%.9lf\n",dp[1]);
  return 0;
}

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

using namespace std;

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

  int T;
  cin >> T;
  while(T--){
    ll n;
    cin >> n;
    if(n&1) cout <<"Odd\n";
    else{
      if(n%4 == 0) cout <<"Even\n";
      else cout <<"Same\n";
    }
  }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}

int main() {
    ll h,w;
    cin >> h >> w;
    Vs v(h);
    rep(i,h) cin >> v[i];
    ll ans=0;
    rep(i,h-1)rep(j,w-1){
        ll x=0,y=0;
        rep(k,2)rep(l,2){
            if(v[i+k][j+l]=='#') x++;
            else y++;
        }
        if(x%2==1) ans++;
    }
    cout << ans << endl;

}

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn=1e6+10;
#define mod 1000000007
int main(){
	fast;
	ll n,m; cin>>n>>m;
	vector<vector<char>> a(n,vector<char>(m,' '));
	vector<vector<ll>> b(n,vector<ll>(m,0));
	for(auto i=0;i<n;++i){
		for(auto j=0;j<m;++j){
			cin>>a[i][j];
		}
	}
	ll cnt=0;
	for(auto i=0;i<n;++i){
		for(auto j=0;j<m;++j){
			if(a[i][j]=='.' && b[i][j]==0){
				if(i-1>=0 && a[i-1][j]=='#' && j-1>=0 && a[i][j-1]=='#'){
					++cnt;
				}if(i-1>=0 && a[i-1][j]=='#' && j+1<m && a[i][j+1]=='#'){
					++cnt;
				}if(i+1<n && a[i+1][j]=='#' && j-1>=0 && a[i][j-1]=='#'){
					++cnt;
				}if(i+1<n && a[i+1][j]=='#' && j+1<m && a[i][j+1]=='#'){
					++cnt;
				}
				b[i][j]=1;
			}else if(a[i][j]=='#' && b[i][j]==0){
				if(i-1>=0 && a[i-1][j]=='.' && j-1>=0 && a[i][j-1]=='.'){
					// b[i][j]=1;
					++cnt;
				}if(i-1>=0 && a[i-1][j]=='.' && j+1<m && a[i][j+1]=='.'){
					// b[i][j]=1;
					++cnt;
				}if(i+1<n && a[i+1][j]=='.' && j-1>=0 && a[i][j-1]=='.'){
					// b[i][j]=1;
					++cnt;
				}if(i+1<n && a[i+1][j]=='.' && j+1<m && a[i][j+1]=='.'){
					// b[i][j]=1;
					++cnt;
				}
				b[i][j]=1;
			}
		}
	}
	cout<<cnt<<'\n';
	return 0;
}
// combnatorics(pigeonhole principle, stars and bars (n+k-1)C(k-1))
// comparator in inbuilt sorting
// lcs
// period of a string(prefix-function) with KMP
// prime func
// subset production
// factorization
// modpow
// modinv ( a^(p-2)=a^(-1) (mod p) )
// sieve
// ncr
// euler totien func (co prime divisiors upto n)
// matrix exponentation(fast fibonacci)
// dsu
// Trees
// Graphs(dfs,bfs,shortes path etc.)
// DP-Recursion


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
int n;
ll k;
ll cnt[3000005];
ll divi(int x)
{
	if (x <= 0) return 0;
	return (ll)(x - 1) * (x - 2) / 2;
}

ll func(int m)
{
	ll p = divi(m) - divi(m - n) * 3LL + divi(m - n - n) * 3LL;
	return p;
}

void init()
{
	read(n); read(k);
	for (int i = 3; i <= n + n + n; ++i)
	{
		cnt[i] = func(i);
		cnt[i] += cnt[i - 1];
	}
}

ll calc(int x)
{
	if (x > n + n) return 0;
	if (x < 2) return 0;
	if (x > n + 1) x = n + n + 2 - x;
	return x - 1;
}

void solve()
{
	ll R = 0; int P = 0;
	for (int i = 3; i <= n + n + n; ++i) if (cnt[i] >= k)
	{
		R = k - cnt[i - 1];
		P = i;
		break;
	}
	int ans1 = 0, ans2 = 0;
	ll t = 0;
	for (int i = 1; i <= n; ++i) if (i <= P)
	{
		ll c = calc(P - i);
		if (t + c >= R)
		{
			R -= t;
			ans1 = i;
			break;
		}
		t += c;
	}
	int now = 0;
	for (int i = 1; i <= n; ++i)
	{
		int o = P - ans1 - i;
		if (o >= 1 && o <= n)
		{
			++now;
			if (now == R)
			{
				ans2 = i;
				break;
			}
		}
	}
	printf("%d %d %d\n", ans1, ans2, P - ans1 - ans2);
}

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

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl
#define all(v) (v).begin(),(v).end()

typedef long long ll;

#define rmin(a,b) a = min<ll>(a,b)
#define rmax(a,b) a = max<ll>(a,b)

#define fi first
#define se second

const int N = 3e6+10;
ll dp[3][N], pref[3][N];
int ms;
void mp(ll *v, ll *p){
	for(int i = ms; i>=0; i--) p[i] = p[i+1]+v[i];
}

ll fsoma(ll *p, int l, int r){
	return p[l]-p[r+1];
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	ll n, k; cin >> n >> k;
	k--;
	ms = 3*(n-1);
	fr(i,n) dp[0][i] = 1;
	mp(dp[0],pref[0]);

	for(int cor = 1; cor<=2; cor++){
		for(int i = 0; i<=3*(n-1); i++){
			dp[cor][i] = fsoma(pref[cor-1],max<int>(0,i-(n-1)),i);
		}
		mp(dp[cor],pref[cor]);
	}

	ll qnt = 0;
	for(ll s = 0; s<=3*(n-1); s++){
		qnt+= dp[2][s];
		if(qnt>k){
			qnt-= dp[2][s];
			fr(a,n){
				ll add = dp[1][s-a];
				if(qnt+add>k){
					s-=a;
					fr(b,n){
						ll add = dp[0][s-b];
						if(qnt+add>k){
							ll c = s-b;
							cout << a+1 << " " << b+1 << " " << c+1 << "\n";
							return 0;
						}
						qnt+=add;
					}
				}
				qnt+=add;
			}
		}
	}
	assert(0);
}


/* これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました */

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	int n;
	cin>>n;
	string s,t;
	cin>>s;
	cin>>t;
	if(count(all(s),'1') != count(all(t),'1'))
	{
		cout<<-1<<'\n';
		return;
	}
	ll ans=0;

	int cnt1=0,cnt2=0;

	for(int i=0;i<n;i++)
	{
		if(s[i]=='0') cnt1++;
		if(t[i]=='0') cnt2++;
		if(cnt1>0 && cnt2>0)
		{
			if(cnt1==1 && cnt2==1)
			{
				cnt1--;
				cnt2--;
				if(s[i]!='0' || t[i]!='0') ans++;
			}
			else if(cnt1>cnt2)
			{
				ans += cnt2;
				cnt1 -= cnt2;
				cnt2 = 0;
			}
			else
			{
				assert(cnt2>cnt1);
				ans += 1LL*cnt1*(cnt1+1)/2;
				cnt2 -= cnt1;
				cnt1 = 0;
			}
		}
	}

	cout<<ans<<'\n';

}

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

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

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
const int mod = 998244353;
//const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int 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
// DEBUG FUNCTIONS END

const int N = 5e5+5;

void solve(){

	int n, m;
	cin>>n>>m;
	vi a(n), b(m), c(n), d(n);
	rep(i,0,n)cin>>a[i];
	rep(i,0,m)cin>>b[i];

	sort(all(a));
	int ans = infl;

	for(int i=1; i<n; i+=2){
		c[i] = (i>1 ? c[i-2] : 0) + a[i] - a[i-1];
	}

	for(int i=n-2; i>=0; i-=2){
		d[i] = (i<n-2 ? d[i+2] : 0) + a[i+1] - a[i];
	}

	trav(t, b){
		int i = lb(all(a),t) - a.begin();
		if(i&1)
			i--;
		int x = abs(a[i] - t);
		if(i!=n-1)
			x += d[i+1];
		if(i)
			x += c[i-1];
		mini(ans, x);
	}

	cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   // cin >> t;
    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

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

int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


//wtrl,everybody hangbeat me
#include<bits/stdc++.h>
/*#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>*/
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<ll,ll> pll;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define all(s) (s).begin(),(s).end()
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define INF 1e9
#define PI acos(-1)
/*=====================================================================*/
string int_to_string(ll n)
{
	string s="";
	while(n)
	{
		ll now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
ll string_to_int(string s)
{
	ll n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
/*======================================================================*/
ll lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}};
ll cnt[20],cnt1[20],cnt2[20];
ll quickpower(ll n,ll k)
{
	ll cnt=1;
	while(k)
	{
	  //cout<<k<<endl;
	  if(k&1)
	  {
	  	cnt*=n;
	  }
	  n*=n;
	  k>>=1;
	}
	//cout<<n<<" "<<k<<" "<<cnt<<endl;
	return cnt;
}
/*======================================================================*/
int main()
{
    std::ios::sync_with_stdio(false);
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  ll k;
  cin>>k;
  rep(i,9)
  {
  	cnt[i+1]=k;
  }
  string S,T;
  cin>>S>>T;
  rep(i,4)
  {
  	cnt[S[i]-'0']--;
  	cnt1[S[i]-'0']++;
  	cnt[T[i]-'0']--;
  	cnt2[T[i]-'0']++;
  }
  ll ans=0;
  forn(i,1,9)
  {
  	forn(j,1,9)
  	{
  	  if(cnt[i]==0||cnt[j]==0||(i==j&&cnt[i]<=1))
	  {
	    continue;
	  }
	  cnt1[i]++;
	  cnt2[j]++;
	  ll ans1=0,ans2=0;
	  forn(k,1,9)
	  {
	  	ans1+=k*quickpower(10,cnt1[k]);
	  	ans2+=k*quickpower(10,cnt2[k]);
	  }
	  if(ans1>ans2)
	  {
	  	if(i==j)
	  	{
	  	  ans+=cnt[i]*(cnt[i]-1);
		}
		else
		{
	  	  ans+=cnt[i]*cnt[j];
	    }
	    //cout<<i<<" "<<j<<endl;
	  }
	  cnt1[i]--;
	  cnt2[j]--;
	}
  }
  //cout<<ans<<" "<<(k*9-8)*(k*9-9)<<endl;
  cout<<fixed<<setprecision(6)<<(double)ans/((k*9-8)*(k*9-9))<<endl;
  return 0;
}
/*
注意数组越界，vector长度为0的时候循环会RE
注意输入顺序
*/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int k;
    string s, t;
    cin >> k >> s >> t;

    int p[10];
    for (int i = 1; i <= 9; i++) {
        p[i] = k;
    }
    for (int i = 0; i < 4; i++) {
        s[i] -= '0';
        t[i] -= '0';
        p[s[i]]--;
        p[t[i]]--;
    }

    auto f = [](const string &s) {
        int p[10] = {};
        for (int i = 0; i < 5; i++) {
            p[s[i]]++;
        }
        int r = 0;
        for (int i = 1; i <= 9; i++) {
            r += i * (int)pow(10, p[i]);
        }
        return r;
    };

    double r = 0;
    int l = k * 9 - 8;
    for (int a = 1; a <= 9; a++) {
        for (int b = 1; b <= 9; b++) {
            if (a == b && p[a] < 2) continue;
            if (p[a] < 1) continue;
            if (p[b] < 1) continue;
            s[4] = a;
            t[4] = b;
            int x = f(s) > f(t);
            r += (double)p[a] / l * (double)(p[b] - (a == b)) / (l - 1) * x;
        }
    }

    printf("%.12f\n", r);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()

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

#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb push_back
#define fo(i,a,n) for(int i=a;i<n;i++)
#define foo(i,a,n) for(int i=a;i>=n;i--)
#define sn s.length()
#define get(n) cin>>n

#define put(n) cout<<n

using namespace std;

signed main()
{
    int t=1;

    //cin>>t;

    while(t--)
    {
      int n,p=0;
      cin>>n;
      cout<<max(p,n);

    }
}


#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

template<class ForwardIterator> void print_vec(ForwardIterator first, ForwardIterator last, string sep = " ", string end="\n") {
	bool ft = true;
	while (first != last) {
		if (! ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

bool predicate(ll mid) {
	return mid > 10;
}

ll bin_search(ll lo, ll hi) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = floorDiv(lo + hi, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

ll num[MAXN];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	TC {
		int n;
		cin >> n;
		FOR(i,0,n){
			cin >> num[i];
		}
		if (n%2 == 1) {
			cout << "Second\n";
			continue;
		}
		map<ll,int> cnt;
		FOR(i,0,n) {
			cnt[num[i]]++;
		}
		bool g = true;
		for (auto &p : cnt) {
			if (p.S%2!=0) {
				g=false;
				break;
			}
		}
		cout << (g ? "Second\n" : "First\n" );
	}

}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define ll long long
#define PI 3.1415926535897932384626
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define br printf("\n")
#define fo(i, n) for(i=0;i<n;i++)
#define Fo(i, k, n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x) cout << #x << " = " << x << endl;
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deba(i, a, n) fo(i, n){cout << a[i] << " ";}
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+)
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
const int mod = 1000000007;
const int N = 3e5;
bool comp(int a, int b)
{
    return (a < b);
}
long long int largest(long long int arr[], long long int n)
{
    long long int i;

    // Initialize maximum element
    long long int max = arr[0];

    // Traverse array elements
    // from second and compare
    // every element with current max
    for (i = 1; i < n; i++)
        if (arr[i] > max)
            max = arr[i];

    return max;
}
int getIndex(vector<int> v, int K)
{
    auto it = find(v.begin(), v.end(), K);
    if (it != v.end())
    {
        int index = it - v.begin();
        return index;
    }
    else {
        return -1;
    }
}
/* ========== SOLUTION ========= */

void solution() {
    int n;
    cin>>n;
    cout<<n-1;
}
/* ========== SOLUTION ========= */
int main() {

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    // freopen("input.txt", "r", stdin);
    // freopen("error.txt", "w", stderr);
    // freopen("output.txt", "w", stdout);

    solution();
    cout<<"\n";

    // int t=1;
    // cin>>t;
    // while(t--) {
    //     solution();
    //     cout<<endl;
    // }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef pair<int,pint> ppint;
typedef pair<ll,pll> ppll;
typedef vector<int> vint;
typedef vector<ll> vll;

const double pi=3.141592653589793;
const int INF10 = 1000000001;
const ll INF15 = 1e15 +1;
const long long INF18 = 1e18 + 1;
const int mod = 1000000007;
//const int mod = 998244353;
const double EPS=0.00001;

#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (ll)(n); i++)
#define rep2(i,start,end) for(int i=(ll)start;i<=(ll)end;i++)
#define vrep(i, n) for(int i=(ll)n-1;i>=0;i--)
#define vrep1(i, n) for(int i=(ll)n;i>0;i--)
#define all(n) n.begin(),n.end()
#define pb push_back
#define debug(x) cerr << #x <<": " << x << '\n'
#define arep(it,a) for(auto it : a )

struct edge{
    edge(int s,int e,long long c){
        to=e;from=s;cost=c;
    }
    edge(int i,long long c=1){
        edge(-1,i,c);
    }
    int from;
    int to;
    long cost;
};
typedef vector<edge> edges;

//bを何回足せばaを超えるか(O(a/b))
//a+b-1/bとすればよし

//2進数表示したときの最高桁(O(log n))
template<class M>
M bi_max(M n){ M m = 0; for (m; (1 << m) <= n; m++); return m-1; }
//bi_eに二進数表示したやつを代入(O(log^2 n))
//bitset<N> a(n)でnの二進数表示が得られて、a[i]=0or1でi番目のfragが立ってるかわかる
//x^n mod m (nが負の時は０)(O(log n))
template<class M,class N,class L>
common_type_t<M,N,L> myPow(M a,N b,L m=mod){
    common_type_t<M,N,L> res=1;
    while(b!=0){
        if(b & 1)(res*=a)%=m;
        b>>=1;
        (a*=a)%=m;
    }return res%m;
}
template<class T>
bool maxin (T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool minin (T &a,T b){if(a>b){a=b;return 1;}return 0;}
template<class M,class N>
common_type_t<M,N> mygcd(M a,N b){
    a=abs(a);b=abs(b);
    if(a < b) return mygcd(b, a);
    M r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
template<class M,class N>
common_type_t<M,N> mylcm(M a,N b){
    return (a/mygcd(a,b))*b;
}

const int N_MAX=100005;
int n;
vint a,b,dp,mem;

void Main(){
    int x=0,y=INF10,z=1;
    //入力
    bool ng=false;
    cin>>n;
    mem.resize(2*n+1,0);
    dp.resize(2*n+1,0);
    rep(i,n){
        cin>>x>>y;
        a.pb(x);b.pb(y);
        if(x!=-1){
            if(mem[x]!=0)ng=true;
            mem[x]=i+1;
        }
        if(y!=-1){
            if(mem[y]!=0)ng=true;
            mem[y]=-(i+1);
        }
    }
    //処理
    if(ng){
        cout << "No" <<endl;
        return;
    }
    bool tof;
    dp[0]=1;
    rep1(p,2*n-1){
        if(!dp[p-1])continue;
        rep1(j,2*n){
            int q=p+2*j-1;
            if(q>2*n)break;
            tof=true;
            rep2(l,p,q){
                if(mem[l]!=0){
                    if(mem[l]<0){
                        int m=-mem[l]-1;
                        if( a[m]!=-1 && ( a[m]<p || a[m]!=l-j ) ){tof=false;break;}
                        else if( a[m]==-1 &&( l-j<p || mem[l-j]!=0 )){tof=false;break;}
                    }else if(mem[l]>0){
                        int m=mem[l]-1;
                        if( b[m]!=-1 && ( b[m]>q || b[m]!=l+j ) ){tof=false;break;}
                        else if(b[m]==-1 &&( l+j>q || mem[l+j]!=0)){tof=false;break;}
                    }
                }
            }
            if(tof)dp[q]=true;
        }
    }
    //出力
    dp[2*n]?cout << "Yes" <<endl:cout << "No" <<endl;;
}

int main(){
    cin.tie(nullptr);
    cout<<fixed<<setprecision(12);
    Main();
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,l,r) for(i=(l);i<=(r);++i)
#define per(i,l,r) for(i=(l);i>=(r);--i)
#define REP(i,l,r) for(i=(l);i< (r);++i)
#define PER(i,l,r) for(i=(l);i> (r);--i)
typedef long long ll;
const int N=105;
struct man{
	int a,b;
}A[N];
int D[N],F[N<<1];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);

	int n,i,l,r,a,b;
	scanf("%d",&n);
	rep(i,1,n)scanf("%d%d",&A[i].a,&A[i].b);
	D[0]=1;
	rep(r,1,n){
		REP(l,0,r)if(D[l]){
			//printf("(%d,%d]\n",l<<1,r<<1);
			rep(i,1,n<<1)F[i]=0;
			rep(i,1,n)if(~(A[i].a&A[i].b)){
				if(~(A[i].a|A[i].b)){
					//printf("%d %d\n",A[i].a,A[i].b);
					if(A[i].b<=A[i].a)break;
					if(A[i].b<=l+l||A[i].a>r+r){}
					else if(A[i].b==A[i].a+r-l&&A[i].a>l+l&&A[i].a<=l+r){
						if(F[A[i].a]||F[A[i].b])break;
						F[A[i].a]=F[A[i].b]=1;
					}else break;
				}else{
					if(~A[i].a){
						if(A[i].a<=l+l||A[i].a>r+r)continue;
						//printf("%d ?\n",A[i].a);
						if(A[i].a> l+r)break;
						if(F[A[i].a    ])break;F[A[i].a    ]=1;
						if(F[A[i].a+r-l])break;F[A[i].a+r-l]=1;
					}else{
						if(A[i].b<=l+l||A[i].b>r+r)continue;
						//printf("? %d\n",A[i].b);
						if(A[i].b<=l+r)break;
						if(F[A[i].b    ])break;F[A[i].b    ]=1;
						if(F[A[i].b+l-r])break;F[A[i].b+l-r]=1;
					}
				}
			}
			//printf("(%d,%d] ans=%d\n",l<<1,r<<1,i>n);
			if(i>n){D[r]=1;break;}
		}
		//printf("D[%d]=%d\n",r,D[r]);
	}
	if(D[n])puts("Yes");else puts("No");
	return 0;
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

typedef vector<vector<int64_t>> Mat;

Mat matmul(Mat A, Mat B){
    assert(A[0].size() == B.size());
    int N = A.size(), M = B[0].size(), K = B.size();
    Mat ans(N, vector<int64_t>(M));
    for(int i=0; i<N; i++) for(int j=0; j<M; j++) for(int k=0; k<K; k++) add(ans[i][j], A[i][k] * B[k][j]);
    return ans;
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<int64_t>> A(N, vector<int64_t>(1));
    for(int i=0; i<N; i++) cin >> A[i][0];
    vector<vector<int>> edges(N);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    int64_t inv2M = inv_mod(2*M);
    vector<vector<int64_t>> X(N, vector<int64_t>(N));
    for(int i=0; i<N; i++){
        X[i][i] = 1;
        for(int j : edges[i]){
            X[j][i] = inv2M;
            add(X[i][i], MOD-inv2M);
        }
    }

    while(K > 0){
        if(K%2) A = matmul(X, A);
        X = matmul(X, X);
        K /= 2;
    }
    for(auto a : A) cout << a[0] << endl;
    return 0;
}

/* stuff you should look for
	* int overflow, array bounds, uppercase/lowercase
	* special cases (n=1?)
	* do sth. instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/
#include<cstdio>
const int mod=1e9+7;
int n,cnt,deg[105];
int h[105],to[20005],ver[20005];
struct matrix {
	int a[105][105];
}A,trans;
inline matrix operator*(const matrix &x,const matrix &y) {
	matrix res;
	for(register int i=1;i<=n;++i) {
		for(register int j=1;j<=n;++j) {
			int ans=0;
			for(register int k=1;k<=n;++k) {
				ans+=x.a[i][k]*1ll*y.a[k][j]%mod;
				if(ans>=mod) ans-=mod;
			}
			res.a[i][j]=ans;
		}
	}
	return res;
}
inline matrix operator^(matrix x,int p) {
	matrix res;
	for(register int i=1;i<=n;++i) {
		for(register int j=1;j<=n;++j) res.a[i][j]=0;
		res.a[i][i]=1;
	}
	for(;p;p>>=1) {if(p&1) res=res*x; x=x*x;}
	return res;
}
inline int read() {
	register int x=0,f=1;register char s=getchar();
	while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline void add(int x,int y) {to[++cnt]=y;ver[cnt]=h[x];h[x]=cnt;}
inline int pow(int x,int p) {int res=1;for(;p;p>>=1) {if(p&1) res=res*1ll*x%mod; x=x*1ll*x%mod;}return res;}
int main() {
	n=read(); int m=read(),K=read();
	for(register int i=1;i<=n;++i) A.a[1][i]=read();
	for(register int i=1;i<=m;++i) {
		int x=read(),y=read();
		++deg[x]; ++deg[y]; add(x,y); add(y,x);
	}
	int inv2=pow(2,mod-2),invm=pow(m,mod-2);
	for(register int i=1;i<=n;++i) {
		trans.a[i][i]=mod+1-deg[i]*1ll*invm%mod*inv2%mod;
		for(register int k=h[i];k;k=ver[k]) {
			int y=to[k];
			trans.a[y][i]=invm*1ll*inv2%mod;
		}
	}
	matrix res=A*(trans^K);
	for(register int i=1;i<=n;++i) printf("%d\n",res.a[1][i]);
	return 0;
}


// Problem: A - Rock-paper-scissors
// Contest: AtCoder - AtCoder Beginner Contest 204
// URL: https://atcoder.jp/contests/abc204/tasks/abc204_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

//code by: Ravi Khatri
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define pb push_back
#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
#define fr(i,n,s) for(int i=(int)n;i>=s;--i)
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
#define mod 1000000007

void solve()
{
	int n;cin>>n;
	int ans=0;
	f(i,1,n){
		int x;cin>>x;
		if(x>10){
			ans+=x-10;
		}
	}
	cout<<ans<<"\n";
}
int main()
{	Fast;
	// int t;cin>>t;
	// while(t--)
	solve();
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=3e5;
const int inf=1e9;
int main(){
	int N,M; cin>>N>>M;
	int x,y;
	pair<int,int> vp[M+1]; vp[0] = {0, N};
	map<pair<int,int>,bool> mp; mp[vp[0]] = true;
	map<int,vector<int>> record; record[N].push_back(0);
	rep(i,0,M){
		cin>>x>>y;
		vp[i+1] = {x, y};
		record[y].push_back(x);
	}
	sort(vp,vp+M+1);
	for(auto it = record.begin(); it != record.end(); it++){
		sort((it->second).begin(), (it->second).end());
      	//print((it->second),,(it->second).size());
	}
	rep(i,1,M+1){
		pair<int,int> p = vp[i];
		mp[p] = false;
		if(p.second > 0 && !record[p.second-1].empty()){
			auto it = lower_bound(record[p.second-1].begin(), record[p.second-1].end(), p.first);
			if(it != record[p.second-1].begin()){
				mp[p] |= mp[{*(it-1), p.second-1}];
			}
		}
		if(p.second < 2*N && !record[p.second+1].empty()){
			auto it = lower_bound(record[p.second+1].begin(), record[p.second+1].end(), p.first);
			if(it != record[p.second+1].begin()){
				mp[p] |= mp[{*(it-1), p.second+1}];
			}
		}//cout<<p.first<<" "<<p.second<<" "<<mp[p]<<endl;
	}
	int ans = 0;
	for(pair<int,vector<int>> pv:record){
      	if(!pv.second.empty()) ans += mp[{pv.second.back(), pv.first}];
	}
	cout<<ans<<endl;
}


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

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

  vector<int> count(31,0);

  for(int i = 2; i <= n; i++) {
    vector<int> counter(31,0);
    int tmp = i;
    for(int j = 2; j<= i; j++) {
      if(tmp < j) break;
      while(tmp % j == 0) {
	counter[j] ++;
	tmp /= j;
      }
    }

    for(int j = 2; j <= n; j++) count[j] = max(count[j], counter[j]);

  }

  long long int sum = 1;

  for(int i = 2;i <=n; i++) {
    for(int j = 0; j < count[i]; j++) sum *= i;
  }

  cout << sum+1 << endl;

  return 0;
}


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

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string s;
    cin >> s;
    if (s.size() <= 3) {
        sort(s.begin(), s.end());
        do {
            if (stoi(s) % 8 == 0) {
                cout << "Yes\n";
                return 0;
            }
        } while (next_permutation(s.begin(), s.end()));
    } else {
        for (int x = 112; x < 1000; x += 8) {
            int cnt[10]{};
            for (int y = x; y > 0; y /= 10) {
                cnt[y % 10]++;
            }
            if (cnt[0]) continue;
            for (char c : s) {
                if (--cnt[c - '0'] == 0) {
                    bool ok = true;
                    for (int i = 0; i < 10; i++) {
                        ok &= (cnt[i] <= 0);
                    }
                    if (ok) {
                        cout << "Yes\n";
                        return 0;
                    }
                }
            }

        }
    }
    cout << "No\n";
    return 0;
}

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

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


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

int main() {
    string S;
    cin >> S;

    int N = S.size();
    vector<int> cnt(10);
    rep(i, N) { ++cnt[S[i] - '0']; }

    if (N >= 3) {
        for (int i = 14; i * 8 < 1000; ++i) {
            int X = i * 8;
            vector<int> tmp(10);
            while (X > 0) {
                ++tmp[X % 10];
                X /= 10;
            }

            bool ok = true;
            rep(i, 10) {
                if (cnt[i] < tmp[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    } else if (N == 2) {
        for (int i = 2; i * 8 < 100; ++i) {
            int X = i * 8;
            vector<int> tmp(10);
            while (X > 0) {
                ++tmp[X % 10];
                X /= 10;
            }

            bool ok = true;
            rep(i, 10) {
                if (cnt[i] < tmp[i]) {
                    ok = false;
                    break;
                }
            }

            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    } else {
        if (S == "8") {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

#define int long long

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int n = s.length();
  if (n == 1) {
    if ((s[0] - '0') % 8 == 0)
      cout << "Yes\n";
    else
      cout << "No\n";
    return 0;
  }
  if (n == 2) {
    int a = stoi(s);
    if (a % 8 == 0)
      cout << "Yes\n";
    else {
      reverse(s.begin(), s.end());
      int b = stoi(s);
      if (b % 8 == 0)
        cout << "Yes\n";
      else
        cout << "No\n";
    }
    return 0;
  }
  vector<int> dp(8);
  for (int i = 0; i < n; i++) {
    int x = s[i] - '0';
    x %= 8;
    for (int j = 0; j < 8; j++) {
      for (int k = 0; k < 8; k++) {
        if ((j == k && dp[j] > 1) || ((j != k) && (dp[j] >= 1 && dp[k] >= 1))) {
          vector<int> nums = {x, j, k};
          sort(nums.begin(), nums.end());
          do {
            int cur = (nums[0] * 100) % 8 + (nums[1] * 10) % 8 + (nums[2]) % 8;
            cur %= 8;
            if (cur == 0) {
              cout << "Yes\n";
              return 0;
            }
          } while (next_permutation(nums.begin(), nums.end()));
        }
      }
    }
    dp[x]++;
  }
  cout << "No\n";
  return 0;
}