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

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

int sx, sy, gx, gy;
ll score;

inline void query(){
    cin >> sx >> sy >> gx >> gy;
}

string get_str(){
    string res = "";
    while(sx < gx) { res += 'D'; ++sx; }
    while(sx > gx) { res += 'U'; --sx; }
    while(sy < gy) { res += 'R'; ++sy; }
    while(sy > gy) { res += 'L'; --sy; }
    return res;
}

inline void output(string s){
    cout << s << endl;
}

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

    for(int i = 0; i < 1000; ++i){
        query();
        output(get_str());
        cin >> score;
    }

    return 0;
}

/*  *Which of the favors of your Lord will you deny ?*  */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define vpnt(ans)                       \
    for (ll i = 0; i < ans.size(); i++) \
        cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x, k) (x |= (1LL << k))
#define clearbit(x, k) (x &= ~(1LL << k)) //x er last theke k-1 tomo ghor
#define checkbit(x, k) (x & (1LL << k))
#define mp make_pair
#define scl(x) scanf("%lld", &x)
#define sci(x) scanf("%d", &x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define pii pair<int, int>
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn cout << "\n";
#define INF (1 << 30)
#define LL_INF (1LL << 32)
#define pll pair<ll, ll>
#define pp(n, p) (ll)(pow(n, p) + 0.5)
#define ok ios::sync_with_stdio(false);
#define fine cin.tie(nullptr);
#define mod 1000000007
#define N 100005

int main()
{
    ll n;
    cin>>n;
    vector<int>a, b;
    map<int,int>m;
    n = (1<<n);
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        a.pb(x);
        m[x] = i+1;
    }
    while(a.size()>2)
    {
        vector<int>t;
        for(int i=0; i<a.size(); i+=2)
        {
            t.pb(max(a[i], a[i+1]));
        }
        a = t;
    }
    int res = min(a[0], a[1]);
    cout<<m[res];nn;
}


#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

// #define int long long
#define int __int128
#define endl "\n"

constexpr int  INF = (int)1e35;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

std::ostream& operator << (std::ostream& os, const __int128& in)
{
    constexpr __int32_t base = 10;
    bool sign = false;
    if(in < 0) sign = true;
    vector<__int32_t> num;

    for(__int128 i = in; i; i /= base){
        num.push_back(i % base);
    }

    if(num.size() == 0) num.push_back(0);

    if(sign) cout<<"-";

    for(__int32_t i = num.size()-1; i >= 0; i--){
        cout<<num[i];
    }

    // cout<<endl;

    return os;
}

std::istream& operator >> (std::istream& is, __int128& out)
{

    char c;
    out = 0;

    while(is.get(c) && isspace(c)) ;

    if(is){
        do out = out * 10 + c - '0';
        while(is.get(c) && !isspace(c));

        if(is) is.unget();
    }

    return is;
}

void extgcd(int a, int b, int &x, int &y){
	if(b == 0){
		x = 1;
		y = 0;
		return ;
	}
	extgcd(b,a%b,y,x);
	y -= a/b * x;
}

int mod_inverse(int a, int m){
	int x, y;
	extgcd(a, m, x, y);
	return (m + x % m ) % m;
}

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

pair<int,int> liner_congruence(const vector<int>& A, const vector<int>& B, const vector<int>& M){

	int x = 0, m = 1;

	for(int i = 0; i < A.size(); i++){
		int a = A[i] * m, b = B[i] - A[i] * x, d = gcd(M[i], a);
		if(b % d != 0) return make_pair(0, -1);
		int t =  b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
		x = x + m * t;
		m *= M[i] / d;
	}

	return make_pair((x%m + m) % m, m);
}

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

	int T;

    cin>>T;

    for(int _ = 0; _ < T; _++){
        int X, Y, P, Q;
        int mini = INF;
        vector<int> A(2), B(2), M(2);

        cin>>X>>Y>>P>>Q;

        M[0] = X * 2 + Y * 2;
        M[1] = P + Q;

        for(int i = 0; i < Y; i++){
            for(int j = 0; j < Q; j++){
                A[0] = 1;
                A[1] = 1;

                B[0] = (X + i);
                B[1] = (P + j);

                pair<int,int> p = liner_congruence(A, B, M);

                if(p.first != 0) {
                    mini = min(mini, p.first);
                }
            }
        }

        if(mini != INF)cout<<mini<<endl;
        else cout<<"infinity"<<endl;
    }

	return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];

    using T = tuple<double, int, int>;
    vector<T> es;
    for(int i=0; i<N; i++) for(int j=0; j<i; j++) es.emplace_back(hypot(X[i]-X[j], Y[i]-Y[j]), i, j);
    for(int i=0; i<N; i++){
        es.emplace_back(100-Y[i], i, N);
        es.emplace_back(Y[i]+100, i, N+1);
    }
    sort(es.begin(), es.end());

    UnionFind uf(N+2);
    for(auto& [d, a, b] : es){
        uf.unite(a, b);
        if(uf.same(N, N+1)){
            cout << fixed << setprecision(10) << d/2 << endl;
            return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;

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

    int a[4];
    int sum=0;
    rep(i,4){
        cin>>a[i];
        sum+=a[i];
    }
    for(int bit=0;bit<(1<<4);bit++){
        int s=0;
        rep(i,4){
            if(bit&(1<<i))s+=a[i];
        }
        if(s*2==sum){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

}


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

int main(){
  int x,b;
  cin >> x;
  if(x%100==0){
  b =100;
  }
  else{
  for(int i=0;i<1001;i++){
   if(0<i*100-x && i*100-x < 100){
    b=i*100-x;
   break;
   }
  }
  }
  cout << b << endl;
  return 0;
}

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X;
    cin >> X;
    cout << 100 - X % 100 << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <cassert>

#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)

using ll = long long;
using ld = long double;

#define RATIO (10000ll)
#define OFFSET (100000000000ll)

ll toLL(std::string &s) {
    int n = s.size(), zeros = 0;
    ll ans = 0;
    bool foundDot = false;
    for (int i=0; i<n || zeros > 0; i++, zeros = std::max(0, zeros-1)) {
        if (i < n) {
            if (s[i] != '.') {
                ans = ans * 10 + (s[i] - '0');
            }
            if (s[i] == '.' || (!foundDot && i == n-1)) {
                zeros = 5;
                foundDot = true;
            }
        } else {
            ans *= 10;
        }
    }
    return ans;
}

ll ceil(ll x) {
    return (x + RATIO - 1) / RATIO * RATIO;
}

int main() {
    std::string xs, ys, rs;
    std::cin >> xs >> ys >> rs;
    const ll x = toLL(xs) + OFFSET, y = toLL(ys) + OFFSET, r = toLL(rs);
    std::cerr << x << ' ' << y << ' ' << r << std::endl;

    ll ans = 0;
    for (ll i=ceil(x - r); i <= x + r; i += RATIO) {
        const ll dd = r * r - (i - x) * (i - x);

        ll left = y, right = y + r + 1;
        while (right - left > 1) {
            ll mid = (left + right) / 2;
            if ((mid - y) * (mid - y) <= dd) {
                left = mid;
            } else {
                right = mid;
            }
        }
        ll max = left;

        left = y - r - 1, right = y;
        while (right - left > 1) {
            ll mid = (left + right + 1) / 2;
            if ((mid - y) * (mid - y) <= dd) {
                right = mid;
            } else {
                left = mid;
            }
        }
        ll min = right;

        ans += max / RATIO - (min - 1) / RATIO;
    }
    std::cout << ans << '\n';
    return 0;
}

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

int main(){
  int a,b,w;
  cin >> a >> b >> w;
  int m=1e9,M=0;
  for(int n=1;n<=1000000;n++){
    if(a*n<=1000*w && 1000*w<=b*n){
      m=min(m,n);
      M=max(M,n);
    }
  }
  if(M==0)cout << "UNSATISFIABLE";
  else cout << m << ' ' << M;
}


// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const ll nax = 200002;
const ll p = 1e9 + 7;

ll dp[nax][2];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<ll> mn(n + 2, INT_MAX), mx(n + 2, INT_MIN);
	for (int i = 0; i < n; ++i) {
		ll x, c;
		cin >> x >> c;
		mn[c] = min(mn[c], x);
		mx[c] = max(mx[c], x);
	}
	mn[n + 1] = mx[n + 1] = 0;
	mn[0] = mx[0] = 0;

	for (int i = 1; i <= n + 1; ++i) {
		if (mn[i] == INT_MAX) {
			dp[i][0] = dp[i - 1][0];
			dp[i][1] = dp[i - 1][1];
			mn[i] = mn[i - 1];
			mx[i] = mx[i - 1];
			continue;
		}
		dp[i][0] = mx[i] - mn[i] + min(abs(mx[i] - mx[i - 1]) + dp[i - 1][1],
									 abs(mx[i] - mn[i - 1]) + dp[i - 1][0]);
		dp[i][1] = mx[i] - mn[i] + min(abs(mn[i] - mx[i - 1]) + dp[i - 1][1],
									 abs(mn[i] - mn[i - 1]) + dp[i - 1][0]);
	}
	cout << dp[n + 1][0];
}


#include<bits/stdc++.h>
using namespace std;
#define io cin.tie(0);ios::sync_with_stdio(false);
#define debug(x) cout<<#x<<"="<<x<<endl
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define mk make_pair
#define ll long long
#define lb long double
#define rs p<<1|1
#define ls p<<1
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline ll read(){
    ll p=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){p=(p<<1)+(p<<3)+(c^48),c=getchar();}
    return f*p;
}

void solve(){
    io;
    lb x, y, R;
    cin >> x >> y >> R;
    R += 1e-14;
    ll ans = 0;
    for(int i = ceil(x - R); i <= floor(x + R); i ++){ //左边界向上取整，有边界向下取整
        lb t, b;
        t = y + sqrt(R * R - (x - i) * (x - i));
        b = y - sqrt(R * R - (x - i) * (x - i));
        ans += floor(t) - ceil(b) + 1; //上边界向下取整，下边界向上取整
    }
    cout << ans << endl;
}

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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll B = 10000;
const ll inf = B * (2e5 + 30);

ll get(string s) {
	auto it = find(all(s), '.');
	ll res = stoi(string(begin(s), it));
	res *= B;
	if (it != end(s)) {
		++it;
		while (distance(it, end(s)) != 4) s.push_back('0');
		res += stoi(string(it, end(s)));
	}
	return res;
}

bool f(ll a, ll b) {
	return a * a <= b;
}

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

	string _a, _b, _r; cin >> _a >> _b >> _r;

	auto a = get(_a);
	auto b = get(_b);
	auto r = get(_r);

	ll ans = 0;
	for (ll x = -inf; x <= inf; x += B) {
		ll d = r * r - (x - a) * (x - a);
		if (d < 0) continue;
		ll l = 0, r = sqrt(d) + 100;
		while (r - l > 1) {
			ll m = l + (r - l) / 2;
			(f(m, d) ? l : r)  = m;
		}
		assert(f(l, d) && !f(r, d));
		ll L = b - l;
		ll R = b + l;
		L += inf;
		R += inf;
		assert(L > 0 && R > 0);
		ans += R / B - (L - 1) / B;
	}

	cout << ans;
}


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

typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) {cout << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) {const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
/*----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

void solve() {
	int n, x; cin >> n >> x;
	string s; cin >> s;
	for (char c : s) {
		if (c == 'x') x = max(x-1, 0);
		else ++x;
	}
	cout << x << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

ll inf = 1e18;
ll p = 998244353 ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,  y, x,  z, g, key,   h, n, m, t, a, b, c, j, k, d;
    ll t2, t3, t4, t1, t5, t6;
    string s, s2;
    ll l, r;
    //cin >> t;
    t = 1;
    while (t--)
    {
        cin >> n >> x;
        cin >> s;
        ll ans = x;
        for (i = 0; i < n; i++)
        {
            if (s[i] == 'o')
                ans++;
            else
            {
                if (ans > 0)
                    ans--;
            }
        }
        cout << ans;

    }

    return 0;
}


/*   --------------------
    |       LOSER        |
    |     ~NOOBOSS~      |
     --------------------
*/
#include <bits/stdc++.h>
using namespace std;
#define      mxx                 LLONG_MAX
#define      mnn                 LLONG_MIN
#define      Y()                 cout<< "YES" <<endl
#define      N()                 cout << "NO"<<endl
#define      endl                "\n"
#define      Ceil(x,y)           ((x+y-1)/y)
#define      sz(s)               (int)s.size()
#define      angle(x)            double(x * acos(-1) / 180.0)
#define      max_3(a,b,c)        max(a, max(b,c))
#define      min_3(a,b,c)        min(a, min(b,c))
#define      gcd(a,b)            __gcd(a,b)
#define      lcm(a,b)           (a*b)/gcd(a,b)
#define      loser               return 0
#define      ll                  long long
#define      PI                  acos(-1)
#define      mem(a,v)            memset(a,v,sizeof(a))
#define      all(v)              v.begin(),v.end()
#define      SORT(v)             sort(v.begin(),v.end())
#define      SRV(v)              sort(v.rbegin(),v.rend())
#define      REV(v)              reverse(v.begin(),v.end())
#define      B                   begin()
#define      E                   end()
#define      V                   vector
#define      F                   first
#define      S                   second
#define      PSB                 push_back
#define      MP                  make_pair
#define      flash               cout.flush()
#define      InTheNameOfGod      ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
constexpr ll MOD = 998244353;
constexpr ll mod = 1e9  + 7;
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
/*-----*/
#define bug1(a)  cerr<<a<<endl;
#define bug2(a,b)  cerr<<a<<" "<<b<<endl;
#define bug3(a,b,c)  cerr<<a<<" "<<b<<" "<<c<<endl;
/*----*/
const ll N=3e5+5;
vector<ll> adj[N];
ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}}
ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;}
ll nsum(ll num){return (num*(num+1))/2;}
void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);}
/*------------------START---------------------*/

/*-----*/
void solve(){
   ll n,m;
   string s;
   cin>>n>>m;
   if(m==0){
    ll bal=1;
    for(ll i=0;i<n;i++){
        cout<<bal<<' '<<bal+1<<endl;
        bal+=2;
    }
    return;
   }
   ll bal=abs(m);
   if((abs(n-m)<=1) || m<0){
    cout<<"-1";
    return;
   }
   ll k=2;
   if(m>0){
      cout<<"1"<<' '<<1000000000<<endl;
      for(ll i=0;i<m;i++){
        cout<<k<<' '<<k+1<<endl;
        k+=2;
      }
      n-=m+1;
      ll l=1000000,r=100000000;
      //cout<<k<<' '<<1000000<<endl;
     // k=1000000;
      //n--;
      for(ll i=0;i<n;i++){
        cout<<l<<' '<<r<<endl;
        r++; l++;
      }

   }

}
/*-----*/
int main(){
   InTheNameOfGod

   ll Test=1;
   //cin>>Test;
   while(Test--){
     solve();
    }
  loser;
}
///////   C O D I N G  I S  L I F E   ///////


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

int main(){

    int N, A, B;
    cin >> N >> A >> B;

    cout << N-A+B << endl;

    return 0;
}

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

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); // __VA_ARGS__可変引数マクロ
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest& ...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w;
// output
template<typename T>void MACRO_OUT(const T t) { std::cout << t; }
template<typename First, typename...Rest>void MACRO_OUT(const First first, const Rest...rest) { std::cout << first << " "; MACRO_OUT(rest...); }
#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist); // std::fixed 浮動小数点の書式 / setprecision 浮動小数点数を出力する精度を設定する。
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(w, a, n) for(int w=(a);w<(n);++w)
#define REP(w, n) for(int w=0;w<int(n);++w)
#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
template<class T> using V = std::vector<T>;
template<class T> using VV = V<V<T>>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = (1 << 30) - 1;                    // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double eps = 1e-7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
template<class T, size_t N> void FILL(T(&a)[N], const T & val) { for (auto& x : a) x = val; }   //  int a[5] = {1,2,3,4,5};	FILL(a,10);
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T & val) { for (auto& b : a) FILL(b, val); }  // ２次元配列でもそのまま使える
template<class T> void FILL(std::vector<T> & a, const T & val) { for (auto& x : a) x = val; }   //	使い方 vector<int> a(3);	FILL(a,10);
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>> & a, const T & val) { for (auto& b : a) FILL(b, val); }  // ２次元配列でもそのまま使える
// ------------>8------------------------------------->8------------

int main() {
INIT;

VAR(int,n,a,b)
OUT(n-a+b)

return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")

#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back

typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};

using Mint = ModInt<998244353>;

