#include <iostream>
#include <stdio.h>
#include <string.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
#include <ctime>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 200005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;}
template<typename U> U gcd(U a, U b){
    if(a == 0)return b;
    if(b == 0)return a;
    if(a >= b)return gcd(a % b, b);
    else return gcd(a, b % a);
}
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}
int pow(int a, ll b, int c){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % c;
        a = 1LL * a * a % c;
        b >>= 1;
    }
    return ans;
}

int a[N], b[N];
int main(){
  int ca = 0, T, i, j, k, K, n, m;
  scanf("%d", &n);
  rep(i, 0, n) scanf("%d", &a[i]);
  reverse(a, a+n);
  rep(i, 0, n) scanf("%d", &b[i]);
  ll ans = 0, tot = 0;;
  set<pii> s;
  rep(i, 0, n){
    tot += a[i] + b[i];
    s.insert({a[i], i});
    s.insert({b[i], i+n});
    ans += s.begin()->x;
    s.erase(s.begin());
  }
  printf("%lld\n", tot - ans);
}

#include <bits/stdc++.h>

// #define ONLINE_JUDGE 1
using namespace std;
#define ll long long int
#define endl '\n'
#define vi vector<int>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define f(var,start,end) for(int var = start; var<=end; var++)
#define all(x) x.begin(),x.end()
#define v(x) vector<x>
#define rall(x) x.rbegin(),x.rend()
#define mod 1000000007LL
const ll INF = (ll)(1e9);

void __print(int x) {cerr << x;}void __print(long x) {cerr << x;}void __print(long long x) {cerr << x;}void __print(unsigned x) {cerr << x;}void __print(unsigned long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(float x) {cerr << x;}void __print(double x) {cerr << x;}void __print(long double x) {cerr << x;}void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}void __print(const string &x) {cerr << '\"' << x << '\"';}void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef _Deep_M
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

// fflush(stdout) or cout.flush() in C ++;
void solver();

int main()
{
#ifdef _Deep_M
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
#else
	ios::sync_with_stdio(0);cin.tie(0);
#endif
ll t;
t = 1;

// cin >> t;

for(int i = 1; i<=t; i++)
{
	// cout << "Case #"<<i<<": ";//google kickstart;
	solver();
}

return 0;
}

void solver()
{
	ll deep;
	ll n;
	ll k;
	cin >> n>> k;
	map<ll,ll> arr;
	for(int i= 0; i<n; i++)
	{
		ll x,y;
		cin >> x>> y;
		arr[x]+=y;
	}

	ll ans = 0;

	for(auto i: arr)
	{
		dbg(i);
		if(i.first-ans<=k)
		{
			k-=i.first;
			k+=i.second;
			ans+=i.first;
		}
		else
		{
			break;
		}
	}
	ans+=k;
	cout << ans<< endl;
}


#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,vector<long long>,greater<long long> >

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

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

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    ll ans = 0;
    LCIN(N);
    vl V(2*N);
    VECCIN(V);
    PQG p;
    ans = accumulate(V.begin(),V.end(), 0LL);
    for(int i = 0; i < N; i++) {
        p.push(V.at(N - 1 - i));
        p.push(V.at(N + i));
        ans -= p.top();
        p.pop();
    }
    cout << ans << endl;
}

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

#include <bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define x first
#define y second

using namespace std;

typedef pair<int, int> pii;

const int md = 998244353;
const int N = 2e5 + 7;

int n, m, f[2][18];
int prvdiv[N];

void addmod(int &a, int b) {
	a=(a+b)%md;
}

void mulmod(int &a, int b) {
	a=(1ll*a*b)%md;
}

int main(){
	// freopen("input.inp", "r", stdin);
	// freopen("output.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i <= 17; ++i) {
		f[0][i] = 1;
	}
	for(int i = 2; i <= n; ++i) {
		int prv = i%2;
		int cur = (i+1)%2;
		f[cur][0] = f[prv][0];
		for(int j = 1; j <= 17; ++j) {
			f[cur][j] = f[cur][j-1];
			addmod(f[cur][j], f[prv][j]);
		}
	}
	int cur = (n+1)%2;
	for(int i = 2; i <= m; ++i) {
		if (prvdiv[i] == 0) {
			prvdiv[i] = i;
			for(long long j = 1ll*i*i; j <= m; j += i) {
				prvdiv[j] = i;
			}
		}
	}
	int ans = 1;
	for(int i = 2; i <= m; ++i) {
		int s = 1;
		int tmp = i;
		while (tmp > 1) {
			int cnt = 0;
			int c = prvdiv[tmp];
			while (tmp % c == 0) {
				tmp /= c;
				++cnt;
			}
			mulmod(s, f[cur][cnt]);
		}
		addmod(ans, s);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 1001
typedef long long ll;
int h,w,ans=0;
typedef pair<int,int> P;
vector<string> s(SIZE);

int main(){
    cin>>h>>w;
    REP(i,h) cin>>s.at(i);

    REP(i,h) REP(j,w){
      if(j+1<w && s.at(i).at(j)=='.'&&s.at(i).at(j+1)=='.') ans++;
      if(i+1<h && s.at(i).at(j)=='.'&&s.at(i+1).at(j)=='.') ans++;
    }

  cout<<ans;
}

#include <cstdio>
#include <iostream>
using namespace std;

char ar[101][101];

int main()
{
	int h, w;
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> ar[i][j];
		}
	}
	int xdir[4] = { 0, 1, 0, -1 };
	int ydir[4] = { 1, 0, -1, 0 };
	int cnt = 0;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (ar[i][j] == '.')
			{
				for (int aa = 0; aa < 4; aa++)
				{
					int nx = i + xdir[aa];
					int ny = j + ydir[aa];
					if (0 <= nx && nx < h && 0 <= ny && ny < w)
					{
						if (ar[nx][ny] == '.') cnt++;
					}
				}
			}
		}
	}
	printf("%d", cnt / 2);
}


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

#define   fi(a,b) for(int i=a;i<b;i++)
#define   fj(a,b) for(int j=a;j<b;j++)
#define   ff first
#define   ss second
#define   ll long long
#define   ld long double
#define   ull unsigned long long
#define   bp(x) __builtin_popcount(x)
#define   pr(x) for(auto it: x) cout<<it<<" "; cout<<endl;
#define   getMax(x) max_element(x.begin(),x.end())
#define   getMin(x) min_element(x.begin(),x.end())
#define   endl "\n"
typedef   vector<int> vi;
typedef   vector< pair<int,int> > vii;
typedef   vector<long long> vl;
typedef   pair<int,int> pii;
typedef   pair<ll,ll> pll;
typedef   vector< pair<ll,ll> > vll;
//int dx[]={1,0,-1,0};
//int dy[]={0,1,0,-1};
//int dx[]={-1,0,1,1,1,0,-1,-1};
//int dy[]={-1,-1,-1,0,1,1,1,0};

void nikal_pehli_fursat_mai(){
    ll n;
    cin>>n;
    vl v(n);
    vl h(401, 0);
    fi(0, n) {
        cin>>v[i];
    }
    ll ans = 0;
    h[v[0]+200]++;
    fi(1, n){
        fj(0, 401){
            ans += abs(v[i]-(j-200))*abs(v[i]-(j-200))*h[j];
        }
        h[v[i]+200]++;
    }
    cout<<ans<<endl;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tc=1;
    // cin>>tc;
    while(tc--){
    nikal_pehli_fursat_mai();
    }
}

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

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

    int n; ll k; cin >> n >> k;
    ll dp[4][3000005] = {0};
    dp[0][0] = 1;
    for(int i = 0; i < 3;i++){
        for(int j = 0; j <= i * n;j++){
            dp[i + 1][j + 1]     += dp[i][j];
            dp[i + 1][j + n + 1] -= dp[i][j];
        }

        for(int j = 1; j <= (i + 1) * n; j++){
            dp[i + 1][j] += dp[i + 1][j - 1];
        }
    }

    int x;
    for(int i = 3; i <= 3 * n; i++){
        if(k <= dp[3][i]){
            x = i; break;
        }else{
            k -= dp[3][i];
        }
    }

    for(int i = 1; i <= n; i++){
        int j_mi = max(1, x - i - n);
        int j_ma = min(n, x - i - 1);

        if(j_mi > j_ma) continue;
        if(k > (j_ma - j_mi + 1)){
            k -= (j_ma - j_mi + 1);
            continue;
        }

        int y = j_mi + k - 1;
        int z = x - i - y;
        cout << i << " " << y << " " << z << endl;
        return 0;
    }
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    string t ="";
    int ans =0;

    rep(i,n){
        t += s[i];
        while(t.size()>=3){
            if(t.substr(t.size()-3,3)=="fox"){
                t = t.substr(0,t.size()-3);
                ans++;
            }
            else{
                break;
            }
        }
    }
    cout << n -  ans*3 << endl;
}

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

#define FIO                     ios::sync_with_stdio(false); cin.tie(nullptr)
#define TC(t)                   int t; cin >> t; for(int i = 1; i <= t; i++)
#define deb(x)                  cerr << #x << " = " << x << endl
#define deb2(x, y)              cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)             for(i = a; i < n; i++)
#define f1(i, a, n)             for(i = a; i <= n; i++)
#define ini(x, y)               memset(x, y, sizeof(x))
#define all(x)                  x.begin(), x.end()
#define sz(x)                   x.size()
#define ll                      long long int
#define pb                      push_back
#define ppb                     pop_back
#define mp                      make_pair
#define ff                      first
#define ss                      second
#define M                       1000000007
#define endl                    '\n'
#define bits(x)                 __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define vi                      vector<int>
#define pii                     pair<int,int>
#define vpii                    vector<pii>
#define ordered_set             tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

const int N = 1e5 + 1;
const int MX = 1e9;
const ll INF = 1e18;

using namespace std;
using namespace __gnu_pbds;

inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
inline ll mod(ll x) {return ( (x % M + M) % M );}

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {for(auto& x : v) os << x << " "; return os << '\n';}
template<typename... T> void in(T&... args) {((cin >> args), ...);}
template<typename... T> void out(T&&... args) {((cout << args << endl), ...);}
template<typename... T> void out2(T&&... args) {((cout << args << " "), ...);}

