#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; }

int main() {
  ll N; cin >> N;
  string S; cin >> S;
  ll Q; cin >> Q;
  ll T[Q], A[Q], B[Q]; rep(i,Q) { cin >> T[i] >> A[i] >> B[i]; A[i]--; B[i]--; }
  bool flip = false;
  rep(i,Q) {
    if (T[i]==1) {
      if (flip) {
        A[i] = (A[i]+N) % (2*N);
        B[i] = (B[i]+N) % (2*N);
      }
      swap(S[A[i]],S[B[i]]);
    }
    else flip = !flip;
  }
  string result = flip ? S.substr(N,N) + S.substr(0,N) : S;
  cout << result << endl;
  return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG)
#include <atcoder/all>
#endif
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>using vec = vector<T>;
template<class T, class U>using umap = unordered_map<T, U>;
template<class T>using uset = unordered_set<T>;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
//using T = tuple<ll, ll, ll>;
using vl = vec<ll>;
#define fi first
#define se second
#define el endl
constexpr ll INF = numeric_limits<ll>::max()/2-1;
#pragma endregion

#pragma region IOMacros
template<class T>
istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;}
template<class T>
ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;}

#define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__);
void __i() {}
template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);}

void O() {cout << el;}
template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);}
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    I(ll, N);
    I(string, S);
    I(ll, Q);
    bool isswap = false;
    REP(i, Q){
        I(ll, T, A, B);
        --A, --B;
        if(T==1){
            if(isswap){
                if(A>=N){
                    A-=N;
                }else{
                    A+=N;
                }
                if(B>=N){
                    B-=N;
                }else{
                    B+=N;
                }
            }
            swap(S[A], S[B]);
        }else{
            isswap=!isswap;
        }
    }
    if(isswap){
        cout << S.substr(N) << S.substr(0, N) << el;
    }else{
        cout << S << el;
    }
}


#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
     ll n,x;
     string s;
     cin>>n>>x>>s;
     com(i,n)
     {
          if(s[i]=='x')
          {
               if(x>0)
                    x--;
          }
          else
               x++;
     }
     cout << x << endl;
}

#include<bits/stdc++.h>
using namespace std;
//#define pb push_back
//typedef long long ll;
int main()
{
	int n,x;
	cin>>n>>x;
	string s;
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='o')x++;
		else if(x>0)x--;
	}
	cout<<x<<endl;
	return 0;
}


#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>

using ll=long long;
constexpr int mod=1000000007;
int N,M,K,inv[2000000]={1,1};
int main(){
  for(int i=2;i<2000000;++i)inv[i]=ll(inv[mod%i])*(mod-mod/i)%mod;
  for(int i=2;i<2000000;++i)inv[i]=ll(inv[i])*inv[i-1]%mod;

  scanf("%d %d %d",&N,&M,&K);
  int p=1;
  for(int i=2;i<=N+M;++i)p=ll(p)*i%mod;
  int ans=ll(p)*inv[N]%mod*inv[M]%mod;
  if(N+M<=K||N==K){
    printf("%d\n",ans);
    return 0;
  }
  if(N>M+K){
    puts("0");
    return 0;
  }
  ++K;
  ans-=ll(p)*inv[N-K]%mod*inv[M+K]%mod;
  if(ans<0)ans+=mod;
  printf("%d\n",ans);
}

#include <bits/stdc++.h>
#include <random>
#include <chrono>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T> void _do(T x){cerr<<x<<"\n";}
template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);}
#define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__);

const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2e18;
const ld PI=3.14159265358979323846;
ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);}
ll fpow(ll a,ll b,ll m)
{
    if(!b) return 1;
    ll ans=fpow(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
ll inv(ll a,ll m) {return fpow(a,m-2,m);}

#define MottoHayaku ios::sync_with_stdio(false);cin.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define F first
#define S second
#define pb push_back
#define SZ(a) ((ll)a.size())
#define reset(a) memset(a,0,SZ(a))
#define cd(a,b) ((a+b-1)/b)
#define pow2(a) (1LL<<a)
#define LB(a,x) (lower_bound(a.begin(),a.end(),x))
#define LPOS(a,x) (lower_bound(a.begin(),a.end(),x)-a.begin())
#define UB(a,x) (upper_bound(a.begin(),a.end(),x))
#define UPOS(a,x) (upper_bound(a.begin(),a.end(),x)-a.begin())
#define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end())))
#define unisort(c) sort(c.begin(),c.end()),uni(c)
ll fac[2000005];
int main()
{
    MottoHayaku
    ll n,m,k;
    cin>>n>>m>>k;
    if(n>m+k)
    {
        cout<<"0\n";
        return 0;
    }
    fac[0]=1;
    rep1(i,n+m) fac[i]=fac[i-1]*i%MOD1;
    ll a=fac[n+m]*inv(fac[n],MOD1)%MOD1*inv(fac[m],MOD1)%MOD1;
    ll b;
    if(n+m<m+k+1) b=0;
    else b=fac[n+m]*inv(fac[m+k+1],MOD1)%MOD1*inv(fac[n-k-1],MOD1)%MOD1;
    cout<<(a-b+MOD1)%MOD1<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);

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

	int n;
	cin>>n;
	string s;
	cin>>s;
	int m = n+1;
	int a[m];
	int k = 1e9;
	for(int i=0;i<m;i++)cin>>a[i];
	for(int i=1;i<m;i++)chmin(k,abs(a[i]-a[i-1]));
	cout << k << endl;
	vector<vector<int>> ans(k);
	for(int i=0;i<k;i++){
		for(int j=0;j<m;j++){
			ans[i].push_back(a[j]/k);
		}
	}
	int rem[m]={};
	for(int i=0;i<m;i++)rem[i] = a[i] % k;
	for(int i=0;i<k;i++){
		for(int j=0;j<m;j++){
			if(rem[j]){
				ans[i][j]+=1;
				rem[j]--;
			}
			cout << ans[i][j] << " ";
		}
		cout << endl;
	}
}

#include <bits/stdc++.h>

using namespace std;
const int MOD = 998244353;
const int N = 505;
int m, n;
char A[N][N];
struct Data
{
    int r,c;
} F[N][N];
int poww[1005];
Data combine(Data X, Data Y)
{
    if(X.r > Y.r) swap(X, Y);
    if(X.r + X.c < Y.r) return {-1,-1};
    X.c -= Y.r - X.r;
    return {Y.r,min(X.c, Y.c)};
}
int G[1005];
int main()
{
    if(fopen("A.inp","r"))
    {
        freopen("A.inp","r",stdin);
        freopen("A.out","w",stdout);
    }
    cin >> m >> n;
    poww[0] = 1;
    for(int i = 1; i <= m + n; i++) poww[i] = (poww[i-1] * 2)%MOD;
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= n; j++) cin >> A[i][j];
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= n; j++)
        {
            int k = 0;
            if(A[i][j] == 'R') k = 1;
            if(A[i][j] == 'B') k = 2;
            if(G[i+j])
            {
                if(G[i+j] != k && k > 0)
                {
                    cout << 0;
                    return 0;
                }
            }
            else G[i+j] = k;
        }
    int cnt = 0;
    for(int i = 2; i <= m + n; i++) cnt += (G[i] == 0);
    cout << poww[cnt];
}


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

const int INF = 1e9 + 7;

int n, m;
string a[2005];

int hor[2005], ver[2005], diag[5005];
int dp[2005][2005];

int offset(int x) {
	return x + 2500;
}