int main() {
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif

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

    int n;
    cin >> n;

    vi v(n);

    for(auto &x : v) cin >> x;

    Mint ans = 0;
    vector< Mint > sp(n + 1);

    sort(all(v));
    for(int i = n-1; ~i; --i) {
        sp[i] = sp[i+1] + sp[i+1] + v[i];
        ans += sp[i+1] * v[i];
        ans += Mint(v[i]) * v[i];
    }

    cout << ans << '\n';

    #ifdef BLAT
        cerr << "\n\nConsumed " << clock() / (double)CLOCKS_PER_SEC << '\n';
    #endif
    return 0;
}

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 998244353
#define inf 1e9
#define f first
#define s second
#define pa pair<ll,ll>
ll arr[sz],brr[sz];
long long binpow(long long a, long long b) {
    a %= mod;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
int main()
{
 /// ios_base::sync_with_stdio(0);cin.tie(0);
 int test_case=1;
 //scanf("%d",&test_case);

 for(int cs=1;cs<=test_case;cs++)
 {
   ll n;
   scanf("%lld",&n);
   for(int i=1;i<=n;i++)
   {
    scanf("%lld",&arr[i]);
   }
   brr[0]=1;
   for(int i=1;i<=n;i++)
    brr[i]=(brr[i-1]*2)%mod;
  ll ans=0,sum=0;
  sort(arr+1,arr+n+1);
  for(int i=1;i<=n;i++)
  {
    ans=(ans+(arr[i]*arr[i])%mod)%mod;
    if(i>1)
      sum=(sum+(brr[i-2]*arr[i])%mod)%mod;
  }
 // printf("%lld\n",sum);
  ll a1=binpow(2,mod-2);
  for(int i=1;i<n;i++)
  {
    ans=(ans+(sum*arr[i])%mod)%mod;
    sum=(sum-arr[i+1]+mod)%mod;
    sum=(sum*a1)%mod;
  }
  printf("%lld\n",ans);
 }
  return 0;
  }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
const int M=2e5+10;
const int inf=1<<30;
const ll mod=1e9+7;
const int bit=32;
const double pi=acos(-1.0);
double dp[M];
int main(){
	int n;
	scanf("%d",&n);
	dp[n]=0;
	for(int i=n-1;i>=1;i--){
		dp[i]=dp[i+1]+1.0*n/(n-i);
	}
	printf("%.10lf\n",dp[1]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	string s;
	cin >> s;
	string t = "ZONe";
	int ans = 0;
	for(int i = 0; i<9; i++){
		if(s.substr(i,4)==t)ans++;
	}
	cout << ans << "\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define ll long long
#define rll register long long
const int N=4e5+10;
int a[N],pos[N];
map<int,int> cnt;
int main(){
	rint n;
	scanf("%d",&n);n<<=1;
	for(rint i=1;i<=n;i++)
		scanf("%d",&a[i]),cnt[a[i]]++;
	rint s=0;
	for(auto &v:cnt){
		v.second+=s;
		s=v.second;
	}
	for(rint i=1;i<=n;i++)
		pos[i]=cnt[a[i]]--;
	rint now=0;
	for(rint i=1;i<=n;i++){
		if(pos[i]<=n/2){
			if(now>=0)putchar('(');
			else putchar(')');
			now++;
		}else {
			if(now<=0)putchar('(');
			else putchar(')');
			now--;
		}
	}
	return 0;
}

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

using namespace std;

const int MAXN=400005;
const ll mod=998244353;

ll n,tag[MAXN];
pair<ll,ll> p[MAXN];

int main(){
	scanf("%lld",&n);
	for(ll i=1;i<=2*n;i++){
		scanf("%lld",&p[i].first);
		p[i].second=i;
	}
	sort(p+1,p+2*n+1);
	for(ll i=n+1;i<=2*n;i++){
		tag[p[i].second]=1;
	}
	ll cntl=0,cntr=0;
	for(ll i=1;i<=2*n;i++){
		if(tag[i]==0){
			if(cntl==0&&cntr==0){
				cntl++;
				printf("(");
			}
			else if(cntl>0&&cntr==0){
				cntl++;
				printf("(");
			}
			else if(cntl==0&&cntr>0){
				cntr--;
				printf(")");
			}
		}
		else if(tag[i]==1){
			if(cntl==0&&cntr==0){
				cntr++;
				printf("(");
			}
			else if(cntl>0&&cntr==0){
				cntl--;
				printf(")");
			}
			else if(cntl==0&&cntr>0){
				cntr++;
				printf("(");
			}
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <cstring>
#include <bits/stdc++.h>
#define IOS ios:: sync_with_stdio(false), cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<int>
#define vll vector<ll>
#define sll set<ll>
#define vvll vector<vll>
#define vpll vector<pll>
#define vpii vector<pii>
#define all(V)  V.begin(),V.end()
#define allr(A) V.rbegin(),V.rend()
#define ff first
#define ss second
#define forz(i,n) for(int i=0;i<n;i++)
#define fora(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007

using namespace std;

vector < ll > fib(100,0);

void precalculate(){
	fib[0] = fib[1] = 1;
	fora(i,2,90){
		fib[i] = fib[i-1] + fib[i-2];
		//cout<<" i:"<<i<<" fib:"<<fib[i]<<" ";
	}
	//fib[87]>10^18
}
int main()
{
	IOS
	ll N,n,i=86,imx = 0;
	cin>>N;
	vector < int > v,ind;
	n = N;
	if(n==1){cout<<"1\n1\n";return 0;}
	else if(n==2){cout<<"2\n1\n1\n";return 0;}
	precalculate();
	/*v.pb(1);
	v.pb(2);
	while(n && i>=0){
		if(n>=fib[i]){n-=fib[i];ind.pb(i);imx = max(imx,i);i-=2;cout<<"check n:"<<n<<" i:"<<i<<endl;}
		else i--;
		//cout<<" n:"<<n<<endl;
	}
	int total = imx + ind.size(),j=0;
	cout<<total<<"\n1\n2\n";
	for( int i = 0; i<=imx; i++){
		if(j<ind.size() && imx-i==ind[j])cout<<(ind[j]%2?"2\n":"1\n");
		if(imax%2)cout<<(i%2?"3\n":"4\n");
		else if(imax%2==0)cout<<(i%2?"4\n":"3\n");
	}*/
	int f[100] = {}, maxi = 0;
	for (int i = 88; i >= 0; i--) {
		if (N >= fib[i]) {
			f[i] = 1;
			N -= fib[i];
			if (maxi == 0) maxi = i;
		}
	}
	vector<int> ans;

	for (int i = maxi; i >= 1; i--) {
		if (f[i]) ans.pb(1 + (i % 2));
		ans.pb(4 - (i % 2));
	}
	cout<<ans.size()<<endl;
	for(auto q:ans)cout<<q<<" ";
	cout<<endl;

return 0;
}

#include<bits/stdc++.h>

using namespace std;
using   ll = long long;
using   ld = long double;

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

#define pb                  push_back
#define mp                  make_pair
#define F                   first
#define S                   second
#define pll                 pair<int , int>
#define int                 long long int
#define endl                "\n"

#define ALL(v)              v.begin(),v.end()
#define ALLR(v)             v.rbegin(),v.rend()
#define pii                 3.14159265358979323
#define inf                 LLONG_MAX
#define ones(x)             __builtin_popcount(x)
#define fill(a,b)           memset(a,b,sizeof(a))
#define mod                 1000000007
#define hell                998244353

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

ll mod_inverse(int a , int m)
{
        return mod_pow(a , m - 2 , m);
}

void solve()
{
        ll n;
        cin >> n;
        ll ans = 0;
        for(ll i=1;i<=1e6;i++)
        {
                ll len = to_string(i).length();
                ll j = i + i*pow(10,len);
                if(j <= n)
                        ans++;
                else
                        break;
        }
        cout << ans;
}

signed main() {
        fast;

        int t = 1;

        //cin >> t;

        int cur = 1;

        while(t--) {
                // cout << "Case #" << cur++ << ": ";
                solve();
        }

        return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define w(x)            int x; cin>>x; while(x--)
#define mii             map<int,int>
#define endl            ("\n")
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define pii             pair<int,int>
#define f(i, a, n)      for(int i=a; i<n; i++)
#define fd(i, a, n, d)  for(int i=a; i<n; i+=d)
#define in(a,n)         f(i,0,n){cin>>a[i];}
#define pb              push_back
#define yy              cout<<"YES\n"
#define nn              cout<<"NO\n"
#define kk              cout<<"-1\n"
#define inf             (long long)1e18
#define mod             1000000007LL
#define cc(r)           cout<<r<<" "
#define ce(r)           cout<<r<<endl
#define out(a,n)        f(i,0,n){cc(a[i]);}

//No use
void inout()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
//No use
void ovector_n() {
    ce(1);
}

int32_t main()
{
    inout();
    int T = clock();
    int n, k, a, b;
    cin >> n >> k;
    mii m;
    int tb = k;
    f(i, 0, n) {
        cin >> a >> b;
        m[a] += b;

    }
    for (auto it : m) {
        //cc(a);
        //ce(b);
        a = it.ff;
        b = it.ss;
        if (tb < a)
            break;

        tb += b;
    }

    ce(tb);

}

#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000  //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265358979323846

using namespace std;

signed main() {
    int n, k;
    cin >> n >> k;
    vector<int> A(n);
    vector<int> B(n);
    vector<pair<int, int>> S(n);
    REP(i, n) {
        cin >> S[i].first;
        cin >> S[i].second;
    }

    sort(ALL(S));

    int ns = 0;

    for (int i = 0; i < n; i++) {
        if (k - S[i].first >= 0) {  //友達の島までつくか
            k += S[i].second;

        } else {
            ns += k;
            goto end;
        }
    }

    if (k > 0) {
        ns += k;
    }

end:
    cout << ns << endl;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
int main() {
	int n, m;
	cin >> n >> m;
	if(n > m) {
		for(int i = 1; i <= n; ++i) {
			cout << i << " ";
		}
		for(int i = 1; i <= m - 1; ++i) {
			cout << -i << " ";
		}
		cout << -1ll * (1 + n) * n / 2ll  + 1ll * m * (m - 1) / 2ll << endl;
	}
	else {
		for(int i = 1; i <= m; ++i) {
			cout << -i << " ";
		}
		for(int i = 1; i <= n - 1; ++i) {
			cout << i << " ";
		}
		cout << -1ll * ( n - 1) * n / 2ll  + 1ll * m * (m + 1) / 2ll << endl;

	}
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
// constexpr i32 mod   = 998244353;

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int h, w;
  cin >> h >> w;

  vector< string > as(h);
  cin >> as;

  auto dp = make_vector(h, w, -inf);
  function<int(int, int, int)> f = [&](int y, int x, int s) {
    if (y == h - 1 and x == w - 1) return 0;

    int &res = dp[y][x];
    if (res != -inf) return res;

    if (y + 1 < h) {
      int d = (as[y + 1][x] == '+' ? 1 : -1);
      chmax(res, -f(y + 1, x, -(s + d)) + d);
    }

    if (x + 1 < w) {
      int d = (as[y][x + 1] == '+' ? 1 : -1);
      chmax(res, -f(y, x + 1, -(s + d)) + d);
    }
    return res;
  };

  int r = f(0, 0, 0);
  if (r == 0) cout << "Draw" << endl;
  else if (r > 0) cout << "Takahashi" << endl;
  else cout << "Aoki" << endl;
}

signed main() {
  solve();
}


#include <iostream>
using namespace std;

int main()
{
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  int ans = 0;
  int x = 0;
  for (int i = 0; i < n; i++) {
    int c = s[i] - '0' + (t[i] - '0') * 2;
    switch (c) {
    case 0:   x != 0 && ans++; break;
    case 1: ++x <= 0 && ans++; break;
    case 2: --x >= 0 && ans++; break;
    }
  }
  cout << (x == 0 ? ans : -1) << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    vector<ll> a, b;
    rep(i,n){
        if(s[i]=='0')a.emplace_back(i);
        if(t[i]=='0')b.emplace_back(i);
    }
    if(a.size() != b.size()){
        cout << -1 << endl;
    }else{
        ll ans = 0;
        rep(i,a.size()){
            if(a[i]!=b[i]) ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


/*
“The only way that we can live is if we grow.
 The only way we can grow is if we change.
The only way we can change is if we learn.
 The only way we can learn is if we are exposed.
 And the only way that we are exposed is if we throw ourselves into the open.”
 ***************************************   ************************   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

//---------------------mishra ka idea------------------
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)     (int)(x).size()
#define ull       unsigned long long
//------------------------mishra ka idea-------------------

//-------------------------alsi hu mai-----------------------
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
#define Output(x) cout << (x ? "Yes" : "No")<<endl;
//-------------------------alsi hu mai-----------------------

//--------------------het se uthaya---------------------
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)

template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}

//--------------------het se uthaya-------------------------------------------------------------------

int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }
int rint(int  l , int r){return rand()%(r-l+1) + l ;}

//---------------------------aab code dekho bahut template dekh liya---------------------------------

signed main()
{
   //freopen("input.txt", "r", stdin);
   //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x;
    int n , m ;
    cin>>n>>m;
    int grid[n+1][m+1];
    string s;
    fo(i,0,n){
      cin>>s;
      fo(j,0,m){
        if(s[j]=='.'){
          grid[i][j]=0;
        }
        else{
          grid[i][j]=1;
        }
       // cout<<grid[i][j]<<" ";
      }
      //cout<<endl;
    }
    int ans=0;
    fo(i,0,n){
      fo(j,0,m-1){
        if(grid[i][j]==0 && grid[i][j+1]==0)ans++;
      }
    }
    fo(i,0,m){
      fo(j,0,n-1){
        if(grid[j][i]==0 && grid[j+1][i]==0){
          //cout<<i<<j<<" ";
         ans++;
        }
      }
    }
    cout<<ans<<endl;

    return 0;
}

//----------------abc tez kar liya iska matlab ye nahi tum legend ho kya pata hagdo aage ------------------

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int H, W;
	cin >> H >> W;
	vector<string> vec(H);
	for (int i = 0; i < H; i++) {
		cin >> vec.at(i);
	}
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W - 1; j++) {
			string str = vec.at(i);
			if (str[j] == '.' && str[j + 1] == '.') ans++;
		}
	}
	for (int i = 0; i < H - 1; i++) {
		for (int j = 0; j < W; j++) {
			string str1 = vec.at(i);
			string str2 = vec.at(i + 1);
			if (str1[j] == '.' && str2[j] == '.') ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline long IN(void)
{
  long x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int main(void)
{
  int sz=0;long N=IN(),temp[5000],keep;
  for(long i=0;i*i<(long)N;i++){if(N%(i+1)==0){OUT(i+1);keep=i+1;if(i+1<N/(i+1)){temp[sz++]=N/(i+1);}}}
  rep(i,sz-1){if(keep==temp[sz-1-i]){continue;}OUT(temp[sz-1-i]);}
  if(N!=1){OUT(N);}
}

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

typedef long long int lli;

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

    int n;
    cin >> n;
    int ans = n%2;
    if(ans==1)
        cout << "Black" << endl;
    else
        cout << "White" << endl;
}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#define ll long long
#define rep(i,n) for(int i = 0;i < (int)n;i ++)
using namespace std;
int main(void){
  ll n;
  cin >> n;
  n = (n*108/100);
  if(n < 206){
    cout << "Yay!" << endl;
  }else if(n == 206){
    cout << "so-so" << endl;
  }else{
    cout << ":(" << endl;
  }
  return 0;
}

/*       In The Name Of ALLAH
        Author:- Ibrahim adnan Tanim     */

#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {

optimize();
    int n;
    cin>>n;
    n=n+(n*.08);
    if(n<206)
        cout<<"Yay!";
    else if(n>206)
        cout<<":(";
    else
        cout<<"so-so";

    return 0;
}


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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
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;}
ll gcd(ll a, ll b){ return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){ return a/gcd(a,b)*b;}
//----------------------------------------------------------------------------

int main(void) {
    ll n;
    cin >> n;
    vector<double> h(n+1);
    h[1] = 1.0;
    REP(i,1,n){
        h[i+1] = h[i] + 1.0/double(i+1);
    }

    prtd(10,double(n)*(h[n])-1.0);
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1<<24;
const ll INFL = (1ll << 60);
//cout << setprecision(20) <<

int n;
int coord[17][3];
int dp[1 << 17][17];

int rec(int S, int v) {
    if (dp[S][v] >= 0) {
        return dp[S][v];
    }

    if (S == (1 << n) - 1 && v == 0) {
        return dp[S][v] = 0;
    }

    int res = INF;
    for (int u = 0; u < n; u++) {
        if (!(S >> u & 1)) {
            int a, b, c, p, q, r;
            a = coord[v][0];
            b = coord[v][1];
            c = coord[v][2];
            p = coord[u][0];
            q = coord[u][1];
            r = coord[u][2];
            int dist = abs(a - p) + abs(b - q) + max(r - c, (int)0);
            res = min(res, rec(S | 1 << u, u) + dist);
        }
    }
    return dp[S][v] = res;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        ll x, y, z; cin >> x >> y >> z;
        coord[i][0] = x;
        coord[i][1] = y;
        coord[i][2] = z;
    }
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 0) << endl;
}


#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 100 + 5 ;
const int M = 1e5 + 5 ;
struct E {
	int to, next ;
} e[M] ;
int n, cnt, head[N], vis[N], D[N] ;
char s[N] ;
void add( int x, int y ) {
	e[++ cnt] = (E){ y, head[x] }, head[x] = cnt;
}
void dfs(int x) {
	if( vis[x] ) return ;
	vis[x] = 1 ;
	Next( i, x ) {
		int v = e[i].to ;
		dfs(v) ;
	}
}
signed main()
{
	n = gi() ;
	rep( i, 1, n ) {
		scanf("%s", s + 1 ) ;
		rep( j, 1, n ) if(s[j] == '1') add(i, j) ;
	}
	rep( i, 1, n ) {
		rep( j, 1, n ) vis[j] = 0 ;
		dfs(i) ;
		rep( j, 1, n ) D[j] = D[j] + vis[j] ;
	}
	long double ans = 0 ;
	rep( i, 1, n ) ans = (ans + 1.0 / (1.0 * D[i])) ;
	printf("%.12Lf\n", ans ) ;
	return 0 ;
}

#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{
  ll n, i, m, x, y, j, k, mn = INT_MAX, ans = 0;
  cin >> n >> m;
  ll a[m + 3];
  a[0] = 0;
  for (i = 1; i <= m; i++)
  {
    cin >> a[i];
  }
  a[m + 1] = n + 1;
  vector<ll>v;
  sort(a, a + m + 2);
  for (i = 1; i <= m + 1; i++)
  {
    x = a[i] - a[i-1] - 1;
    if(x!=0)
    {
      v.pb(x);
    }
  }
  sort(all(v));
  if(v.size()==0)
  {
    cout<<"0"<<endl;
    return 0;
  }
  mn=v[0];
  //cout<<mn<<endl;
  for (i = 0; i < v.size(); i++)
  {
    ans += ceil(double((v[i]*1.00) / mn));

  }
  cout << ans << endl;

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m;
map<ll,ll> p;
ll dfs(ll x,ll c)
{
	if(p.find(x)!=p.end())return p[x];
	if(x<=c)return c-x;
	p[x]=x-c;
	if(x&1)p[x]=min(p[x],min(dfs(x-1,c),dfs(x+1,c))+1);
	else p[x]=min(p[x],dfs(x/2,c)+1);
	return p[x];
}
int main()
{
	cin>>n>>m;
	cout<<dfs(m,n);
}

//@ikung
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define f(i,k) for(int i=0;i<k;i++)
#define F first
#define dbg(x)  cout<<#x<<" "<<x<<endl;
#define S second
#define endl "\n"
#define rep(i,n) for(int i=1;i<=n;i++)
#define rew(i,a,b) for(int i=a;i<=b;i++)
#define mod 1000000007
const int inf = 1e18;
const int N=200005;

int n,X,Y;
map<int, int> m;

int rechx(int y)
{
    if(y==X)
    {
        return 0;
    }
    if(y==1)
    {
        return abs(X - y);
    }
    if(m[y]!=0)
        return m[y];

    if(y%2)
        return m[y]=min({abs(X - y), rechx((y + 1) / 2) + 2, rechx((y - 1) / 2) + 2});
    else
        return m[y]=min({abs(X - y), rechx((y) / 2) + 1});

}

void solve()
{
    int i, j, k;
    cin >> X >> Y;
    if(Y<X)
    {
        cout << X - Y << endl;
        return;
    }
    else
    {
        cout << rechx(Y)<<endl;
    }

    return;
}

signed main()
{
    fast
    int t = 1, i, j, k;
    //cin >> t;
    while (t--)
    {
        solve();
    }
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
}

void sub_sum(set<lli>&v, vector<lli>a, lli n, lli T)
{
  for (lli i = 0; i < pow(2, n); ++i)
  {
    lli s = 0, x = i;
    for (lli j = 0; j < n; ++j)
    {
      if (x % 2 == 1)
        s += a[j];
      x /= 2;
    }
    if (s <= T)
      v.isrt(s);
  }
}

int main()
{
  c_p_c();

  lli T, n;
  cin >> n >> T;
  if (n <= 20)
  {

    vector<lli>a(n);
    for (lli i = 0; i < n; ++i)
      cin >> a[i];

    set<lli>v;
    sub_sum(v, a, n, T);
    cout << *(prev(v.end())) << endl;

  }
  else
  {
    vector<lli>a(20);
    vector<lli>b(n - 20);
    for (lli i = 0; i < 20; ++i)
      cin >> a[i];

    for (lli j = 0; j < (n - 20); ++j)
      cin >> b[j];

    set<lli>v1;
    set<lli>v2;
    sub_sum(v1, a, 20, T);
    sub_sum(v2, b, n - 20, T);
    lli ans = 0;
    for (auto it : v1)
    {
      lli k = (T - it);
      auto itr = v2.upper_bound(k);
      --itr;
      ans = maxm(ans, it + *itr);
    }
    for (auto it : v2)
    {
      lli k = (T - it);
      auto itr = v1.upper_bound(k);
      --itr;
      ans = maxm(ans, it + *itr);
    }

    cout << ans << endl;
  }

  return 0;
}

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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int M = (1e9)+7;
const int N = 105;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,t;
        cin>>n>>t;
        int a[n];
        for(int i=0;i<n;i++)cin>>a[i];
        if(n == 1)
        {
            cout<<(a[0] <= t ? a[0] : 0)<<endl;
            return 0;
        }
        set<int> l,r;
        int m = n/2;
        for(int i=0;i<(1LL<<m);i++)
        {
            int tot = 0;
            for(int j=0;j<m;j++)if((i>>j)&1LL)tot += a[j];
            if(tot <= t)l.insert(tot);
        }
        m = n - m;
        for(int i=0;i<(1LL<<m);i++)
        {
            int tot = 0;
            for(int j=0;j<m;j++)if((i>>j)&1LL)tot += a[(n/2) + j];
            if(tot <= t)r.insert(tot);
        }
        int ans = 0;
        if(l.size())ans = max(ans, *l.rbegin());
        if(r.size())ans = max(ans, *r.rbegin());
        for(int x:l)
        {
            int need = t - x;
            auto it = r.lower_bound(need);
            if(it != r.end() && *it > need)
            {
                if(it != r.begin())
                {
                    it--;
                    ans = max(ans, x + *it);
                }
            }
            else if(it == r.end())
            {
                if(it != r.begin())
                {
                    it--;
                    ans = max(ans, x + *it);
                }
            }
            else ans = t;
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
typedef long long ll;
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,int y){x=upd(x+y-mod);}
inline void iadd(int &x,int y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
/*
typedef pair<int,int> P;
*/
#define rep(i,l,r) for (int i(l);i<=(r);i++)
#define per(i,l,r) for (int i(r);i>=(l);i--)

int n;
void solve(){
	n=read();
	printf("%d\n",(1<<n)-1);
	rep(i,1,(1<<n)-1){
		rep(j,0,(1<<n)-1) putchar("AB"[__builtin_parity(i&j)]);
		puts("");
	}
}
int main()
{
	for (int T=1;T--;) solve();
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<bool>>se(50,vector<bool>(50));
vector<vector<int>>sc(50,vector<int>(50));
vector<vector<int>>pe(50,vector<int>(50));//タイプ
vector<bool>ty(2505);//色
int pmax=0;
string smax;
int kaisu=0;
int ti=clock();
void dfs(int nx,int ny,int P,string S){//今のx,今のy,スコア,ルート
  if(pmax<P){
    pmax=P;smax=S;
  }
  kaisu++;
  //cout<<(long double)(clock())/(long double)(CLOCKS_PER_SEC)<<" "<<pmax<<endl;
  se[nx][ny]=true;
  ty[pe[nx][ny]]=true;
  if(nx!=0&&!se[nx-1][ny]&&!ty[pe[nx-1][ny]]){
    dfs(nx-1,ny,P+sc[nx-1][ny],S+'U');
    if(kaisu>14600000)return;
    se[nx-1][ny]=false;
    ty[pe[nx-1][ny]]=false;
  }
  if(nx!=49&&!se[nx+1][ny]&&!ty[pe[nx+1][ny]]){
    dfs(nx+1,ny,P+sc[nx+1][ny],S+'D');
    if(kaisu>14600000)return;
    se[nx+1][ny]=false;
    ty[pe[nx+1][ny]]=false;
  }
  if(ny!=0&&!se[nx][ny-1]&&!ty[pe[nx][ny-1]]){
    dfs(nx,ny-1,P+sc[nx][ny-1],S+'L');
    if(kaisu>14600000)return;
    se[nx][ny-1]=false;
    ty[pe[nx][ny-1]]=false;
  }
  if(ny!=49&&!se[nx][ny+1]&&!ty[pe[nx][ny+1]]){
    dfs(nx,ny+1,P+sc[nx][ny+1],S+'R');
    if(kaisu>14600000)return;
    se[nx][ny+1]=false;
    ty[pe[nx][ny+1]]=false;
  }
}
signed main(){
  int I,J;cin>>I>>J;
  ty.assign(2505,false);
  for(int X=0;X<50;X++){
    for(int Y=0;Y<50;Y++){
      cin>>pe[X][Y];
    }
  }
  for(int X=0;X<50;X++){
    for(int Y=0;Y<50;Y++){
      cin>>sc[X][Y];
      se[X][Y]=false;
    }
  }
  dfs(I,J,sc[I][J],"");
  cout<<smax<<endl;
}


#include<cstdio>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <map>
#include<vector>
#include <iostream>
using namespace std;
#define ll long long
#define mod 998244353
ll a[200005];
ll mul(ll a,ll n)
{
    ll sum=1;
    while(n)
    {
        if(n%2) sum=sum*a%mod;
        a=a*a%mod;
        n/=2;
    }
    return sum;
}
ll get(ll p)
{
    return mul(p,mod-2);
}
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+n+1);
    ll sum=0;
    ll ans=0;
    for(int i=n;i>=1;i--)
    {
        ans=(ans+a[i]*a[i]%mod+sum*a[i]%mod)%mod;
        sum=(sum*2+a[i])%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// Modint
// modint<MOD> で宣言
template<long long MOD>
struct modint{
  long long x;
  long long mod = MOD;
  modint(long long x=0):x(x%MOD){}
  modint& operator+=(const modint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator-=(const modint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator*=(const modint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  modint operator+(const modint a) const{
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint a) const{
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint a) const{
    modint res(*this);
    return res*=a;
  }
  modint pow(long long t) const{
    if(!t) return 1;
    modint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }

  //for prime mod
  modint inv() const{
    return pow(MOD-2);
  }
  modint& operator/=(const modint a){
    return (*this) *= a.inv();
  }
  modint operator/(const modint a) const{
    modint res(*this);
    return res/=a;
  }
};
using mint = modint<998244353>;

const int NMAX=1000010; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int n; cin >> n;
  vector<mint> pow2(n+1);
  pow2[0].x = 1;
  rep(i,n) pow2[i+1] = pow2[i] * mint(2);
  vi a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(),a.end());
  mint res;
  mint sum;
  rep1(i,n-1) {
    sum += mint(a[i]) * pow2[i-1];
  }
  rep(i,n) {
    res += mint(a[i]) * sum;
    res += mint(a[i]) * mint(a[i]);
    if(i+1 < n) {
      sum -= a[i+1];
      sum /= mint(2);
    }
  }
  cout << res.x << "\n";

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;

int64_t mod = 998244353 ;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

vector<int> getprime(int n){
    vector<int> p(0) ;
    vector<bool> table(n+1,0) ;
    for (int i = 2; i <= n; i++)
    {
        if (table.at(i) == 0)
        {
            p.push_back(i) ;
            for (size_t j = 2; j < n/i ; j++)
            {
                table.at(i*j) = 1 ;
            }

        }

    }
    return p ;
}

int getnum(vector<int> &array, vector<char> &c, char a){
    for (int i = 0; i < c.size(); i++)
    {
        if (a == c.at(i))
        {
            return array.at(i) ;
        }

    }

}

int64_t repeatmod(int64_t n, int64_t pow, int64_t p){
    if (pow == 1)
    {
        return n%p ;
    }

    if (pow % 2)
    {
        return (repeatmod(n, pow-1,p) * n) % p ;
    }else
    {
        return (repeatmod(n,pow/2,p) * repeatmod(n,pow/2,p)) % p ;
    }

}

int main(){
    int64_t n,p ;
    cin >> n >> p ;
    if (n == 1)
    {
        cout << p-1 << endl ;
        return 0 ;
    }

    int64_t mod = 1000000007 ;
    int64_t ans = ( (p-1) * repeatmod(p-2,n-1,mod) ) % mod ;
    cout << ans << endl ;
}

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

typedef long long ll;

const ll MOD = (ll)1e9 + 7;
ll n, p;

ll pow_(ll high)
{
    if (high==0)return 1;
    ll val = pow_(high / 2);
    if (high % 2==0)return val * val % MOD;
    return val * val % MOD * (p-2)% MOD;
}

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

    cin >> n >> p;
    ll val = (p-1)*pow_(n-1)%MOD;
    cout << val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e17
#define EPSILON 1e-14
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;
}
//浮動小数点はなるべく使うな、powも気をつけろ
int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    vector<ll> acc(N+1, 0);
    rep(i, N){
        acc.at(i+1) = acc.at(i) + A.at(i);
    }
    ll ans = 0;
    rep(i, N){
        ans += A.at(i)*A.at(i);
    }
    ans *= N-1;
    rep(i, N-1){
        ans -= 2 * A.at(i) * (acc.at(N)-acc.at(i+1));
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int main(){
    int n; cin >> n;
    VI p[3];
    ll a; char c;
    REP(i,n*2){
        cin >> a >> c;
        if(c=='R')
            p[0].push_back(a);
        else if(c=='G')
            p[1].push_back(a);
        else
            p[2].push_back(a);
    }
    if(p[0].size()%2==0&&p[1].size()%2==0&&p[2].size()%2==0){
        cout << 0 << endl;
        return 0;
    }
    REP(i,3){
        sort(ALL(p[i]));
    }
    VI x, y, z; bool f=0;
    REP(i,3){
        if(p[i].size()%2==1){
            if(!f)
                x=p[i];
            else
                y=p[i];
            f=1;
        }
        else
            z=p[i];
    }
    ll ans=INF;
    for(auto i:x){
        auto it=lower_bound(ALL(y),i);
        if(it!=y.end())
            ans=min(ans,abs(i-*it));
        if(it!=y.begin())
            ans=min(ans,abs(i-*(it-1)));
    }
    for(auto i:y){
        auto it=lower_bound(ALL(x),i);
        if(it!=x.end())
            ans=min(ans,abs(i-*it));
        if(it!=x.begin())
            ans=min(ans,abs(i-*(it-1)));
    }
    if(z.size()>0){
        vector<P> xmxs, ymxs;
        REP(i,z.size()){
            ll xmx=INF, ymx=INF;
            auto it=lower_bound(ALL(x),z[i]);
            if(it!=x.end())
                xmx=min(xmx,abs(z[i]-*it));
            if(it!=x.begin())
                xmx=min(xmx,abs(z[i]-*(it-1)));
            auto it2=lower_bound(ALL(y),z[i]);
            if(it2!=y.end())
                ymx=min(ymx,abs(z[i]-*it2));
            if(it2!=y.begin())
                ymx=min(ymx,abs(z[i]-*(it2-1)));
            xmxs.push_back({xmx,i});
            ymxs.push_back({ymx,i});
        }
        sort(ALL(xmxs));
        sort(ALL(ymxs));
        if(xmxs[0].second!=ymxs[0].second)
            ans=min(ans,xmxs[0].first+ymxs[0].first);
        else{
            ans=min(ans,xmxs[0].first+ymxs[1].first);
            ans=min(ans,xmxs[1].first+ymxs[0].first);
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
#define            pb            push_back
#define            pl            pair<ll,ll>
#define            pll           pair<ll,pair<ll,ll>>
#define            ll            long long
#define            vl            vector<ll>
#define            fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define            mp            make_pair
#define            w(t)          int t;cin>>t;while(t--)
#define            inf           1e18
#define            fi(a,n)       for(ll i=a;i<n;i++)
#define            fr(i,a,b)     for(ll i=a;i>=b;i--)
#define            fj(a,n)       for(ll j=a;j<n;j++)
#define            k(a,n)        for(ll k=a;k<n;k++)
#define            endl          "\n"
#define            all(v)        (v).begin(),(v).end()
#define            set1(x)       __builtin_popcount(x)
#define            gcd(a,b)      __gcd(a,b)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
using namespace std;
const ll mod= 1000000007;
const ll N =1000005;
void solve()
{
  double a,b;
  cin>>a>>b;
  double x=100;
  cout<<(a*b)/x<<endl;

}
int main()
{
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
      // w(t)
      solve();

}

#include <bits/stdc++.h>
using namespace std;
typedef bool boool;
typedef long long ll;
#define vl vector<ll>
#define vb vector<boool>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define vvp vector<vector<pair<ll, ll>>>
#define mod 998244353
#define all(x) x.begin(), x.end()
#define rep1(i, n) for (long long i=0; i<(long long)(n); i++)
#define rep2(i, s, e) for (long long i=(s); i<(long long)(e); i++)
#define GET_MACRO(_1,_2,_3,NAME,...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> mpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return mpow(minv(r), -n);
        auto t = mpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> minv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};
using mint = Fp<mod>;

int main() {
  ll n, k;
  cin >> n >> k;
  vl vec(n);
  rep(i, n) cin >> vec[i];
  vector<mint> fac(k+1);
  fac[0] = 1;
  rep(i, 1, k+1) fac[i] = fac[i-1]*i;
  vector<vector<mint>>  table(k+1, vector<mint>(n+1, 1));
  table[0][n] = n;
  rep(i, 1, k+1){
    mint tmp(0);
    rep(j, n){
      table[i][j] = table[i-1][j] *= vec[j];
      tmp += table[i][j];
    }
    table[i][n] = tmp;
  }
  rep(i, 1, k+1){
	mint ans(0);
 	rep(j, i+1){
      mint denom = fac[j]*fac[i-j];
      mint num = fac[i] * minv(denom);
      num *= table[j][n];
      num *= table[i-j][n];
      ans += num;
    }
    mint dup = mpow(mint(2), i) * table[i][n];
    ans -= dup;
    ans /= 2;
    cout << ans << endl;
  }
  return 0;
}


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

#define pb push_back
#define all(s) s.begin(), s.end()
#define FOR0(i, a) for (int i = 0; i < a; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<bool> vb;

int main (void) {
    cin.tie(0), cout.tie(0)->sync_with_stdio(0);

    int n;
    cin >> n;

    ll max1, max2;
    max1 = max2 = 0;
    ll max1Ind = 0, max2Ind = 0;

    int N = pow(2, n);
    FOR(i, 1, N + 1) {
        ll temp;
        cin >> temp;
        if (i <= N/2) {
            if (temp > max1) {
                max1 = temp;
                max1Ind = i;
            }
        }
        else {
            if (temp > max2) {
                max2 = temp;
                max2Ind = i;
            }
        }
    }

    //cout << max1 << " " << max1Ind << " " << max2 << " " << max2Ind << "\n";

    if (max1 > max2) {
        cout << max2Ind << "\n";
    }
    else {
        cout << max1Ind << "\n";
    }

    return 0;
}

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

int main(){
     int A[3];
     for(int i = 0; i < 3; i++){
          cin >> A[i];
     }

     for(int i = 0; i < 2; i++){
          for(int j = 0; j < 2 - i; j++){
               if(A[j] < A[j + 1]){
                    int tmp = A[j + 1];
                    A[j + 1] = A[j];
                    A[j] = tmp;
               }
          }
     }

     if(A[0] - A[1] == A[1] - A[2]){
          cout << "Yes" << endl;
     }else{
          cout << "No" << endl;
     }

     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	bool p=0;
	for(int i=0;i<s.size();i+=2)
		if(s[i]>'z'||s[i]<'a')
			p=1;
	for(int i=1;i<s.size();i+=2)
		if(s[i]>'Z'||s[i]<'A')
			p=1;
	if(p==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

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

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

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

int main()
{
  FAST/**/

  string s;
  cin>>s;

  rep(s.length())
  {
      if(i%2 == 0 && isupper(s[i]))
      {
          cout<<"No\n";
          return 0;
      }

      if(i%2 == 1 && islower(s[i]))
      {
          cout<<"No\n";
          return 0;
      }
  }

  cout<<"Yes\n";

  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;

class UnionFind{
public:
    vector<ll> par,num;

    int find(ll v){
        return (par[v]==v)? v: (par[v]=find(par[v]));
    }
    explicit UnionFind(ll N):par(N),num(N,1){
        iota(par.begin(),par.end(),0);
    }
    void unite(ll u,ll v){
        u=find(u),v=find(v);
        if(u==v)return ;
        if(num[u]<num[v])swap(u,v);
        num[u] += num[v];
        par[v] = u;
    }
    bool same(ll u,ll v){
        return find(u) == find(v);
    }
    bool ispar(ll v){
        return v=find(v);
    }
    ll size(ll v){
        return num[find(v)];
    }
};
//arc111
int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<int> a(n),b(n);
    UnionFind uf(400000);
    V<bool> used(400000,0);
    rep(i,n){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        used[a[i]]=1;
        used[b[i]]=1;
        uf.unite(a[i],b[i]);
    }
    V<bool> seen(400000,0);
    V<int> cnt(400000,0);
    rep(i,n){
        int x=uf.find(a[i]);
        cnt[x]++;
    }
    int ans=0;
    rep(i,400000){
        if(!used[i]) continue;
        int x=uf.find(i);
        if(seen[x]) continue;
        seen[x]=1;
        if(uf.size(i)-cnt[x]==1) ans+=uf.size(i)-1;
        else ans+=uf.size(i);
    }
    out(ans);
}

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

void Main(){
    int N; cin >> N;
    VVI edge(400400);
    REP(i,N){
        int a,b; cin >> a >> b; a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans = 0;
    vector<bool> vis(400400,false);
    REP(i,400400){
        if(vis[i]) continue;
        stack<Pair> s({Pair(i,0)});
        int nv = 0, ne = 0;
        while(!s.empty()){
            auto [v,ptr] = s.top(); s.pop();
            if(!vis[v]){
                vis[v] = true;
                nv++;
            }
            for(int j=ptr; j<(int)edge[v].size(); j++){
                ne++;
                if(vis[edge[v][j]]) continue;
                s.emplace(v,j+1);
                s.emplace(edge[v][j],0);
                break;
            }
        }

        ne /= 2;
        if(nv == ne+1) ans += nv-1;
        else ans += nv;
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) {
  if(b < 0)b *= -1;
  return a > b && (a = b, true);
}

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

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

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

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

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  sort(begin(A), end(A));
  int64 ans = 1LL * N * (N - 1) / 2;
  int pre = -1, cnt = 0;
  for(int i = 0; i <= N; i++) {
    if(i == N or A[i] != pre) {
      ans -= 1LL * cnt * (cnt - 1) / 2;
      if(i != N) pre = A[i];
      cnt = 0;
    }
    ++cnt;
  }
  cout << ans << "\n";
}

/**
 *  author: mahfuzz
 *  created: 24.06.2021
**/

#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    ll n; cin >> n;
    map<ll, ll> mp;

    ll cnt = 0;
    for(ll i = 1; i <= n; i++){
		ll x; cin >> x;
		mp[x]++;

		cnt += (i - mp[x]);
	}

	cout << cnt << "\n";

    return 0;
}


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

template<int M>
struct static_mint {
	static_assert(0 < M, "Module must be positive");

	int val;
	static_mint(): val() {}
	static_mint(long long x) : val(x % M) { if (val < 0) val += M; }
	static_mint pow(long long n) const { static_mint ans = 1, x(*this); while (n) { if (n & 1) ans *= x; x *= x; n /= 2; } return ans; }
	static_mint inv() const { return pow(M - 2); }

	friend static_mint pow(const static_mint &m, long long n) { return m.pow(n); }
	friend static_mint inv(const static_mint &m) { return m.inv(); }

	static_mint operator+() const { static_mint m; m.val = val; return m; }
	static_mint operator-() const { static_mint m; m.val = M - val; return m; }
	static_mint &operator+=(const static_mint &m) { if ((val += m.val) >= M) val -= M; return *this; }
	static_mint &operator-=(const static_mint &m) { if ((val -= m.val) < 0) val += M; return *this; }
	static_mint &operator*=(const static_mint &m) { val = (long long) val * m.val % M; return *this; }
	static_mint &operator/=(const static_mint &m) { val = (long long) val * m.inv().val % M; return *this; }

	friend static_mint operator+ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) += rhs; }
	friend static_mint operator- (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) -= rhs; }
	friend static_mint operator* (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) *= rhs; }
	friend static_mint operator/ (const static_mint &lhs, const static_mint &rhs) { return static_mint(lhs) /= rhs; }
	friend bool operator==(const static_mint &lhs, const static_mint &rhs) { return lhs.val == rhs.val; }
	friend bool operator!=(const static_mint &lhs, const static_mint &rhs) { return lhs.val != rhs.val; }

	static_mint &operator++() { return *this += 1; }
	static_mint &operator--() { return *this -= 1; }
	static_mint operator++(int) { static_mint result(*this); *this += 1; return result; }
	static_mint operator--(int) { static_mint result(*this); *this -= 1; return result; }

	template <typename T> explicit operator T() const { return T(val); }

	friend std::ostream &operator<<(std::ostream &os, const static_mint &m) {
		return os << m.val;
	}

	friend std::istream &operator>>(std::istream &is, static_mint &m) {
		long long x; is >> x; m = x;
		return is;
	}
};

template <typename>
struct is_mint : public std::false_type { };

template <int M>
struct is_mint<static_mint<M>> : public std::true_type { };

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

	using mint = static_mint<998244353>;

	int n;
	cin >> n;

	vector<int> f(n);
	for (auto &x : f) cin >> x, --x;

	int cycles = 0;
	vector<bool> visited(n);
	vector<int> in_cycle(n);

	for (int i = 0, v; i < n; i++) {
		if (visited[i])
			continue;
		for (v = i; !visited[v]; v = f[v]) {
			visited[v] = true;
		}
		if (in_cycle[v] == 0) {
			for (; in_cycle[v] == 0; v = f[v]) {
				in_cycle[v] = 1;
			}
			cycles += 1;
		}
		for (v = i; in_cycle[v] == 0; v = f[v]) {
			in_cycle[v] = -1;
		}
	}
	cout << mint(2).pow(cycles) - 1 << '\n';
	return 0;
}

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
constexpr unsigned long long MOD = 998244353;
constexpr unsigned long long IM = 18479187003;
constexpr unsigned long long MOD32 = 665496236;

    char f[5000][5000];
    unsigned long long dp[5000];
int main(){
    int H=0, W=0, K=0;
    char c=getchar_unlocked();
    while(c<='9'&&c>='0') {H=(H<<1)+(H<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {W=(W<<1)+(W<<3)+c-'0'; c=getchar_unlocked();}
    c=getchar_unlocked();
    while(c<='9'&&c>='0') {K=(K<<1)+(K<<3)+c-'0'; c=getchar_unlocked();}

    unsigned long long y = H * W - K;
    while(--K>=0){
        int h=0, w=0;
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {h=(h<<1)+(h<<3)+c-'0'; c=getchar_unlocked();}
        c=getchar_unlocked();
        while(c<='9'&&c>='0') {w=(w<<1)+(w<<3)+c-'0'; c=getchar_unlocked();}
        f[h-1][w-1] = getchar_unlocked();
        getchar_unlocked();
    }
    --H; --W;
    dp[0] = 1;
    for(int i = 0; i < H; ++i){
        for (int j = 0; j < W; ++j){
            switch(f[i][j]) {
                case 'R':
                    dp[j + 1] += dp[j];
                    dp[j] = 0;
                    break;
                case '\0':{
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] = dp[j] - x * MOD+MOD;
             }
                case 'X':
                    dp[j + 1] += dp[j];
            }
        }
            switch(f[i][W]) {
                case 'R':
                    dp[W] = 0;
                    break;
                case '\0':{
        dp[W] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[W], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64);
#endif
       dp[W]= dp[W] - x * MOD+MOD;
             }
            }
    }
    for (int j = 0; j < W; ++j){
        switch(f[H][j]) {
            case '\0':{
        dp[j] *= MOD32;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(dp[j], IM, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(dp[j])*IM) >> 64);
#endif
        dp[j] = dp[j] - x * MOD+MOD;
               }
            case 'R':
            case 'X':
                dp[j + 1] += dp[j];
        }
    }

    unsigned long long x = 3;
    while(y) {
      if(y & 1) {
        dp[W] *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(dp[W], IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(dp[W])*IM) >> 64);
#endif
        dp[W] = dp[W] - x2 * MOD+MOD;
               }
      {
        x *= x;
#ifdef _MSC_VER
        unsigned long long x2;
        _umul128(x, IM, &x2);
#else
        unsigned long long x2 =
            (unsigned long long)(((unsigned __int128)(x)*IM) >> 64);
#endif
        x = x- x2 * MOD + MOD;}
      y >>= 1;
    }
    printf("%d", dp[W] % MOD);

    return 0;
}


// C - Duodecim Ferra
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define vec vector
#define rp(i,s,e) for(ll i=(s);i<(e);++i)

// 素数と個数を求める
vector<pair<ll,ll>> factorize(ll n){
	vec<pair<ll,ll>> res;
	for(ll i=2L; i*i<=n; ++i){
		if (n%i) continue;
		res.emplace_back(i,0);
		while(n%i == 0){
			n /= i;
			res.back().second++;
		}
	}
	if(n != 1) res.emplace_back(n,1L);
	return res;
}

ll nCr(ll n, ll r){
	if(n-r < r) r = n - r;
	vec<int> c(n+1);
	ll ret = 1;
	for(ll i=n; i>=n-r+1; --i){
		auto pc = factorize(i);
		for(auto x:pc) c[x.first] += x.second;
	}
	rp(i, 1, r+1){
		auto pc = factorize(i);
		for(auto x:pc) c[x.first] -= x.second;
	}
	rp(p, 1, n+1){
		if(c[p] > 0){
			while(c[p]--) ret *= p;
		}
	}
	return ret;
}

int main() {
	ll L; cin>>L;
	cout<< nCr(L-1, 11) <<endl;
}

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")
//#pragma GCC optimize("branch-target-load-optimize")
//#pragma GCC optimize("branch-target-load-optimize2")
//#pragma GCC optimize("btr-bb-exclusive")

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;

void solve();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
}

#define int long long

const int N = 5e5 + 100, K = 3e5, A = 2e5 + 100, MOD = 1e9 + 7, base = 131, INF = 1e18;

int n;
vector < string > s;
set < string > se;

void solve() {
    cin >> n;
    s.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        se.insert(s[i]);
    }
    for (int i = 0; i < n; i++) {
        if (se.count("!" + s[i])) {
            cout << s[i];
            return;
        }
    }
    cout << "satisfiable";
}


#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}
long long lcm2(long long a, long long b) {
    long long d = gcd(a, b);
    return a / d * b;
}
long long lcm(const vector<long long> &vec) {
    long long l = vec[0];
    for (int i = 0; i < vec.size() - 1; i++) {
        l = lcm2(l, vec[i + 1]);
    }
    return l;
}
long long int mypow(long long int a,long long int b){
    long long int i=0,ans;
    for(i=0;i<b;i++)
    {
        if(i==0)
        {
            ans=a;
        }
        else
        {
            ans*=a;
        }
    }
    return ans;
}
struct UnionFind{
    int n;
    vector<int> par; // 親の番号
    vector<int> siz; // サイズを表している。

    // 初期化する。parは自身を指す（iotaは 0 ~ nまでの数字を順に入れていく）
    // size(siz) は最初はすべて１
    UnionFind(int n) : n(n){
        par.resize(n);
        iota(par.begin(),par.end(),0);
        siz.assign(n,1);
    }

    // 頂点の親を求める。
    // 再帰関数を使っており、経路圧縮もしている。
    int root(int x){
        // ここは親の処理。
        if (par[x] == x){
            return x;
        }

        //経路圧縮をしながら値を返す。
        // par[x] = root(par[x]);
        // return par[x];
        // と同じ意味。
        return par[x] = root(par[x]);
    }

    // unite :: a と bを同じグループに入れる。
    // もし初めから同じなら何もしない。
    void unite(int a,int b){
        int ra = root(a);
        int rb = root(b);

        if(ra == rb){
            return;
        }

        // サイズの大きい方にサイズの小さいほうを合成するので、swapしている。
        if (siz[ra] < siz[rb]){
            swap(ra,rb);
        }
        // サイズが大きい方に小さいのを合体
        // 小さいほうの親は大きい方の親になる。
        siz[ra] += siz[rb];
        par[rb] = ra;
    }

    //　同じグループかどうか判定するには、親が一緒かどうかをみたらよい
    bool same(int x,int y){
        return root(x) == root(y);
    }

    // 頂点が含まれるグループの頂点を求める。
    int get_size(int x){
        return siz[root(x)];
    }
};
    long long int facctorialMethod(int k){
    long long int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
#define PI 3.14159265359
int main()
{
	[[maybe_unused]]long long int i=0,j=0,b,c,n=0;
    [[maybe_unused]]double ab,bc;
    string s1;
    cin >> b >> c;
    if(b<0)
    {
        n=1;
    }
    b=abs(b);
    if(b==0)
    {
        cout << c;
    }
    else if(b*2+2>=c && c>=3 && n==1)
    {
        cout << (c-2)*2+3;
        return 0;
    }
    else if(b*2>=c && c>=3 && n==0)
    {
        cout << (c-2)*2+3;
        return 0;
    }
    else if(b*2+2<c && c>=3 && n==1)
    {
        cout << b*2+c;
        return 0;
    }
    else if(b*2<c && c>=3 && n==0)
    {
        cout << b*2+c-1;
        return 0;
    }
    else
    {
        cout << c+1;
    }
    return 0;
}

#include <cstdio>
#include <algorithm>
long long b, c;
int main() {
    scanf("%lld%lld", &b, &c);
    if(b == 0) printf("%lld", (c-1)/2 + 1 + c/2);
    else if(b > 0) printf("%lld", std::min(c/2, b) + std::min((c-1)/2, b-1) + (c-1)/2 + 1 + std::max(c/2-1, 0ll) + 1);
    else printf("%lld", std::min(std::max(c/2-1, 0ll), -b-1) + std::min((c-1)/2+1, -b+1) + 1 + c/2 + (c-1)/2);
    return 0;
}