void solve() {
        ll n, i;
        string s;
        cin >> n >> s;

        i = 0;
        while(i < n-2) {
                if(s[i] == 'f' && s[i+1] == 'o' && s[i+2] == 'x') {
                        // deb(i);
                        s.erase(s.begin()+i);
                        s.erase(s.begin()+i);
                        s.erase(s.begin()+i);
                        if(i >= 2) i-=2;
                        else if(i >= 1) i-=1;
                        n -= 3;
                        // deb(i);
                        // deb(s);
                } else i++;
        }
        out(sz(s));
}

int main () {
        FIO;
        // TC(t)
        solve();
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

int main(){
  int N;
  string S;
  cin >> N >> S;
  map<char,int> ma;
  map<int,char> am;
  ma['R'] = 0; am[0] = 'R';
  ma['B'] = 1; am[1] = 'B';
  ma['W'] = 2; am[2] = 'W';

  vector<int> f(N,1),c(N,0);
  FOR(i,1,N){
    int k = i;
    while(k%3==0){
      k /= 3;
      c[i]++;
    }
    f[i] = f[i-1] * k % 3;
    c[i] += c[i-1];
  }
  int ans = 0;
  FOR(i,0,N){
    ans += f[N-1] * f[i] * f[N-1-i] * ma[S[i]] * ( (c[N-1]-c[i]-c[N-1-i]) == 0 );
    ans %= 3;
  }
  if(N%2 == 0) ans = -ans;
  ans = ( (ans % 3) + 3 ) % 3;
  cout << am[ans] << endl;
}

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

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
 os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os << "(" << P.first << "," << P.second << ")";}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::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...);
}
#else
#define trace(...) 1
#endif

#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector< pii >

const int mod=3;
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}
inline void modadd(int &a,int &b){a+=b;if(a>=mod)a-=mod;}

const int M = 4e5 + 12;

int cal(int x){
	int ret = 0;
	while(x > 0) {
		ret += x/3;
		x = x/3;
	}
	return ret;
}

int P[M];
int fac[M];
int ifac[M];
int red[M];

void pre() {
	fac[0] = 1;
	P[0] = 1;
	ifac[0] = 1;
	for(int i=1; i<M; i++) {
		int x = i;
		P[i] = cal(i);
		while((x%3) == 0) x/=3;
		red[i] = x;
		fac[i] = mul(x, fac[i-1]);
	}

	ifac[M-1] = inv(fac[M-1]);

	for(int i=M-2;i>0;i--){
		ifac[i] = mul(ifac[i+1], red[i+1]);
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n; cin>>n;
	// vi c(n);
	pre();
	int ans = 0;

	for(int i=1;i<=n;i++){
		char x; cin>>x;
		int y;
		if(x=='B') y = 0;
		else if(x=='W') y = 1;
		else if(x=='R')  y = 2;

		int r = n - i;

		int dif = P[n-1] - P[r] - P[n-r-1];

		if(dif > 0) continue;

		int con = mul(fac[n-1], mul(ifac[r], ifac[n-r-1]));

		// trace(n-1, r, fac[n-1], ifac[r], ifac[n-r-1]);

		// trace(y, con, ans);

		con = mul(con, y);

		ans = add(ans, con);
	}

	if(((n-1) % 2)==1 ) ans = sub(0 , ans);

	// trace(ans);

	if( ans == 0) cout<<'B';
	else if (ans == 1) cout<<'W';
	else cout<<'R';

}


#include<bits/stdc++.h>
#define LL long long
#define SZ(x) (int)x.size()-1
#define F(i,a,b) for (int i=a;i<=b;++i)
#define DF(i,a,b) for (int i=a;i>=b;--i)
#define pb push_back
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
LL read(){
    char ch=getchar(); LL w=1,c=0;
    for (;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
    for (;isdigit(ch);ch=getchar()) c=(c<<3)+(c<<1)+(ch^48);
    return w*c;
}
struct Li{
	LL l,r;
};
bool cmp(Li A,Li B){
	return A.l<B.l;
}
LL B,C;
Li a[10];
int main(){
	cin>>B>>C;
	if (C==1){
		cout<<(B ? 2 : 1)<<"\n";
		return 0;
	}
	a[0]=(Li){B-C/2,B},a[2]=(Li){-B-(C-1)/2,-B};
	a[1]=(Li){-B,-(B-(C-1)/2)},a[3]=(Li){B,B+(C-2)/2};
	sort(a,a+4,cmp);
	LL ans=0,pos=a[0].r,lp=a[0].l;
	F(i,1,3){
		if (a[i].l>pos){
			ans=pos-lp+1;
			pos=a[i].r;
			lp=a[i].l;
		}
		else pos=max(pos,a[i].r);
	}
	ans+=pos-lp+1;
	cout<<ans<<'\n';
    return 0;
}

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

int main(){
  long long int b, c; cin >> b >> c;
  long long int ansin = 0, ansout = 0;
  long long int C = c, B = b;

  long long int p1 = 0, p2 = 1;
  p1 = 2*abs(b)+1;
  if(b<0){
  	if(c>0){
    	C--;
    	p2++;
    }
    p2 += C-1;
  }
  else{
    if(c>0) p2++;
    p2 += C-1;
  }
  ansin = min(p1, p2);

  if(b>0){
  	b *= -1;
  	c--;
  }
  ansout = c-1;
  if(c<=0) ansout = 0;

  cout << ansin + ansout << endl;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int h,w,a,ans=0;
bool f[16][16];
inline void dfs(int x,int y,int n) {
	if(y>w) {
		y=1,
		++x;
	}
	if(x==h&&y==w) {
		if(n==0) {
			++ans;
		}
		return;
	}
	dfs(x,y+1,n);
	if(n>0&&f[x][y]) {
		if(f[x+1][y]) {
			f[x+1][y]=f[x][y]=false;
			dfs(x,y+1,n-1);
			f[x+1][y]=f[x][y]=true;
		}
		if(f[x][y+1]) {
			f[x][y+1]=f[x][y]=false;
			dfs(x,y+1,n-1);
			f[x][y+1]=f[x][y]=true;
		}
	}
	return;
}
signed main() {
	memset(f,false,sizeof f);
	cin>>h>>w>>a;
	for(int i=1; i<=h; ++i) {
		for(int j=1; j<=w; ++j) {
			f[i][j]=true;
		}
	}
	dfs(1,1,a);
	cout<<ans;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int H, W, A, B, ans = 0;

void dfs(int i, long long bit, int a, int b) {
  if (i == H*W) {
    ans++;
    return;
  }

  if (bit & (1 << i)) {
    dfs(i + 1, bit, a, b);
    return;
  }

  bit |= (1 << i);

  if (a) {
    if ((i + 1) <= H*W && ((i + 1) % W) != 0 && (~bit & 1 << (i + 1))) {
      dfs(i + 1, bit | (1 << (i + 1)), a-1, b);
    }

    if ((i + W) <= (W*H)) {
      dfs(i + 1, bit | (1 << (i + W)), a-1, b);
    }
  }

  if (b) {
    dfs(i + 1, bit, a, b-1);
  }
}

int main()
{
  cin >> H >> W >> A >> B;
  dfs(0, 0, A, B);
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod=1e9+7;
int h,w,a,b;
int ans=0;
int mat[20][20];
void calc(int mark){
    if(mark==a){
        ans++;
    }
    else{
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(i!=h && mat[i][j]==0 && mat[i+1][j]==0){
                    mat[i][j]=1;
                    mat[i+1][j]=1;
                    calc(mark+1);
                     mat[i][j]=0;
                    mat[i+1][j]=0;
                }
                if(j!=w && mat[i][j]==0 && mat[i][j+1]==0){
                     mat[i][j]=1;
                    mat[i][j+1]=1;
                    calc(mark+1);
                     mat[i][j]=0;
                    mat[i][j+1]=0;
                }
            }
        }
    }
}
signed main(){
#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
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int t=1;
 //       cin>>t;
        while(t--){
            cin>>h>>w>>a>>b;
            calc(0);
            for(int i=1;i<=a;i++){
                ans=ans/i;
            }
            cout<<ans<<endl;
         }
        return 0;
}

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

int h,w;
bool used[16][16];

int Dfs(int i, int j, int a, int b){
    if(a < 0 || b < 0) return 0;
    if(j == w) j = 0, i++;
    if(i == h) return 1;
    if(used[i][j]) return Dfs(i, j + 1, a, b);
    int res = 0;
    used[i][j] = 1;
    res += Dfs(i, j + 1, a, b - 1);
    if(j + 1 < w && !used[i][j + 1]){
        used[i][j + 1] = 1;
        res += Dfs(i, j + 1, a - 1, b);
        used[i][j + 1] = false;
    }
    if(i + 1 < h && !used[i + 1][j]){
        used[i + 1][j] = 1;
        res += Dfs(i, j + 1, a - 1, b);
        used[i + 1][j] = false;
    }
    used[i][j] = false;
    return res;
}

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

   int a,b; cin >> h >> w >> a >> b;
   cout << Dfs(0,0,a,b) << endl;
}


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

#define ll long long
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define P pair<ll, ll>
#define all(a) (a).begin(), (a).end()

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

    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    vector<bool> x(1001, true);
    rep(i, n){
        drep(j, 0, a[i]-1) x[j] = false;
        drep(j, b[i]+1, 1000) x[j] = false;
    }

    ll ans = 0;
    rep(i, x.size()) if(x[i]) ans++;

    cout << ans << endl;
}

#include<string>
#include<iostream>
int main(){
    int N,A[100],B[100],z=1000,w=0;
    std::cin>>N;
    for(int f=0;f<N;f++){
        std::cin>>A[f];
    }
    for(int i=0;i<N;i++){
        std::cin>>B[i];
    }
    for(int t=0;t<N;t++){
       if(z>=B[t])z=B[t];
       if(w<=A[t])w=A[t];
    }
    if(z>=w)std::cout<<z-w+1;
    else std::cout<<0;
    return 0;
}


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

int main(){
  int N,D,H;
  cin >> N >> D >> H;

  vector <float> dnum(N);
  vector <float> hnum(N);
  for(int i=0;i<N;i++){
    cin >> dnum[i] >> hnum[i];
  }
  float lean = 1000;
  for(int i=0;i<N;i++){
    hnum[i] = H-hnum[i];
    dnum[i] = D-dnum[i];
    if((hnum[i]/dnum[i]) < lean)
      lean = hnum[i]/dnum[i];
  }
  float b = 0;
  b = H - lean*D;
  if(b < 0)
    b = 0;
  cout << b << endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (v).size()
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    read(__VA_ARGS__)
#define LL(...)                                                                \
    ll __VA_ARGS__;                                                            \
    read(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    read(__VA_ARGS__)
#define STRING(...)                                                            \
    string __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
    vector<type> name(size);                                                   \
    read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int to;
    T cost;
    edge(int t, T c) : to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}

void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
    read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
    for(auto &a : v)
        read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
    read(head), read(tail...);
}
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    INT(n, m, k);
    VEC(int, a, k);
    vector<bool> trap(n + 1);
    rep(i, k) { trap[a[i]] = 1; }
    int len = 0;
    rep(i, n + 1) {
        if(trap[i] == 1)
            len++;
        else {
            len = 0;
        }
        if(len >= m) {
            cout << -1 << endl;
            return 0;
        }
    }
    auto dp = make_vec(n + 1, make_pair(0.0, 0.0));
    dp[n] = {0, 0};
    double x = 0, y = 0;
    for(int i = n - 1; i >= 0; i--) {
        if(!trap[i])
            dp[i] = {x / m, y / m + 1};
        else
            dp[i] = {1, 0};

        x += dp[i].first;
        y += dp[i].second;

        if(i + m <= n) {
            x -= dp[i + m].first;
            y -= dp[i + m].second;
        }
    }
    double b = dp[0].first, c = dp[0].second;
    cout << fixed << setprecision(10) << c / (1 - b) << endl;
}