int add(int x, int y) {
	return ((long long) (x + y)) % INF;
}

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

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

	dp[1][1] = hor[1] = ver[1] = diag[offset(1 - 1)] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '#') {
				hor[i] = ver[j] = diag[offset(i - j)] = 0;
				continue;
			}
			if (i == 1 && j == 1) continue;

			dp[i][j] = add(add(hor[i], ver[j]), diag[offset(i - j)]);

			hor[i] = add(hor[i], dp[i][j]);
			ver[j] = add(ver[j], dp[i][j]);
			diag[offset(i - j)] = add(diag[offset(i - j)], dp[i][j]);
		}
	}

	cout << dp[n][m] << "\n";

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e18;
const ll MOD = 1000000007;
int N, M;
void dfs(int t, vector<P> &V, set<int> &checked, vector<vector<int>> &G) {
    for(auto &i : G[t]) {
        if(checked.count(i))
            continue;
        V.push_back(P(i, t));
        checked.insert(i);
        dfs(i, V, checked, G);
    }
    return;
}
int C[25];
ll search(int now_id, vector<P> &V, vector<vector<int>> &G) {
    if(now_id == V.size()) {
        for(auto &s : V) {
            for(auto &t : G[s.first]) {
                if(C[s.first] == C[t]) {
                    return 0;
                }
            }
        }
        return 1;
    }
    if(now_id == 0) {
        ll ret = 0;
        C[V[now_id].first] = 1;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        C[V[now_id].first] = 2;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        C[V[now_id].first] = 3;
        ret += search(now_id + 1, V, G);
        C[V[now_id].first] = 0;
        return ret;
    } else {
        ll ret = 0;
        for(int i = 1; i <= 3; ++i) {
            if(C[V[now_id].second] != i) {
                C[V[now_id].first] = i;
                ret += search(now_id + 1, V, G);
                C[V[now_id].first] = 0;
            }
        }
        return ret;
    }
}
int main() {
    cin >> N >> M;
    vector<vector<int>> G(N);
    REP(i, M) {
        int A, B;
        cin >> A >> B, A--, B--;
        G[A].push_back(B), G[B].push_back(A);
    }
    ll ans = 1;
    set<int> checked;
    REP(i, N) {
        if(checked.count(i))
            continue;
        vector<P> V;
        set<int> s;
        s.insert(i);
        V.push_back(P(i, -1));
        dfs(i, V, s, G);
        for(auto &x : V) {
            checked.insert(x.first);
        }
        ans *= search(0, V, G);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main(){
    ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	int a , b;
	cin>>a>>b;
	cout<<(a+b)/2<<" "<<(a-b)/2<<"\n";
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<ll>
#define mat vector<vec>

const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n, x;
    cin >> n >> x;
    vec a(n);
    vec r(n-1);
    rep(i, n) cin >> a[i];
    rep(i, n-1) r[i] = a[i+1] / a[i];
    vec X(n);
    ll x_ = x;
    rrep(i, n){
        X[i] = x_ / a[i];
        x_ %= a[i];
    }
    // rep(i, n){
    //     cout << X[i] << " ";
    // }cout << endl;
    // rep(i, n){
    //     cout << r[i] << " ";
    // }cout << endl;
    mat dp(n, vec(2));
    dp[0][0] = 1;
    dp[0][1] = 0;
    rep(i, n-1){
        if(X[i] == r[i]-1){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][0] + dp[i][1];
        }else if(X[i] == 0){
            dp[i+1][0] = dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][1];
        }else{
            dp[i+1][0] = dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][0] + dp[i][1];
        }
        // cout << dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    cout << dp[n-1][0] + dp[n-1][1] << endl;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#define debug(a) cout<<#a<<" = "<<a<<endl

using namespace std;

typedef long long ll;
const int N = 5010;
const int MOD = 998244353;

int n , m;
ll C[N];
ll f[N];

ll Q_power(ll a ,ll b){
    ll res = 1;
    while(b){
        if(b & 1) res = res * a % MOD;
        b >>= 1;
        a = a*a % MOD;
    }
    return res;
}

ll X_1(ll a){ return Q_power(a ,MOD - 2) ;}

void init(){
    C[0] = 1;
    for(int i = 1 ; i <= n ; i ++){
        C[i] = C[i - 1] * (n - i + 1) % MOD * X_1(i) % MOD;
    }
}

ll F(int m){
    if(~f[m] == 0){
        f[m] = 0;
        if(!(m & 1)){
            for(int i = 0 ; i * 2 <= m ; i ++){
                f[m] = (f[m] + C[i * 2] * F(m / 2 - i) % MOD) % MOD;
            }
        }
    }
    return f[m];
}

int main(){
    cin >> n >> m;
    memset(f,0xff,sizeof f);
    init(); f[0] = 1;
    cout << F(m) << endl;
    return 0;
}

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

#define ll long long
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define fd(i,x,y) for(ll i=x;i>=y;i--)

using namespace std;
const int N=5010,M=5010;
const int E=17;

const ll mod=998244353;

ll n,m,i,j,k,tot,ans,s,t,x,y,z;

ll f[E][M];
ll e[E];

ll jie[M],ny[M];

void read(ll &a) {
	a=0; char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') {a=a*10-48+c; c=getchar();}
	return;
}

ll ksm(ll i,ll j) {
	ll re=1;
	while (j>0) {
		if (j&1) re=re*i%mod;
		j/=2; i=i*i%mod;
	}
	return re;
}

void ycl() {
	jie[0]=1;
	fo(i,1,M-1) jie[i]=jie[i-1]*i%mod;
	ny[M-1]=ksm(jie[M-1],mod-2);

	fd(i,M-2,0) ny[i]=ny[i+1]*(i+1)%mod;
}

ll C(ll x,ll y) {return jie[x]*ny[y]%mod*ny[x-y]%mod;}

int main() {
	ycl();

	read(n); read(m);

	e[1]=1;
	fo(i,2,E-1) e[i]=e[i-1]*2;
	f[0][0]=1;

	fo(i,1,E-1) {
		if (e[i]>m) {t=i-1; break;}
		for (j=0;j<=m/e[i]&&j<=n;j+=2) {
			fo(k,0,m-e[i]*j) f[i][k+e[i]*j]=(f[i][k+e[i]*j]+f[i-1][k]*C(n,j))%mod;
		}
	}

	ans=f[t][m];
	printf("%lld\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=998244353;
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	a=a*(a+1)/2; b=b*(b+1)/2; c=c*(c+1)/2;
	a%=mod;b%=mod;c%=mod;
	cout<<a*b%mod*c%mod;
	return 0;
}

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

const int N = 105 ;

double dp[N][N][N] ;

double solve(int a, int b, int c){
	if(a == 100 || b == 100 || c == 100){
		return 0 ;
	}
	if(dp[a][b][c]){
		return dp[a][b][c] ;
	}else{
		int num = a+b+c ;
		double ans = 1.0 + (double)(1.0*a/num)*solve(a+1, b,c) + (double)(1.0*b/num)*solve(a, b+1 ,c) + (double)(1.0*c/num)*solve(a, b,c+1) ;
		return dp[a][b][c] = ans ;
	}

}

int main(){

	int a, b, c ;
	double ans = 0 ;

	cin >> a >> b >> c ;
	solve(a,b, c) ;

	printf("%.9lf", dp[a][b][c]) ;

	return 0 ;
}


#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<pair<int, int>> edges(n - 1);
	vector<vector<int>> adj(n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		cin >> a >> b;
		--a, --b;
		edges[i] = {a, b};
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	vector<int> depth(n, -1);
	queue<int> q;
	depth[0] = 0;
	q.push(0);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int y: adj[x]){
			if(depth[y] < 0){
				depth[y] = 1 + depth[x];
				q.push(y);
			}
		}
	}

	vector<ll> save(n);
	int Q;
	cin >> Q;
	while(Q--){
		int t, e, x;
		cin >> t >> e >> x;

		auto [a, b] = edges[e - 1];
		if(t == 2) swap(a, b);

		if(depth[a] < depth[b]){
			save[0] += x;
			save[b] -= x;
		}
		else{
			save[a] += x;
		}
	}

	assert(q.empty());
	q.push(0);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(int y: adj[x]){
			if(depth[y] > depth[x]){
				save[y] += save[x];
				q.push(y);
			}
		}
	}

	for(ll i: save){
		cout << i << "\n";
	}
}

#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,7)+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; }

struct edge { ll to, d1, d2; };
vector<vector<edge>> adj;
vector<ll> result;
ll pl = 0;

