#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    ll ans = 0;
    map<ll, ll> mp;
    rep(i, n) {
        for(auto p : mp){
            ans += (a[i] - p.first) * (a[i] - p.first) * p.second;
        }
        mp[a[i]]++;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long long int x,y,a,b;
    cin >> x >> y >> a >> b;
    long long int ans=0;
    while((double)a*x<=2e18 && a*x<=x+b && a*x<y ){
        ans+=1;
        x*=a;

    }
    cout << ans+(y-1-x)/b <<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define M 1000000007
#define pb push_back
#define mp make_pair
#define pi 3.1415926536
#define prior priority_queue<int,vector<int>,greater<int>>
#define fi first
#define se second
const int INF =1e9 +5;
const int N=4e6+5;

/*int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

int fact[N],invfact[N];
void init(){
    fact[0]=1;
    int i;
    for(i=1;i<N;i++)
    {
            fact[i]=i*fact[i-1]%M;
    }
    i--;
    invfact[i]=pw(fact[i],M-2,M);
    for(i--;i>=0;i--){
        invfact[i]=(i+1)*invfact[i+1]%M;
    }
}
int ncr(int n,int r,int p){
    return (((fact[n]*invfact[n-r])%p)*invfact[r])%p;
}
int f(int r1,int r2,int k){
	int ans= ncr(k+1+r2,k,M) - ncr(k+r1,k,M)+M;
	ans%=M;
	return ans;
}*/
int32_t main()
{
    IOS;
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        cout<<(n/100)+bool (n%100);
    }

}

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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0)
#define MOD 100000007

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<ll> vi;
typedef set<ll> sit;

int main()
{
    fast_io;
    string str, str2;
    ll size, elm, tc, lim, n;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        cin>>str;
        vi vec(10, 0);
        size = str.size();
        for(ll x = 0; x < size; x++)
        {
            vec[str[x] - '0']++;
        }
        ll ans = 0;
        if(size < 3)
        {
            if(size == 1 && (str[0]-'0')%8 == 0)
                cout<<"Yes";
            else if(size == 1)
                cout<<"No";
            else if(size == 2 && (stoi(str) % 8 == 0))
                cout<<"Yes";
            else if(size == 2)
            {
                swap(str[0], str[1]);
                if((stoi(str) % 8 == 0))
                    cout<<"Yes";
                else
                    cout<<"No";
            }

        }
        else
        {
            for(ll x = 104; x < 999; x+=8)
            {
                vi vec2;
                str = to_string(x);
                for(ll i=0; i < 10; i++)
                    vec2.pb(vec[i]);
                ll is = 1;
                for(ll y = 0; y < str.size(); y++)
                {
                    if(vec2[str[y] - '0'] <= 0)
                    {
                        is = 0;
                        break;
                    }
                    else
                        vec2[str[y] - '0']--;
                }
                if(is)
                {
                    ans = x;
                    //cout<<ans;
                }
            }
            if(!ans)
                cout<<"No";
            else
                cout<<"Yes \n";
        }
    }
    return 0;
}


#include <iostream>

using namespace std;