/**
 *    author:  tourist
 *    created: 15.12.2020 16:15:36
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  string t;
  cin >> s;
  cin >> t;
  vector<int> p;
  int ptr = 0;
  int last = -1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (t[i] == '1') {
      p.push_back(i);
    }
    if (s[i] == '1') {
      if (last != -1) {
        ans += i - last;
        last = -1;
      } else {
        if (ptr < (int) p.size()) {
          ans += i - p[ptr++];
        } else {
          last = i;
        }
      }
    }
  }
  if (last != -1 || ptr < (int) p.size()) {
    ans = -1;
  }
  cout << ans << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> X(n), Y(n);
  rep(i, n) cin >> X[i] >> Y[i];
  int ans = 0;
  rep(i, n) REP(j, i+1, n) {
    if(-abs(X[j]-X[i]) <= (Y[j]-Y[i]) && (Y[j]-Y[i]) <= abs(X[j]-X[i])) ans++;
  }
  cout << ans << endk;
  return 0;
}


#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define V vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F first
#define S second
#define sqr(x) (x)*(x)
#define mp make_pair
#define mtp make_tuple
#define tpii tuple<int,int,int>
#define ckmax(a,b) a=max(a,b)
#define ckmin(a,b) a=min(a,b)
#define rep(n) for(int i=0;i<n;i++)
#define inf INT_MAX
#define debug(x) cerr<<x<<'\n';
#define quick ios_base::sync_with_stdio(0),cin.tie(0);long double nownow=clock();
#define total_time cerr<<(clock()-nownow)/CLOCKS_PER_SEC*1000<<" (ms)\n";
using namespace std;
template<typename T>void in(vector<T> &a){for(auto &i:a)cin>>i;}
template<typename T>void in(vector<T> &a,int n){for(auto i=0;i<n;i++)cin>>a[i];}
template<typename T>void out(vector<T> &a){for(auto &i:a)cout<<i<<' ';cout<<'\n';}
#define int long long
#define input freopen("/Users/wangkaiyu/Downloads/Q_6_24_3.in","r",stdin);

signed main(){
    quick
    int n,k;
    cin>>n>>k;
    cout<<(n*n+n)*k*50+(k*k+k)/2*n;
    cout<<'\n';
    total_time
    return 0;
}

#include<bits/stdc++.h>
#define lli long long
#define lld double
#define test int t;cin>>t;while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define  mod 1000000007
#define ff first
#define ss second
#define ppl pair<lli , lli>
#define ppi pair<int , int>
#define large 1000000000000000000
using namespace std;
bool comp(const ppl &a,const ppl &b)
{
    return (a.ss < b.ss);
}
void solve()
{
    int n , k , ans = 0;
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= k ; j++)
        {
            int x = 100*i + j;
            ans += x;
        }
    }
    cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
#endif
    fast_io;
    //test
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef        long long int   ll;
typedef      long double   ld;
typedef     vector<ll>      vll;
#define     fi              first
#define     se              second
#define     pb              push_back
#define     nn              "\n"
#define     all(p)          p.begin(),p.end()
#define     zz(v)           (ll)v.size()
#define     S(a)            scanf("%lld",&a)
#define     SS(a,b)         scanf("%lld %lld",&a,&b)
#define     SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define     ss              ' '
#define     pii             pair<ll,ll>
#define     gcd(a,b)        __gcd(a,b)
#define     lcm(a,b)        (a*b)/gcd(a,b)

int main()
{

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

    ll a,b,c;
    cin>>a>>b>>c;
    cout<<(7-a)+(7-b)+(7-c)<<nn;

}

/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/

/* IF WA???

1. corner case! n=1?k=1? something about 0?

2. check code(avoid stupid mistake)

3. read the statement again(if there any missing point???)

4. check the idea(check all possible counter test case again!!!)

5. be calm,don't be panic!!!.(***this problem not going to decide your future***)

6. don't waste too much time. move to next problem

*/

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

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

// ２項係数
/*
ll ncrmod(ll n, ll r)
{
  ll ans;

  return ans;
}
*/

// 繰り返し二乗法
ll powmod(int a, int n){//aのn乗を計算します(MOD)。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = (x*a) % MOD;
    }
    a = (a*a) % MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

void solve()
{
  ll N; cin >> N;
  string s; cin >> s;
  string t; cin >> t;

  vector<int> s0, t0;
  rep(i, N) {
	if(s[i] == '0') s0.push_back(i);
	if(t[i] == '0') t0.push_back(i);
  }

  if(s0.size() != t0.size()) {
	cout << -1 << endl;
	return ;
  }

  ll ans = 0;
  rep(i, s0.size()) {
	if(s0[i] != t0[i]) ans ++;
  }

  cout << ans << endl;

}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
constexpr ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
template<class T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
constexpr int dy[4]={-1,0,1,0};
constexpr int dx[4]={0,-1,0,1};

struct UnionFind{
private:
    vector<int> par;
    vector<int> siz;
public:
    UnionFind(int N=0){
        init(N);
    }
    void init(int N){
        par.resize(N);
        siz.resize(N);
        for(int i=0; i<N; i++) par[i] = i;
        for(int i=0; i<N; i++) siz[i] = 1;
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return;
        if(siz[rootA] < siz[rootB]) swap(rootA, rootB);
        par[rootB] = rootA;
        siz[rootA] += siz[rootB];
    }
    int root(int a){
        if(par[a] == a) return a;
        return par[a] = root(par[a]);
    }
    bool same(int a, int b){
        return root(a) == root(b);
    }
    int size(int a){
        return siz[root(a)];
    }
};

int H, W;
string S[1000];

UnionFind uf;
bool ok[1000][1000];

signed main(){
    cin >> H >> W;
    rep(i, H) cin >> S[i];

    uf.init(H*W);

    rep(i, H) ok[i][0] = ok[i][W-1] = true;
    rep(i, W) ok[0][i] = ok[H-1][i] = true;
    rep(i, H){
        int bef = -1;
        rep(j, W){
            if(S[i][j] == '#'){
                if(bef != -1){
                    int a = uf.root(i*W+j);
                    int b = uf.root(i*W+bef);
                    uf.unite(i*W+j, i*W+bef);
                    int r = uf.root(i*W+j);
                    ok[r/W][r%W] |= ok[a/W][a%W];
                    ok[r/W][r%W] |= ok[b/W][b%W];
                }
                bef = j;
            }
        }
    }
    rep(i, W){
        int bef = -1;
        rep(j, H){
            if(S[j][i] == '#'){
                if(bef != -1){
                    int a = uf.root(j*W+i);
                    int b = uf.root(bef*W+i);
                    uf.unite(j*W+i, bef*W+i);
                    int r = uf.root(j*W+i);
                    ok[r/W][r%W] |= ok[a/W][a%W];
                    ok[r/W][r%W] |= ok[b/W][b%W];
                }
                bef = j;
            }
        }
    }

    int base = 0;
    rep(i, H){
        rep(j, W){
            if(S[i][j] == '#' && uf.root(i*W+j) == i*W+j && !ok[i][j]){
                base++;
            }
        }
    }

    // 横
    int ans1 = 0;
    rep(i, H){
        if(i == 0 || i == H-1) continue;
        bool ex = false;
        rep(j, W){
            if(S[i][j] == '#') ex = true;
        }
        if(!ex) ans1++;
    }

    // 縦
    int ans2 = 0;
    rep(j, W){
        if(j == 0 || j == W-1) continue;
        bool ex = false;
        rep(i, H){
            if(S[i][j] == '#') ex = true;
        }
        if(!ex) ans2++;
    }

    cout << base + min(ans1, ans2) << endl;
}

#include<bits/stdc++.h>
#include<bits/extc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t){
	while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<": "; for(auto i:x) cerr<<i<<" "; cerr<<endl;}}
#define debugr(l, r, x) {{cerr<<#x<<": "; for(int i=l;i<=r;i++) cerr<<x<<" "; cerr<<endl;}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debugr(l, r, x)
#define cerr while(0) cerr
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

char a[1005][1005];
bool vis[3005];
vi adj[3005];
void dfs(int x){
	vis[x]=true;
	for(int y:adj[x]){
		if(!vis[y]) dfs(y);
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w;
	cin>>h>>w;
	set<int> row, col;
	auto add=[&](int x, int y){
		adj[x].push_back(h+y);
		adj[h+y].push_back(x);
		row.insert(x);
		col.insert(h+y);
	};
	add(1, 1);
	add(1, w);
	add(h, 1);
	add(h, w);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>a[i][j];
			if(a[i][j]=='#'){
				add(i, j);
			}
		}
	}
	int ccs=0;
	for(int i:row){
		if(!vis[i]){
			dfs(i);
			ccs++;
		}
	}
	for(int i:col){
		if(!vis[i]){
			dfs(i);
			ccs++;
		}
	}
	debug(row.size(), col.size());
	cout<<ccs+min(h-row.size(), w-col.size())-1<<endl;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