void dfs(ll n=0, ll p=-1, ll sum=0) {
  result[n] += sum;
  for (auto x: adj[n]) {
    if (x.to==p) continue;
    pl += x.d2;
    dfs(x.to,n,sum+(x.d1-x.d2));
  }
}

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

  ll a[N-1], b[N-1]; rep(i,N-1) { cin >> a[i] >> b[i]; a[i]--; b[i]--; }
  ll toa[N-1] = {}, tob[N-1] = {};
  ll Q; cin >> Q;
  rep(i,Q) {
    ll t, e, x; cin >> t >> e >> x; e--;
    if (t==1) toa[e] += x;
    else tob[e] += x;
  }

  adj.resize(N);
  rep(i,N-1) {
    adj[a[i]].push_back({b[i],tob[i],toa[i]});
    adj[b[i]].push_back({a[i],toa[i],tob[i]});
  }

  result.resize(N); dfs();
  rep(i,N) result[i] += pl;
  debug(all(result));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    string s, t = "";
    bool rev = false;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            rev = !rev;
            continue;
        }
        if (t == "") {
            t += s[i];
            continue;
        }
        if (!rev) {
            if (s[i] == t[t.size() - 1]) {
                t.pop_back();
                continue;
            }
            t += s[i];
        }
        if (rev) {
            if (s[i] == t[0]) {
                t.erase(t.begin());
                continue;
            }
            t.insert(0, {s[i]});
        }
    }
    string ans = "";
    if (!rev) ans = t;
    if (rev) {
        for (int i = t.size() - 1; i >= 0; i--) ans += t[i];
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define gc() getchar()
#define pc(a) putchar(a)
#define int long long
#define inf (1ll<<60)
inline int read()
{
    int x=0,f=1;
    char c=gc();
    while(c<'0'||c>'9')
    {
        if(c=='-') f=-f;
        c=gc();
    }
    while(c>='0'&&c<='9') x=x*10+c-'0',c=gc();
//    cout<<x<<endl;
    return x*f;
}
int nnu[25];
inline void write(int x)
{
    if(x<0) pc('-'),x=-x;
    if(!x)
    {
        pc('0');
        return;
    }
    int tp=0;
    while(x) nnu[++tp]=x%10,x/=10;
    while(tp) pc(nnu[tp--]+'0');
    return;
}
#define ma 500005
char s[ma];
int cnt[ma];
signed main()
{
	int A=read(),B=read(),C=read(),D=read();
	B=D*C-B;
//	cout<<B<<endl;
	if(B<=0) puts("-1");
	else cout<<(int)max(0.0,ceil(1.0*A/B));
}


/****Bismillahir rahmanir rahim****/

#include<bits/stdc++.h>

using namespace std;

typedef long long            ll;
typedef long double          ld;
typedef vector<int>          vi;
typedef vector<long long>    vl;
typedef vector<double>       vd;

#define All(a) a.begin(),a.end()

template <typename T>
void get_vector(T &a)
{
    for(auto &e: a) cin >> e;
}

template <typename T>
void put_vector(T a)
{
    for(auto e :a)cout << e << " ";
    cout << endl;
}

int main()
{
    int n;
    cin >> n;
    vd a(n),b(n),c(n),d(n);
    int x = 0,y = 0;
    for(int i = 0 ;i <n; i++)
    {
        cin >> a[i]>>b[i];
        x += a[i];y += b[i];
        a[i]*=n;b[i]*=n;
    }
    for(int i = 0; i<n ; i++)
    {
        a[i] -= x; b[i]-= y;
    }x = 0, y = 0;
    for(int i = 0 ;i <n; i++)
    {
        cin >> c[i]>>d[i];
        x += c[i];y += d[i];
        c[i]*=n;d[i]*=n;
    }
    for(int i = 0; i<n ; i++)
    {
        c[i] -= x; d[i]-= y;
    }
    double X,Y;
    for(int i=0; i<n; i++){
        if(a[i]!=0 || b[i]!=0){
            swap(a[i],a[0]);
            swap(b[i],b[0]);
        }
    }
    X = a[0];
    Y = b[0];
   // put_vector(a); put_vector(b);put_vector(c);put_vector(d);
    //cout << "x = " << X << " Y = " << Y << endl;
    const double diff = 1e-6;
    string ans = "No";
    for(int i = 0; i <n;i++)
    {
        double angle = atan2(d[i],c[i]) - atan2(Y,X);
        bool ok = true;
        for(int j = 0; j<n; j++)
        {
            double cx = a[j]*cos(angle) - b[j]*sin(angle);
            double cy = a[j]*sin(angle) + b[j]*cos(angle);
            bool ok2 = false;
            for(int k = 0; k<n; k++)
            {
                if(abs(cx-c[k])<=diff&&abs(cy-d[k])<=diff)ok2 = true;
            }
            ok &= ok2;
        }

        if(ok)ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

/*
 ______________________     _______ _______ _______ _______
(  ____ \__   __(  __  \   (  ____ |  ___  |  ____ (  ___  )
| (    \/  ) (  | (  \  )  | (    )| (   ) | (    \/ (   ) |
| (_____   | |  | |   ) |  | (____)| (___) | (_____| (___) |
(_____  )  | |  | |   | |  |     __)  ___  (_____  )  ___  |
      ) |  | |  | |   ) |  | (\ (  | (   ) |     ) | (   ) |
/\____) |__) (__| (__/  )  | ) \ \_| )   ( /\____) | )   ( |
\_______)_______(______/___|/   \__//     \_______)/     \|
                      (_____)
One day I will be Candidate Master on Codeforces
I didn't come this far to only come this far */
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fe(i, a, b) for (int i = a; i <= b; i++)
#define fl(i, a, b) for (int i = a; i < b; i++)
#define vi vector<int>
#define e1(a) int a; cin>>a;
#define e2(a,b) int a,b; cin>>a>>b;
#define e3(a,b,c) int a,b,c; cin>>a>>b>>c;
#define av(arr,n) vector<int> arr(n); fl(i,0,n) cin>>arr[i];
#define aa(arr,n) int arr[n]; fl(i,0,n) cin>>arr[i];
#define es(s) string(s); cin >> (s);
#define rz resize
#define sz(s) s.size()
#define mod 1000000007
#define ff first
#define ss second
#define tn -10e15
#define bg 10e15
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define mii map<int,int>
#define st(a, n) memset(a, n, sizeof(a))
#define vl(n) cout << n << "\n"
#define vs(n) cout << n << " "
#define el cout<<"\n"
#define vn(n) cout << n
#define dsc greater<int>()
#define ps(x,y)  fixed<<setprecision(y)<<x
#define R return
#define B break
#define C continue
#define YC cout<<"YES"<<"\n"
#define YS cout<<"Yes"<<"\n"
#define NC cout<<"NO"<<"\n"
#define NS cout<<"No"<<"\n"
#define lcm(a,b) (a/__gcd(a,b))*b
#define pa(a) for(auto e:a)cout<<e<<" "
const int N = 4e5 + 5;

void solve()
{
    e1(n);
    aa(a, n);
    vi f(202, 0);
    vi f2(202, 0);
    fl(i,0,n){
        if(a[i]>0)
        f[abs(a[i])]++;
        else
        {
            f2[abs(a[i])]++;
        }
    }
    int ans = 0;
    fl(i,0,n){
        int x = a[i];
        fe(j,0,201){
            if(f[j]>0){
            int p = abs(x - j);
            p *= p;
            ans += p * f[j];
            }
        }
        fe(j, 0, 201)
        {
            if(f2[j]>0){
            int p = abs(x + j);
            p *= p;
            ans += p * f2[j];
            }
        }
    }
    vl(ans/2);
}

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define REP(i,k,n) for(ll i=k;i<ll(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end())
#define decimal cout<<fixed<<setprecision(10)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)
using ll=long long;
using P=pair<ll,ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
constexpr ll inf=1001001001001001;
constexpr int INF=1001001001;
constexpr int mod=3;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
void YesNo(bool b){if(b)out("Yes");else out("No");}
void yesno(bool b){if(b)out("yes");else out("no");}
void YESNO(bool b){if(b)out("YES");else out("NO");}
ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;}

ll bb(char c){
    if(c=='B') return 0;
    if(c=='W') return 1;
    if(c=='R') return 2;
}

vi v(410000),cnt(410000);

void init(ll n){
    v[1]=1,cnt[1]=0;
    REP(i,2,n+5){
        if(i%3==0){
            ll j=i,c=0;
            while(j%3==0){j/=3; c++;}
            v[i]=v[i-1]*j%3;
            cnt[i]=cnt[i-1]+c;
        }
        else{
            v[i]=v[i-1]*i%3;
            cnt[i]=cnt[i-1];
        }
    }
}

ll COM(ll n,ll r){
    if(r==0||n==r) return 1;
    else if(cnt[n]>cnt[r]+cnt[n-r]) return 0;
    else{
        ll a=v[n],b=v[r]*v[n-r]%3;
        if(a==b) return 1;
        else return 2;
    }
}

int main(){
    ll n; cin>>n;
    init(n);
    string c;
    cin>>c;
    ll sum=0;
    rep(i,n){
        if(i>n-i-1) break;
        sum+=bb(c[i])*COM(n-1,i)%mod;
        sum%=mod;
        //out(sum);
        if(i<n-i-1) sum+=bb(c[n-1-i])*COM(n-1,i)%mod;
        sum%=mod;
        //out(sum);
    }
    ll ans;
    if(n%2==0) ans=(3-sum)%3;
    else ans=sum;
    if(ans==0) out("B");
    else if(ans==1) out("W");
    else out("R");
    /*REP(i,1,10){
      rep(j,i+1) cout<<COM(i,j);
      cout<<endl;
    }*/
}

#include<iostream>
#include<iterator>
#include<algorithm>
#include<climits>
#include<map>
#include<set>
#include<cmath>
#include<numeric>
#include<string>
#include<sstream>
#include<cstdio>
#include<vector>
#include<bitset>
// #include <atcoder/segtree>
#define ll long long
using namespace std;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll a[101] = {0};
    ll b[101] = {0};
    for(int i = 1; i <= m; ++i){
        cin >> a[i] >> b[i];
    }
    ll k;
    cin >> k;
    ll c[17] = {0};
    ll d[17] = {0};
    for(int i = 1; i <= k; ++i){
        cin >> c[i] >> d[i];
    }
    unsigned long long pow2k = (unsigned long long)pow(2,k);
    ll max_meet_count = 0;
    for (unsigned long long i = 0; i < pow2k; ++i){
        ll dish[101] = {0};
        bitset<64> bs(i);
        for(int shift=0; shift<k; ++shift){
            bool valid = (i>>shift)&1ull;

            if (valid){
                dish[c[shift+1]]+=1;
            }else{
                dish[d[shift+1]]+=1;
            }
        }
        ll meet_count = 0;
        for(int j = 1; j <= m; ++j){
            if (dish[a[j]] > 0 && dish[b[j]] > 0){
                ++meet_count;
            }
        }
        if (max_meet_count < meet_count){
            max_meet_count = meet_count;
        }

    }
    cout << max_meet_count << endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,L,R) for(int i=L;i<R;i++)
using namespace std;
typedef vector<vector<int>> Graph;

//decralation

//struct area

// Erathostenes's sieve

//main area
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    vector<ll> cnt(200,0);
    rep(i,N) cnt[(A[i])%200]++;
    ll ans = 0;
    rep(i,200){
        ans += cnt[i]*(cnt[i]-1)/2;
    }
    cout << ans << endl;
}
/*

*/

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

    using namespace std;

    int main(){
        string question, no_rev;
        char this_char, prev_char;
        int i = 0, rev;

        cin >> question;
        rev = -1;
        while((this_char = question[i++]) != '\0'){
            if(this_char == 'R'){
                rev *= -1;
            } else if (rev == -1) {
                no_rev.push_back(this_char);
            } else {
                no_rev.insert(0, 1, this_char);
            }
        }

        if(rev == 1){
            reverse(no_rev.begin(),no_rev.end());
        }

        i = 0;
        prev_char = '\0';
        string answer;
        while((this_char = no_rev[i++]) != '\0'){
            if(this_char == prev_char){
                answer.pop_back();
            } else {
                answer.push_back(this_char);
            }
            prev_char = answer[answer.length() - 1];
        }
        cout << answer << '\n';
    }


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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<LL> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
LL INF = 60;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define FOR(a, b, c) for (int(a) = (b); (a) < (c);)
#define FORN(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)

int main()
{
   double a,b,x,y;
   cin>>a>>b;
   x = (a+b)/2.0;
   y = a-x;
   cout<<x<<" "<<y<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
        int A,B;
        cin >> A >> B;
        cout << (A+B)/2 << " " << (A-B)/2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e7+10;
const int mod7=1e9+7;
const int mod=998244353;
const int M=1e7;
const double pi=acos(-1);
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0')
        if(ch=='-')
            d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9')
        a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
	int n;read(n);
	printf("%d\n",n-1);
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
#define N 100010
using namespace std;

int n, cnt;
bool f;
char ch, a[N], b[N];

inline int read(){
	int s = 0, w = 1;
	char ch = getchar();
	for (; ch < '0' || ch > '9'; w *= ch == '-' ? -1 : 1, ch = getchar());
	for (; ch >= '0' && ch <= '9'; s = s * 10 + ch - '0', ch = getchar());
	return s * w;
}

int main(){
	n = read();
	for (int i = 1; i <= n + 1; ++i){
		cin >> a[i];
		if (a[i] != a[i - 1]) b[++cnt] = a[i];
		if (a[i] == a[i - 1] && b[cnt] != b[cnt - 1]) b[++cnt] = a[i];
	}
	cnt--;
	if (b[1] != b[cnt]){
		puts("1");
		exit(0);
	}
	ch = b[1];
	f = 0;
	for (int i = 1; i <= cnt; ++i){
		if (ch == b[i]) f = 0;
		if (ch != b[i]){
			if (f == 1){
				puts("2");
				exit(0);
			}
			f = 1;
		}
	}
	if (f) puts("1");
	else puts("-1");
	return 0;
}


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

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

    int N, K;
    cin >> N >> K;

    int ijk_sum;
    int num = 0;
    auto num_s = [&](int s){
        if(s < 3) return 0LL;
        if(s <= N+2) return (s-2)*(s-1)/2;
        if(s <= 2*N+1) return (s-1)*(2*N-s+2)/2 + (3*N-s+1)*(-N+s-2)/2;
        else return (3*N-s+1)*(3*N-s+2)/2;
    };

    auto num_two = [&](int t){
        if(t < 2) return 0LL;
        if(t <= N+1) return t-1;
        if(t <= 2*N) return 2*N-t+1;
        else return 0LL;
    };

    for(ijk_sum=3; ijk_sum<=3*N; ijk_sum++){
        int ns = num_s(ijk_sum);
        if(num + ns >= K) break;
        num += ns;
    }

    int i;
    for(i=1; i<=N; i++){
        int nt = num_two(ijk_sum-i);
        if(num + nt >= K) break;
        num += nt;
    }

    int j = max(1LL, ijk_sum-i-N), k = min(ijk_sum-i-1, N);
    j += K-num-1;
    k -= K-num-1;

    cout << i << " " << j << " " << k << endl;

    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
long long dp[4][3000005];
int ans[4];
int main()
{
    int n,st;
    long long k,sum,now;
    int all;
    scanf("%d%lld",&n,&k);
    dp[0][0]=1;
    for(int i=1;i<=3;i++)
    {
        sum=0;
        for(int j=0;j<=i*n;j++)
        {
            dp[i][j]=sum;
            sum+=dp[i-1][j];
            if(j>=n)
                sum-=dp[i-1][j-n];
        }
    }
    now=0;
    for(int i=0;i<=3*n;i++)
    {
        now+=dp[3][i];
        if(now>=k)
        {
            all=i;
            k-=now-dp[3][i];
            break;
        }
    }
    now=0;
    for(int i=1;i<=n;i++)
    {
        now+=dp[2][all-i];
        if(now>=k)
        {
            ans[1]=i;
            for(int j=1;j<=n;j++)
                if(all-ans[1]-j>=1&&all-ans[1]-j<=n)
                {
                    ans[2]=j;
                    ans[3]=all-ans[1]-ans[2];
                    break;
                }
            for(int j=0;j<k-(now-dp[2][all-i])-1;j++)
            {
                ans[2]++;
                ans[3]--;
            }
            printf("%d %d %d\n",ans[1],ans[2],ans[3]);
            break;
        }
    }
    return 0;
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
char X[70];
long long M;
int main(){
  int i;
  long long res = 0;
  long long d;
  long long mx;
  long long b;
  __int128_t val;
  N = rd(X);
  rd(M);
  for(i=(0);i<(N);i++){
    X[i] -= '0';
  }
  int Q5VJL1cS;
  char e98WHCEY;
  if(N==0){
    e98WHCEY = 0;
  }
  else{
    e98WHCEY = X[0];
    for(Q5VJL1cS=(1);Q5VJL1cS<(N);Q5VJL1cS++){
      e98WHCEY = max_L(e98WHCEY, X[Q5VJL1cS]);
    }
  }
  d =e98WHCEY;
  if(N==1){
    if(X[0] <= M){
      res++;
    }
    wt_L(res);
    wt_L('\n');
    return 0;
  }
  if(N==2){
    res = (M - X[1]) / X[0] - d;
    chmax(res, 0);
    wt_L(res);
    wt_L('\n');
    return 0;
  }
  long long FmcKpFmN;
  long long xr20shxY;
  long long WYIGIcGE;
  FmcKpFmN = d;
  xr20shxY = 1e9;
  while(FmcKpFmN < xr20shxY){
    if((FmcKpFmN + xr20shxY)%2==0){
      WYIGIcGE = (FmcKpFmN + xr20shxY) / 2;
    }
    else{
      WYIGIcGE = (FmcKpFmN + xr20shxY + 1) / 2;
    }
    val = 0;
    for(i=(0);i<(N);i++){
      val = val * WYIGIcGE + X[i];
      if(val > M){
        break;
      }
    }
    if(val <= M){
      FmcKpFmN = WYIGIcGE;
    }
    else{
      xr20shxY = WYIGIcGE - 1;
    }
  }
  b =xr20shxY;
  res = b - d;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210103-1 [bug fixed 4]

// --- original code ---
// int N; char X[70];
// ll M;
// {
//   ll res = 0, d, mx, b;
//   __int128_t val;
//   rd(X@N,M);
//   rep(i,N) X[i] -= '0';
//   d = max(X(N));
//
//   if(N==1){
//     if(X[0] <= M) res++;
//     wt(res);
//     return 0;
//   }
//   if(N==2){
//     res = (M - X[1]) / X[0] - d;
//     res >?= 0;
//     wt(res);
//     return 0;
//   }
//   b = bsearch_max[ll,b,d,1e9][
//     val = 0;
//     rep(i,N){
//       val = val * b + X[i];
//       if(val > M) break;
//     }
//   ](val <= M);
//   res = b - d;
//   wt(res);
// }

#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

string toBase(long long M, long long b) {
    string s;

    while (M) {
        long long maxVal = min(9LL, (M%b));
        if (M%b > 9) {
            for (int i = 0; i < s.size(); ++i) {
                s[i] = '9';
            }
        }
        s += (maxVal+'0');
        M /= b;
    }

    reverse(s.begin(), s.end());

    return s;
}

int main() {
    string X;
    long long M;
    cin >> X >> M;

    long long minb = 0;
    long long maxb = M;
    // d*B^X <= M => logd + X log B <= log M => X log B <= logM - logd
    reverse(X.begin(), X.end());
    for (int i = 0; i < X.size(); ++i) {
        long long digit = X[i]-'0';
        minb = max(minb, digit+1LL);
    }

    if (X.size() == 1) { //only one digit
        maxb = minb;
    }

    long long low = minb;
    long long up = maxb;
    long long ans = minb-1;
    // cout << "DEBUG " << low << " " << maxb << endl;
    // cout << exp(log(1)) << endl;

    reverse(X.begin(), X.end());

    while (low <= up) {
        long long mid = (low+up) / 2;

        bool ok = true;

        string MS = toBase(M, mid);
        // cout << "DEBUGGO " << mid << " " << MS << endl;

        if (MS.size() < X.size() || (MS.size() == X.size() && MS < X)) {
            ok = false;
        }

        if (ok) {
            low = mid+1;
            ans = mid;
        } else {
            up = mid-1;
        }
    }

    cout << (ans-minb)+1 << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin() , x.end()
#define vi vector<int>
#define vP vector<pair<int,int>>
#define vll vector<ll>

const static int INF = 1001001001;
const static ll LINF = 1001001001001001001LL;
const static lld PI = 3.1415926535897932384626L;
const static int MOD = 1000000009;
//const static int MOD = 998244353;

template < typename T > T gcd (T a , T b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd (b , a % b); }
template < typename T > T lcm (T a , T b) { return (a / gcd (a , b) * b); }
template < typename T > void chmin (T &a , T b) { if (a > b) a = b; }
template < typename T > void chmax (T &a , T b) { if (a < b) a = b; }

void io_setup () {
    cout << fixed << setprecision(30);
    cin.tie(0);
    ios::sync_with_stdio(false);
}

//memo
////v.erase(unique(v.begin(), v.end()), v.end());

int main () {
    io_setup();
    lld n;
    cin >> n;
    lld ans = 0.0;
    for (int i = 1; i <= n - 1; i++) {
        ans += n / (lld)i;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define all(x) x.begin(),x.end()

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

int digits (int a1)
{
    int a=a1;
    int x = 0;
    while(a!=0){
        a/=10;
        x++;
    }
    return x;
}

void solve()
{
  int n; cin >> n;
  int d = digits(n);
  int nr = n;
  vector<int> di;
  rep(i,0,d){
    di.push_back(nr%10);
    nr/=10;
  }
  reverse(all(di));
  int ans = 0;
  int y=1;
  for(int i=2; i<d; i+=2){
     int b = (i/2);
     if(i!=2) y*=10;
     ans += 9*y;
  }
  if(d%2==1){
    cout << ans << endl;
    return;
  }
  int l=0,r=0;
  int p = (d/2)-1;
  for(int i=0;i<d/2;i++){
    l += di[i]*pow(10,p-i);
    r += di[(d/2)+i]*pow(10,p-i);
  }
  int k = l-pow(10,p);
  k++;
  ans += k;
  if(l<=r) cout << ans << endl;
  else cout << ans-1 << endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--) solve();
    return 0;
}


#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string A, B;
    cin >> A >> B;

    int nA=0, nB=0;
    for(int i=0;i<3;i++){
        nA += A[i]-'0';
        nB += B[i]-'0';
    }

    cout << max(nA, nB) <<endl;

  	return 0;
}

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

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(long long x){return __builtin_popcount(x);}

template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
const ld PI=acosl(-1);

void Main();
int main(){cout<<fixed<<setprecision(15);Main();}

void Main(){

int A,B;cin>>A>>B;
vector<int> ans;
if(A>=B){
    int y=(A*(A+1)-B*(B+1))/2;
    rep(i,A)ans.push_back(i+1);
    rep(i,B)ans.push_back(-(i+1));
    ans.back()-=y;
}
else{
    int y=(B*(B+1)-A*(A+1))/2;
    rep(i,A)ans.push_back(i+1);
    rep(i,B)ans.push_back(-(i+1));
    ans[A-1]+=y;
}
rep(i,A+B){
    if(i)cout<<" ";
    cout<<ans[i];
}
cout<<endl;

}


#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m;
signed main() {
	cin >> n >> m;
//	for(int i = 1; i <= n; )
	if(m == 0) {
		for(int k = 1, i = 1; i <= n; ++i, k += 2) {
			cout << k << ' ' << k + 1 << endl;
		}
		return 0;
	}
	if(m > 0 && m < n - 1) {
		int mx = 0;
		for(int i = n - m - 1 + 3, k = 1; k <= m + 1; ++k, i += 2) {
			cout << i << ' ' << i + 1 << endl;
			mx = i + 1;
		}
		int l = n - m - 1 + 2;
		for(int k = 1; k <= n - m - 1; ++k) {
			cout << --l << ' ' << ++mx << endl;
		}
	} else {
		cout << -1;
	}

}

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

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

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

//おそそう

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

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

	int N = getint(), M = getint();
	int w[8];
	rep(i, N) w[i] = getint();

	ll lv[100001];
	rep(i, M) {
		ll l = getint();
		int v = getint();
		lv[i] = l << 32 | v;
	}
	pakuri_sort(M, lv);
	lv[M] = 1000000001ll;

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
		li[i] = li[i] << 30 | i;
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while ((lv[k] & (1 << 30) - 1) < li[i] >> 30) {
			if (saidai < lv[k] >> 32) saidai = lv[k] >> 32;
			k++;
		}
		li[i] = ll(saidai) << 30 | (li[i] & (1 << 30) - 1);
	}
	rep(i, 1 << N) li2[li[i] & (1 << 30) - 1] = li[i] >> 30;

	rep(i, N) {
		if (w[i] > (lv[0] & (1 << 30) - 1)) {
			printf("-1");
			return 0;
		}
	}
	int P[8];
	rep(i, N) P[i] = i;

	int kotae = 1e9;
	do {
		int tmp[8] = {};
		rep(p, N - 1) {
			int omosa = 1 << P[p];
			for (int q = p + 1; q < N; q++) {
				omosa |= 1 << P[q];
				int kari = tmp[p] + li2[omosa];
				if (tmp[q] < kari) tmp[q] = kari;
			}
		}
		if (kotae > tmp[N - 1]) kotae = tmp[N - 1];

	} while (next_permutation(P, P + N));

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

	Would you please return 0;
}


#include <sys/time.h>

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

using namespace std;

using ll = long long;
using i_i = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll MOD =  1000000007;

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

	string s[h];

	rep(i, h) {
		cin >> s[i];
	}
	ll ch[h][w];
	ll cv[h][w];
	ll cr[h][w];

	ll total = 0;

	rep(y, h) {
		rep(x, w) {
			ch[y][x] = 0;
			cv[y][x] = 0;
			cr[y][x] = 0;
			if (s[y][x] == '.') {
				total ++;
			}
		}
	}

	rep(y, h) {
		int count = 0;
		int start = 0;
		rep(x, w) {
			if (s[y][x] == '.') {
				if (count == 0) {
					start = x;
				}
				count++;
			} else {
				if (count == 0) continue;
				for (int cx = start; cx < x; cx++) {
					ch[y][cx] = count;
				}
				count = 0;
			}
		}
		if (count > 0) {
			for (int cx = start; cx < w; cx++) {
				ch[y][cx] = count;
			}
		}
	}

	rep(x, w) {
		int count = 0;
		int start = 0;
		rep(y, h) {
			if (s[y][x] == '.') {
				if (count == 0) {
					start = y;
				}
				count++;
			} else {
				if (count == 0) continue;
				for (int cy = start; cy < y; cy++) {
					cv[cy][x] = count;
				}
				count = 0;
			}
		}
		if (count > 0) {
			for (int cy = start; cy < h; cy++) {
				cv[cy][x] = count;
			}
		}
	}

	rep(y, h) {
		rep(x, w) {
			cr[y][x] = ch[y][x] + cv[y][x];
			if (cr[y][x] > 0) cr[y][x] --;
		}
	}

	vector<ll> power2(2010 * 2010, 0);

	power2[0] = 1;
	rep(i,2010 * 2010) {
		power2[i + 1] = power2[i] * 2;
		power2[i + 1] %= MOD;
	}
	ll ans = 0;

	rep(y, h) {
		rep(x, w) {
			if (cr[y][x] == 0) continue;
			ll cur = (power2[cr[y][x]] - 1) * power2[total - cr[y][x]];
			cur %= MOD;
			ans += cur;
			ans %= MOD;
		}
	}
	cout << ans << endl;

	return 0;
}

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

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"
const double PI = acos(-1);

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
  return (a >= b ? a : b);
}

lli minm(lli a, lli b)
{
  return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
  lli res = 1;

  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  lli pro = 1, k = n;
  while (k > r)
  {
    pro *= k;
    pro %= p;
    --k;
  }

  k = 2;
  while (k <= (n - r))
  {
    pro *= power(k, (p - 2), p);
    pro %= p;
    ++k;
  }

  return pro;
}

lli first_big(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = n;
  l = 0;
  r = n - 1;

  while (l <= r) {
    lli m = l + (r - l) / 2;

    if (arr[m] > k) {
      ans = m;
      r = m - 1;
    }

    else
      l = m + 1;
  }

  return ans;
}

lli last_small(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = -1;
  l = 0;
  r = n - 1;

  while (l <= r)
  {
    lli mid = (l + r) / 2;

    if (arr[mid] <= k)
    {
      ans = mid;
      l = mid + 1;
    }
    else
      r = mid - 1;
  }

  return ans;
}

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
}
#define MAXN 4000010