int main(){
  int n, c = 0, jud = 0, max = 0;
  int a[100], b[100], judge[100];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    cin >> b[i];
    if(b[i] > max){
      max = b[i];
    }
  }

  for(int i = 0; i < max+1; i++){
    for(int j = 0; j < n; j++){
      if(a[j] <= i && b[j] >= i){
        judge[j] = 1;
      }
      else{
        judge[j] = 0;
      }
    }
    for(int i = 0; i < n; i++){
      if(judge[i] == 1){
        jud = 1;
      }
      else{
        jud = 0;
        break;
      }
    }
    if(jud == 1){
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

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

#define fs(n) fixed << setprecision(n)
using ll = long long;

int fact(int x) { return x <= 1 ? 1 : x * fact(x - 1); }

int sign(int x){
  return (x > 0) - (x < 0);
}

bool isLeapYear(int y, int m){
  return (y % 400 == 0 || (y % 4 == 0 && y % 100)) && m == 2;
}

vector<int> AllDivs(int d){
	vector<int> resDivs(0);
	for(int i = 1; i < (int)sqrt(d); i++){
		if(d % i == 0){
			resDivs.push_back(i);
			resDivs.push_back(d / i);
		}
	}
	sort(resDivs.begin(), resDivs.end());
	return resDivs;
}

bool IsPrime(int num){
	bool ans = true;
	if(num < 2) return false;
	else if (num == 2) return true;
	else{
		for(int i = 2; i <= (int)sqrt(num); i++){
			if(num % i == 0){
					ans = false;
			}
		}
	}
	return ans;
}

int NextPrime(int d){
	int ans = d;
	while(true){
		ans++;
		if(IsPrime(ans)) break;
	}
	return ans;
}

vector<int> Dec2Bin(int x, int len){
	vector<int> res(len, 0);
	int d = 1, pt = len - 1;
	while(d <= x){
		res[pt] = (x & d ? 1 : 0);
		d *= 2; pt--;
	}
	return res;
}

int avg(int a, int b){
  return (a + b) / 2;
}

int main(){
  int n; cin >> n;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];
  int amin = *max_element(a.begin(), a.end());
  int bmin = *min_element(b.begin(), b.end());
  int ans = bmin - amin + 1;
  cout << max(0, ans) << endl;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define erep(i,j) for(int i=hd[j];i;i=nxt[i])
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}

using namespace std;
const int M=1e6+5;
int mob[M],vis[M],cnt[M];
int E[M*20],hd[M*20],nxt[M*20];
int tot;
void add(int a,int b){
	E[++tot]=b,nxt[tot]=hd[a];
	hd[a]=tot;
}
long long que(int l,int r){
	long long ans=0;
	rep(i,1,r)cnt[i]=0;
	rep(i,l,r){
		erep(j,i){
			int t=E[j];
			ans+=cnt[t];
			cnt[t]+=mob[t];
		}
	}
	return ans;
}
int main() {
	int L=read(),R=read();
	rep(i,1,M-1)mob[i]=1;
	rep(i,2,M-1){
		if(vis[i])continue;
		mob[i]=-1;
		for(int j=i+i;j<M;j+=i){
			vis[j]=1;
			if(j/i%i==0)mob[j]=0;
			else mob[j]=-mob[j];
		}
	}
	rep(i,1,M-1)for(int j=i;j<M;j+=i)add(j,i);
	long long ans=0;
	rep(i,2,M-1){
		int mi=2e9,mx=-2e9;
		for(int j=i+i;j<M;j+=i)if(j>=L&&j<=R)mi=min(mi,j/i),mx=max(mx,j/i);
		if(mi<=mx)ans+=que(mi,mx);
	}
	printf("%lld\n",ans*2);
	return 0;
}

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = 998244353ll;

#define l_ength size

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

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll memo[5050][5050];

ll rwpw(ll a, ll p){
	return memo[a][p];
}

int main(void){
	int n,m,i,j,v;
	ll ans = 0ll, calc, tmp;
	std::cin >> n >> m;
	for(i=0; i<=m; ++i){
		memo[i][0] = 1ll;
		for(j=1; j<=n; ++j){
			memo[i][j] = memo[i][j-1]*i%MOD;
		}
	}
	for(v=1; v<=m; ++v){
		// 端&端
		add_mod(ans,rwpw(m-v+1,n));
		add_mod(ans,MOD-rwpw(m-v,n));
		for(i=1; i<n; ++i){
			// 片方が端
			calc = 0ll;
			add_mod(calc,rwpw(m-v+1,i));
			add_mod(calc,MOD-rwpw(m-v,i));
			mul_mod(calc,v-1);
			tmp = calc;
			mul_mod(tmp,rwpw(m,n-i-1));
			mul_mod(tmp,2ll);
			add_mod(ans,tmp);
			if(n-i<2){
				continue;
			}
			tmp = calc;
			mul_mod(tmp,v-1);
			mul_mod(tmp,rwpw(m,n-i-2));
			mul_mod(tmp,n-i-1);
			add_mod(ans,tmp);
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


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

int main() {

string x;
int p;
cin >> x;

p = x.find(".");

if(p == -1){
    cout << x << endl;
}
else{
    cout << x.substr(0,p) << endl;
}

}

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <stdlib.h>
#include <math.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;

int main() {
    string s;
    cin>>s;
    int index=0;
    while(s[index] != '.' && index < s.length()){
        char c = s[index];
        int n = c;
        cout<<n-48;
        index++;
    }
    cout<<endl;

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define pre(a,b) cout<<fixed<<setprecision(a)<<b<<"\n";//a for precision b for answer
//#define mp make_pair
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define pb push_back
 #define INF 1e18
#define min(a,b) (a<b?a:b)
#define forn(n) for(ll i=0;i<n;i++)
#define ff first
#define ss second
#define MAX 1e18;
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound
#define vmin *min_element
#define vmax *max_element
#define pii pair<int,int>
int mod = 1e9+7;
#define N 100005
#define pi 3.141592653589793238

using namespace std;

vector<int>adj[N];
vector<int>vis(N,0);
vector<int>color(N,0);
vector<int>good(N,0);

map<int,int>mp;
void dfs(int s,int par)
{
	vis[s]=1;
	mp[color[s]]++;
	for(int i=0; i<adj[s].size();i++)
	{
		if(adj[s][i]!=par)
		{
		dfs(adj[s][i],s);
		}
	}

	if(mp[color[s]]==1)
	{
		good[s] = 1;
		mp[color[s]]--;
	}
	else
	{
		mp[color[s]]--;
	}

 }

void solve(int cc)
{
	int n;
	cin>>n;
	for(int i=1; i<=n;i++)
	{
		cin>>color[i];
	}
int p =n-1;
while(p--)
{
	int a,b;
	cin>>a>>b;
	adj[a].pb(b);
	adj[b].pb(a);
}
dfs(1,0);
for(int i=1; i<=n; i++)
if(good[i]==1)
cout<<i<<endl;

}
signed  main()
{
IOS;

int t = 1;
//cin>>t;
 int cc =0;
 while(t--)
 {
 //	cout<<f(0,0,4,);
 	cc++;
solve(cc);
cout<<endl;

 }
}
//110101
//((()))
//(())()

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<ll>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
// void warshall_floyd(ll n)
// {
//     for (size_t i = 0; i < n; i++)
//     {
//         for (size_t j = 0; j < n; j++)
//         {
//             for (size_t k = 0; k < n; k++)
//             {
//                 dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
//             }
//         }
//     }
// }

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
struct Matrix
{
    int sz;
    ll x[33][33];
};

Matrix multiply(Matrix A, Matrix B)
{
    Matrix C;
    C.sz = A.sz;
    for (int i = 0; i < C.sz; i++)
    {
        for (int j = 0; j < C.sz; j++)
        {
            C.x[i][j] = 0;
        }
    }

    for (int i = 0; i < A.sz; i++)
    {
        for (int j = 0; j < A.sz; j++)
        {
            for (int k = 0; k < A.sz; k++)
            {
                C.x[i][k] += A.x[i][j] * B.x[j][k];
                C.x[i][k] %= MOD;
            }
        }
    }

    return C;
}

Matrix powers(Matrix A, ll T)
{
    Matrix E[64], F;
    E[0] = A;
    for (int i = 1; i < 62; i++)
    {
        E[i] = multiply(E[i - 1], E[i - 1]);
    }

    F.sz = E[0].sz;

    for (int i = 0; i < F.sz; i++)
    {
        for (int j = 0; j < F.sz; j++)
        {
            if (i == j)
                F.x[i][j] = 1;
            else
                F.x[i][j] = 0;
        }
    }

    for (int i = 62; i >= 0; i--)
    {
        if ((T & (1LL << i)) != 0LL)
        {
            F = multiply(F, E[i]);
        }
    }
    return F;
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

vector<ll> ans;
vector<bool> seen;
vector<long long> C;

void dfs(Graph &G, int v, map<ll, ll> &color)
{
    seen[v] = true;
    if (color[C[v]] == 0)
    {
        ans.push_back(v);
    }
    color[C[v]]++;
    for (auto nv : G[v])
    {
        if (seen[nv])
            continue;

        dfs(G, nv, color);
    }
    color[C[v]]--;
}

int main()
{

    long long N;
    scanf("%lld", &N);
    C.assign(N, 0);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &C[i]);
    }
    Graph G(N);
    seen.assign(N, false);
    for (int i = 0; i < N - 1; i++)
    {
        ll a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    map<ll, ll> color;
    dfs(G, 0, color);

    SORT(ans);
    for (auto &&i : ans)
    {
        cout << i + 1 << endl;
    }

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    string ans;
    int x = 108 * N / 100;
    if (x < 206) ans = "Yay!";
    else if (x == 206) ans = "so-so";
    else ans = ":(";
    cout << ans << endl;
}

#include<bits/stdc++.h>

using namespace std;

#define FOR(i, x, y) for(int i = (int)(x); i < (int)(y); ++i)
#define MP make_pair
#define fst first
#define snd second
typedef pair<int, int> pii;

const int maxn = 4e5 + 5;

int n, top = 0;
int a[maxn], ord[maxn], rev[maxn], stk[maxn];
char s[maxn];

inline bool cmp(const int &i, const int &j){ return a[i] < a[j]; }

int main(){
	scanf("%d", &n);
	FOR(i, 0, n << 1){
		scanf("%d", a + i);
		ord[i] = i;
	}
	sort(ord, ord + (n << 1), cmp);
	FOR(i, 0, n << 1)
		rev[ord[i]] = i;
	FOR(i, 0, n << 1){
		if(top && (rev[stk[top]] < n) != (rev[i] < n)){
			s[stk[top]] = '(', s[i] = ')';
			--top;
		}
		else
			stk[++top] = i;
	}

	puts(s);
	return 0;
}


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

// For Policy Based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
// ---------------------------------------
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pll             pair<int,int>
#define vll             vector<int>
#define vpll            vector<pair<int,int>>
#define all(c)          (c).begin(), (c).end()
#define bs              binary_search
#define pqb             priority_queue<int>
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define mem(arr,x)      memset(arr,x,sizeof(arr))
#define pi              3.14159265358979323846
#define inf             2000000000000000000
#define ps(x,y)         fixed<<setprecision(y)<<x
#define test(x)         int x; cin>>x;while(x--)

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template<class A> void read(vector<A>& x) {
  for (auto &a : x)
    read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
  for (auto &a : x)
    read(a);
}

const int d4i[4] = { -1, 0, 1, 0};
const int d4j[4] = {0, 1, 0, -1};
const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1};
const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void c_p_c()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
string int_to_string(int n) {
  ostringstream str1;
  str1 << n;
  string sar = str1.str();
  return sar;
}
int pow(int a, int b, int m)
{
  int res = 1;
  while (b > 0)
  {
    if (b % 2)
      res = (res * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return res;
}
int ncr(int  n, int k)
{ if (k == 0)
    return 1;
  if (k > n - k)
    k = n - k;
  int a = 1, b = 1, d;
  while (k)
  { a *= n; b *= k;
    d = __gcd(a, b);
    a /= d; b /= d;
    n--; k--;
  }
  return a;
}
int modinv(int k, int m)
{
  return pow(k, m - 2, m);
}
/***************************CODE BEGINS**************************************/
const int N = 102;
double dp[102][102][102];
double cal_dp(int x, int y, int z)
{
  if (x == 100 || y == 100 || z == 100) {
    return dp[x][y][z] = 0.0;
  }
  if (dp[x][y][z] != -1.0) {
    return dp[x][y][z];
  }
  int temp = x + y + z;
  double t1 = ((double)x / (double)temp) * (cal_dp(x + 1, y, z) + 1.0);
  double t2 = ((double)y / (double)temp) * (cal_dp(x, y + 1, z) + 1.0);
  double t3 = ((double)z / (double)temp) * (cal_dp(x, y, z + 1) + 1.0);
  return dp[x][y][z] = t1 + t2 + t3;
}
void solve ()
{
  int a, b, c;
  read(a, b, c);
  for (int i = 0; i <= 101; i++) {
    for (int j = 0; j <= 101; j++) {
      for (int k = 0; k <= 101; k++) {
        dp[i][j][k] = -1.0;
      }
    }
  }
  cout << ps(cal_dp(a, b, c), 8);
}
int32_t main()
{
  c_p_c();
  // test(x)
  solve();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
template <class T> vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

double dfs(int a, int b, int c, vector<vector<vector<double>>> &dp) {
    if(dp[a][b][c] != 0)
        return dp[a][b][c];
    if(a == 100 || b == 100 || c == 100)
        return 0;

    double ret = 0;
    ret += (a / (double)(a + b + c)) * (dfs(a + 1, b, c, dp) + 1.0);
    ret += (b / (double)(a + b + c)) * (dfs(a, b + 1, c, dp) + 1.0);
    ret += (c / (double)(a + b + c)) * (dfs(a, b, c + 1, dp) + 1.0);
    return dp[a][b][c] = ret;
}

int main() {
    ll A, B, C;
    cin >> A >> B >> C;
    auto dp = make_vec(101, 101, 101, 0.0);
    cout << fixed << setprecision(10) << dfs(A, B, C, dp) << endl;
}


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

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);

  int ans=0;
  vector<int> check(200005,0);

  rep(i,n){
    check.at(p.at(i))=1;
    if(ans!=p.at(i)) cout << ans << endl;
    else{
      while(check.at(ans)==1) ans++;
      cout << ans << endl;
    }
  }
}

#include "bits/stdc++.h"

#define pb push_back
#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vs vector<string>
#define vl vector<ll>
#define vll vector<vl>
#define all(x) x.begin(), x.end()
#define nl endl
#define rev(x) reverse(all(x))
#define ull unsigned ll
#define vpl vector<pll>
using namespace std;

//ull find(ull x){
//    return (x * (x + 1)) / 2;
//}

//vector<int> findCharacters(string s){
//    vector<int> a(26);
//    for(char el : s)
//        a[el - 'a']++;
//    return a;
//}

vl read(vl a) {
    for (auto &el : a)
        cin >> el;
    return a;
}

//int req(int l, int r){
//    cout << "? " << l + 1 << " " << r + 1 << endl;
//    int val;
//    cin >> val;
//    return val;
//}

void solve() {
    string s;
    cin >> s;
    bool sw = 1;
    for(int i = 0; i < s.size(); i++){
        char el = s[i];
        if(i % 2){
            if(el < 'A' || el > 'Z'){
                sw = 0;
                break;
            }
        } else {
            if(el < 'a' || el > 'z'){
                sw = 0;
                break;
            }
        }
    }
    cout << (sw ? "Yes" : "No") << endl;
}

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


#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int cnt = 0;
  int xcnt = 0;
  int scnt = 0;
  for (int i = 0; i < S.size(); i++)
  {
    if (S[i] == 'o')
      cnt++;
    else if (S[i] == 'x')
      xcnt++;
    else
      scnt++;
  }
  if (cnt > 4 || xcnt == 10)
  {
    cout << 0 << endl;
    return 0;
  }
  if (cnt == 4)
  {
    cout << 4 * 3 * 2 << endl;
    return 0;
  }
  if (cnt == 3)
  {
    cout << 36 + scnt * 4 * 3 * 2 << endl;
    return 0;
  }
  if (cnt == 2)
  {
    cout << 14 + scnt * 3 * 4 * 3 * 2 / 2 + scnt * (scnt - 1) / 2 * 4 * 3 * 2 << endl;
    return 0;
  }
  if (cnt == 1)
  {
    cout << 1 + scnt * 14 + scnt * (scnt - 1) / 2 * 36 + scnt * (scnt - 1) * (scnt - 2) / 6 * 4 * 3 * 2 << endl;
    return 0;
  }
  if (cnt == 0)
  {
    cout << scnt + scnt * (scnt - 1) / 2 * 14 + scnt * (scnt - 1) * (scnt - 2) / 6 * 36 + scnt * (scnt - 1) * (scnt - 2) * (scnt - 3) / 24 * 4 * 3 * 2 << endl;
    return 0;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pi pair<int, int>
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define FIO ios_base::sync_with_stdio(0), cin.tie(0)
#define fi first
#define se second

int fact(int n) {
    if (n <= 1) return 1;
    if (n == 2) return 2;
    if (n == 3) return 6;
    if (n == 4) return 24;
    return 0;
}

set<vector<int>> num;

void get(vector<int>& a, vector<int>& c, int i) {
    if (i == 4) {
        vector<int> x = a;
        sort(all(x));
        num.insert(x);
        return;
    }
    for (auto x : c) {
        a.pb(x);
        get(a, c, i + 1);
        a.pop_back();
    }
}

signed main() {
    FIO;
    string s;
    cin >> s;
    vector<int> a;
    set<int> v;
    for (int i = 0; i < 10; i++) {
        if (s[i] == 'o') {
            a.pb(i);
            v.insert(i);
        } else if (s[i] == '?') {
            v.insert(i);
        }
    }
    if (a.size() > 4) {
        cout << "0";
        return 0;
    }
    if (a.size() == 4) {
        cout << "24";
        return 0;
    }
    if (v.size() == 0) {
        cout << "0";
        return 0;
    }
    vector<int> c;
    for (auto it : v) c.pb(it);
    int i = a.size();
    get(a, c, i);
    int ans = 0;
    for (auto it : num) {
        unordered_map<int, int> freq;
        for (auto y : it) {
            freq[y]++;
        }
        int f = 24;
        for (auto p : freq) f /= fact(p.se);
        ans += f;
    }
    cout << ans;
}


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

int main() {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    int64_t max = 0;
    for (int i = 0; i < N; i++){
        int64_t counter = 1;
        for (int j = i - 1; j >= 0; j--){
            if(A.at(j) >= A.at(i)){
                counter++;
            }else{
                break;
            }
        }
        for (int j = i + 1; j < N; j++){
            if(A.at(j) >= A.at(i)){
                counter++;
            }else{
                break;
            }
        }
        if(max < counter * A.at(i)){
            max = counter * A.at(i);
        }
    }
    cout << max << endl;
}

#include<iostream>

using namespace std;

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

int main(){
    int N;
    cin >> N;
    int as[N];
    rep(i,N) cin >> as[i];

    int ma=0;
    rep(l,N){
        int mi=101000;
        for(int r=l;r<N;r++){
            mi = min(mi, as[r]);
            ma = max(ma, mi*(r-l+1));
        }
    }

    cout << ma << endl;
    return 0;

}


#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;
constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }

ll gcd(ll x, ll y) {	if (x == 0) return y;	return gcd(y%x, x);}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }
ll modpow(ll a, ll n, ll p) {	if(n==0) return (ll)1;  if (n == 1) return a % p;  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;  ll t = modpow(a, n / 2, p);  return (t * t) % p;}
ll modinv(ll a, ll m) {	if(m==0)return (ll)1;	ll b = m, u = 1, v = 0;	while (b) {		ll t = a / b;		a -= t * b; swap(a, b);		u -= t * v; swap(u, v);	}	u %= m;	if (u < 0) u += m;	return u;}
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {	fac[0] = fac[1] = 1;	finv[0] = finv[1] = 1;	inv[1] = 1;	for (int i = 2; i < MAX; i++) {		fac[i] = fac[i - 1] * i % MOD;		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;		finv[i] = finv[i - 1] * inv[i] % MOD;	}}
ll COM(ll n, ll k) {	if (n < k) return 0;	if (n < 0 || k < 0) return 0;	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll com(ll n,ll m){   if(n<m || n<=0 ||m<0){		return 0;	}	if( m==0 || n==m){		return 1;	}	ll k=1;	for(ll i=1;i<=m;i++){       k*=(n-i+1); 	   k%=MOD;	   k*=modinv(i,MOD);	   k%=MOD;	}	return k;}
ll rad(ll u, ll p){ ll cnt=0;	while(u%p==0){		u/=p;		cnt++;	}	return cnt;}
////////////////////////////////////////////////////////////////////

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

ll n;
cin>>n;

ll a[2*n+1];
rep(i,2*n){
    cin>>a[i];
}

vector <pair<ll,ll>> v;
rep(i,2*n){
v.pb(mp(a[i],i));
}

ll bw[2*n+1];
rep(i,2*n)
{bw[i]=0;}

sort(ALL(v));
for(int i=0;i<=n-1;i++){
bw[v[i].second]=1;
}

ll ans[2*n+1];
 stack<ll> s;
ll sz=1;

for(int i=1;i<=2*n;i++){
if(i==1){s.push(bw[i]); ans[i]=1;}
else if(i==2*n){ans[i]=2;}

else{
ll t=s.top();
if(sz==0){s.push(bw[i]); ans[i]=1; sz++; continue;}
if(t!=bw[i]){ans[i]=2;s.pop(); sz--;}
if(t==bw[i]){ans[i]=1;s.push(bw[i]); sz++;}

}
}

for(int i=1;i<=2*n;i++){
if(ans[i]==1){cout<<'(';}
else cout<<')';

}
cout<<endl;
return 0;

}

#include <iostream>
#include <functional>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <climits>
#include <cmath>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <complex>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

#ifdef QLEG_DEBUG
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << '{'; string sep; for (const auto& x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

template<class Fun>
class _y_combinator_result {
    Fun fun_;
public:
    template<class T>
    explicit _y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

    template<class ...Args>
    decltype(auto) operator()(Args &&...args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
    return _y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

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

  int N; cin >> N;
  vector<ll> v(2*N);
  for (auto& x : v) cin >> x;
  vector<pll> w;
  for (int i = 0; i < 2*N; i++) w.pb({v[i], i});
  sort(w.begin(), w.end());
  for (int i = 0; i < 2*N; i++) {
    auto [_, j] = w[i];
    v[j] = i < N;
  }
  vector<int> st;
  for (int k : v) {
    if (!st.empty() && k != st.back()) {
      cout << ')';
      st.pop_back();
    } else {
      cout << '(';
      st.pb(k);
    }
  }
  cout << '\n';
}


//Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined) {virtual,upsolve}
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
typedef long long ll;
#define rep(a,n) for(int i = a;i<n;i++)
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y);
#define F first
#define S second
#define all(x) x.begin(),x.end()
const int mod = 1e9+7;
const int mxN = 1+100*1000;
inline int lcm(int a,int b)
{
	return (a*b)/(__gcd(a,b));
}
signed main()
{

int n;
cin>>n;
vector<ll> a(n),b(n),c(n);
for(int i = 0;i<n;i++) cin>>a[i];
for(int i = 0;i<n;i++) cin>>b[i];
set<ll,greater<ll>> l;
for(int i = 0;i<n;i++)
{
    l.insert(a[i]);
    if(i==0)
    {
    	c[i] = (*l.begin())*b[i];
	}
	else {
		c[i] = max(c[i-1],b[i]*(*l.begin()));
	}
}

for(auto i : c) cout<<i<<endl;

}

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>
#include <numeric>
#include <chrono>
#include <random>

using namespace std;

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

#define debug(x) cerr << #x << " = " << (x) << endl;
#define debug_pii(x) cerr << "(" << x.first << "," << x.second << ")";
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int gcd(int x, int y) {
  return (y == 0 ? x : gcd(y, x % y));
}

int lcm(int x, int y) {
    return (x*y)/gcd(x, y);
}

const int nmax = 2e5 + 10;
int n,m,u,v,w;
vector<pii> g[nmax];
ll dist[nmax][2][2];
const ll inf = 1e16;

struct state {
  int node;
  bool skip;
  bool add2;
  state(int node, bool skip, bool add2) {
    this->node=node;
    this->skip=skip;
    this->add2=add2;
  }
};

bool operator<(state const& lhs, state const& rhs) {
  return tie(lhs.node, lhs.skip, lhs.add2) < tie(rhs.node, rhs.skip, rhs.add2);
}

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  ll up = a[0];
  ll down = b[0];
  c[0] = up*down;
  ll maxm = up;

  for(int i = 1;i < n;i++) {
    c[i] = c[i-1];
    maxm = max(maxm, a[i]);
    if(b[i]*maxm > c[i]) {
      c[i] = b[i]*maxm;
    }
  }
  rep(i,n)cout<<c[i]<<endl;
}

//   10           -10
//       22  -22
//                       11     -11
//
// 55                                    -55
// 19                 -19
// k = 4 n = 6
// 1 2 3 |4| 3 2 ---> a

// 1 2  3 4 5    6 7 8 |9| 8 7 6

// p1 p2 p3 p4 p3 p2 --> b (inversion cnt b  <= a,   b is lex lexi.. maxm)
// 4 3 2 |1| 2 3

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);
 // cout << fixed << setprecision(15);2000000000

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);
 // prime_factors();
 int t = 1;
 // cin >> t;
 while (t--) {
   solve();
 }

 return 0;
}


/**~~~~~~~~~~~~~~~~~~~~~~~~~~~**\
*  Bismillahir Rahmanir Rahim.  *
*          Imtiaz_rafi          *
*        PCIU, CHITTAGONG       *
\**~~~~~~~~~~~~~~~~~~~~~~~~~~~**/

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

typedef long long int ll;
typedef vector<ll>vi;
typedef map<ll,ll>mi;
typedef pair<ll,ll>pll;
typedef vector<pll> vll;
typedef set<ll>st;
typedef set<char>sc;
ll dx[] = {-1,+1,0,0,+1,-1,+1,-1};
ll dy[] = {0,0,-1,+1,+1,+1,-1,-1};
const ll mx = 1e5+123;
const ll MOD = 1e9+7;
const ll INF = LLONG_MAX;

#define speed() ios::sync_with_stdio(0);cin.tie(0);
#define file()  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define sl(a)   scanf("%lld",&a)
#define all(v)  v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,b,e) for(__typeof(e) i=(b)-(b>e);i!=(e)-(b>e);i+=1-2*(b>e))
#define trace(x)   cerr << #x << " = " << x << endl
#define mem(dp,i)  memset(dp,i,sizeof(dp))
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi acos(-1)
#define en '\n' //(1LL<<(3)) *2^3

template <class T> T power(T a,T b){a%=MOD;if(!a) return 0;T p=1;while(b>0){if(b&1){p*=a;p%=MOD;}a*=a;a%=MOD;b=b>>1;}return p;}
template <class T> void print(vector<T> &v){for(T u:v){cout<<u<<" ";}cout<<endl;}
template <class T> T gcd(T a, T b){return (b!=0?gcd<T>(b,a%b):a);}
template <class T> T lcm(T a, T b){return (a/gcd<T>(a,b)*b);}

int main()
{
    speed();
    ll t,a,i,b,c,ans=0,j,m = INT_MAX;
    cin>>a>>b;
    ll x[a][b];
    rep(i,0,a)
    {
        rep(j,0,b)
        {
            cin>>x[i][j];
            m = min(x[i][j],m);
        }
    }
    rep(i,0,a)
    {
        rep(j,0,b)
        {
            ans+= (x[i][j]-m);
        }
    }
    cout<<ans<<endl;

return 0;
}

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

using ll = long long;
using vll = vector<ll>;
using Pl = pair<ll, ll>;
int main() {
    ll N, P; cin >> N >> P;
    map<ll, ll> dat;
    for (int i = 0; i < N; i++) {
        ll A, B, C; cin >> A >> B >> C;
        dat[A] += C;
        dat[B+1] -= C;
    }
    ll sum = 0, p = 0;
    ll ans = 0;
    for (auto &v : dat) {
        ll now = v.first;
        if (sum > P) ans += (now-p)*P;
        else ans += (now-p)*sum;
        sum += v.second;
        p = now;
    }
    cout << ans << endl;
}


// Jai Shree Ram

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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

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

 		vector<vector<pii>>vec(n+1);

 		rep(i,0,m){
 			int x,y,z; cin >> x >> y >> z;
 			y--;
 			vec[x].push_back({y,z});
 		}
 		vector<vector<int>>dp(n+1,vector<int>(1 << n));
 		dp[0][0] = 1;

 		for(int i = 1; i <= n; i++){
 			sort(all(vec[i]));

 			for(int mask = 0; mask < (1 << n); mask++){
 				int z = __builtin_popcount(mask);
 				if(z != i){
 					continue;
 				}
 				vector<int>t;

 				for(int j = 0; j < n; j++){
 					if((1<<j)&mask)t.push_back(j);
 				}
 				int j = 0;
 				bool bad = 0;
 				for(auto [y,z]:vec[i]){
 					while(j < t.size() and t[j] <= y){
 						j++;
 					}
 					if(j > z)bad=1;
 				}
 				if(bad)continue;
 				for(int j = 0; j < n; j++){
 					if(mask&(1<<j)){
 						dp[i][mask] += dp[i-1][mask^(1 << j)];
 					}
 				}
 			}
 		}
 		cout << dp[n][(1<<n)-1] << endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "[ ";
  for (auto const &x : v) {
    os << x;
    if (&x != &v.back()) {
      os << " : ";
    }
  }
  os << " ]" << endl;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, vector<vector<T>> &v) {
  os << "[" << endl;
  for (auto const &x : v) {
    os << " ";
    print_vec(x);
  }
  os << "]" << endl;
  return os;
}

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