typedef long long ll;

using namespace std;

int main(void) {
  ll H, W;
  cin >> H >> W;
  vector<string> S(H);
  vector<vector<int> > cnt(H);
  for (int i = 0; i < H; i++) cin >> S[i];
  ll K = 0;
  for (int i = 0; i < H; i++) {
    cnt[i].resize(W);
    int l = 0;
    for (int j = 0; j <= W; j++) {
      if (j == W || S[i][j] == '#') {
        for (int k = j - 1; k >= max(0, j - l); k--) {
          cnt[i][k] += l;
        }
        l = 0;
      } else {  // if (S[i][j] == '.') {
        l++;
        K++;
      }
    }
  }

  for (int j = 0; j < W; j++) {
    int l = 0;
    for (int i = 0; i <= H; i++) {
      if (i == H || S[i][j] == '#') {
        for (int k = i - 1; k >= max(0, i - l); k--) {
          cnt[k][j] += l;
        }
        l = 0;
      } else {
        l++;  // if (S[i][j] == '.') l++;
      }
    }
  }

  vector<ll> p2ma;
  ll v = 1;
  for (int x = 0; x <= 4000000; x++) {
    p2ma.push_back(v);
    v *= 2;
    v %= 1000000007;
  }
  ll tot = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (cnt[i][j] > 0) {
        cnt[i][j]--;

        ll ij = ((p2ma[cnt[i][j]] - 1) * (p2ma[K - cnt[i][j]])) % 1000000007;
        tot += ij;
        tot = tot % 1000000007;
      }
    }
  }
  cout << tot << endl;

  return 0;
}

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

ll mod = 1000000007;

bool field[2000][2000];
int ltor[2000][2000];
int rtol[2000][2000];
int ttob[2000][2000];
int btot[2000][2000];
ll pow2[4000001];

int main() {
  int h, w;
  cin >> h >> w;
  ll maxLight = 0;
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      if (s[j] == '.') { field[i][j] = true; maxLight++; }
      else field[i][j] = false;
    }
  }

  rep(i, h) {
    int cnt = 0;
    rep(j, w) {
      if (field[i][j]) {
        cnt++;
      } else {
        cnt = 0;
      }
      ltor[i][j] = cnt;
    }
    cnt = 0;
    for (int j = w - 1; j >= 0; j--) {
      if (field[i][j]) {
        cnt++;
      } else {
        cnt = 0;
      }
      rtol[i][j] = cnt;
    }
  }

  rep(i, w) {
    int cnt = 0;
    rep(j, h) {
      if (field[j][i]) {
        cnt++;
      } else {
        cnt = 0;
      }
      ttob[j][i] = cnt;
    }
    cnt = 0;
    for (int j = h - 1; j >= 0; j--) {
      if (field[j][i]) {
        cnt++;
      } else {
        cnt = 0;
      }
      btot[j][i] = cnt;
    }
  }

  /*rep(i, h) {
    rep(j, w) cout << ltor[i][j] << " ";
    cout << endl;
  }

  rep(i, h) {
    rep(j, w) cout << rtol[i][j] << " ";
    cout << endl;
  }*/

  ll total = 1;
  rep(i, maxLight) total = (2 * total) % mod;
  ll pow = 1;
  rep(i, h * w + 1) {
    pow2[i] = pow;
    pow = (pow * 2) % mod;
  }
  //cout << "total " << total << endl;

  ll ans = 0;

  rep(i, h) rep(j, w) {
    if (field[i][j]) {
      int cnt = ltor[i][j] + (j + 1 < w ? rtol[i][j + 1] : 0)
              + (i > 0 ? ttob[i - 1][j] : 0) + (i + 1 < h ? btot[i + 1][j] : 0);
      //cout << i << " " << j << " " << cnt << endl;
      ans = (ans + total - pow2[maxLight - cnt] + mod) % mod;
    }
  }

  cout << ans << endl;

  return 0;

}
/*
*/


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--)
#define endl "\n"
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define out(x) cout<<setprecision(15)<<x<<endl,exit(0)
#define pii pair<int,int>
#define pb push_back
#define all(v) v.begin(),v.end()
#define I first
#define S second
#define ld long double
ld pi=3.14159265359;

const int N=1e5+9;
int n,m,vis[N],ans[N];
vector <pii> v[N];

int slv(int x){
	x++;
	if(x>n) x=1;
	return x;
}

void dfs(int x,int prv){
	ans[x]=prv;
	vis[x]=1;
	for(auto it:v[x]){
		if(vis[it.I]) continue;
		if(it.S==prv) dfs(it.I,slv(prv));
		else dfs(it.I,it.S);
	}
}

int32_t main(){
   ios;
   cin>>n>>m;
   F(i,1,m){
   	int x,y,w;
   	cin>>x>>y>>w;
   	v[x].pb({y,w});
   	v[y].pb({x,w});
   }

   dfs(1,1);
   F(i,1,n) cout<<ans[i]<<endl;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define pi 2*acos(0.0)

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const int mxN = 107;
double dp[mxN][mxN][mxN];

double prob(int a, int b, int c){
    if(a>99 || b>99 || c>99) return 0;
    if(dp[a][b][c]>=0) return dp[a][b][c];
    double s=a+b+c;
    dp[a][b][c] = 1+prob(a+1,b,c)*a/s+prob(a,b+1,c)*b/s+prob(a,b,c+1)*c/s;
    return dp[a][b][c];
}

// solve case for 2 then do 3
void solve(){
    int a,b,c; cin >> a >> b >> c;
    memset(dp,-1,sizeof(dp));
    double ans = prob(a,b,c);
    cout << fixed << setprecision(9) << ans;
}

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

	solve();
	return 0;
}


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

ll solve_sub(ll N, string S, vector<ll>& A) {
    ll d_min = 1e5;
    for ( int i = 0; i < N; i++ ) {
        d_min = min(d_min, abs(A[i]-A[i+1]));
    }
    vector<ll> mn(N+1,0);
    for ( int i = 1; i <= N; i++ ) {
        if ( S[i-1] == '<' ) {
            mn[i] = max(mn[i],mn[i-1]+1);
        }
    }
    for ( int i = N-1; i >= 0; i-- ) {
        if ( S[i] == '>' ) {
            mn[i] = max(mn[i],mn[i+1]+1);
        }
    }

    ll k = d_min;
    vector<vector<ll>> ans(k, vector<ll>(N+1));
    for ( int j = 0; j < k; j++ ) {
        for ( int i = 0; i < N+1; i++ ) {
            ans[j][i] = A[i] / k + (j < A[i]%k ? 1 : 0) ;
        }
    }

    cout << k << "\n";
    for ( int j = 0; j < k; j++ ) {
        for ( int i = 0; i <= N; i++ ) {
            cout << ( i != 0 ? " " : "") << ans[j][i];
        }
        cout << "\n";
    }

    // debug
    vector<ll> b(N+1);
    for ( int i = 0; i <= N; i++ ) {
        b[i] = ans[k-1][i];
    }
    for ( int i = 0; i <= N; i++ ) {
        bool ok = true;
        if ( i > 0 ) {
            if ( b[i-1] < b[i] && S[i-1] == '>' ) ok = false;
            if ( b[i-1] > b[i] && S[i-1] == '<' ) ok = false;
            if ( b[i-1] == b[i] ) ok = false;
            if ( !ok ) {
                int z = 1;
            }
        }

    }
    for ( int i = 0; i <= N; i++ ) {
        b[i] = ans[0][i];
    }
    for ( int i = 0; i <= N; i++ ) {
        bool ok = true;
        if ( i > 0 ) {
            if ( b[i-1] < b[i] && S[i-1] == '>' ) ok = false;
            if ( b[i-1] > b[i] && S[i-1] == '<' ) ok = false;
            if ( b[i-1] == b[i] ) ok = false;
            if ( !ok ) {
                int z = 1;
            }
        }

    }

    return 0;
}

ll solve() {
    ll N;
    string S;
    cin >> N >> S;
    vector<ll> A(N+1);
    for ( int i = 0; i < N+1; i++ ) cin >> A[i];
    ll ans = solve_sub(N,S,A);
    return ans;
}

struct Data {
    int id;
    ll N;
    string S;
    vector<ll> A;
};
void test() {
    mt19937_64 mt64(0);
    uniform_int_distribution<ll> rnd_n(3, 3);
    uniform_int_distribution<ll> rnd_v(2, 20);

    int id = 0;
    vector<Data> ts;
    ts.push_back({++id,3,"<><",{3,8,6,10}});
    ts.push_back({++id,3,"<<>",{0,2,4,2}});
    for ( int i = 0; i < 100; i++ ) {
        int n = rnd_n(mt64);
        vector<ll> a;
        for ( int j = 0; j < n+1; j++ ) {
            a.push_back(rnd_v(mt64));
        }
        string s;
        for ( int j = 0; j < n; j++ ) {
            if ( a[j] == a[j+1] ) a[j+1]++;
            char c = a[j] < a[j+1] ? '<' : '>';
            s.push_back(c);
        }
        ts.push_back({++id,n,s,a});
    }

    for ( Data& t : ts ) {
        auto ans0 = solve_sub(t.N, t.S, t.A);
        if ( ans0 >= 0 ) {
            int z = 1;
        }

        // auto ans1 = solve_small_1(t.N,t.S,t.A);
        // if ( ans0 != ans1 ) {
        //     cout << t.id << " " << ans0 << " " << ans1 << "\n";
        // }
    }
    cout << "end" << "\n";
}