int main()
{
  c_p_c();

  lli h, w, k = 0, pro = 1, c = 0;
  vector<lli>pow_mod(MAXN);

  for (int i = 0; i < MAXN; ++i)
  {
    pow_mod[i] = pro;
    pro *= 2;
    pro %= mod;
  }

  cin >> h >> w;
  string str;

  char v[h][w];
  lli arr[h][w];
  memset(arr, 0, sizeof(arr));

  for (int i = 0; i < h; ++i)
  {
    cin >> str;
    for (int j = 0; j < w; ++j)
    {
      v[i][j] = str[j];
      if (str[j] == '.')
        ++k;
    }
  }

  for (lli i = 0; i < h; ++i)
  {
    for (lli j = 0; j < w; ++j)
    {
      if (v[i][j] == '.')
        ++c;
      else
      {
        if (c != 0)
          for (int p = j - c; p < j; ++p)
            arr[i][p] += c;
        c = 0;
      }
    }

    if (c != 0)
      for (int p = w - c; p < w; ++p)
        arr[i][p] += c;
    c = 0;
  }

  for (lli i = 0; i < w; ++i)
  {
    for (lli j = 0; j < h; ++j)
    {
      if (v[j][i] == '.')
        ++c;
      else
      {
        if (c != 0)
          for (int p = j - c; p < j; ++p)
            arr[p][i] += (c - 1);
        c = 0;
      }
    }

    if (c != 0)
      for (int p = h - c; p < h; ++p)
        arr[p][i] += (c - 1);
    c = 0;
  }

  lli ans = pow_mod[k];
  ans *= k;
  ans %= mod;

  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      if (arr[i][j] != 0)
      {
        ans -= pow_mod[k - arr[i][j]];
        ans = (ans + mod) % mod;
      }

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


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }
int n, q;
vector<map<int, int>> H;
vector<int> p;