struct P {
  ll x = 0;
  ll y = 0;

  P &operator+=(const P &p) {
    x += p.x;
    y += p.y;
    return *this;
  }
  P &operator-=(const P &p) {
    x -= p.x;
    y -= p.y;
    return *this;
  }

  P operator+(const P &p) const {
    P _p = *this;
    return _p += p;
  }
  P operator-(const P &p) const {
    P _p = *this;
    return _p -= p;
  }

  ll operator&(const P &p) const { return x * p.y - y * p.x; }
};

ostream &operator<<(ostream &os, P p) {
  os << p.x << " " << p.y;
  return os;
}

void rotate(P &p, ll n) {
  if (n < 0) {
    n = n + ((-n - 1) / 4 + 1) * 4;
  }

  ll x = p.x;
  if (n == 1) {
    p.x = p.y;
    p.y = -x;
  } else if (n == 2) {
    p.x = -p.x;
    p.y = -p.y;
  } else if (n == 3) {
    p.x = -p.y;
    p.y = x;
  }
}

void rotateX(P &p, ll x) { p.x = 2 * x - p.x; }
void rotateY(P &p, ll y) { p.y = 2 * y - p.y; }

void apply(P &p, P &vx, P &vy, P &o) {
  ll r = 0;
  if (vx.x == 0) {
    if (vx.y == 1)
      r = 3;
    else
      r = 1;
  } else if (vx.x == -1) {
    r = 2;
  }

  // cout << "apply " << vx << " " << r << endl;

  rotate(p, r);
  if ((vx & vy) < 0) {
    if (vx.x == 0) {
      rotateX(p, 0);
    } else {
      rotateY(p, 0);
    }
  }

  p += o;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, Q, M, a, b;
  cin >> N;

  vector<P> plist(N);

  P o, vx, vy, p;
  vx.x = 1;
  vy.y = 1;

  REP(i, N) { cin >> plist[i].x >> plist[i].y; }
  cin >> M;

  vector<P> olist(M + 1);
  vector<P> vxlist(M + 1);
  vector<P> vylist(M + 1);

  vxlist[0] = vx;
  vylist[0] = vy;

  REP(i, M) {
    cin >> a;
    if (a == 1 || a == 2) {
      ll r = a == 1 ? 1 : -1;
      rotate(o, r);
      rotate(vx, r);
      rotate(vy, r);
    } else {
      cin >> b;
      if (a == 3) {
        rotateX(o, b);
        rotateX(vx, b);
        rotateX(vy, b);
      } else {
        rotateY(o, b);
        rotateY(vx, b);
        rotateY(vy, b);
      }
    }

    olist[i + 1] = o;
    vxlist[i + 1] = vx - o;
    vylist[i + 1] = vy - o;

    // cout << (i + 1) << " o " << o << " vx " << (vx - o) << " vy " << (vy - o)
    //     << endl;
  }

  cin >> Q;

  REP(i, Q) {
    cin >> a >> b;
    o = olist[a];
    vx = vxlist[a];
    vy = vylist[a];
    p = plist[b - 1];

    apply(p, vx, vy, o);
    cout << p << endl;
  }
}


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define ll long long