int main() {
    // test();

    solve();
    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

vector<P> warps[30];

ll warp_points[2010][2010];

ll maze[2010][2010];

vector<P> get_warp(ll y, ll x) {
  ll wid = warp_points[y][x];

  return warps[wid];

  // auto point1 = warps[wid][0];
  // auto point2 = warps[wid][1];

  // if (point1.first == y && point1.second == x) {
  //   return point2;
  // } else {
  //   return point1;
  // }
}

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll H, W;
  scanf("%lld %lld", &H, &W);

  fill(maze[0], maze[2005], -1);

  ll sy, sx, gy, gx;

  // インデックス1開始なので注意
  reps(y, H) {
    string line;
    cin >> line;

    reps(x, line.size()) {
      char ch = line[x - 1];
      if (ch == '#') {
        maze[y][x] = -1;
      } else if (ch == '.') {
        maze[y][x] = INF;
      } else if (ch == 'S') {
        sy = y;
        sx = x;
        maze[y][x] = 0;
      } else if (ch == 'G') {
        gy = y;
        gx = x;
        maze[y][x] = INF;
      } else {
        // ワープ
        ll wid = ch - 'a' + 1;
        warps[wid].emplace_back(mp(y, x));
        warp_points[y][x] = wid;

        maze[y][x] = INF;
      }
    }
  }

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

  deque<l_l> que;
  que.emplace_back(mp(sy, sx));
  maze[sy][sx] = 0;

  for (;;) {
    if (que.empty()) {
      break;
    }
    auto pos = que.front();
    que.pop_front();
    ll y = pos.first;
    ll x = pos.second;

    // cout << "y:" << (y) << ",x:" << (x) << endl;

    ll c = maze[y][x];

    for (auto e : {mp(y - 1, x), mp(y, x - 1), mp(y + 1, x), mp(y, x + 1)}) {
      if (maze[e.first][e.second] == -1) {
        continue;
      }
      if (maze[e.first][e.second] <= c + 1) {
        continue;
      }
      maze[e.first][e.second] = c + 1;
      que.emplace_back(make_pair(e.first, e.second));
    }

    if (warp_points[y][x]) {
      ll wid = warp_points[y][x];

      auto warp_list = get_warp(y, x);

      rep(i, warp_list.size()) {
        auto next = warp_list[i];

        warp_points[next.first][next.second] = 0;

        if (maze[next.first][next.second] > c + 1) {
          // cout << "WARP!:"
          //      << "next.first:" << (next.first) << ",next.second:" << (next.second) << endl;
          maze[next.first][next.second] = c + 1;
          que.emplace_front(make_pair(next.first, next.second));
        }

        warp_points[next.first][next.second] = 0;
      }
    }
  }

  ll ans = maze[gy][gx];

  if (ans == INF) {
    cout << (-1) << endl;
    return 0;
  }
  cout << ans << endl;
}


#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>

using ll = long long;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

    int count[3] = {0};

    while(N) {
        count[N % 10 % 3]++;
        N /= 10;
    }

    int total = count[1] + count[2] * 2;
    int count_total = count[0] + count[1] + count[2];
    int ans;

    if(total % 3 == 0) {
        ans = 0;
    } else if (total % 3 == 1) {
        if(count[1] >= 1 && count_total > 1) {
            ans = 1;
        } else {
            if(count[2] >= 2 && count_total > 2) {
                ans = 2;
            } else {
                ans = -1;
            }
        }
    } else if (total % 3 == 2) {
        if(count[2] >= 1 && count_total > 1) {
            ans = 1;
        } else {
            if(count[1] >= 2 && count_total > 2) {
                ans = 2;
            } else {
                ans = -1;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

int n;
cin>>n;
int k = n%100;
cout<<100-k;

	return 0;

}


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

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    string s[3];
    cin>>s[0]>>s[1]>>s[2];
    map<char , ll> pos;
    ll idx = 0;
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < sz(s[i]); j++){
            if(pos.find(s[i][j]) == pos.end()){
                pos[s[i][j]] = idx;
                idx++;
            }
        }
    }
    if(idx > 10){
        cout<<"UNSOLVABLE\n";
        return 0;
    }
    vector<ll> d(10);
    iota(all(d) , 0);
    do {
        vector<ll> ans(3);
        bool flag = 1;
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < sz(s[i]); j++){
                ans[i] *= 10;
                ans[i] += d[pos[s[i][j]]];
            }
            if(d[pos[s[i][0]]] == 0){
                flag = 0;
                break;
            }
        }
        if(flag && ans[0] + ans[1] == ans[2]){
            for(int k = 0; k < 3; k++){
                cout<<ans[k]<<"\n";
            }
            return 0;
        }
    }while(next_permutation(all(d)));

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

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=998244353,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=2e6+10,MAXM=3e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

void solve()
{
    ll n,k,ans=0;
    R(n,k);
    for(ll i=2;i<=n*2;i++)
    {
        if(i>k+1)
        {
            ans=(ans+min(i-1,n*2-i+1)*max(min(i-k-1,n*2-(i-k)+1),0ll));
            //W(i,i-1,n*2-i+1,i-k-1,n*2-(i-k)+1);
        }
    }
    W(ans);
}

int main()
{
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

const int N = 200010, M = 2 * N, INF = 0x3f3f3f3f;

int h[N], e[M], ne[M], idx, n, m, k;
int f[N], g[N], cnt;    //f[u]:u的子孙结点中，最近的特殊点距离u点的距离
                        //g[u]:u的子孙结点中，最远的没被特殊点覆盖的点距离u点的最远的距离
bool st[N];

void add(int a, int b) {
    e[idx] = b, ne[idx] = h[a], h[a] = idx ++;
}

void dfs(int u, int father, int mid) {
    f[u] = INF, g[u] = 0;
    for (int i = h[u]; i != -1; i = ne[i]) {
        int j = e[i];
        if (j == father)    continue;
        dfs(j, u, mid);
        f[u] = min(f[j] + 1, f[u]);
        g[u] = max(g[j] + 1, g[u]);
    }
    if (f[u] + g[u] <= mid) g[u] = -INF;
    else if (g[u] == mid) g[u] = -INF, f[u] = 0, cnt ++;
}

int check(int mid) {
    cnt = 0;
    dfs(1, -1, mid);
    if (g[1] >= 0)  cnt ++; //g[1] = 0说明1虽然被覆盖但是它的子节点还有没被覆盖的，且没被覆盖的点距离u的最远距离<mid
    return cnt;
}

int main() {
    memset(h, -1, sizeof h);
    cin >> n >> k;
    for (int i = 1; i < n; i ++)    {
        int a, b;
        cin >> a >> b;
        add(a, b), add(b, a);
    }
    int l = 1, r = n;
    int ans = 1e9;
    while (l < r)  {
        int mid = l + r >> 1;
        if (check(mid) <= k) r = mid;
        else l = mid + 1;
    }
    cout << l;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int h,w;
  cin>>h>>w;
  int ans=0;
  vector<vector<char>>s(h,vector<char>(w));
  rep(i,h){
    rep(j,w)
      cin>>s[i][j];
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(s[i][j]=='.' && s[i][j+1]=='.')
        ans++;
    }
  }
  for(int i=0;i<w;i++){
    for(int j=0;j<h-1;j++){
      if(s[j][i]=='.' && s[j+1][i]=='.')
        ans++;
    }
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxN = 1e5 + 5;
vector <tuple<int, int, int>> adj[maxN];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;

	for(int i = 0; i < m; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		adj[a].emplace_back(b, c, d);
		adj[b].emplace_back(a, c, d);
	}

	priority_queue <pair<ll, int>, vector <pair<ll, int>>, greater<pair<ll, int>>> pq;
	vector <ll> dist(n + 1, 1e18);

	pq.emplace(0, 1);
	dist[1] = 0;

	while(!pq.empty()) {
		auto [val, x] = pq.top();
		pq.pop();

		if(dist[x] < val) continue;

		for(auto &[v, c, d] : adj[x]) {
			ll new_dist = 0;
			ll sq = sqrt(d);

			if(sq * sq != d) sq++;
			sq--;

			if(val < sq) {
				new_dist = sq - val + c + d / (sq + 1);
			}
			else {
				new_dist = c + d / (val + 1);
			}

			if(dist[v] > val + new_dist) {
				dist[v] = val + new_dist;
				pq.emplace(dist[v], v);
			}
		}
	}
	cout << (dist[n] == 1e18 ? -1 : dist[n]);
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
// #include <atcoder/all>
// using namespace atcoder;

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

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,int> P;
typedef long double ld;

ll find_bottom (ll d) {
    if (d <= 1) return 0;
    if (d == 2) return 1;
    ll l = 0, r = d + 1;
    while (r - l > 1) {
        ll m = (r + l) >> 1;
        (m * (m + 1) <= d ? l : r) = m;
    }
    --l;
    if (l + d / (l + 1) >= l + 1 + d / (l + 2)) ++l;
    if (l + d / (l + 1) >= l + 1 + d / (l + 2)) ++l;
    return l;
}

struct edge {
    ll to, c, d, bottom;
    edge (ll to, ll c, ll d) : to(to), c(c), d(d), bottom(find_bottom(d)) {};
};

constexpr ll INF = 1e18;
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<vector<edge>> g(n);
    rep (_, m) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a; --b;
        g[a].emplace_back(b, c, d);
        g[b].emplace_back(a, c, d);
    }
    rep (i, 21) eprintf("%lld ", find_bottom(i));

    vector<ll> d(n, INF); d[0] = 0;
    priority_queue<P, vector<P>, greater<P>> pq; pq.emplace(0, 0);
    while (!pq.empty()) {
        auto [dist, u] = pq.top(); pq.pop();
        if (dist > d[u]) continue;
        for (auto &e : g[u]) {
            ll t = max((ll)e.bottom, d[u]);
            if (chmin(d[e.to], e.c + t + e.d / (t + 1))) {
                pq.emplace(d[e.to], e.to);
            }
        }
    }
    cout << (d.back() >= INF ? -1 : d.back()) << '\n';
    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<math.h>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rrep(i,l,r) for(int i=l;i<=r;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define unq(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define mod 1000000007
//#define mod 998244353
#define ad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
void readv(vector<ll> &a,ll n){
	rep(i,n){
		ll x;
		cin>>x;
		a.push_back(x);
	}
}
void outv(vector<ll> &a,ll n){
	rep(i,n){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<"\n";
}
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FACMAX 200010
ll fac[FACMAX],inv[FACMAX],ivf[FACMAX];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=1;i<FACMAX;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=po(fac[i],mod-2);
	}
}
ll P(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll C(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k-1,k);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll a=(i*2+1)%n,b=(i*2+2)%n;
		cout<<a+1<<" "<<b+1<<endl;
	}
}

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

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        int a = i * 2;
        int b = i * 2 + 1;
        while(a > n)
        {
            a = a - n;
        }
        while(b > n)
        {
            b = b - n;
        }
        cout << a << " " << b << "\n";
    }
    return 0;
}