int par(int x){
    if (p[x] == x)
        return x;
    return p[x] = par(p[x]);
}
void merge(int x, int y){
    int px = par(x);
    int py = par(y);
    if (px == py) return;
    if (H[px].size() < H[py].size())
        swap(px, py);
    p[py] = px;
    for(auto it : H[py])
        H[px][it.first] += it.second;
}
int get(int x, int ci){
    int px = par(x);
    return H[px][ci];
}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    cin >> n >> q;
    p.resize(n+1);
    H.resize(n+1);
    FOR(i, n){
        int ci;
        cin >> ci;
        H[i+1][ci]++;
        p[i+1] = i+1;
    }

    FOR(i, q){
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 1)
            merge(x, y);
        else
            cout << get(x, y) << '\n';
    }

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

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

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

	int n; cin >> n;
	int ans = 1e9+7;

	FOR(i, n){
		int a, b, c; cin >> a >> b >> c;

		if(c > a) ans = min(ans, b);
	}

	if(ans == 1e9+7) cout << "-1\n";
	else cout << ans << '\n';

	return 0;
}


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

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

    cout << (y * z + x - 1) / x - 1 << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,srt,end) for(ll i = (srt); i < (ll)(end); i++)
//ll MOD=1000000007;
//ll mod=998244353;
//int inf=1000001000;
//ll INF=1e18+5;
//cout << std::fixed << std::setprecision(15) << y << endl;