#define INF 2147483647

#define LINF ((1LL << 62) - (1LL << 31))

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

#define lrep(i, n) for (ll i = 0; i < n; i = i + 1)

#define array(N, t) (t*)calloc(N, sizeof(t))

#define max(p, q)((p) > (q) ? (p) : (q))

#define min(p, q)((p) < (q) ? (p) : (q))

#define swap(a, b) { int temp = a; a = b; b = temp; }

#define lswap(a, b) { ll temp = a; a = b; b = temp; }

#define cswap(a, b) { char temp = a; a = b; b = temp; }

void reverse(char * a, int n) {

  int l = 0;

  int r = n - 1;

  while(l < r) {

    cswap(a[l], a[r]);

    l += 1;

    r -= 1;

  }

}

int main() {

  char s[100010];

  scanf("%s",s);

  int l=strlen(s);

  // printf("%d\n",l);

  // puts(s);

  reverse(s,l);

  // puts(s);

  rep(i,l){

    // printf("%c\n",s[i]);

    // if(s[i]=='0'){}

    // if(s[i]=='1'){}

    if(s[i]=='6'){

      // printf("%c\n",s[i]);

      s[i]='9';

      // printf("%c\n",s[i]);

    } else {

    // if(s[i]=='8'){}

      if(s[i]=='9'){

        s[i]='6';

      }

    }

  }

  puts(s);

  return 0;

}

#include<bits/stdc++.h>
#define S std
#define f(i, a, b) for(R int i = a; i <= b; i++)
#define R register
int T(int x)
{
	if(x == 0||x == 1|| x == 8)return x;
	else if(x == 6)return 9;
	else if(x == 9)return 6;
}
int main()
{
	S::string s;
	S::cin >> s;
	int l = s.length();
	for(int i = l-1; i >= 0; i--)
	{
		S::cout<<T(s[i]-'0');
	}
	return 0;
}


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

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

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

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