// 2021-03-14 08:00-08:
#include <bits/stdc++.h>
using namespace std;

int main(){
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		long long l, r;
		cin >> l >> r;
		long long count = 0;
		if(r < 2 * l){
			cout << count << endl;
			continue;
		}
		count = ((r - l + 1) * (r - 3 * l + 2) + (l - 1) * l) / 2;
		cout << count << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(var) (var).begin(), (var).end()
#define sz(x) (int)x.size()
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define vvpi vector<vector<pair<int,int> > >

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,d,h;
	cout << fixed << setprecision(15);
	double ans = 0.0;
	cin >> n >> d >> h;
	for(int i=0;i<n;i++)
	{
		int x, y;
		cin >> x >> y;
		double m = (1.0 * (y - h)) / (1.0 * (x - d));
		double c = 1.0 * y - m * (1.0 * x);
		ans = max(ans, c);
	}

	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int tdmckmlklgnjdnmclnbjhn;
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a==c && b==d)
		cout<<"0"<<endl;
	else if(a+b==c+d || a-b==c-d || abs(a-c)+abs(b-d)<=3)
		cout<<1<<endl;
	else if((a+b+c+d)%2==0 || abs(a-c)+abs(b-d)<=6 ||
		abs(a+b-c-d)<=3 || abs(a-b-c+d)<=3)
		cout<<2<<endl;
	else
		cout<<3<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N,M,T;
  cin>>N>>M>>T;
  ll a[M];
  ll b[M+1];
  rep(i,M){
    cin>>a[i]>>b[i+1];
  }
  b[0]=0;
  ll bat=N,ans=0;
  rep(i,M){
    bat-=a[i]-b[i];
    if(bat<=0){
      ans=1;
    }
    bat+=b[i+1]-a[i];
    bat=min(bat,N);
  }
  bat-=T-b[M];
  if(bat<=0){
    ans=1;
  }
  if(ans){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int k;
unordered_map<int, int> s,t, rest;

int winTaka(int taka, int aoki, unordered_map<int, int> s, unordered_map<int, int> t) {
  s[taka]++;
  t[aoki]++;
  int total = 0;
  for (int i=1; i<10; i++) {
    int e = int(pow(10, s[i]))-int(pow(10, t[i]));
    total+= i*e;
  }
  return total>0.0;
}

int main() {
  INCANT;
  cin >> k;
  char c;
  rep(i, 5) {
    cin >> c;
    if (i==4) continue;
    s[c-'0']++;
  }
  rep(i, 5) {
    cin >> c;
    if (i==4) continue;
    t[c-'0']++;
  }

  rep(i, 9) {
    int num = i+1;
    rest[num] = k-s[num]-t[num];
  }
  double denominator = 9*k-8;
  double coeffient;
  double ans = 0.0;
  for(int i=1; i<10; i++) {
    for (int j=1; j<10; j++) {
      if (i==j && rest[i]-2<0) continue;
      if (rest[i]-1<0) continue;
      if (rest[j]-1<0) continue;
      if (i==j) {
        coeffient = double(rest[i]) * double(rest[i]-1);
      } else {
        coeffient = double(rest[i]) * double(rest[j]);
      }
      coeffient/=denominator;
      coeffient/=(denominator-1);

      ans+=coeffient * winTaka(i, j, s,t);
    }
  }
  cout << ans << "\n";
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <math.h>
#include <string.h>
#include <stdlib.h>

using namespace std;

#if __cplusplus >= 201103L
    #include <unordered_set>
    #include <unordered_map>
    #include <chrono>
    #include <random>
    #include <bits/stdc++.h>
    struct pairhash {
        template<class T, class U>
        size_t operator() (const pair<T,U> &p) const {
            static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
            return splitmix64(p.first + FIXED_RANDOM) ^ splitmix64(p.second+ FIXED_RANDOM);
        }
        static uint64_t splitmix64(uint64_t x) {
            x += 0x9e3779b97f4a7c15;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
            x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
            return x ^ (x >> 31);
        }
    };
    mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

    inline int randint(int l, int r) {
        return uniform_int_distribution<int>(l,r)(rng);
    }

    inline double randdouble(double l, double r) {
        return uniform_real_distribution<double>(l,r)(rng);
    }
#endif

#define fastio ios::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ll128 __int128_t
#define PI 3.14159265358979323846
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a<b)?(b):(a))
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<ll,ll>

template <typename T>
inline void read(T& x) {
    x = 0;
    bool f = 0;
    char ch = (char)getchar();
    while (ch < '0' || ch > '9') {  // ch 不是数字时
        if (ch == '-') f = 1;        // 判断是否为负
        ch = (char)getchar();               // 继续读入
    }
    while (ch >= '0' && ch <= '9') {  // ch 是数字时
        x = x*10 + (ch&15);  // 将新读入的数字’加’在 x 的后面, ch&15等同于ch-'0'
        ch = (char)getchar();  // 继续读入
    }
    if (f) x = -x;
}

template <typename T>
inline void write(T x) {
    static int st[35];
    int top = 0;
    do {
        st[top++] = x % 10; x /= 10;
    } while (x);
    while (top) putchar(st[--top] + '0');
}

const double pi = acos(-1.0);
const double eps = (double)1e-4;

const int mod = 1e9+7;
const int maxn = 1e5+5;
const int maxm = 2e5+10;

int cnt[10];
int a[10], b[10];
int pow10[7];

bool check() {
    int s1 = 0, s2 = 0;
    for (int i = 1; i <= 9; i++) s1 += i * pow10[a[i]];
    for (int i = 1; i <= 9; i++) s2 += i * pow10[b[i]];

    return s1 > s2;
}

int main() {

    int k;
    string s,t; cin >> k >> s >> t;
    for (int i = 1; i <= 9; i++) cnt[i] = k;
    for (char c : s) {
        if (c != '#') cnt[c-'0']--, a[c-'0']++;
    }
    for (char c : t) {
        if (c != '#') cnt[c-'0']--, b[c-'0']++;
    }
    pow10[0] = 1;
    for (int i = 1; i <= 6; i++) pow10[i] = pow10[i-1] * 10;

    double all = 0.0;
    double win = 0.0;

    for (int i = 1; i <= 9; i++) {
        if (cnt[i] == 0) continue;

        cnt[i]--; a[i]++;
        for (int j = 1; j <= 9; j++) {
            if (cnt[j] == 0) continue;

            all += (double)(cnt[i]+1.0) * (double)(cnt[j]);
            b[j]++;
            if (check()) {
                win += (double)(cnt[i] + 1.0) * (double)(cnt[j]);
            }
            b[j]--;
        }
        cnt[i]++; a[i]--;
    }
    double ans = win / all;
    printf("%.10f\n",ans);
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=200005;

int n,a[N],b[N],c[N],t[N];
map<int,priority_queue<int,vector<int>,greater<int> > > pq;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]+=i;
	for(int i=1;i<=n;i++) scanf("%d",&b[i]),b[i]+=i;
	for(int i=1;i<=n;i++) pq[a[i]].push(i);
	for(int i=1;i<=n;i++){
		if(pq[b[i]].empty()){
			cout<<"-1\n";
			return 0;
		}
		int pv=pq[b[i]].top();
		pq[b[i]].pop();
		c[i]=pv;
	}
	LL ans=0LL;
	for(int i=n;i;i--){
		for(int j=c[i];j;j-=(j&-j)) ans+=1LL*t[j];
		for(int j=c[i];j<=n;j+=(j&-j)) t[j]++;
	}
	cout<<ans<<'\n';
	return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
template<class T> struct Fenwick {
    int n;
    T* d;
    Fenwick() : n(0), d(NULL) {}
    Fenwick(int n_) : n(n_) {
	d = new T[n_]();
    }
    Fenwick(const Fenwick &y) : n(y.n) {
	d = new T[n];
	memcpy(d, y.d, sizeof (T) * n);
    }
    ~Fenwick() {
	delete[] d; d = NULL;
	n = 0;
    }
    friend void swap(Fenwick &x, Fenwick &y) {
	swap(x.n, y.n); swap(x.d, y.d);
    }
    Fenwick& operator=(Fenwick y) {
	swap(*this, y);
	return *this;
    }
    inline void add(int i, const T &x) {
	for (; i<n; i|=i+1) d[i] += x;
    }
    inline T sum(int r) const {
	T s = T();
	for (; r; r&=r-1) s += d[r-1];
	return s;
    }
    T sum(int l, int r) const {
	return sum(r) - sum(l);
    }
};

int N;
LL A[200011];
LL B[200011];

bool valid() {
    vector<LL> X(A, A+N);
    vector<LL> Y(B, B+N);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    return X == Y;
}

void MAIN() {
    scanf("%d", &N);
    REP (i, N) scanf("%lld", A+i);
    REP (i, N) scanf("%lld", B+i);

    REP (i, N) {
	A[i] += i;
	B[i] += i;
    }

    if (valid()) {
	map<LL, int> cnt;
	map<pair<LL, int>, int> mp;

	REP (i, N) {
	    int k = cnt[A[i]];
	    mp[make_pair(A[i], k)] = i;
	    cnt[A[i]]++;
	}

	cnt.clear();
	LL ans = 0;
	Fenwick<int> F(N);
	REP (i, N) {
	    int k = cnt[B[i]];
	    int pos = mp[make_pair(B[i], k)];
	    cnt[B[i]]++;
	    ans += F.sum(pos, N);
	    F.add(pos, 1);
	}
	printf("%lld\n", ans);
    } else {
	puts("-1");
    }

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

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

    char c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    if(c1==c2 && c2==c3) cout << "Won" << endl;
    else cout << "Lost" << endl;
}

#include <cstdio>
#include <algorithm>

using namespace std;

int a[100000];

void solve() {
    int n, i;

    scanf("%d", &n);

    for (i = 0; i < n; i++) scanf("%d", &a[i]);

    sort(a, a + n);

    if (n % 2 == 0) {
        for (i = 0; i < n; i += 2) {
            if (a[i] != a[i + 1]) break;
        }

        if (i < n) {
            puts("First");
        } else {
            puts("Second");
        }
    } else {
        puts("Second");
    }
}

int main() {
    int t, i;

    scanf("%d", &t);

    for (i = 0; i < t; i++) solve();

    return 0;
}