// For debug
// Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define dump(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << "\n";}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } }
template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); }

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x, y, z;
    cin >> x >> y >> z;

    ll ans = 0;
    rep(i,0,10000000){
        if(z*y > x*i) ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}


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

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

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

vector <ll> dv;

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

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

        dv.pb(i);
        if(n/i != i) dv.pb(n/i);
    }

    sort(all(dv));
    for(ll &d : dv) pf("%lld\n", d);

    return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>

using namespace std;

class InputReader {
public:
    InputReader() {}
    InputReader(const char *file_name) {
        input_file = fopen(file_name, "r");
        cursor = 0;
        fread(buffer, SIZE, 1, input_file);
    }
    inline InputReader &operator >>(int &n) {
        while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
            advance();
        }
        int sign = 1;
        if (buffer[cursor] == '-') {
            sign = -1;
            advance();
        }
        n = 0;
        while('0' <= buffer[cursor] && buffer[cursor] <= '9') {
            n = n * 10 + buffer[cursor] - '0';
            advance();
        }
        n *= sign;
        return *this;
    }
private:
    FILE *input_file;
    static const int SIZE = 1 << 17;
    int cursor;
    char buffer[SIZE];
    inline void advance() {
        ++ cursor;
        if(cursor == SIZE) {
            cursor = 0;
            fread(buffer, SIZE, 1, input_file);
        }
    }
};