int main()
{
  FAST/**/

  ll n;
  cin>>n;

  ll arr[n];
  rep(n)
        cin>>arr[i];// mx = max(mx, arr[i]), sum += arr[i];
  ll maxi[n], psum[n];
  maxi[0] = psum[0] = arr[0];
  for(ll i=1;i<n;i++)
        psum[i] = psum[i-1] + arr[i]*(i+1), maxi[i] = max(maxi[i-1], arr[i]);
  ll sm = 0;
  rep(n)
  {
      sm += arr[i];
      ll ans = (i+1)*(maxi[i]+sm-arr[i]) + sm;
      if(i>0)
            ans -= psum[i-1];
      else ans = 2*arr[0];
      cout<<ans<<"\n";
  }

  return 0;
}

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

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

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

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

void no(){
    cout<<"UNSOLVABLE"<<endl;
    exit(0);
}

unordered_map<char, int> num;

ll conv(string &s){
    ll res = 0;
    if(num[s[0]] == 0) return 0;
    for(char c : s) (res *= 10) += num[c];
    return res;
}

void judge(vector<string> &s){
    vec tmp(3);
    rep(i, 3) tmp[i] = conv(s[i]);
    if(tmp[0] + tmp[1] == tmp[2] && *min_element(ALL(tmp)) > 0){
        rep(i, 3) cout<<tmp[i]<<endl;
        exit(0);
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<string> s(3);
    set<char> cs;
    rep(i, 3){
        cin>>s[i];
        for(char c : s[i]) cs.insert(c);
    }
    if(cs.size() > 10){
        no();
    }else{
        vec ord(10);
        iota(ALL(ord), 0);
        do{
            int i = 0;
            for(char c : cs) num[c] = ord[i++];
            judge(s);
        }while(next_permutation(ALL(ord)));
    }
    no();
}


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

const int nax = 102;
ll dp[nax][nax * nax * nax];

int mod;

int main()
{
    int n,k; cin>>n>>k; cin>>mod;
    dp[0][0] = 1;
    for(int i=1;i<=n;i++)
    {
        for(int c=0;c<nax * nax * nax / 2;c++)
        {
            if(c < i)
            {
                dp[i][c] = dp[i - 1][c];
            }
            else
            {
                dp[i][c] = dp[i][c - i];
                dp[i][c] += dp[i - 1][c];
                int taken = (c + i) / i;
                if(taken > k + 1) dp[i][c] -= dp[i - 1][c - i * (k + 1)];
                dp[i][c] += mod;
                dp[i][c] %= mod;
            }
        }
    }

    for(int x=1;x<=n;x++)
    {
        ll ways = k + 1;

        int ans = 0;
        for(int j=1;j<nax * nax * nax / 2;j++)
        {
            int v1 = x - 1;
            int v2 = n - x;
            ll cur = ways * dp[v1][j];
            cur %= mod;
            cur *= dp[v2][j];
            cur %= mod;
            ans += cur;
            if(ans >= mod) ans -= mod;
        }
        ans += k;
        cout<<ans<<"\n";
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;//1152921504606846976
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
struct unionfind{
    vector<int> par,rank;
    unionfind(int x){
        par.resize(x);
        rank.resize(x);
        for(int i=0; i<x; i++)par[i]=-1,rank[i]=0;
    }
    int root(int x){
        if(par[x]<0)return x;
        return par[x]=root(par[x]);
    }
    void uni(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return;
        if(rank[x]<rank[y]){par[y]+=par[x];par[x]=y;}
        else{
            par[x]+=par[y];par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    unionfind uf(n);
    rep(i,n){
        ll f;cin>>f;
        uf.uni(i, f-1);
    }
    set<ll> m;
    rep(i,n)m.insert(uf.root(i));
    cout<<(mint(2).pow(m.size())-1).x<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define PER(i,a,b) for (int i = (b); i >= (a); --i)
#define log2(x) (31-__builtin_clz(x))
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define mup(x,y) x = std::min(x,y)
#define Mup(x,y) x = max(x,y)
#define debug(x) cout << #x << " is " << x << endl
#define endl '\n'
using namespace std; using ll = long long; using ii = pair<int,int>; using iii = tuple<int,int,int>;
void solution(); int main() {ios::sync_with_stdio(0); cin.tie(0); solution();}
const int N = 200003;
int n;
vector<ll> r, g, b;

ll calc(vector<ll>& x, vector<ll>& y) {
    ll a = 0, b = 0, r = 10000000000000000;
    while (a < SZ(x) && b < SZ(y)) {
        if (x[a] < y[b]) mup(r, y[b]-x[a++]);
        else if (x[a] > y[b]) mup(r, x[a]-y[b++]);
        else return 0;
    }
    return r;
}

void input() {
    cin >> n;
    REP(i,1,2*n) {
        ll a; char c;
        cin >> a >> c;
        if (c == 'R') r.push_back(a);
        else if (c == 'G') g.push_back(a);
        else b.push_back(a);
    }
}
void solution() {
    input();
    sort(ALL(r)); sort(ALL(g)); sort(ALL(b));
    bool pr = SZ(r)&1, pg = SZ(g)&1, pb = SZ(g)&1;
    if (pr == 0 && pg == 0 && pb == 0) {cout << 0; return;}
    auto x = calc(r,g), y = calc(r,b), z = calc(g,b);
    if (SZ(r)%2 == 0) swap(x,z);
    else if (SZ(g)%2 == 0) swap(x,y);

    // cout << x << ' ' << y << ' ' << z << endl;
    cout << min(x,y+z);
}

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

ll MX=100000000000000000LL;

ll ck(vector<ll> a, vector<ll> b)
{
    ll mn=MX;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(int i=0;i<a.size();i++)
    {
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            mn=min(mn, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            mn=min(mn, abs(*it-a[i]));
        }
    }
    return mn;

}

ll ck1(vector<ll> a, vector<ll> b, vector<ll> c)
{
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<ll> dl(a.size()), dr(a.size());
    for(int i=0;i<a.size();i++)
    {
        ll x=MX;
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        if(i>0) dl[i]=min(x, dl[i-1]);
        else dl[i]=x;
    }
    for(int i=a.size()-1;i>=0;i--)
    {
        ll x=MX;
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        if(i!=a.size()-1) dr[i]=min(x, dr[i+1]);
        else dr[i]=x;
    }

    ll mn=MX;
    for(int i=0;i<a.size();i++)
    {
        ll x=MX;
        auto it=upper_bound(c.begin(), c.end(), a[i]);
        if(it!=c.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=c.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        ll y=MX;
        if(i>0) y=min(y, dl[i-1]);
        if(i+1<a.size()) y=min(y, dr[i+1]);
        mn=min(mn, x+y);
    }
    return mn;
}

int main()
{
    ll n;
    cin>>n;
    map<char, vector<ll> > mp;
    for(int i=1;i<=2*n;i++)
    {
        ll x;
        char c;
        cin>>x>>c;
        mp[c].push_back(x);
    }
    if(mp['B'].size()%2==0 and mp['R'].size()%2==0 and mp['G'].size()%2==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(mp['B'].size()%2==0)
    {
        ll x=ck(mp['R'], mp['G']);
        if(mp['B'].size()>=2)
            x=min(x, ck1(mp['B'], mp['R'], mp['G']));
        cout<<x<<endl;
        return 0;
    }

    if(mp['R'].size()%2==0)
    {
        ll x=ck(mp['B'], mp['G']);
        if(mp['R'].size()>=2)
        {
            x=min(x, ck1( mp['R'], mp['B'], mp['G'] ));
        }
        cout<<x<<endl;
        return 0;
    }

    if(mp['G'].size()%2==0)
    {
        ll x=ck(mp['R'], mp['B']);
        if(mp['G'].size()>=2)
        {
            x=min(x, ck1(mp['G'], mp['R'], mp['B']));
        }
        cout<<x<<endl;
        return 0;
    }

    return 0;
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

#define PI 3.141592653589793

signed main(){
    double N,x_min,x_max,y_min,y_max;

    cin >> N >> x_min >> y_min >> x_max >> y_max;

	double x_center = (x_min+x_max)/2;
	double y_center = (y_min+y_max)/2;

	double x_1,y_1;

	double coses = cos(2/N*PI);
	double sines = sin(2/N*PI);

	double x_0 = x_min - x_center;
	double y_0 = y_min - y_center;

	x_1 = coses*x_0 - sines*y_0 + x_center;
	y_1 = coses*y_0 + sines*x_0 + y_center;

	cout << fixed << setprecision(10) << x_1 << " " << y_1 << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mx=1e6+5;
//考虑括号序列的匹配问题
inline int read() {
	int x=0,f=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return x*f;
}
struct node{
	int x,id;
	bool operator <(const node &a) {
		return x<a.x;
	}
}a[mx];
int n,b[mx],s[mx],cnt;
ll res;
char c[mx];
int main() {
//	freopen("data.in","r",stdin);
//	freopen("ans.out","w",stdout);
	n=read(); n*=2;
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].id=i;
	sort(a+1,a+1+n);
	for(int i=n/2+1;i<=n;i++) b[a[i].id]=1;
	for(int i=1;i<=n;i++) {
		if(b[i]) {
			if(cnt&&!b[s[cnt]]) c[s[cnt]]='(',c[i]=')',cnt--;
			else s[++cnt]=i;
		}
		else {
			if(cnt&&b[s[cnt]]) c[s[cnt]]='(',c[i]=')',cnt--;
			else s[++cnt]=i;
		}
	}
//	for(int i=1;i<=n/2;i++) {
//		int x=a[i].id,y=a[n-i+1].id;
//		res+=a[n-i+1].x-a[i].x;
//		printf("%d %d\n",a[n-i+1].x,a[i].x);
//		if(x<y) c[x]='(',c[y]=')';
//		else c[x]=')',c[y]='(';
//	}
//	printf("%d",res);
	for(int i=1;i<=n;i++) printf("%c",c[i]);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

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

struct dijkstra {

  ll N;
  struct edge {
    ll to, C, D;
    ll f(ll x) { return C+D/(x+1); }
    ll cost(ll d) {
      ll sqd = sqrt(D);
      ll result = d+f(d);
      repr(i,sqd-2,sqd+3) if (i>=d) result = min(result,i+f(i));
      return result;
    }
  };
  vector<vector<edge>> adj;
  vector<ll> minlen;

  dijkstra(ll n) { N = n; adj.resize(N); minlen.assign(N,LLINF); }
  ll operator[](const ll &x) const { return minlen[x]; }

  void add_edge(ll from, ll to, ll C, ll D){
    adj[from].push_back({to, C, D});
  }
  vector<ll> calc(ll n=0) {
    minlen.assign(N,LLINF);
    auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
    priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
    minlen[n] = 0; q.push(make_pair(n,0));
    while(q.size()) {
      p_ll now = q.top(); q.pop();
      ll np = now.first, nd = now.second;
      if (nd>minlen[np]) continue;
      for (auto x: adj[np]) {
        if (minlen[x.to]<=x.cost(minlen[np])) continue;
        q.push(make_pair(x.to, x.cost(minlen[np])));
        minlen[x.to] = x.cost(minlen[np]);
      }
    }
    return minlen;
  }

};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------
int main() {
  ll N, M; cin >> N >> M;
  ll A[M], B[M], C[M], D[M]; rep(i,M) { cin >> A[i] >> B[i] >> C[i] >> D[i]; A[i]--; B[i]--; }
  dijkstra ds(N);
  rep(i,M) {
    ds.add_edge(A[i],B[i],C[i],D[i]);
    ds.add_edge(B[i],A[i],C[i],D[i]);
  }
  vector<ll> d = ds.calc();
  // debug(all(d));
  ll result = d[N-1]!=LLINF ? d[N-1] : -1;
  cout << result << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll t, n;
  cin >> t >> n;
  set<ll> st;
  FOR(r, 1, 100 + 1) {
    ll p = (100 + t) * r / 100;
    st.insert(p);
  }
  ll maxi = *st.rbegin();
  vector<ll> a;

  FOR(x, 1, maxi + 1) {
    if (st.find(x) == st.end()) {
      a.push_back(x);
    }
  }
  ll s = SZ(a), l = 100 + t;
  n--;
  ll ans = a[n % s] + l * (n / s);
  cout << ans << endl;
}


#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(v) ((v).begin()), ((v).end())
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

signed main()
{
	int n;
    cin >> n;
    vector<pair<double, double>> v(n);
    rep(i, 0, n)
        cin >> v[i].first >> v[i].second;
    int res = 0;
    rep(i, 0, n-1)
        rep(j, i+1, n)
        {
            if (v[i].first == v[j].first)
                continue;
            double s = (v[i].second - v[j].second) / (v[i].first - v[j].first);
            if (s <= 1 && s >= -1)
                res++;
        }
    cout << res;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll T; cin >> T;
  rep(_,T) {
    ll N; cin >> N;
    ll a[N]; rep(i,N) cin >> a[i];
    map<ll, ll> m; rep(i,N) m[a[i]]++;
    string result = "Second";
    if (N%2==0) {
      for (auto x: m) {
        if (x.second%2==1) result = "First";
      }
    }
    cout << result << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

  int A, B;

  cin >> A;

  int i = 1;
  B = 0;

  while (B < A) {

    B = B + i;

    i++;

  }

  cout << i - 1;

}

#include<bits/stdc++.h>

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

#define  all(v)       (v).begin(),(v).end()
#define  rall(v)      (v).rbegin(),(v).rend()
#define  pb           push_back
#define  pob          pop_back
#define  eb           emplace_back
#define  ins          insert
#define  mp           make_pair
#define  ff           first
#define  ss           second
#define  pf           push_front
#define  bs           binary_search
#define  lb           lower_bound
#define  ub           upper_bound
#define  sz(a)        (ll)a.size()
#define  dec(x)       fixed<<setprecision(x)
#define  lcm(a,b)     (a*b/__gcd(a,b))

typedef  priority_queue<ll>  pq;
typedef  priority_queue<ll,vector<ll>,greater<ll> > pqmn;
typedef  pair<ll,ll> pll;
typedef  vector<ll> vll;
typedef  vector<pll> vpll;
typedef  vector<vector<ll> > vvll;
typedef  vector<string> vstr;
typedef  set<ll> sll;
typedef  set<pll> spll;
typedef  map<ll,ll> mll;

const    ll inf=LLONG_MAX;
const    ll mod=1e9+7;
const    ld pi=acos(-1);
const    ll N=100001;

void solution()
{
    int n,w;
    cin>>n>>w;
    cout<<n/w;
}

int main()
{
	//freopen("t","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solution();
        cout<<"\n";
    }
    return 0;

}


#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array>
#include <tuple>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin >> N;
  int x[N], y[N];
  int a, b, p;
  p=0;
  for (int i=0; i<N; i++){
    cin >> a >> b;
    x[i]=a;
    y[i]=b;
  }
  for (int i=0; i<N-2; i++){
    for (int j=i+1; j<N-1; j++){
      for (int k=j+1; k<N; k++){
        if ((y[j]-y[i])*(x[k]-x[i])==(y[k]-y[i])*(x[j]-x[i])){
          p=1;
       }
      }
    }
  }
  if (p==1){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

const int INF = 1e9+7;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

  ll N;
  cin >> N;

  vector<pair<int, int>> A(N);
  loop(0, N, i) {
    ll a, b;
    cin >> a >> b;
    A[i] = make_pair(a, b);
  }

  loop(0, N, i) {
    loop(i+1, N, j) {
      loop(j+1, N, k) {
        double dx = A[j].first - A[i].first;
        double dy = A[j].second - A[i].second;
        double dx2 = A[k].first - A[i].first;
        double dy2 = A[k].second - A[i].second;
        if (dx * dy2 == dx2 * dy) {
          print("Yes");
          return 0;
        }
      }
    }
  }
  print("No");
}


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

//最大公約数
ll gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

	if(x < y){
		swap(x,y);
	}
	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}

map<ll,ll> MAP;

void func(ll num,ll base){

	auto at = MAP.find(base);
	if(at == MAP.end()){

		MAP[base] = num;
	}else{

		ll tmp = MAP[base];
		MAP[base] = gcd(tmp,num);
	}
}

int main(){

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

	ll A;
	ll mini = HUGE_NUM;

	for(int i = 0; i < N; i++){

		scanf("%lld",&A);
		mini = min(mini,A);

		for(ll k = 1; k*k <= A; k++){
			if(A%k != 0)continue;

			func(A,k);
			func(A,A/k);
		}
	}

	int ans = 1;
	for(auto at = MAP.begin(); at != MAP.end(); at++){

		if(at->first < mini && at->first == at->second){

			ans++;
		}
	}

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

	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    ll n;
    cin >> n;
    if(n<=10){
        cout << 0 << endl;
        return 0;
    }
    ll n2 = n;
    ll dig = log10(n);
    n /= pow(10, dig/2+1);

    if(dig%2==0){
        cout << pow(10, dig/2)-1 << endl;
        return 0;
    }
    if(n*pow(10, dig/2+1)+n<=n2){
        cout << n << endl;
    }
    else{
        cout << n-1 << endl;
    }
    return 0;
}


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

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

 ll nPr(int n, int r) {
    if (n < 0 || r < 0 || n < r) return 0;
    return fac[n] * finv[n - r] % mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();
    int n,k;cin >>n>>k;
    vector<vector<mint>>a(n,vector<mint>(k+1,1));
    for (int i = 0; i < n; ++i) {
        int c;cin >>c;
        a[i][1]=c;
    }
    for (int i = 0; i < n; ++i) {
        auto r=a[i][1];
        for (int j = 2; j <=k; ++j) {
            a[i][j]=a[i][j-1]*r;
        }
    }
    vector<mint>sum(k+1,0);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <=k; ++j) {
            sum[j]+=a[i][j];
        }
    }
    for (int x = 1; x <=k; ++x) {
        mint ans=0;
        for (int i = 0; i <=x; ++i) {
            ans+=(sum[i]*sum[x-i]-sum[x])*COM(x,i);
        }
        ans/=2;
        cout <<ans<<"\n";
    }
}

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

typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;

#define pb push_back
#define ff first
#define ss second
#define MAX 100005
#define MOD 1000000007
#define INF 1e9+100
vector<alll>adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };
int dp[101][101],n,K,arr[101];
ll x;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int k,m,q;
    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        cin>>n>>x;
        for(int i=1; i<=n; i++)
            cin>>arr[i];

        ll ans=2e18;

        for(int k=1; k<=n; k++)
        {
            memset(dp,-1,sizeof dp);
            dp[0][0]=0;
            for(int i=1; i<=n; i++)
            {
                for(int j=k-1; j>=0; j--)
                {
                    for(int m=0; m<k; m++)
                    {
                        if(dp[j][m]!=-1)
                            dp[j+1][(m+arr[i])%k]=max(dp[j+1][(m+arr[i])%k],dp[j][m]+arr[i]);
                    }
                }
            }
            ll cur=x%k;
            if(dp[k][cur]>0)
                ans=min(ans,(x-dp[k][cur])/k);
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   int a, b;
   cin >> a >> b;
   for(int i = -1000; i <= 1000; i++) {
      for(int j = -1000; j <= 1000; j++) {
         if(i + j == a and i - j == b) {
            cout << i << " " << j << "\n";
            return 0;
         }
      }
   }
}

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int x, y;
    scanf("%d%d", &x, &y);
    int a = (x+y)/2;
    int b = x-a;
    printf("%d %d\n", a, b);
    return 0;
}


// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define lll __int128
// #define mp std::make_pair
#define pii std::pair<int,int>
#define pll std::pair<ll,ll>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define mtp std::make_tuple

const double PI = atan(1.0) * 4;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
const int mod = 1e9 + 7 ;
const int INF = 1e9 ;
ll gcd (ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

// function<void(int, int)> dfs = [&](int u , int p) {
// };

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T ;
	// cin >> T ;
	T = 1 ;
	while (T--) {
		int n , m ;
		cin >> n >> m ;
		int mn = 105 ;
		vector<vector<int>> a(n , vector<int>(m))  ;
		for (int i = 0 ; i < n ; i++) {
			for (int j = 0 ; j < m ; j++) {
				cin >> a[i][j] ;
				mn = min(mn , a[i][j]) ;
			}
		}
		// cout << mn << "\n" ;
		int ans = 0 ;
		for (int i = 0 ; i < n; i++) {
			for (int j = 0 ; j < m ; j++) {
				ans += (a[i][j] - mn) ;
			}
		}
		cout << ans << "\n" ;

	}

	return 0 ;

}

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

    for(int i=2;i<=2*n;i++)
    {
        int b=i-k;
        if(b>=2&&b<=2*n)
        {
            int l=0;
            if(i>n)
            {
                int cha=i-n;
                l=(n-cha+1);
            }
            else
            {
                l=i-1;

            }
             // if(l%2==0)l--;
        //    l*=2;
         //   if(i%2==0)l--;
            int r=0;
            if(b>n)
            {
                int cha=b-n;

                r=(n-cha+1);
               // if(r%2==0)

            }
            else
            {
                r=b-1;

            }
           //  if(r%2==0)r--;
       //    r*=2;
        //   if(b%2==0)r--;

            ans+=l*r;
        //   printf("%lld %lld\n",l,r);

        }

    }
    cout<<ans;
}


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

ll M = 998244353;
vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

int main(){
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    int n, m; cin >> n >> m;

    // if (m % 2 != 0) {
    //     cout << 0 << endl;
    //     return 0;
    // }

    vvec<ll> dp(14, vec<ll>(m+1, 0));
    vec<ll> pow2(15, 0);
    pow2[0] = 1;
    rep(i, 14) pow2[i+1] = pow2[i] * 2;

    // dp[0][0] = 1;
    rep(j, m + 1) if (j % 2 == 0) if (m >= j) if (n >= j) dp[0][j] = comb(n, j);

    for(int i = 1; i < 14; i++) for(int j = 0; j <= m; j++) {
        // if (i >= 2) break;
        int jn = 0;
        while(true) {
            if (j - jn * pow2[i + 1] < 0) break;
            if (n < jn * 2) break;
            // sum = j - jn;
            ll add = 0;
            add = dp[i-1][j - jn * pow2[i + 1]] * comb(n, jn*2);
            add %= M;
            // if ((i == 1) && (j == 20)) cout << jn << " " << add << endl;

            dp[i][j] += add;
            dp[i][j] %= M;
            // cout << i << " " << j << " " << jn << " " << add << endl;
            jn++;
        }
    }
    // rep(i, 14) {
    //     rep(j, m + 1) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    // cout << endl;

    cout << dp[13][m] << endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define fore(i_in,a) for (auto& i_in: a)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fio() cin.tie(nullptr);ios::sync_with_stdio(false);
#define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl
template<class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (a>b) {a = b; return 1;} return 0;}
template<class T> void print(const T &t) {cout << t << "\n";}
const ll INF = 1LL << 62;
const int iINF = 1 << 30;

int n;
ll a;
char c;
using vi = vector<int>;

ll check(vl&x, vl&y){
    if(x.empty() or y.empty()) return INF/2;
    ll res=INF;
    fore(z,x){
        auto tmp=lower_bound(all(y),z);
        ll t1=*tmp,t2=INF;
        if(tmp!=y.begin()) t2=*(--tmp);
        chmin(res,min(abs(z-t1),abs(z-t2)));
    }
    return res;
}

int main() {
    fio(); cin>>n;
    vl R,G,B;
    rep(i,2*n) {
        cin>>a>>c;
        if(c=='R') R.emplace_back(a);
        if(c=='G') G.emplace_back(a);
        if(c=='B') B.emplace_back(a);
    }
    sort(all(R));sort(all(G));sort(all(B));
    if(sz(R)%2==0 and sz(G)%2==0 and sz(B)%2==0) print(0);
    else{
        if(sz(G)%2==0) swap(R,G);
        else if(sz(B)%2==0) swap(R,B);
        print(min(check(G,B),check(B,R)+check(R,G)));
    }
}


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

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void read(vec &v)
{
  for(auto &i:v)cin>>i;
}
void solve()
{
  string s;
  cin>>s;
  string ans="";
  bool flip=true;
  for(char i:s)
  {
    if(i=='R')flip^=1;
    else
    {
      if(flip)
      {
        if(ans.empty())
        {
          ans.pb(i);
        }
        else if(ans.back()==i)
        {
          ans.ppb();
        }
        else
          ans.pb(i);
      }
      else
      {
        if(ans.empty())
        {
          string u="";
          u+=i;
          ans.insert(0,u);
        }
        else if(ans.front()==i)
        {
          ans.erase(0,1);
        }
        else
        {
          string u="";
          u+=i;
          ans.insert(0,u);
        }
      }
    }
  }
  if(!flip)reverse(all(ans));
  cout<<ans<<"\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    fr3(i,1,t){
      // cout<<"Case #"<<i<<": ";
        solve();
    }
   return 0;
}

// atcoder/zone2021/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  str s;
  while (cin >> s) {
    deque<char> q;
    bool f = true;
    each (c, s) {
      if (c == 'R') f = !f;
      else {
        if (f) q.push_back(c);
        else q.push_front(c);
      }
    }
    str t;
    if (f) {
      while (q.size()) {
        t += q.front();
        q.pop_front();
      }
    } else {
      while (q.size()) {
        t += q.back();
        q.pop_back();
      }
    }

    str u;
    each (c, t) {
      if (u.size() && u.back() == c) u.pop_back();
      else u += c;
    }
    cout << u << endl;
  }

  return 0;
}


#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>

using namespace std;

#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define cdeb(val) cout << #val << ":" << val << endl;
#define pdeb(val) printf("%s : %lld\n", #val, val);

typedef long long int ll;
typedef pair<ll, ll> P;

struct MATRIX {
  vector<vector<ll>> a;
  vector<ll> b;
  MATRIX(const vector<vector<ll>> & _a = {{1,0}, {0,1}},
    const vector<ll>& _b = {0,0}) : a(_a), b(_b) {}
  MATRIX operator*(const MATRIX& x) const {
    MATRIX res({{0,0},{0,0}});
    rep(i,2) {
      rep(j,2) {
        rep(k, 2) {
          res.a[i][j] += x.a[i][k]*a[k][j];
        }
      }
    }

    res.b = MATRIX(x.a)*b;
    rep(i,2) {
      res.b[i] += x.b[i];
    }
    return res;
  }

  vector<ll> operator*(const vector<ll>& x) const {
    vector<ll> res = b;
    rep(i,2) {
      rep(j,2) {
        res[i] += a[i][j]*x[j];
      }
    }
    return res;
  }
};

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

  vector<vector<ll>> p(n, vector<ll>(2));
  rep(i,n) {
    cin >> p[i][0] >> p[i][1];
  }
  ll m;
  cin >> m;
  vector<MATRIX> d(1);
  rep(i,m) {
    ll op;
    cin >> op;
    MATRIX x;
    if (op == 1) {
      x = MATRIX({{0,1},{-1,0}});
    } else if (op == 2) {
      x = MATRIX({{0,-1},{1,0}});
    } else {
      ll p;
      cin >> p;
      if (op == 3) {
        x = MATRIX({{-1,0},{0,1}}, {2*p,0});
      } else {
        x = MATRIX({{1,0},{0,-1}}, {0,2*p});
      }
    }
    MATRIX y = d.back();
    d.push_back(y*x);
  }
  ll q;
  cin >> q;
  rep(i,q) {
    ll a, b;
    cin >> a >> b;
    b--;
    vector<ll> ans = d[a]*p[b];
    printf("%lld %lld\n", ans[0], ans[1]);
  }
  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast")
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
template<typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 200005;

int n,m,Q;
ii a[MAXN];
vector<pair<ii,int>> q;
vector<ii> eve;
ii ans[MAXN];

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

	cin>>n;
	forn(i,0,n) cin>>a[i].F>>a[i].S;
	cin>>m;
	forn(i,0,m)
	{
		int t; cin>>t;
		ll p=0;
		if(t>=3) cin>>p;
		eve.pb({t,p});
	}
	cin>>Q;
	forn(i,0,Q)
	{
		int a,b; cin>>a>>b; a--; b--;
		q.pb({{a,b},i});
	}

	sort(q.begin(), q.end(), greater<pair<ii,int>>());

	bool swapped=0;
	bool sign[2]{};
	ll off[2]{};

	while(q.back().F.F==-1)
	{
		int p=q.back().F.S, id=q.back().S;
		q.pop_back();
		ans[id]=a[p];
	}

	forn(i,0,m)
	{
		int t=eve[i].F; ll p=eve[i].S;
		if(t==1)
		{
			sign[swapped]^=1;
			off[swapped]*=-1;
			swapped^=1;
		}
		if(t==2)
		{
			sign[swapped^1]^=1;
			off[swapped^1]*=-1;
			swapped^=1;
		}
		if(t==3)
		{
			sign[swapped]^=1;
			off[swapped]*=-1;
			off[swapped]+=2*p;
		}
		if(t==4)
		{
			sign[swapped^1]^=1;
			off[swapped^1]*=-1;
			off[swapped^1]+=2*p;
		}
		while(q.size() && q.back().F.F==i)
		{
			int p=q.back().F.S; int id=q.back().S;
			q.pop_back();
			ii tmp;
			tmp.F=(sign[0]?-1:1)*a[p].F+off[0];
			tmp.S=(sign[1]?-1:1)*a[p].S+off[1];
			if(swapped) swap(tmp.F, tmp.S);
			ans[id]=tmp;
		}
	}

	forn(i,0,Q)
	{
		cout<<ans[i].F<<" "<<ans[i].S<<'\n';
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

ll n, m;
bool v[1005][1005];
ll cp[2005];
bool v1[2005], v2[2005];
ll cnt1, cnt2;

ll fnd(ll p)
{
    if(cp[p] == p) return p;
    return cp[p] = fnd(cp[p]);
}

void uni(ll p, ll q)
{
    if(fnd(p) == fnd(q)) return;
    cp[fnd(p)] = fnd(q);
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < n + m; i++) cp[i] = i;
    for(ll i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        for(ll j = 0; j < m; j++)
        {
            if(s[j] == '#') v[i][j] = true, uni(i, j + n);
        }
    }
    uni(0, n - 1);
    uni(0, n);
    uni(0, m + n - 1);
    for(ll i = 0; i < n; i++)
    {
        if(!v1[fnd(i)]) cnt1++, v1[fnd(i)] = true;
    }
    for(ll i = 0; i < m; i++)
    {
        if(!v2[fnd(i + n)]) cnt2++, v2[fnd(i + n)] = true;
    }
    printf("%lld\n", min(cnt1 - 1, cnt2 - 1));
    return 0;
}


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

int fib(int n)
{
    if (n <= 1)
        return n;
    return fib(n-1) + fib(n-2);
}

int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,tmp=0;
    cin>>n;
    ll tm=log10(n);
    tm/=2;
    tmp=pow(10,tm-1)-1;
    ll ans=tmp;
    tmp+=1;
    //cout<<ans<<" "<<tmp<<"\n";
    for(ll i=tmp;i<=tmp*100;i++)
    {
         ll y=(log10(i)+1);
         ll mul=pow(10,y);
        ll k=i*mul;
         k+=i;
         //cout<<k<<" ";
        if(k<=n)
        ans++;
        else
        break;
    }
    cout<<ans;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

void solve(){
}
int main()
{
    fast_cin();
    ll n,sum=0;
    string s;
    int max,fh,sh;
    cin >> n;
    s = to_string(n);
    int len = s.length();
    if(len == 1) {
        cout << 0;
    }
    else if(len % 2 == 1) {
        for(int i=1; i<=len/2; i++) {
            cout << 9;
        }
    }
    else {
        fh = stoi(s.substr(0,len/2));
        sh = stoi(s.substr(len/2));
        if(fh <= sh) {
            cout << fh;
        }
        else {
            cout << fh-1;
        }
    }
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
//#define MOD 1000000007
#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
const int inf = 1 << 30;
//四方向への移動ベクトル
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;

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

int main(){
    ll n,ans=0,sc=0;
    cin >> n;
    string s,t;
    cin >> s >> t;
    queue<ll> que;
    queue<ll> que2;
    for (ll i=0;i<n;i++){
        if (t[i]=='1')que.push(i);
        if (s[i]=='1'){
            if (!que2.empty()){
                ans+=i-que2.front();
                que2.pop();
            }else if (que.empty()){
                que2.push(i);
            }else{
                ans+=i-que.front();
                que.pop();
            }
        }
    }
    if (que.empty() and que2.empty()){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD int(1e9+7)
#define INF int(1e9+7)
#define LINF ll(1e18+7)
#define PI acos(-1)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define P pair<ll,ll>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

vector<int> dp[210000];

int main(){
  int n;
  string s;
  string x;
  cin>>n>>s>>x;
  dp[n].push_back(0);
  for(int i=n-1; i>=0; i--){
    if(x[i]=='A'){
      rep(r,7){
        bool a=0, b=0;
        for(auto p : dp[i+1]){
          if(10*r%7==p) a=1;
          if((10*r+s[i]-'0')%7==p) b=1;
        }
        if(a && b) dp[i].push_back(r);
      }
    }else{
      rep(r,7){
        for(auto p : dp[i+1]){
          if(10*r%7==p || (10*r+s[i]-'0')%7==p){
            dp[i].push_back(r);
            break;
          }
        }
      }
    }
  }
  for(auto x : dp[0]){
    if(x==0){
      cout<<"Takahashi"<<endl;
      return 0;
    }
  }
  cout<<"Aoki"<<endl;
}


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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b, a--, b--;
    G.at(a).push_back(b);
  }

  vector<int> DP(N, INT_MIN);
  auto dfs = [&](auto&& dfs, int now, int pre, int mi) -> void {
    cmin(mi, A.at(now));
    for (const auto& next : G.at(now)) {
      if (next == pre) continue;
      if (cmax(DP.at(next), A.at(next) - mi)) dfs(dfs, next, now, mi);
    }
  };
  for (int i = 0; i < N; i++) {
    dfs(dfs, i, -1, INT_MAX);
  }
  cout << *max_element(DP.begin(), DP.end()) << '\n';
}

//BISMILAHIRAHMANIR RAHIM
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#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 allr(x)			  (x).rbegin(),(x).rend()
#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 loop(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 br                break
#define con               continue

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
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;}

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

priority_queue<pii, vector<pii>, greater<pii> >q;
const int mxx = 2e5+5;
vector<vector<int>>adj(mxx);
vector<int>up(mxx,-1e18);
vector<int>v(mxx);
map<int,int>vis;
void dfs(int j){
	vis[j]=1;

	up[j]=max(up[j],v[j]);

	for(int i:adj[j]){
		if(vis[i]==0)dfs(i);
		up[j]=max(up[i],up[j]);
	}
}
void solv(){
	int n,m,x,y;
	cin>>n>>m;
	loop(i,1,n+1)cin>>v[i];

	loop(i,0,m){
		cin>>x>>y;
		adj[x].pb(y);
	}

	loop(i,1,n+1){
		if(vis[i]==0)dfs(i);
	}
	int mx = -1e18;

	loop(i,1,n+1){
		for(int j:adj[i])mx = max(mx,up[j]-v[i]);
	}
	cout<<mx<<endl;
}
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	solv();

}
///ALHAMDULILLAH//


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI a(n), b(n), c(n), d(n);
    REP(i,n) cin >> a[i] >> b[i], a[i]*=n, b[i]*=n;
    REP(i,n) cin >> c[i] >> d[i], c[i]*=n, d[i]*=n;
    if(n==1){
        cout << "Yes" << endl;
        return 0;
    }
    double csx=0, csy=0, ctx=0, cty=0;
    REP(i,n){
        csx+=a[i];
        csy+=b[i];
        ctx+=c[i];
        cty+=d[i];
    }
    csx/=n, csy/=n, ctx/=n, cty/=n;
    REP(i,n){
        a[i]-=csx;
        b[i]-=csy;
        c[i]-=ctx;
        d[i]-=cty;
    }
    if(a[0]==0&&b[0]==0){
        swap(a[0],a[1]);
        swap(b[0],b[1]);
    }
    REP(i,n){
        if(c[i]==0&&d[i]==0)
            continue;
        double ang=atan2(d[i],c[i])-atan2(b[0],a[0]);
        bool ok=1;
        REP(j,n){
            double x=a[j]*cos(ang)-b[j]*sin(ang);
            double y=a[j]*sin(ang)+b[j]*cos(ang);
            bool f=0;
            REP(k,n){
                if(abs(x-c[k])<=1e-6&&abs(y-d[k])<=1e-6)
                    f=1;
            }
            if(!f){
                ok=0;
                break;
            }
        }
        if(ok){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
typedef std::pair<int, int> PII;
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int k;
    std::cin>>k;
    int deck[10], ht[10]={}, ha[10]={};
    for(int i=1;i<10;++i)deck[i]=k;
    std::string s, t;
    std::cin>>s>>t;
    ll st, sa;
    st=0;
    sa=0;
    for(int i=0;i<4;++i){
        ++ht[s[i]-48];
        ++ha[t[i]-48];
        --deck[s[i]-48];
        --deck[t[i]-48];
    }
    for(int i=1;i<10;++i){
        st += i * std::pow(10, ht[i]);
        sa += i * std::pow(10, ha[i]);
    }
    double ans = 0;
    double total=9*k-8;
    for(int i=1;i<10;++i){
        if(deck[i]==0)continue;
        for(int j=1;j<10;++j){
            if(i==j){
                if(deck[j]<=1)continue;
            }
            else{
                if(deck[j]==0)continue;
            }
            if(st+i*std::pow(10, ht[i])*9>sa+j*std::pow(10, ha[j])*9){
                if(i==j)ans+=deck[i]/total * (deck[i]-1)/(total-1);
                else{
                    ans += deck[i]/total * (deck[j])/(total-1);
                }
            }
        }
    }
    std::cout<<std::setprecision(8)<<ans<<"\n";
}