#include <memory.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
ll n, minv[200111], maxv[200111];
ll reachMinv[200111], reachMaxv[200111];
vector<ll> ids;
int main(void) {
	scanf("%lld", &n);
	for (ll i = 0; i <= n + 1; i++) {
		minv[i] = 9e18;
		maxv[i] = -9e18;
	}
	ll lastV = -1;
	ids.push_back(0);
	for (ll i = 1; i <= n; i++) {
		ll a, b; scanf("%lld %lld", &a, &b);

		ids.push_back(b);

		minv[b] = min(minv[b], a);
		maxv[b] = max(maxv[b], a);
	}
	ids.push_back(n + 1);

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

	minv[0] = maxv[0] = minv[ids.back()] = maxv[ids.back()] = 0;
	reachMinv[0] = reachMaxv[0] = 0;
	for (ll i = 1; i < ids.size(); i++) {
		ll curi = ids[i];
		ll prei = ids[i - 1];

		ll minToMax = reachMinv[prei] + (maxv[prei] - minv[prei]);
		ll maxToMin = reachMaxv[prei] + (maxv[prei] - minv[prei]);

		reachMinv[curi] = min(
			minToMax + abs(maxv[prei] - minv[curi]),
			maxToMin + abs(minv[prei] - minv[curi])
		);
		reachMaxv[curi] = min(
			minToMax + abs(maxv[prei] - maxv[curi]),
			maxToMin + abs(minv[prei] - maxv[curi])
		);
	}

	printf("%lld\n", reachMinv[ids.back()]);
}

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

#define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++)
#define rfor(i, a, b) for (int i = (int) a ; i >= b ; i--)

#define vec vector
#define PB push_back

#define MP make_pair
#define MT make_tuple
#define F first
#define S second

using ll = long long int; // watch out for overflows in your code
using pii = pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void debug() { cout << "\n"; };
template <typename T, typename... Targs>
void debug(T t, Targs... args) {
    cout << t << " ";
    debug(args...);
}

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

template <typename T>
inline ostream& operator << (ostream& os, const vec<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const vec<vec<T>>& m) {
    for(auto& v : m) {
        for(auto& t : v) {
            os << t << " ";
        }
        os << "\n";
    }
    return os;
}

template <typename T>
inline ostream& operator << (ostream& os, const set<T>& v) {
    for(auto& t : v) {
        os << t << " ";
    }
    return os;
}

template <typename K, typename V>
inline ostream& operator << (ostream& os, const map<K,V>& m) {
    for(auto& p : m) {
        os << p.F << " -> " << p.S << "\n";
    }
    return os;
}

const ll INF = 9 * 1e18;

int N;
vec<ll> lo, hi;

ll dist(ll st, ll fn, ll x) {
    return abs(x-st) + abs(st-fn);
}

vec<vec<ll>> dp;

void compute_dp() {
    dp.assign(N+1, vec<ll>(2,0));
    ffor(c, 1, N) {
        if(lo[c] == lo[c-1] && hi[c] == hi[c-1]) {
            dp[c][0] = dp[c-1][0];
            dp[c][1] = dp[c-1][1];
        }
        else {
            dp[c][0] = min(dp[c-1][0] + dist(hi[c], lo[c], lo[c-1]), dp[c-1][1] + dist(hi[c], lo[c], hi[c-1]));
            dp[c][1] = min(dp[c-1][0] + dist(lo[c], hi[c], lo[c-1]), dp[c-1][1] + dist(lo[c], hi[c], hi[c-1]));
        }
    }
}

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

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

    cin >> N;
    lo.assign(N+1, INF);
    hi.assign(N+1, -INF);
    lo[0] = hi[0] = 0;
    ffor(i, 1, N) {
        ll x; int c;
        cin >> x >> c;
        lo[c] = min(lo[c], x);
        hi[c] = max(hi[c], x);
    }

    ffor(c, 1, N) {
        if(lo[c] == INF) lo[c] = lo[c-1];
        if(hi[c] == -INF) hi[c] = hi[c-1];
    }

    compute_dp();
    cout << min(dp[N][0] + abs(lo[N]), dp[N][1] + abs(hi[N])) << "\n";
}


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

struct ios
{
    inline char read()
    {
        static const int IN_LEN = 1e6 + 10;
        static char buf[IN_LEN], *s, *t;
        return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), s == t ? -1 : *s++;
    }
    template <typename _Tp>
    inline ios &operator>>(_Tp &x)
    {
        static char c11, boo;
        for (c11 = read(), boo = 0; !isdigit(c11); c11 = read())
        {
            if (c11 == -1)
                return *this;
            boo |= c11 == '-';
        }
        for (x = 0; isdigit(c11); c11 = read())
            x = x * 10 + (c11 ^ '0');
        boo && (x = -x);
        return *this;
    }
} io;

namespace IO
{
    template <typename T>
    inline void w(T x)
    {
        if (x > 9)
            w(x / 10);
        putchar(x % 10 + 48);
    }
    template <typename T>
    inline void write(T x, char c)
    {
        if (x < 0)
            putchar('-'), x = -x;
        w(x);
        putchar(c);
    }
    template <typename T>
    inline void read(T &x)
    {
        x = 0;
        T f = 1;
        char c = getchar();
        for (; !isdigit(c); c = getchar())
            if (c == '-')
                f = -1;
        for (; isdigit(c); c = getchar())
            x = (x << 1) + (x << 3) + (c ^ 48);
        x *= f;
    }
} // namespace IO

#define int long long
#define x first
#define y second
#define PII pair<int,int>
#define LL long long
#define pb push_back
#define pqp priority_queue<PII,vector<PII>,greater<PII>>
#define pqi priority_queue<int,vector<int>,greater<int>>
#define PSS pair<string,string>
#define in insert
#define line inline
// #define sort(s) sort(s.begin(),s.end());
#define reverse(s) reverse(s.begin(),s.end());
#define max_(s) *max_element(s.begin(), s.end())
#define V vector<int>
#define VV vector<V>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

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

int n;
bool check(int a,int b,int c)
{
    return a * b * c <= n;
}

void solve()
{
    cin >> n;
    int sum = 0;
	for(int i = 1; i <= n; i ++){
	  	  int k = n / i;
	  	  for(int j = 1; j <= k; j++){
	  	  	 sum += (k/j);
		  }
	  }
	  printf("%lld\n",sum);
}