long long cmmdc(long long a, long long b) {
    while (b) {
        long long r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    //ifstream cin("input.txt");
    int n;
    cin >> n;
    long long answer = 1;
    for (long long i = 2; i <= n; i++) {
        answer = answer * i / cmmdc(answer, i);
    }
    cout << answer + 1 << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

void Main();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

void Main(){
  int k; cin >> k;
  ll ans = 0;
  for(int a=1; a <= k; a++){
    for(int b = 1; b <= k; b++){
      if(a * b > k){
        break;
      }
      ans += (ll)k / (a * b);
    }
  }
  cout << ans << endl;
}

/*
少加头文件，爆零两行泪
DP后效性，爆零两行泪
文件读入错，爆零两行泪
文件名写错，爆零两行泪
调完不编译，爆零两行泪
结论不证明，爆零两行泪
数组没开够，爆零两行泪
ll开 int，爆零两行泪
 dp 没初值，爆零两行泪
深搜没边界，爆零两行泪
广搜忘出队，爆零两行泪
模数没看清，爆零两行泪
越界不特判，爆零两行泪
多测不清空，爆零两行泪
空间胡乱开，爆零两行泪
无向变有向，爆零两行泪
调试忘删除，爆零两行泪
文件不保存，爆零两行泪
题目提交错，爆零两行泪
*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
P<int,int> p[20000005];
int a[2005],cnt;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,mini=1e9;
	cin>>n;
	FOR(i,1,n){
		cin>>a[i];
		gmin(mini,a[i]);
		for(int j=1;j*j<=a[i];j++){
			if(a[i]%j==0){
				p[++cnt]=MP(j,i);
				if(j*j!=a[i])p[++cnt]=MP(a[i]/j,i);
			}
		}
	}
	sort(p+1,p+cnt+1);
	int GCD=a[p[1].S],ans=0;
	FOR(i,2,cnt){
		if(p[i].F!=p[i-1].F){
//			cout<<p[i-1].F<<' '<<GCD<<'\n';
			if(GCD==p[i-1].F)ans++;
			GCD=a[p[i].S];
		}else{
			GCD=__gcd(GCD,a[p[i].S]);
		}
		if(p[i].F>mini)break;
	}
	if(GCD<=mini&&GCD==p[cnt].F)ans++;
	cout<<ans;
	RE 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int K;
int S[10];
int T[10];

signed main()
{
	cin >> K;
	string s;
	string t;
	cin >> s;
	cin >> t;
	for (int i = 0; i < 4; i++)
	{
		S[s[i] - '0']++;
		T[t[i] - '0']++;
	}

	int all = (K * 9 - 8) * (K * 9 - 9);
	int sum = 0;

	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			S[i]++;
			T[j]++;

			int score_i = 0;
			int score_j = 0;
			for (int k = 1; k <= 9; k++)
			{
				int ss = 1;
				for (int l = 0; l < S[k]; l++)
				{
					ss *= 10;
				}
				int tt = 1;
				for (int l = 0; l < T[k]; l++)
				{
					tt *= 10;
				}

				score_i += k * ss;
				score_j += k * tt;
			}

			S[i]--;
			T[j]--;

			if (score_i > score_j)
			{
				if (i == j)
				{
					int rest = K - (S[i] + T[i]);
					int pat = rest * (rest - 1);
					sum += pat;
				}
				else
				{
					int rest_i = K - (S[i] + T[i]);
					int rest_j = K - (S[j] + T[j]);
					sum += rest_i * rest_j;
				}
			}
		}
	}

	cout << fixed << setprecision(10);
	cout << (sum / (double)all) << endl;
	//cout << sum << "/" << all << endl;
}

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

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fly ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define nl "\n"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;
#define mt make_tuple
#define vec vector
#define ld long double
#define eps 1e-9

#define int long long

const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;

typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void solve() {

	int n; cin >> n ;
	int x[n], y[n];
	rep(i,0,n) cin >> x[i] >> y[i] ;

	int ans = 0 ;

	for(int i = 0 ; i < n ; ++i) {
		for(int j = i+1 ; j < n ; ++j) {
			ld slope = (ld)(y[j]-y[i])/(ld)(x[j]-x[i]) ;
			if(slope >= -1 and slope <= 1) ++ans ;
		}
	}

	cout << ans ;
}

int32_t main() {

#ifdef LOCAL
    freopen("error.txt", "w", stderr);
#endif

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

    // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
	cin>>n>>m;
	cout<<n*(1+m)*m/2+m*(1+n)*n/2*100;
}

#include <iostream>
using namespace std;

typedef long long int ll;

int main(void){

    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<k; j++) {
            ans += 100*(i+1) + j+1;
        }
    }

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


#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<ll, ll>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    vector<ll> cnt(N + 1, 0);
    for (auto& a : A) {
        ++cnt[a];
    }
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, 0, N + 1) {
        que.emplace(cnt[i], i);
    }
    ll now_cnt = 0;
    ll max_a = N + 1;
    ll ans = 0;
    while (K) {
        while (!que.empty() && max_a < que.top().second) {
            que.pop();
        }
        if (que.empty()) {
            break;
        }
        P now = que.top();
        que.pop();
        ll diff = min(max(now.first - now_cnt, 0LL), K);
        ans += max_a * diff;
        now_cnt += diff;
        max_a = now.second;
        K -= diff;
    }
    cout << ans << endl;
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define ll long long
const int inf = 1e3+10;
const int row[]={1,-1,0,0},col[]={0,0,1,-1};
int main()
{
	int h,w;
	cin>>h>>w;
	string ab[h];
	int st=0,st1=0,gi,gj;
	vector <pair<int,int> > v[26];
	int alphavis[26];
	memset(alphavis,0,sizeof(alphavis));
	for (int i = 0; i < h; ++i)
	{
		cin>>ab[i];
		for (int j= 0; j<w ; ++j)
		{
			if(ab[i][j]=='S')
			{
				st=i,st1=j;
			}
			else if(ab[i][j]=='G')
			{
				gi=i;
				gj=j;
			}
			else if(ab[i][j]>='a'&&ab[i][j]<='z')
			{
				v[ab[i][j]-'a'].push_back({i,j});
			}
		}
	}
	queue<pair<int,int> >q;
	q.push({st,st1});
	int visit[h][w];
	memset(visit,-1,sizeof(visit));
	visit[st][st1]=0;
    while(!q.empty())
    {
        auto it=q.front();
        int r=it.first;
        int c=it.second;
        q.pop();
        for(int i=0;i<4;i++)
        {
        	int rr=r+row[i],cc=c+col[i];
        	if(rr>=0&&rr<h&&cc>=0&&cc<w&&ab[rr][cc]!='#')
        	{
        		if(visit[r][c]+1<visit[rr][cc]||visit[rr][cc]==-1)
        		{
           			if(ab[rr][cc]>='a'&&ab[rr][cc]<='z')
        			{
        				int sized=v[ab[rr][cc]-'a'].size();
        				if(alphavis[ab[rr][cc]-'a']==0){
        				for(int k=0;k<sized;k++)
        				{
        					int x=ab[rr][cc]-'a';
        					if(v[x][k].first==rr&&v[x][k].second==cc)
        					visit[v[x][k].first][v[x][k].second]=visit[r][c]+1;
        					else
        					visit[v[x][k].first][v[x][k].second]=visit[r][c]+2;
        					q.push({v[x][k].first,v[x][k].second});
           				}
           				alphavis[ab[rr][cc]-'a']=1;
           			  }
           			else
           				visit[rr][cc]=visit[r][c]+1;
        			}
        			else {
        			visit[rr][cc]=visit[r][c]+1;
        			q.push({rr,cc});
        		}
        		}
        	}
        }
    }
    cout<<visit[gi][gj]<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {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 updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    LL(n,k);
    vector2d(ll,a,n,2);
    in(a);
    sort(all(a));
    ll now=0,ans=0;
    for(int i=0;i<n;i++){
        if((a[i][0]-now)<=k){
            k-=a[i][0]-now;
            k+=a[i][1];
            now=a[i][0];
        }else{
            out(now+k);
            return 0;
        }
    }
    out(now+k);
}

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

int main(){
    int N; cin >> N;
    double x0,y0,xN2,yN2;
    cin >> x0 >> y0;
    cin >> xN2 >> yN2;

    // 中心座標を求める
    double xc = (x0 + xN2) / 2.0;
    double yc = (y0 + yN2) / 2.0;

    // 回転させる必要がある角度は360/N度
    double degree = 360.0 / N;
    double theta = degree * M_PI / 180.0;

    // xc,ycを中心にthetaラジアン回転させる
    double x1 = (x0 - xc) * cos(theta) - (y0 - yc) * sin(theta) + xc;
    double y1 = (x0 - xc) * sin(theta) + (y0 - yc) * cos(theta) + yc;

    cout << fixed << setprecision(8) << x1 << ' ' << y1 << endl;
}


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

int main()
{
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	if (a<=b)
	  cout<<(b-a)*min(y,2*x)+x;
	else
	  cout<<(a-b-1)*min(y,2*x)+x;
	return 0;
}

#include <stdio.h>
#include <math.h>
#define PI 3.1415926535

int main()
{
	int a;
	scanf("%d",&a);

	int x1,y1,x2,y2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	double xr = (double)(x1+x2)/2;
	double yr = (double)(y1+y2)/2;
	double xvec = x1 - xr;
	double yvec = y1 - yr;
	double xvec2 = cos(2*PI/a) * xvec - sin(2*PI/a) * yvec;
	double yvec2 = sin(2*PI/a) * xvec + cos(2*PI/a) * yvec;
	printf("%.12lf %.12lf",xvec2 + xr, yvec2 + yr);
}


// author: Halit
#include <bits/stdc++.h>

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

  std::vector<int> a(n);
  for (int& el : a) {
    std::cin >> el;
  }

  constexpr double eps = 0.0000001;
  auto check = [&](double x) {
    long double compute = 0;
    for (int a_i : a) {
      compute += x + a_i - std::min(double(a_i), 2*x);
    }

    return compute / n;
  };

  double l = 0, r = 1e9+7;
  for (int i = 1;i <= 100; ++i) {
    double point_1 = (r-l)/3 + l;
    double point_2 = (r-l)/3 * 2 + l;

    if (check(point_2)-check(point_1) > eps) r = point_2;
    else l = point_1;
  }

  double ans = l;
  std::cout << std::fixed << std::setprecision(7) << check(ans);
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<math.h>
#include<iostream>
#include<cmath>
#include<queue>
#include<vector>
#define IOS ios::sync_with_stdio(false);cin.tie();cout.tie(0)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pll;
const int N=1e5+10;
const int mod=1e9+7;
double a[N],s[N];

int main()
{
    IOS;
    int n;
    cin>>n;
    double n1=n*1.0;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+a[i];

    double sum=1e18;
    for(int i=1;i<=n;i++)
    {
        double w=a[i]/2;
        double w1=(s[n]-s[i])-(n-i-i)*w;
        sum=min(sum,w1);
        //cout<<sum/n1<<endl;
    }
    printf("%.6lf",sum/n1);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void leftrotate(string &s, int d)
{
    reverse(s.begin(), s.begin()+d);
    reverse(s.begin()+d, s.end());
    reverse(s.begin(), s.end());
}

int main(){
  string s;
  cin>>s;
  leftrotate(s, 1);
    cout << s << endl;

}

#include <bits/stdc++.h>

using namespace std;

int main() {
    long long n;
    cin>>n;
    ++n;
    // long long a=109109109109109109;
    // long long b=109109108641970782;
    // long long c=467138327;
    // long double x=sqrt(1+8*n);
    // long long d=(x+1.0)/2.0;
    // cout<<n-d+1;
    long long i=1;
    while(i*(i+1)/2<=n){
        ++i;
    }
    cout<<n-i+1;

}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define dl long double
#define all(arr) arr.begin(), arr.end()
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pie 3.14159265358979323846264338327950L
#define mid(l, r) l + (r - l) / 2
#define memo(arr) memset(arr, 0,sizeof(arr));
#define mem1(arr) memset(arr,-1,sizeof(arr));
#define vec vector<int>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
#define sz(x) (int)x.size()
#define template_array_size (int)1e6 + 6
#define INF (int)1e18
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#define trace7(arr)              for(auto it : arr) cerr<<it<<" "; cout<<endl;
using namespace std;

int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);}
int lcm(int a, int b) { return (a*b)/ gcd(a,b);}

const int N = 3e5;
const int mod = 1e9 + 7;

void sout(){
	cout<<endl;
}
template <typename T,typename... Types>
void sout(T var1,Types... var2){
	cout<<var1<<" ";
	sout(var2...);
}
template<typename T>
void sout(vector<T> arr) {
    for(auto it : arr) {
        cout<<it<<" ";
    }
    sout();
}

//____________________________________________

void test_case () {

    int n;
    cin>>n;

    vector<int> arr(n);
    for(auto &it : arr) {
        cin>>it;
    }

    sort(all(arr));

    int ans = 0;
    int sum = 0;

    for(int i=0; i<n; i++) {
        ans+= (i * arr[i]) - sum;
        sum+= arr[i];
    }
    cout<<ans;

}

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

    #ifndef ONLINE_JUDGE
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif

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

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

/* run in terminal

 g++ -std=c++14 -o a actionKamen.cpp && ./a

*/

#include<bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
//#define pb push_back
//#define ppb pop_back
//#define mp make_pair
//#define ff first
//#define ss second
#define PI 3.141592653589793238462
//#define set_bits __builtin_popcountll
//#define sz(x) ((int)(x).size())
//#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
bool isValid(ll arr[], ll n, ll q, ll total){
	ll count=0;
	ll time=0;
	for(ll i=0;i<n;i++){
		ll j=1;
		time=0;
		while(1){
          time+=j*arr[i];
          j++;

          if(time>total)
          	break;
           count++;
		}
	}
	return count>=q;
}
int main(){
	  #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
  freopen("Error.txt","w",stderr);
 freopen("output.txt","w",stdout);
    #endif
 fastio();
int t;
t=1;
while(t--){
	ll a,b,c;
	cin>>a>>b>>c;
	cout<<21-(a+b+c);

}

}


#include <bits/stdc++.h>
#define lg long long int
#define loop(i, s, e) for (lg i = s; i <= e; i++)
#define iloop(i, s, e) for (lg i = e; i >= s; i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;

lg min(lg a, lg b)
{
	return a < b ? a : b;
}
lg max(lg a, lg b)
{
	return a > b ? a : b;
}
lg lcm(lg a, lg b)
{
	return (a * b) / __gcd(a, b);
}
lg ans = 0;
lg n, a,b;
lg bin_Search(vector<lg>& nums, lg low,lg high,lg num){
	if(nums[low]>=num) return low;
	else if(nums[high]<=num) return high+1;
	else if(high-low<2) return high;
	else {
		lg mid = (low+high)/2;
		if(nums[mid]>num) return bin_Search(nums,low,mid,num);
		else if(nums[mid]<num) return bin_Search(nums,mid,high,num);
		else return mid;
	}
}
int main()
{
	cin>>n>>a>>b;
	cout<<n-a+b<<endl;
}

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

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;

const int N=25;

int ans = 1;
vector<int> v[N];
int vis[N];
int col[N];
int lvl[N];

int dfs(int z){
	int ret = 1;
	vis[z] = 1;
	for(int x:v[z]){
		if(vis[x] != 0 && lvl[x] != lvl[z] + 1){
			if(col[x] == col[z]){
				ret = 0;
			}
			continue;
		}
		lvl[x] = lvl[z] + 1;
		int tmp = 0;
		rep(i,1,4){
			if(i == col[z]) continue;
			col[x] = i;
			tmp += dfs(x);
			col[x] = 0;
		}
		ret *= tmp;
	}
	return ret;
}

void solve(){
	int n,m;
	cin >> n >> m;
	rep(i,0,m){
		int a,b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}

	rep(i,1,n+1){
		if(vis[i]) continue;
		col[i] = 1;
		lvl[i] = 1;
		ans *= 3 * dfs(i);
	}

	cout << ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	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 <bits/stdc++.h>
using namespace std;
const int md = 998244353;
int n, m, i, j, r;
char s[505][505], c[1010];
void solve() {
    scanf("%d%d", &n, &m);
    for (i = 0; i < n; i++) {
        scanf("%s", s[i]);
        for (j = 0; j < m; j++) if (s[i][j] != '.') {
                if (c[i + j] != 0 && c[i + j] != s[i][j]) { puts("0"); return ;}
                c[i + j] = s[i][j];
            }
    }
    for (r = 1, i = 0; i <= n + m - 2; i++) if (c[i] == 0) r = (r * 2) % md;
    printf("%d\n", r);
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxn = 500+10;
const int mod = 998244353;

ll powmod(ll a, ll b) {
	ll ret = 1;
	while(b) {
		if(b&1ll) ret*=a, ret%=mod;
		a*=a; a%=mod; b>>=1;
	}
	return ret;
}

map<char, int> diag[2*mxn];

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

	int n, m; cin>>n>>m;
	for(int i=0; i<n; i++) for(int j=0; j<m; j++) {
		char c; cin>>c; diag[i+j][c]++;
	}

	ll ans = 1;
	for(int i=0; i<n+m-1; i++) {
		if(diag[i].count('R') and diag[i].count('B')) {
			ans = 0; break;
		}
		if(diag[i].count('R') or diag[i].count('B')) continue;
		ans*=2; ans%=mod;
 	}

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


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

int main() {
    int N;
    string T;
    cin >> N >> T;
    auto solve = [&]() -> long long {
        long long V = 10000000000LL;
        if (T == "0") return V;
        else if (T == "1") return V * 2;

        if (T.size() >= 1 && T.substr(0, 1) == "0") T = T.substr(1), --V;
        else if (T.size() >= 2 && T.substr(0, 2) == "10") T = T.substr(2), --V;
        if (T.size() % 3 == 1) {
            if (T.substr(T.size()-1) != "1") return 0;
            T = T.substr(0, T.size()-1);
            --V;
        }
        else if (T.size() % 3 == 2) {
            if (T.substr(T.size()-2) != "11") return 0;
            T = T.substr(0, T.size()-2);
            --V;
        }
        for (int i = 0; i < T.size(); i += 3) if (T.substr(i, 3) != "110") return 0;
        return V - T.size()/3 + 1;
    };
    cout << solve() << endl;
}

#include<cstdio>

int main(){
    unsigned N;
    scanf("%u\n", &N);
    bool T[N];
    char tmp;
    for (unsigned i = 0; i < N; i++){
        scanf("%c", &tmp);
        T[i] = tmp == '1';
    }
    unsigned long long answer = 0;
    bool flag = true;
    for (unsigned i = 0; i < N; i++){
        if(T[i] ^ (i%3 != 2)){
            flag = false;
            break;
        }
    }
    if(flag) answer += 10000000000 - (N-1)/3;
    flag = true;
    for (unsigned i = 0; i < N; i++){
        if(T[i] ^ (i%3 != 1)){
            flag = false;
            break;
        }
    }
    if(flag) answer += 10000000000 - N/3;
    flag = true;
    for (unsigned i = 0; i < N; i++){
        if(T[i] ^ (i%3 != 0)){
            flag = false;
            break;
        }
    }
    if(flag) answer += 10000000000 - (N+1)/3;
    printf("%llu\n", answer);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll M=1e9+7;
void cal(vector<ll>&v){
	v[0]=1;
	ll b=2;
	for(ll i=1;i<=4000000;i++){
		v[i]=b*v[i-1];
		v[i]%=M;
	}
	return ;
}

int main(){
	io;
	ll n,m;
	cin>>n>>m;
	string s[n];
	for(ll i=0;i<n;i++)cin>>s[i];
	ll tot=0;
	vector<vector<ll> >left(n,vector<ll>(m,0)),right(n,vector<ll>(m,0)),up(n,vector<ll>(m,0)),down(n,vector<ll>(m,0));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(s[i][j]=='.')tot++;
			if(s[i][j]=='#')continue;
			if(j-1>=0)left[i][j]=1+left[i][j-1];
			else left[i][j]=1;
			if(i-1>=0)up[i][j]=1+up[i-1][j];
			else up[i][j]=1;
		}
	}

	for(ll i=n-1;i>=0;i--){
		for(ll j=m-1;j>=0;j--){
			if(s[i][j]=='#')continue;
			if(j+1<m)right[i][j]=1+right[i][j+1];
			else right[i][j]=1;
			if(i+1<n)down[i][j]=1+down[i+1][j];
			else down[i][j]=1;
		}
	}

	vector<ll>v(4000004);
	cal(v);

	ll ans=0;
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(s[i][j]=='#')continue;
			ll ilum=left[i][j]+right[i][j]+up[i][j]+down[i][j]-3;
			ll val=(v[ilum]-(ll)1);
			ll rem=tot-ilum;
			val*=(v[rem]);
		//	cout<<ilum<<" "<<rem<<" "<<tot<<endl;
			val%=M;
			ans+=val;
			ans%=M;
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO

	int n;
	cin >> n;

	map <string, bool> mp;
	map <string, bool> mp_r;
	for(int i = 0; i < n; i ++)
	{
		string s;
		cin >> s;

		if(s[0] == '!')
		{
			s.erase(0, 1);
			mp_r[s] = true;
		}
		else
			mp[s] = true;
		if(mp[s] == true && mp_r[s] == true)
		{
			cout << s << endl;
			return 0;
		}
	}

	cout << "satisfiable" << endl;
}

/*

	CODE TEMPLATE APRATIM

*/

#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define veci vector<ll>
#define it map<string, vv>::iterator
#define MOD 1000000007
#define N (ll)3e+5
#define test int T;cin>>T;while(T--)
#define nl "\n"
#define FULL(iii) iii.begin(),iii.end()
#define setbit(_) __builtin_popcount(_)
#define INF 9223372036854775807
#define TOUPR(str) transform(str.begin(), str.end(),str.begin(), ::toupper)
#define TOLWR(str) transform(str.begin(), str.end(),str.begin(), ::tolower)
#define pb push_back
#define len(s) s.length()
#define pb push_back
#define eb emplace_back
#define S second
#define F first
#define len(s) s.length()
#define coutp cout<<setprecision(15)
#define pow(a,b) (ll)(pow(a,b)+0.5)
#define bin(x) stoull(x,0,2)
#define lld long double
#define yy cout<<"Yes"<<nl;
#define nn cout<<"No"<<nl;
map<ll,ll> mapy;
veci mapv;
class Graph
{
	private:
	map<ll,veci>m;
	public:
	void edges(ll source, ll destination)
	{
		m[source].pb(destination);
		m[destination].pb(source);
	}
	vector<ll> BFS(ll s)
	{
		queue<ll> q;
		map<ll,ll>vis;
		veci x;
		vis[s]=1;
		q.push(s);
		while(!q.empty())
		{
			s=q.front();x.pb(s);
			q.pop();
			for(auto node:m[s])
			{
				if(!vis[node])
				vis[node]=1,q.push(node);
			}
		}
		return x;

	}

};
ll powi(ll a,ll b)
{
	if(b==0) return (ll)1;
	if(b==1) return a;
	else if(b%2) return a*powi(a,b-1);
	else return powi(a*a,b/2);
}
ll b(vector<ll>a,ll n)
{
	ll l=0,r=n-1;
	while(l<=r)
	{
		int m = r-(r-l)/2;
		if(a[m]==0)
			l = m+1;
		else{
			if(a[m-1]==0 || m==0) return m;
			else r = m-1;
		}
	}
	return -1;
}

bool prime(ll n)
{
	ll i;
	if(n==0 || n==1) return 0;
		for(i=2;i*i<=n;i++)
		{
			if(n%i==0) return 0;
		}
		return 1;
}
ll nearest_prime(ll n)
{
	ll i;
	for(i=n+1;;i++)
	{
		if(prime(i)){
			if(!prime(i-n)) return i-n;
		}
	}
	return 0;
}

void primeFactors(ll n)
{
	ll i;
	while(n%2==0)
    {
    	mapv.pb(2);
    	n/=2;
    }
    for(i=3;i*i<=n;i=i+2)
    {
    	while (n%i==0)
    	{
    		mapv.pb(i);n/=i;
    	}
    }
    if(n>2)
    mapv.pb(n);
}
// void rev(int a, int b, veci a)
// { int i;
// 	for(i=a;i<b;i++)
// 	{
// 		a[i]=a[b-i-1];
// 	}
// 	for(auto i:a)cout<<i<<" ";
// }
map<string,int> vis;
map<string,vector<string>>stry;
//vector<string> stry[1000];
void dfs(string v)
{
	vis[v]=1;
	//cout<<v<<" ";
	for(auto i:stry[v])
	{
		if(vis[i]==0)
		dfs(i);
	}
}
ll solve(ll dp[][1000], ll a[],ll low,ll high,ll turn)
{
    if (low == high)
        return a[low] * turn;
    if (dp[low][high] != 0)
        return dp[low][high];
    dp[low][high] = max(a[low] * turn + solve(dp, a,
                            low + 1, high, turn + 1),
                        a[high] * turn + solve(dp, a,
                           low, high - 1, turn + 1));

    return dp[low][high];
}
int search(ll n)
{
	ll i;
	string s=to_string(n);
	for(i=0;i<s.size();i++)
	{
		if(s[i]!='0')
		{
			if(n%(s[i]-'0')!=0)
			return 0;
		}
	}return 1;
}
int main() {
	fio;
	//test
	{
		ll n,i;
		cin>>n;
		set<string> s;
		string x;
		vector<string> a;
		for(i=0;i<n;i++) cin>>x,a.pb(x),s.insert(x);

		//for(auto i:s) cout<<i<<" ";

		for(i=0;i<n;i++)
		{
		//	if(a[i][0]!='!')
			{
				string x=a[i];
				a[i]='!'+a[i];
				if(s.find(a[i])!=s.end())
				{
					cout<<x;
					return 0;
				}

			}

		}
		cout<<"satisfiable";
	}
}

/*

4
1 2 4 7

7
1 2 4 8 10 12 6

7
1 2 3 4 5 6 8

*/