signed main()
{
    // IOS
    // int _; cin >> _; while(_ --)

    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10
using ll = long long;

using P = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
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; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 300000;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error

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

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

    vp tmp(n);

    rep(i, n) {
        cin >> ab[i].fs >> ab[i].sc;
        tmp[i].fs = 2 * ab[i].fs + ab[i].sc;
        tmp[i].sc = i;
    }
    sort(rall(tmp));

    vl ad(n), iad(n + 1);

    ad[0] = (ll)ab[tmp[0].sc].fs + ab[tmp[0].sc].sc;
    rep(i, n - 1) {
        P p = ab[tmp[i + 1].sc];
        ad[i + 1] = ad[i] + p.fs + p.sc;
    }

    iad[n - 1] = ab[tmp[n - 1].sc].fs;
    rep(i, n - 1) {
        P p = ab[tmp[n - 1 - (i + 1)].sc];
        iad[n - 1 - (i + 1)] = iad[n  - (i + 1)] + p.fs;
    }

    rep(i, n) {
        ll a = ad[i];
        ll b = iad[i + 1];
        if (a > b) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    string S;
    cin >> N >> S;
    vvc<ll> A(N + 1, vl(4));
    rep(i, N){
        rep(j, 4) A[i + 1][j] += A[i][j];
        if (S[i] == 'A')
            A[i + 1][0]++;
        else if(S[i] == 'T')
            A[i + 1][1]++;
        else if(S[i] == 'C')
            A[i + 1][2]++;
        else
            A[i + 1][3]++;
    }

    ll ans = 0;
    rep(i, N) repe(j, i + 1, N + 1){
        vl cnt(4);
        rep(k, 4) cnt[k] = A[j][k] - A[i][k];
        if (cnt[0] == cnt[1] and cnt[2] == cnt[3]) ans++;
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define dump_1(x1) cerr << #x1 << ": " << x1 << endl
#define dump_2(x1, x2) \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define dump_3(x1, x2, x3)                                                \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << endl
#define dump_4(x1, x2, x3, x4)                                            \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << endl
#define dump_5(x1, x2, x3, x4, x5)                                        \
  cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
       << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define dump(...) \
  CHOOSE((__VA_ARGS__, dump_5, dump_4, dump_3, dump_2, dump_1, ~))(__VA_ARGS__)
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using namespace std;

using ll = long long;

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

vector<bool> s(200001, false);

void solve(ll N, std::vector<ll> p) {
  vector<ll> ans(N);

  int mj = 0;

  rep(i, N) {
    s.at(p.at(i)) = true;

    int j = mj;
    while (j < N) {
      if (!s.at(j)) break;
      j++;
    }
    mj = j;

    ans.at(i) = j;
  }

  rep(i, N) cout << ans.at(i) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  std::vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  solve(N, std::move(p));
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
struct UnionFind {
    int n;
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> group,sm;
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
        n=N;
        sm.resize(n,1);
    }
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    int size(int x){
        return sm[root(x)];
    }
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        sm[ry]+=sm[rx];
        sm[rx]=0;
    }
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
signed main(){
  int h,w;cin>>h>>w;
  UnionFind tree(h+w+10);
  vector<string> s(h);
  rep(i,h)cin>>s[i];
  s[0][0]='#';
  s[h-1][0]='#';
  s[0][w-1]='#';
  s[h-1][w-1]='#';
  rep(i,h)rep(j,w)if(s[i][j]=='#')tree.unite(i,h+j);
  int res=inf;
  int sm=0;
  set<int> st;
  rep(i,h){
      if(!tree.same(0,i)){
          if(st.find(tree.root(i))==st.end()){
              st.insert(tree.root(i));
              ++sm;
          }
      }
  }
  res=min(res,sm);
  sm=0;
  set<int> st2;
  rep(i,w){
      if(!tree.same(0,h+i)){
          if(st2.find(tree.root(h+i))==st2.end()){
              st2.insert(tree.root(h+i));
              ++sm;
          }
      }
  }
  res=min(res,sm);
  cout<<res<<"\n";
  return 0;
}

#include <bits/stdc++.h>

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

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

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

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

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

const ll MOD = 998244353;
struct MLL {
  ll x, mod;
  MLL(ll y=0, ll m=MOD) { x = y; mod = m; }

  MLL &operator+= (const MLL &p) { x = (x+p.x)%mod;       return *this; }
  MLL &operator-= (const MLL &p) { x = (x-p.x+mod)%mod;   return *this; }
  MLL &operator*= (const MLL &p) { x = (x*p.x)%mod;       return *this; }
  MLL &operator/= (const MLL &p) { x = (x*p.inv().x)%mod; return *this; }
  MLL  operator+  (const MLL &p) const { return MLL(*this)+=p; }
  MLL  operator-  (const MLL &p) const { return MLL(*this)-=p; }
  MLL  operator*  (const MLL &p) const { return MLL(*this)*=p; }
  MLL  operator/  (const MLL &p) const { return MLL(*this)/=p; }
  bool operator== (const MLL &p) const { return x==p.x; }
  bool operator!= (const MLL &p) const { return x!=p.x; }
  bool operator<  (const MLL &p) const { return x< p.x; }
  bool operator<= (const MLL &p) const { return x<=p.x; }
  bool operator>  (const MLL &p) const { return x> p.x; }
  bool operator>= (const MLL &p) const { return x>=p.x; }
  MLL pow(MLL n) const { MLL result(1), p(x); ll tn = n.x; while(tn){ if (tn&1) result*=p; p*=p; tn>>=1; } return result; }
  MLL inv() const { return pow(MOD-2); }
};

MLL operator+ (ll x, MLL p) { return (MLL)x+p; }
MLL operator- (ll x, MLL p) { return (MLL)x-p; }
MLL operator* (ll x, MLL p) { return (MLL)x*p; }
MLL operator/ (ll x, MLL p) { return (MLL)x/p; }

vector<MLL> fac;
void c_fac(ll x=pow(10,7)+10) { fac.resize(x); rep(i,x) fac[i] = i ? fac[i-1]*i : 1; }
MLL nck(MLL n, MLL k) { return fac[n.x]/(fac[k.x]*fac[(n-k).x]); };

ostream &operator<< (ostream &ost, const MLL &p) { return ost << p.x; }
istream &operator>> (istream &ist, MLL &p) { return ist >> p.x; }

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

int main() {
  ll H, W, K; cin >> H >> W >> K;
  ll pos[H][W] = {};
  rep(i,K) {
    ll h, w; cin >> h >> w; h--; w--;
    char c; cin >> c;
    if (c=='R') pos[h][w] = 1;
    if (c=='D') pos[h][w] = 2;
    if (c=='X') pos[h][w] = 3;
  }
  // rep(i,H) debug(pos[i],pos[i]+W);

  MLL dp[H][W] = {}; dp[0][0] = 1;
  MLL m3 = 3, inv3 = m3.inv();
  rep(i,H) rep(j,W) {
    if (i!=H-1) {
      if (pos[i][j]==0) dp[i+1][j] += dp[i][j]*2*inv3;
      if (pos[i][j]==1) dp[i+1][j] += dp[i][j]*0;
      if (pos[i][j]==2) dp[i+1][j] += dp[i][j]*1;
      if (pos[i][j]==3) dp[i+1][j] += dp[i][j]*1;
    }
    if (j!=W-1) {
      if (pos[i][j]==0) dp[i][j+1] += dp[i][j]*2*inv3;
      if (pos[i][j]==1) dp[i][j+1] += dp[i][j]*1;
      if (pos[i][j]==2) dp[i][j+1] += dp[i][j]*0;
      if (pos[i][j]==3) dp[i][j+1] += dp[i][j]*1;
    }
  }
  // rep(i,H) debug(dp[i],dp[i]+W);

  MLL result = dp[H-1][W-1]*m3.pow(H*W-K);
  cout << result << endl;
  return 0;
}


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

int main()
{
    long long n; cin >> n;
    vector<long long> d_s, d_l;
    long long i = 1;
    while(i*i < n)
    {
        if (n % i == 0)
        {
            d_s.push_back(i);
            d_l.push_back(n / i);
        }
        i++;
    }
    if (i * i == n) d_s.push_back(i);

    reverse(d_l.begin(), d_l.end());
    for (auto d: d_s) cout << d << endl;
    for (auto d: d_l) cout << d << endl;
    return 0;
}

// author: xay5421
// created: Sat Dec 26 19:58:52 2020
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	rep(i,1,n){
		printf("%d %d\n",(i*2-1)%n+1,i*2%n+1);
	}
	return 0;
}


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

int h[30][29], v[29][30], hc[30][29], vc[29][30];
int si, sj, ti, tj, prev_si, prev_sj, prev_ti, prev_tj;
int prev_result;
int i=0, j=0;

int border=1;
int repeat_count=1000;

string query(int si, int sj, int ti, int tj){
 string path;
 while(si!=ti || sj!=tj){
  if(si==ti){
   if(sj<tj){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"L";
    sj--;
   }
  }
  else if(sj==tj){
   if(si<ti){
    path=path+"D";
    si++;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //左上
  else if(si<ti && sj<tj){
   if(hc[si][sj]<border || vc[si][sj]<border){
    if(hc[si][sj]<vc[si][sj]){
     path=path+"R";
     sj++;
    }
    else{
     path=path+"D";
     si++;
    }
   }
   else if(h[si][sj]<v[si][sj]){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"D";
    si++;
   }
  }
  //左下
  else if(si>ti && sj<tj){
   if(hc[si][sj]<border || vc[si-1][sj]<border){
    if(hc[si][sj]<vc[si-1][sj]){
     path=path+"R";
     sj++;
    }
    else{
     path=path+"U";
     si--;
    }
   }
   else if(h[si][sj]<v[si-1][sj]){
    path=path+"R";
    sj++;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //右下
  else if(si>ti&& sj>tj){
   if(hc[si][sj-1]<border || vc[si-1][sj]<border){
    if(hc[si][sj-1]<vc[si-1][sj]){
     path=path+"L";
     sj--;
    }
    else{
     path=path+"U";
     si--;
    }
   }
   else if(h[si][sj-1]<v[si-1][sj]){
    path=path+"L";
    sj--;
   }
   else{
    path=path+"U";
    si--;
   }
  }
  //右上
  else{
   if(hc[si][sj-1]<border || vc[si][sj]<border){
    if(hc[si][sj-1]<vc[si][sj]){
     path=path+"L";
     sj--;
    }
    else{
     path=path+"D";
     si++;
    }
   }
   else if(h[si][sj-1]<v[si][sj]){
    path=path+"L";
    sj--;
   }
   else{
    path=path+"D";
    si++;
   }
  }
 }
 return path;
}

void sethv(int prev_si, int prev_sj, string prev_path, int prev_result){
 int delta=(int)round(prev_result/prev_path.length())-5000;
 while(prev_path.empty()==0){
  if(prev_path[0]=='R'){
   h[prev_si][prev_sj]=(int)round((h[prev_si][prev_sj]*hc[prev_si][prev_sj]+delta)/(hc[prev_si][prev_sj]+1));
   hc[prev_si][prev_sj]++;
   prev_sj++;
  }
  else if(prev_path[0]=='D'){
   v[prev_si][prev_sj]=(int)round((v[prev_si][prev_sj]*vc[prev_si][prev_sj]+delta)/(vc[prev_si][prev_sj]+1));
   vc[prev_si][prev_sj]++;
   prev_si++;
  }
  else if(prev_path[0]=='L'){
   h[prev_si][prev_sj-1]=(int)round((h[prev_si][prev_sj-1]*hc[prev_si][prev_sj-1]+delta)/(hc[prev_si][prev_sj-1]+1));
   hc[prev_si][prev_sj-1]++;
   prev_sj--;
  }
  else{
   v[prev_si-1][prev_sj]=(int)round((v[prev_si-1][prev_sj]*vc[prev_si-1][prev_sj]+delta)/(vc[prev_si-1][prev_sj]+1));
   vc[prev_si-1][prev_sj]++;
   prev_si--;
  }
  prev_path.erase(0, 1);
 }
}

void read_s_t(){
  cin>>si;
  cin>>sj;
  cin>>ti;
  cin>>tj;
}

void set_prev_s_t(){
 prev_si=si;
 prev_sj=sj;
 prev_ti=ti;
 prev_tj=tj;
}

void read_result(){
 cin>>prev_result;
}

int main(){
 //h初期化
 for(i=0; i<=29; i++){
  for(j=0; j<=28; j++){
   h[i][j]=0;
   hc[i][j]=0;
  }
 }
 //v初期化
 for(i=0; i<=28; i++){
  for(j=0; j<=29; j++){
   v[i][j]=0;
   vc[i][j]=0;
  }
 }

 for(i=0; i<repeat_count; i++){
  read_s_t();
  set_prev_s_t();
  string path=query(si, sj, ti, tj);
  cout<<path<<"\n"<<flush;
  read_result();
  sethv(prev_si, prev_sj, path, prev_result);
 }
 return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sc(x) scanf("%lld",&(x));
#define pb push_back
#define fi first
#define se second
#define P pair<int,int>

int qp(int x,int n,int mod){
    int ans = 1;
    while(n){
        if(n&1){
            ans = (ans * x)%mod;
        }
        n >>= 1;
        x = (x*x)%mod;
    }
    return ans;
}
int n;
int A[34][34];
void init(){
    A[0][1] = 1;
    A[1][0] = 1;
    for(int i = 0; i <= 30; i++){
        A[i][0] = 1;
        A[0][i] = 1;
    }
    A[0][0] = 0;
    for(int i = 1; i <= 30; i++){
        for(int j = 1; j <= 30; j++){
            A[i][j] = A[i-1][j] + A[i][j-1];
        }
    }

}
signed main() {
    int a,b,k;
    init();

    sc(a)sc(b)sc(k)
    while(a > 0 || b > 0){
        if(a == 0){
            cout << 'b';
            b--;
        }else if(b == 0){
            cout << 'a';
            a--;
        }else if(A[a-1][b] >= k){
            cout << 'a';
            a --;
        }else{
            k -= A[a-1][b];
            cout << 'b';
            b--;
        }
    }
    return 0;
}