#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define prl(a) cout << (a) << endl
#define allrange(a) a.begin(),a.end()

bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
    int N = S.size();
    int dx = S[0].first-T[0].first;
    int dy = S[0].second-T[0].second;
    bool flg = true;
    reps(i,1,N){
        if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
    }
    return flg;
}
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
    int N = S.size();
    vector<pair<int,int>> PS(N);
    auto pt0 = S[0];
    PS[0] = pt0;
    bool flg = true;
    int dx,dy,x,y;
    reps(i,1,N){
        dx = S[i].first - pt0.first;
        dy = S[i].second - pt0.second;
        x=dx*a-dy*b;
        y=dx*b+dy*a;
        if(((x%c)!=0) || ((y%c)!=0)) {flg = false; break;}
        PS[i] = make_pair(x/c+pt0.first, y/c+pt0.second);
    }
    if(flg) return PS;
    else return vector<pair<int,int>>();
}

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

    vector<pair<int,int>> S(N),T(N);
    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        S[i].first = x;S[i].second = y;
    }

    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        T[i].first = x;
        T[i].second = y;
    }
    sort(allrange(T));

/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
    constexpr int tri[12][3] ={
    {3,4,5},
    {4,3,5},
    {-3,4,5},
    {-4,3,5},
    {0,1,1},
    {1,0,1},
    {-1,0,1},
    {0,-1,1},
    {-3,-4,5},
    {-4,-3,5},
    {3,-4,5},
    {4,-3,5}
    };

 /*
    vector<vector<int>> tri(0);
    tri.push_back(vector<int>({3,4,5}));
    tri.push_back(vector<int>({4,3,5}));
    tri.push_back(vector<int>({-3,4,5}));
    tri.push_back(vector<int>({-4,3,5}));
    tri.push_back(vector<int>({0,1,1}));
    tri.push_back(vector<int>({1,0,1}));
    tri.push_back(vector<int>({-1,0,1}));
    tri.push_back(vector<int>({0,-1,1}));
    tri.push_back(vector<int>({-3,-4,5}));
    tri.push_back(vector<int>({-4,-3,5}));
    tri.push_back(vector<int>({3,-4,5}));
    tri.push_back(vector<int>({4,-3,5}));
 //   tri.push_back(vector<int>({-5, -12, 13}));
 //   tri.push_back(vector<int>({-12, -5, 13}));
 //   tri.push_back(vector<int>({-8,-15,17}));
 //   tri.push_back(vector<int>({-15,-8,17}));
 //   tri.push_back(vector<int>({5, 12, 13}));
 //   tri.push_back(vector<int>({12, 5, 13}));
 //   tri.push_back(vector<int>({8,15,17}));
 //   tri.push_back(vector<int>({15,8,17}));
 //   tri.push_back(vector<int>({-5, 12, 13}));
 //  tri.push_back(vector<int>({-12, 5, 13}));
  //  tri.push_back(vector<int>({-8,15,17}));
  //  tri.push_back(vector<int>({-15,8,17}));
 //   tri.push_back(vector<int>({5, -12, 13}));
 //   tri.push_back(vector<int>({12, -5, 13}));
 //   tri.push_back(vector<int>({8,-15,17}));
 //   tri.push_back(vector<int>({15,-8,17}));

 */
    bool flg;

    if(N==2){
        auto sx = S[0].first-S[1].first;
        auto sy = S[0].second-S[1].second;
        auto tx = T[0].first-T[1].first;
        auto ty = T[0].second-T[1].second;
        flg= (sx*sx+sy*sy==tx*tx+ty*ty);
    } else {
        rep(j,12){
            auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
            if(S2.empty()) continue;
            sort(allrange(S2));
            flg = solve_translated(S2,T);
            if(flg) break;
        }
    }
    if(flg) prl("Yes"); else prl("No");
}

#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007

int main() {
    FIN;
    ll n; cin >> n;
    vector<ll> v(n);
    forn(i,n) cin >> v[i];
    sort(all(v));
    ll ans=(n*(n+1))/2, curr=1;
    forr(i,1,n)
    {
		if(v[i]==v[i-1])
		{
			curr++;
		}
		else
		{
			ans-=(curr*(curr+1))/2;
			curr=1;
		}
	}
	ans-=(curr*(curr+1))/2;
	cout << ans << "\n";
	return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())

#ifdef LOCAL
#include <print.h>
#else
#define trace(...)
#endif

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); // Remove in interactive problems
	int n; cin >> n;
	vector<int> dp(n + 1, 1);
	for(int i = 1; i <= n; i++){
		for(int j = 2 * i; j <= n; j += i) dp[j] = max(dp[j], dp[i] + 1);
		cout << dp[i] << " ";
	}
	cout << endl;
}

#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
int main(void){
	long long n,i;
	cin >> n;
	vector<long long> a;
	a.resize(n+1);
	a.assign(n+1,-1);
	a[1] = 1;
	for(i=2;i<=n;i++) {
		if(a[i] == -1) {
			long long j;
			for(j=i*2;j<=n;j+=i) a[j] = -2;
			a[i] = 2;
		}
	}
	for(i=4;i<=n;i++) {
		if(a[i] == -2){
			if(i%2==0) a[i] = a[i/2]+1;
			else {
				long long j;
				for(j=3;j*j<=i;j+=2) {
					if(i%j==0){
						a[i] = a[i/j]+1;
						break;
					}
				}
			}
		}
	}
	for(i=1;i<n;i++) cout << a[i] << " ";
	cout << a[n] << '\n';
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, a[110], b[110];
bool d[210];
bool bl[210];
pair<int, int> p[210];

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i];
	for (int i = 0; i < n; i++) {
		if (0 < a[i] && 0 < b[i] && a[i] >= b[i]) {
			cout << "No" << endl;
			return 0;
		}
		if ((0 < a[i] && bl[a[i]]) || (0 < b[i] && bl[b[i]])) {
			cout << "No" << endl;
			return 0;
		}
		if (0 < a[i]) {
			bl[a[i]] = true;
			p[a[i]] = make_pair(i, 1);
		}
		if (0 < b[i]) {
			bl[b[i]] = true;
			p[b[i]] = make_pair(i, 2);
		}
	}
	d[0] = true;
	for (int i = 0; i < 2 * n; i++) {
		if (!d[i])continue;
		for (int j = i + 2; j <= 2 * n; j += 2) {
			bool bo = true;
			for (int k = 0; k < n; k++)if (0 < a[k] && 0 < b[k] && (a[k] <= i && i < b[k] && b[k] <= j) || (i < a[k] && a[k] <= j && j < b[k]))bo = false;
			int q = (j - i) / 2;
			for (int k = i + 1; k <= i + q; k++) {
				if (p[k].second&&p[k + q].second) {
					if (p[k].first != p[k + q].first)bo = false;
				}
				else if (p[k].second) {
					if (p[k].second == 2)bo = false;
				}
				else if (p[k + q].second) {
					if (p[k + q].second == 1)bo = false;
				}
			}
			if (bo)d[j] = true;
		}
	}
	if (d[2 * n])cout << "Yes" << endl;
	else cout << "No" << endl;
}

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 210;
#define int ll
const long double pi = 3.14159265358979323846;

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
    exit(0);
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<Pll> v(2 * n, {-1, -1});
    rep(i, 0, n) {
        ll a,b; cin >> a >> b;
        if(a != -1){
            a--;
            if (v[a] != Pll{-1, -1}) YES(false);
            v[a] = {0, i};
        }
        if(b != -1){
            b--;
            if (v[b] != Pll{-1, -1}) YES(false);
            v[b] = {1, i};
        }
        if(a != -1 && b != -1){
            if (a > b) YES(false);
        }
    }

    // [l, r]の区間を正しく補完できるかチェック
    auto check = [&](ll l, ll r) {
        if (l & 1) return false;
        if (~r & 1) return false;

        ll len = (r - l + 1) / 2;
        bool res = true;

        rep(i, l, r + 1){
            ll j;
            if (i <= (l + r) / 2) {
                j = i + len;
                res &= v[i].first != 1;
                if(v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}){
                    res &= v[j].first == 1 && v[i].second == v[j].second;
                }
            } else {
                j = i - len;
                res &= v[i].first != 0;

                if (v[i] != Pll{-1, -1} && v[j] != Pll{-1, -1}) {
                    res &= v[j].first == 0 && v[i].second == v[j].second;
                }
            }
        }

        if (res) debug(l, r);
        return res;
    };

    bitset<n_max> dp(0);
    rep(i,0,2 * n){
        if (~i & 1) continue;

        rep(j, 0, i) {
            if (!dp[j]) continue;
            if (check(j + 1, i)){
                dp[i] = 1;
                break;
            }
        }
        if (check(0, i)) dp[i] = 1;
    }
    debug(dp);
    YES(dp[2 * n - 1]);
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	int N = 0;
	int x[100000];

	unsigned long int M = 0;
	double E = 0;
	double u = 0;
	unsigned long int C = 0;

	int i;

	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%d", x + i);
	}

	for (int i = 0; i < N; i++)
	{
		M = M + abs(x[i]);
	}

	for (int i = 0; i < N; i++)
	{
		E = x[i];
		E = E * E;
		u = u + E;
	}
	u = sqrtl(u);

	C = abs(x[0]);

	for (int i = 1; i < N; i++)
	{
		if (C < abs(x[i]))
		{
			C = abs(x[i]);
		}
	}

	printf("%15ld\n", M);
	printf("%.15f\n", u);
	printf("%15ld\n", C);
	return 0;
}

#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    long long n, man = 0, yuk = 0, tye = 0; cin >> n;

    vector<int> a(n);
    for(int i = 0; i < n; i++){
        int b = 0;
        cin>>b;
        if(b<=0) b = -b;
        a.at(i) = b;
    }
    for(long long e : a){
        man += e;
        yuk += e*e;
        tye = max(tye, e);
    }
    long double yukans = (long double)sqrt(yuk);
    cout << man << endl;
    cout << setprecision(20) << yukans << endl;
    cout << tye << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,a,n) for (int i=a;i<n;i++)
const int  MOD = 1e9+7;

void solve() {
	int n; cin >> n;
	vector<int> v(n);
	rep(i,0,n) {
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	if(n%2==1) {
		cout << "Second" << endl;
	}
	else {
		bool b = true;
		for(int i = 0; i <n; i+=2) {
			if (v[i] != v[i+1]) {
				b = false;
				break;
			}
		}
		(b) ? cout << "Second"<<endl: cout << "First"<<endl;
	}

}

int main() {
	std:ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
#define itn int
#define sacnf scanf
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 3e5 + 1;

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> v(n + 1);
	for (int i = 0; i < n; i++)
	{
		int a;
		scanf("%d", &a);
		v[a]++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (v[i] != 1) return printf("No"), 0;
	}
	printf("Yes");
	return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    ll mod = m * m;
    ll ans = 1, temp = 10 % mod;
    while (n) {
        if (n & 1) {
            ans *= temp;
            ans = ans % mod;
        }
        n >>= 1;
        temp = temp * temp % mod;
    }
    cout << ans / m << endl;
    return 0;
}

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

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) (v).begin() , (v).end() , comp

# define ll long long

# define line cout << "\n" ;
# define fast ios_base :: sync_with_stdio ( false ) ; cin.tie ( 0 ) ;

# define pii pair < int , int >
# define pll pair < ll , ll >

# define F first
# define S second

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

ll n , m , mod ;

ll mult ( ll a , ll b )
{
    a *= b ;
    a %= mod ;

    return a ;
}

int mod_pow ( ll a , ll b )
{
//    cout << "a : " << a << " and b : " << b ; line ;
//    getchar() ;

    if ( b == 0 ) return 1 ;
    if ( b == 1 ) return a%mod ;
    if ( b == 2 ) return mult ( a , a ) ;

    return mult ( mod_pow ( mod_pow ( a , b/2 ) , 2 ) , mod_pow ( a , b%2 ) ) ;
}

void solve ( int test_case )
{
    cin >> n >> m ;
    mod = m * m ;

//    cout << "mod : " << mod ; line ;
//    cout << "n : " << n ; line ;

    ll ans = mod_pow ( 10 , n ) ;
//    cout << "ans : " << ans ; line ;

    ans /= m ;
    ans %= m ;

    cout << ans ; line ;
}

int main()
{
    int t = 1 ;
    // cin >> t ;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0 ;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    string S,T; cin>>S>>T;
    queue<int> v1,v2;
    rep(i,N)if(S[i]=='1') v1.push(i);
    rep(i,N)if(T[i]=='1') v2.push(i);

    ll ans=0;
    {
        int t = (v2.empty()) ? N : v2.front();
        while(!v1.empty()){
            if (v1.front()<t){
                if (v1.size()<2){
                    cout<<"-1\n";
                    return 0;
                }
                int x = v1.front(); v1.pop();
                int y = v1.front(); v1.pop();
                ans+=y-x;
            }else{
                int x = v1.front(); v1.pop();
                ans+=x-t;
                v2.pop();
                t = (v2.empty()) ? N : v2.front();
            }
        }
        if (!v2.empty()){
            cout<<"-1\n";
            return 0;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
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 FOR(i, l, r) for (int i = (l); i < (r); ++i)
#define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<ll, ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1; // 1073741824 - 1
// static const ll INF = (1LL << 60) - 1;  // 4611686018427387904 - 1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

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

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

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

    int ans = 1;
    double total = 0;
    REP(i, n) {
        double v, p;
        cin >> v >> p;
        total += v * p;
        if (total > x * 100) {
            break;
        }
        ans++;
    }
    if (ans > n) {
        ans = -1;
    }
    COUT(ans);
    return 0;
}


//Hello,I'm Mitsubachi.
//This is a test. This code is made by my friend's macbook.

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

using ll = long long;
#define fi first
#define se second

int main(){
  int n;
  cin>>n;
  ll a[n],b[n];
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    ans+=a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  vector<ll> even,odd;
  for(int i=0;i<n;i++){
    if(i%2==0){
      even.push_back(b[i]-a[i]);
    }
    else{
      odd.push_back(b[i]-a[i]);
    }
  }
  sort(even.begin(),even.end());
  reverse(even.begin(),even.end());
  sort(odd.begin(),odd.end());
  reverse(odd.begin(),odd.end());
  ll answer=ans;
  for(int i=0;i<n/2;i++){
    ans+=even[i]+odd[i];
    answer=max(answer,ans);
  }
  cout<<answer<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}
#ifdef LOCAL
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cerr<<(*i)<<" ";cerr<<endl;}
#else
template<class T>void pv(T a,T b){}
#endif

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll INF = 1LL << 61;
const int MAX_N = 112345;
ll dp[MAX_N][3];

int main2() {

  int N = nextLong();
  vector<ll> A(N), B(N);
  REP(i, N) A[i] = nextLong();
  REP(i, N) B[i] = nextLong();

  ll s = accumulate(ALL(A), 0LL);

  vector<ll> c0, c1;
  REP(i, N) {
    if (i % 2 == 0) c0.push_back(B[i] - A[i]);
    if (i % 2 == 1) c1.push_back(B[i] - A[i]);
  }
  sort(ALL(c0)); reverse(ALL(c0));
  sort(ALL(c1)); reverse(ALL(c1));

  ll ans = s;
  REP(i, c0.size()) {
    ll gain = c0[i] + c1[i];
    if (gain > 0) ans += gain;
    else break;
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


#include<set>
#include<map>
#include<stack>
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
const int MAXN=500000;
const int INF=0x3f3f3f3f;
const int Mod=998244353;
#define mp make_pair
int n,m;
vector<pair<int,int> > G[MAXN+5];
int a[MAXN+5],b[MAXN+5],c[MAXN+5],ans[MAXN+5];
void DFS(int u,int fa){
	for(int i=0;i<(int)G[u].size();i++){
		int v=G[u][i].first,id=G[u][i].second;
		if(ans[id]||v==fa) continue;
		if(a[id]==u) ans[id]=1;
		else ans[id]=2;
		DFS(v,u);
	}
	return ;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		a[i]=read(),b[i]=read();
		G[a[i]].push_back(mp(b[i],i));
		G[b[i]].push_back(mp(a[i],i));
	}
	for(int i=1;i<=n;i++)
		c[i]=read();
	for(int i=1;i<=m;i++){
		if(c[a[i]]>c[b[i]])
			ans[i]=1;
		else if(c[a[i]]<c[b[i]])
			ans[i]=2;
	}
	for(int i=1;i<=n;i++)
		DFS(i,-1);
	for(int i=1;i<=m;i++)
		puts(ans[i]==1?"->":"<-");
    return 0;
}

#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k;
    std::cin >> n >> k;
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        std::cin >> u >> v;
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int l = 0, r = n - 1;
    while (l < r) {
        int m = (l + r) / 2;
        int count = 0;
        std::function<int(int, int)> dfs = [&](int u, int p) {
            int x = 0;
            for (auto v : e[u]) {
                if (v == p) {
                    continue;
                }
                int y = dfs(v, u) + 1;
                if (x + y < 0) {
                    x = std::min(x, y);
                } else {
                    x = std::max(x, y);
                }
            }
            if (x == m) {
                x = -m - 1;
                count++;
            }
            return x;
        };
        if (dfs(0, -1) >= 0) {
            count++;
        }
        if (count <= k) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    std::cout << l << "\n";
    return 0;
}


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

    int main() {
      float a,b;
      float c;
      cin >> a >> b;

      c=(b/100)*a;
      cout << c << endl;
    }

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; }
template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; }
inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; }
inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

//#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

const int INF = (1<<30)-1;
const long long LINF = 1LL<<60;
const double EPS = 1e-9;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int dx[8] = {-1,0,1,0,1,-1,1,-1};
const int dy[8] = {0,1,0,-1,1,-1,-1,1};

//-------------------------- Libraries --------------------------//

//--------------------------- Solver ----------------------------//

void solve() {
    int a,b;
    cin >> a >> b;
    cout << (double)a*b/100 << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int t = 1;
    //cin >> t;
    while (t--) solve();

    return 0;
}


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

long long next(long long x)
{
  string s1 = to_string(x);
  sort(s1.begin(), s1.end());
  string s2 = s1;
  reverse(s2.begin(), s2.end());
  return stoll(s2) - stoll(s1);
}

long long rec(long long n, int i, int k)
{
  if (i == k)
  {
    return n;
  }
  return rec(next(n), i + 1, k);
}

int main()
{
  long long n, k;
  cin >> n >> k;
  cout << rec(n, 0, k) << endl;
}

#include<iostream>
#include<sstream>

using namespace std;

int main() {
	long long n,k;
	cin >> n >> k;
	while(k--){
		if(n % 200 == 0){
			n/=200;
		}else{
			string str = "";
			stringstream ss;
			ss << n;
			ss >> str;
			str += "200";
			stringstream ss1;
			ss1 << str;
			ss1 >> n;
		}
	}
	cout << n;
	return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define pi 3.14159265358979
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
void chmax(int &x,int y){x=max(x,y);}
void chmin(int &x,int y){x=min(x,y);}

int ma=310;
ll mod=998244353;
ll f(ll n=mod-2){
  if(n==0)return 1;
  if(n==1)return 2;
  if(n%2)return 2*f(n-1)%mod;
  ll res=f(n/2);
  return res*res%mod;
}

int main(){
  cci(n,k);
  vll v(n);
  rep(i,0,n)ci(v[i]);

  V<vll> nck(ma,vll(ma,0));
  nck[0][0]=1;
  rep(i,0,ma-1){
    rep(j,0,i+1){
      ll now=nck[i][j];
      (nck[i+1][j]+=now)%=mod;
      (nck[i+1][j+1]+=now)%=mod;
    }
  }

  V<vll> vx(k+1,vll(n,1));
  vll All(k+1,0);
  rep(x,1,k+1){
    ll now=0;
    rep(i,0,n){
      now+=vx[x][i]=vx[x-1][i]*v[i]%mod;
      now%=mod;
    }
    All[x]=now;
  }

  ll inv2=f();
  rep(x,1,k+1){
    ll ans=0;
    rep(i,1,x){
      ll now=All[i]*All[x-i]%mod;
      (now*=nck[x][i])%=mod;
      (ans+=now)%=mod;
    }
    (ans*=inv2)%=mod;
    (ans+=(n-f(x-1))*All[x]%mod+mod)%=mod;
    co(ans);
  }
}

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int n, a[N], m, s[400], c[400][400];
const ll mod = 998244353;

ll ksm(ll a, ll b) {
    ll c = 1;
    for (; b; b >>= 1) {
        if (b & 1) c = (ll) c * a % mod;
        a = (ll) a * a % mod;
    }
    return c;
}

int inv2;

int solve(int x) {
    int ans = 0;
    for (int j = 0; j <= x; j++) {
        ans = (ans + 1ll * c[x][j] * (1ll * s[x - j] * s[j] % mod - s[x] + mod) % mod) % mod;
    }
    return 1ll * (ans + mod) % mod * inv2 % mod;
}

int main() {
    inv2 = ksm(2ll, mod - 2) % mod;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
        for (int j = 0, x = 1; j <= m; ++j, x = 1ll * x * a[i] % mod) {
            s[j] = (s[j] + x) % mod;
        }
    }
    c[0][0] = 1;
    for (int i = 1; i <= m; i++) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
    for (int i = 1; i <= m; i++) {
        printf("%d\n", solve(i));
    }
    return 0;
}


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

#define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
#define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--)
#define all(v) v.begin(), v.end()

typedef long long ll;
template <class T> using V = vector<T>;
template <class T> using VV = vector<V<T>>;

/* 提出時これをコメントアウトする */
#define LOCAL true

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    constexpr char endl = '\n';

    int n;
    cin >> n;
    VV<ll> a(n,V<ll>(5));
    rep(i,0,n) {
        rep(j,0,5) cin >> a[i][j];
    }
    V<ll> mx(1<<5);

    rep(i,0,n) {
        rep(j,0,(1<<5)) {
            ll mi = 1e9+7;
            rep(k,0,5) {
                if ((j>>k)&1) {
                    mi = min(mi, a[i][k]);
                }
            }
            mx[j] = max(mx[j], mi);
        }
    }

    ll pow = 3*3*3*3*3;
    ll ans = 0;
    rep(i,0,pow) {
        int num[3] = {};
        int tmp = i;
        rep(j,0,5) {
            num[tmp%3] += (1<<j);
            tmp /= 3;
        }
        ans = max(ans, min({mx[num[0]], mx[num[1]], mx[num[2]]}));
    }

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

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

int main(){
    int n;
    int m=5;

    cin >> n;
    vector<vector<int>> s(n,vector<int>(m));

    rep(i,n)rep(j,m) cin >> s[i][j];

    int l=0; int r=1001001001;
    while(l+1<r){
        int mid = (l+r)/2;
        int x;
        vector<int> b;
        rep(i,n){
            x=0;
            rep(j,m){
                if(s[i][j]>=mid){
                    x|=1<<j;
                }
            }
        b.push_back(x);
        }
        sort(b.begin(),b.end());
        b.erase(unique(b.begin(),b.end()),b.end());
        bool ok=false;
        rep(i,b.size())rep(j,i+1)rep(k,j+1){
            if((b[i]|b[j]|b[k])==(1<<m)-1){
                ok=true;
            }
        }
        if(ok){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << l << endl;
    return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;

    vector<LL> b(N), a(N);
    for(int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < N; ++i) {
        cin >> b[i];
    }

    LL amx = 0;
    LL resmx = 0;
    vector<LL> res;
    for(int i = 0; i < N; ++i) {
        amx = max(a[i], amx);
        resmx = max(amx * b[i], resmx);
        cout << resmx << endl;
    }

    return 0;
}

/**
*
*    created: 16.01.2021 21:01:06
**/

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

int main() {

  ll n,t=0,ma;
  cin >> n;
  vector <unsigned long long>a(n),b(n),c(n);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n){
    cin >> b.at(i);
  }

c.at(0)=a.at(0)*b.at(0);
//cout << c.at(0) << endl;
  ma=a.at(0);
  rep(i,n-1){
    if(ma<a.at(i+1)){
       t=i+1;
       ma=a.at(i+1);
     }
   if(a.at(i+1)>a.at(i)){
     if(b.at(i+1)>b.at(i)){
       c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i));
     }else{
       c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i));
     }

   }else{
     if(b.at(i+1)>b.at(i)){
       c.at(i+1)=max(a.at(t)*b.at(i+1),c.at(i));
       //cout << 888 << endl;
     }else{
       c.at(i+1)=c.at(i);
     }
   }
  }

  rep(i,n)
    cout << c.at(i) << endl;

}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e5+10;
const int INF = 0x7f7f7f7f;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
int n,p,ans=0;
int a[55];
map<pair<signed,int>,int>mp;
int DFS(signed x,int rest)
{
    if(mp[{x,rest}])
        return mp[{x,rest}];
    if(x<=0)
        return 1;
    int fake=rest;
    int ck=abs(rest);
    fake%=a[x];
    ck=ck-abs(fake)+a[x];
    mp[{x,rest}]+=DFS(x-1,fake);
    if(ck<a[x+1])
    {
        if(fake>0)
            mp[{x,rest}]+=DFS(x-1,fake-a[x]);
        else if(fake<0)
            mp[{x,rest}]+=DFS(x-1,fake+a[x]);
    }
    return mp[{x,rest}];
}
signed main()
{
    fio
    cin>>n>>p;
    for(int i=0; i<n; ++i)
        cin>>a[i];
    p%=a[n-1];
    ans+=DFS(n-2,p);
    if(p)
        ans+=DFS(n-2,p-a[n-1]);
    cout<<ans;
    return 0;
}

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

#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}

mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */

void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}

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

const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;

ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 4191;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;

void nika_orz(int tc = 0) {
	ll x;
	cin >> n >> x;

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

	ll dp[55][3]; // 0 - less, 1 - equal, 2 - greater
	memset(dp, 0, sizeof(dp));
	dp[0][1] = 1;

	ll ans = 0;

	for (ll i = 0; i < n; i++) {
		ll val = x;
		if (i < n - 1) val %= a[i + 1];
		ll next_val = 3 * max(x, a[i]);
		if (i < n - 1) next_val = a[i + 1];

		ll limit = next_val / a[i];

		ll req = val / a[i];

		if (req == 0) {
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][1] += dp[i][1];
			dp[i + 1][2] += dp[i][2];
		} else {
			dp[i + 1][0] += dp[i][0];

			dp[i + 1][0] += dp[i][1];
			dp[i + 1][1] += dp[i][1];

			dp[i + 1][0] += dp[i][2];
			dp[i + 1][2] += dp[i][2];
		}

		if (req + 1 < limit) {
			dp[i + 1][2] += dp[i][0];
		}

		ll x_req = x / a[i];
		if (x_req < limit) {
			ans += dp[i + 1][2];
			dp[i + 1][2] = 0;
		}

		// cout << dp[i + 1][0] << " " << dp[i + 1][1] << " " << dp[i + 1][2] << endl;
	}

	cout << ans + 1 << '\n';
}

int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif

	send help

	#ifndef galen_colin_local
		// usaco("cowpatibility");
	#endif

	// usaco("cowland");

	// freopen("tc.cpp", "r", stdin);

	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) nika_orz(t);

	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
}


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

int main() {
  int a, b ,c;
  cin >> a >> b >> c;
  cout << 7-a+7-b+7-c << endl;
  return 0;
}

#include <bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define endl "\n"
#define Sara ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long long mod=1e6+3;
const double PI=acos(-1);
int main()
{
    Sara
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<char>v(3);
    for(int i=0;i<3;i++) cin>>v[i];
    char d=v[0];
    v[0]=v[1];
    v[1]=v[2];
    v[2]=d;
    for(int i=0;i<3;i++){
        cout<<v[i];
    }
        return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
	int n=read(),m=read(),ans=1;
	inv[1]=1;
	for(register int i=2;i<=20;++i){
		inv[i]=1ll*inv[P%i]*(P-P/i)%P;
	}
	for(register int i=2,t;i<=m;++i){
		if(!v[i]){
			f[i]=n,g[i]=1,p[++r]=i;
		}
		for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
			v[t]=1;
			if(i%p[j]){
				f[t]=1ll*f[i]*n%P,g[t]=1;
			}
			else{
				f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
				break;
			}
		}
		ans+=f[i];
		(ans>=P)&&(ans-=P);
	}
	printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll H[200005];
ll W[200005];
ll SUM[200005];
int main() {
    ll N, M;
    cin >> N >> M;
    rep(i, N)cin >> H[i];
    rep(i, M)cin >> W[i];
    sort(H, H + N);
    sort(W, W + M);

    SUM[N] = SUM[N - 1] = 0;
    for (int i = N - 2; i >= 0; i--)
    SUM[i] = SUM[i + 2] + H[i + 1] - H[i];

    //rep(i, M){
    //    cout << i << " " << W[i] << endl;
        //cout << i << " " << SUM[i] << endl;
    //}
    ll ans = 1e17;

    if (N == 1){
        rep(j, M)chmin(ans, abs(W[j] - H[0]));
        cout << abs(ans);
        return 0;
    }

    ll a = SUM[0];

    if (W[0] >= H[N - 1]){
        cout << a + W[0] - H[N - 1];
        return 0;
    }

    rep(j, M){
        if (W[j] >= H[N - 1]){
            chmin(ans, a + W[j] - H[N - 1]);
            continue;
        }

        int i = lower_bound(H, H + N, W[j]) - H;
        ll x;
        if (i == N - 1){
            x = a + H[i] - W[j];
            chmin(ans, x);
        } else if (i %2 == 0){
            x = a + H[i] - W[j] + SUM[i + 1] - SUM[i];
            chmin(ans, x);
        } else {
            x = a - (H[i] - W[j]) + SUM[i] - SUM[i + 1];
            chmin(ans, x);
        }
        //cout << "hoge "  << H[i] << " " << W[j] << " " << i << " " << x << endl;
    }
    cout << abs(ans);

}


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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    rep(i, n)
    {
        rep2(j, i + 1, n)
        {
            rep2(k, j + 1, n)
            {
                int dx = (x[j] - x[i]), dy = (y[j] - y[i]);
                int ddx = (x[k] - x[i]), ddy = (y[k] - y[i]);
                if ((dx * ddy) == (dy * ddx))
                {
                    cout << "Yes" << '\n';
                    return 0;
                }
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int N = 20010;
ll n, m, k;
int a[N];
vector<int> path;
vector<int> res1, res2;
vector<int> keep[N];
bool success=0;
void dfs(int u,int sum)
{
    sum %= 200;
    if(success) return ;
    if(u == n + 1)
    {
        if(keep[sum].size() && path.size())
        {
            success = 1;
            res1 = keep[sum];
            res2 = path;
        }
        else keep[sum] = path;
        return ;
    }

    dfs(u+1,sum);//不选这个数

    //选这个数
    path.push_back(u);
    dfs(u+1,sum + a[u]);
    path.pop_back();
}

int main()
{
    cin >> n;

    for(int i=1;i<=n;i++) scanf("%d",a+i);

    dfs(1,0);

    if(success)
    {
        puts("YES");
      	cout << res1.size() << " ";
        for(auto it : res1) cout << it << " ";
        cout << endl;
      cout << res2.size() << " ";
        for(auto it : res2) cout << it << " ";
    }
    else puts("NO");

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=205,INF=1<<30;

#define int short

struct dat{
    int i;
    int j;
    int k;
    int t;
    int tt;
    int ttt;
};

dat can[MAX][MAX][MAX][2][2][2];

signed main(){

    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        ll x;cin>>x;
        x%=200;
        A[i]=x;
    }

    for(int i=0;i<=N;i++) for(int j=0;j<200;j++) for(int k=0;k<200;k++) for(int t=0;t<2;t++) for(int tt=0;tt<2;tt++) for(int ttt=0;ttt<2;ttt++) can[i][j][k][t][tt][ttt]={-1,-1,-1,-1,-1,-1};
    can[0][0][0][0][0][0]={0,0,0,0,0,0};

    for(int i=0;i<N;i++){
        for(int j=0;j<200;j++){
            for(int k=0;k<200;k++){
                for(int t=0;t<2;t++){
                    for(int tt=0;tt<2;tt++){
                        for(int ttt=0;ttt<2;ttt++){
                            if(can[i][j][k][t][tt][ttt].i==-1) continue;

                            can[i+1][j][k][t][tt][ttt]={i,j,k,t,tt,ttt};
                            can[i+1][(j+A[i])%200][k][1][tt][1]={i,j,k,t,tt,ttt};
                            can[i+1][j][(k+A[i])%200][t][1][1]={i,j,k,t,tt,ttt};
                            can[i+1][(j+A[i])%200][(k+A[i])%200][1][1][ttt]={i,j,k,t,tt,ttt};
                        }
                    }
                }
            }
        }
    }

    for(int jj=0;jj<200;jj++){
        if(can[N][jj][jj][1][1][1].i==N-1){
            vector<int> X,Y;
            int nowj=jj,nowk=jj,nowt=1,nowtt=1,nowttt=1;
            for(int i=N;i>=1;i--){
                auto par=can[i][nowj][nowk][nowt][nowtt][nowttt];
                if(par.j!=nowj||nowt!=par.t) X.push_back(i-1);
                if(par.k!=nowk||nowtt!=par.tt) Y.push_back(i-1);

                nowj=par.j;
                nowk=par.k;
                nowt=par.t;
                nowtt=par.tt;
                nowttt=par.ttt;
            }

            sort(all(X));
            sort(all(Y));

            cout<<"Yes"<<endl;
            cout<<si(X)<<" ";
            for(int a:X) cout<<a+1<<" ";
            cout<<endl;

            cout<<si(Y)<<" ";
            for(int a:Y) cout<<a+1<<" ";
            cout<<endl;

            return 0;
        }
    }

    cout<<"No"<<endl;
}


# include<bits/stdc++.h>
using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

#define ai(n) array<l,n>

const l MOD=1e9+7;
const l N=2 * 1e5 + 10;
const l INF=1e18;

ai(N) Pi; // Prefix function Pi
string P, T(200000,' '); // P is pattern, T is string
l n,m; // n is size of string, m is size of pattern

l startIdx=-1;

// This populates Pi
// Pi [i] gives length of longest suffix of Pi (1 indexed) that is a proper prefix of Pi.
void computePrefixFunction() {
	l k=0;
	Pi[1]=0;
	rep(q,1,m) {
		while(k>0 && P[k]!=P[q]) {
			k = Pi[k];
		}
		if(P[k]==P[q]) {
			k = k + 1;
		}
		Pi[q+1]=k;
	}
}

// If q==m, match found. Add code there to handle scenario when pattern is found
void KMPMatcher() {
	computePrefixFunction();
	n=T.length();
	l q=0;
	rep(i,0,n) {
		while(q>0 && P[q]!=T[i]) {
			q = Pi[q];
		}

		if(P[q]==T[i]) {
			q = q + 1;
		}
		if(q==m) {
			startIdx=i-m+1;
			q=Pi[q];
			return;
		}

	}
}

void solve() {
	m=0;
	cin>>m;
	n=T.length();
	rep(i,0,n) {
		if(i%3==2) {
			T[i]='0';
		} else {
			T[i]='1';
		}
	}
	cin>>P;

	n=T.length();
	KMPMatcher();
	if(m==1 && P[0]=='1') {
		l ans = 2 * 1e10;
		cout<<ans<<"\n";
		return;
	}
	if(startIdx==-1) {
		cout<<"0\n";
	} else {
		l numStringsReqd= (m-1+startIdx)/3;
		l ans= 1e10 - numStringsReqd;
		cout<<ans<<"\n";
	}
	return;
}

int main(){
	io;
	int t;
	// cin >> t;
	rep(i,0,1) {
		solve();
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
    int n;
    cin >>n;
    vector<int>a(n),b(n);
    rep(i,n){
        cin >>a[i];
    }
    rep(i,n){
        cin >>b[i];
    }
    ll ans=0;
    rep(i,n){
        ll tmp=(ll)a[i]*b[i];
        ans+=tmp;
    }
    if(ans==0) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
    return 0;
}

//
// Created by ideal on 2021/03/06.
//
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> A(n);
    for(auto && i:A) cin >> i;
    ll aa=0, sa=0;
    for(ll a:A){
        aa += a*a;
        sa += a;
    }
    cout << n*aa-sa*sa << endl;
}


//I'll always miss you like a darling.
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>
#define LOWBIT(x) x & (-x)

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

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=1e9+7;
const double eps=1e-10;
const double pi=acos(-1);

struct fastio
{
    static const int S=1e7;
    char rbuf[S+48],wbuf[S+48];int rpos,wpos,len;
    fastio() {rpos=len=wpos=0;}
    inline char Getchar()
    {
        if (rpos==len) rpos=0,len=fread(rbuf,1,S,stdin);
        if (!len) return EOF;
        return rbuf[rpos++];
    }
    template <class T> inline void Get(T &x)
    {
        char ch;bool f;T res;
        while (!isdigit(ch=Getchar()) && ch!='-') {}
        if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
        while (isdigit(ch=Getchar())) res=res*10+ch-'0';
        x=(f?res:-res);
    }
    inline void getstring(char *s)
    {
        char ch;
        while ((ch=Getchar())<=32) {}
        for (;ch>32;ch=Getchar()) *s++=ch;
        *s='\0';
    }
    inline void flush() {fwrite(wbuf,1,wpos,stdout);fflush(stdout);wpos=0;}
    inline void Writechar(char ch)
    {
        if (wpos==S) flush();
        wbuf[wpos++]=ch;
    }
    template <class T> inline void Print(T x,char ch)
    {
        char s[20];int pt=0;
        if (x==0) s[++pt]='0';
        else
        {
            if (x<0) Writechar('-'),x=-x;
            while (x) s[++pt]='0'+x%10,x/=10;
        }
        while (pt) Writechar(s[pt--]);
        Writechar(ch);
    }
    inline void printstring(char *s)
    {
        int pt=1;
        while (s[pt]!='\0') Writechar(s[pt++]);
    }
}io;

template<typename T> inline void check_max(T &x,T cmp) {x=max(x,cmp);}
template<typename T> inline void check_min(T &x,T cmp) {x=min(x,cmp);}
template<typename T> inline T myabs(T x) {return x>=0?x:-x;}
template<typename T> inline T mygcd(T x,T y) {return y==0?x:mygcd(y,x%y);}
inline int add(int x) {if (x>=MOD) x-=MOD;return x;}
inline int add(int x,int MO) {if (x>=MO) x-=MO;return x;}
inline int sub(int x) {if (x<0) x+=MOD;return x;}
inline int sub(int x,int MO) {if (x<0) x+=MO;return x;}
inline void Add(int &x,int y) {x=add(x+y);}
inline void Add(int &x,int y,int MO) {x=add(x+y,MO);}
inline void Sub(int &x,int y) {x=sub(x-y);}
inline void Sub(int &x,int y,int MO) {x=sub(x-y,MO);}
template<typename T> inline int quick_pow(int x,T y) {int res=1;while (y) {if (y&1) res=1ll*res*x%MOD;x=1ll*x*x%MOD;y>>=1;}return res;}
template<typename T> inline int quick_pow(int x,T y,int MO) {int res=1;while (y) {if (y&1) res=1ll*res*x%MO;x=1ll*x*x%MO;y>>=1;}return res;}

const int MAXN=2e5;

int sum[MAXN+48],n;

int isprime[MAXN+48];int p[MAXN+48],tot;

void sieve()
{
    rep(i,1,MAXN) isprime[i]=i;
    rep(i,2,MAXN) if (isprime[i]==i)
        for (int j=i*2;j<=MAXN;j+=i) if (isprime[j]==j) isprime[j]=i;
}

int Count(int x)
{
    int res=1;
    while (x!=1)
    {
        int cur=isprime[x];
        int cnt=0;
        while (x%cur==0) cnt++,x/=cur;
        res*=(cnt+1);
    }
    return res;
}

int main ()
{
#ifndef ONLINE_JUDGE
    double TIME=clock();
    freopen ("a.in","r",stdin);
    freopen ("a.out","w",stdout);
    cerr<<"Running..."<<endl;
#endif
    scanf("%d",&n);
    sieve();
    rep(i,1,n) sum[n/i]++;
    REP(i,n-1,1) sum[i]+=sum[i+1];
    LL ans=0;
    rep(i,1,n) ans+=1ll*Count(i)*sum[i];
    printf("%lld\n",ans);
#ifndef ONLINE_JUDGE
    cerr<<"Exec Time: "<<(clock()-TIME)/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}


#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 4020000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    int n; cin >> n;
    vl a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    ll ans = inf;
    rep(i,n){
        rep(j,n){
            if(i == j) chmin(ans, a[i]+b[i]);
            else{
                chmin(ans, max(a[i],b[j]));
                chmin(ans, max(a[j],b[i]));
            }
        }
    }
    cout << ans << "\n";
}


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

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

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

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

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

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

signed main(){
  int N;
  cin>>N;
  if(N%2==0){
    cout<<"White";
  }else{
    cout<<"Black";
  }
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using ll = long long;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)

#define INF (int)1e9
#define LLINF (long long)1e12
#define MOD (int)1e9 + 7
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define co cout <<
#define en << endl;
#define __MAGIC__              \
  ios::sync_with_stdio(false); \
  cin.tie(nullptr);

#define YESNO(T)           \
  if (T)                   \
  {                        \
    cout << "YES" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "NO" << endl;  \
  }
#define yesno(T)           \
  if (T)                   \
  {                        \
    cout << "yes" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "no" << endl;  \
  }
#define YesNo(T)           \
  if (T)                   \
  {                        \
    cout << "Yes" << endl; \
  }                        \
  else                     \
  {                        \
    cout << "No" << endl;  \
  }

#define Graph vector<vector<int>>
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int, int>>
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
#define DDD fixed << setprecision(10)

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/

/*.....................DEFINE FUNCTIONS ......................*/
ll dist(ll x, ll y)
{
  return (x * x) + (y * y);
};
/*.........................kemkemG0...........................*/
signed main()
{
  __MAGIC__
  int a, b, c;
  cin >> a >> b >> c;

  if (c == 0)
  {
    if (a <= b)
    {
      co "Aoki" en
    }
    else
    {
      co "Takahashi" en
    };
  }
  else
  {
    if (b <= a)
    {
      co "Takahashi" en
    }
    else
    {
      co "Aoki" en
    };
  };
  return 0;
}

#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <stack>
#include <queue>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);

	double dp[101][101][101] = {};
	dp[a[0]][a[1]][a[2]] = 1;
	FOR(A,a[0],100){
		FOR(B,a[1],100){
			FOR(C,a[2],100){
				if(A+B+C == 0) continue;
				dp[A+1][B][C] += dp[A][B][C] * (A/(double)(A+B+C)) ;
				dp[A][B+1][C] += dp[A][B][C] * (B/(double)(A+B+C));
				dp[A][B][C+1] += dp[A][B][C] * (C/(double)(A+B+C)) ;
			}
		}
	}

	double ans = 0.0;

	FOR(A,a[0],101){
		FOR(B,a[1],101){
			FOR(C,a[2],101){
				if(A==100 || B==100 || C==100){
					ans += dp[A][B][C]  * (A+B+C-(a[0]+a[1]+a[2]));
				}
			}
		}
	}

	printf("%.10f\n",ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 60
#define INF 1000000005
#define INFLL (ll)1000000000000000005
#define PI 3.1415926535897
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
#define per(a,mod) ((a)%(mod)+(mod))%(mod)
typedef pair<int,int> P;
const int MAX = (1<<20);
const int MOD = 1000000007;

int dp[N];
void solve(){
    int n;
    cin>>n;
    vector<int>x(n);
    REP(i,n)cin>>x[i];
    map<int,int>t;
    map<int,int>mp[N];
    REP(i,n){
        int tmp=x[i];

        for(int j=2;j*j<=x[i];j++){
            while(tmp%j==0){
                mp[i][j]++;
                tmp/=j;
            }
        }
        if(tmp!=1)mp[i][tmp]++;
        for(auto p:mp[i]){
            t[p.first]++;
        }
    }
    {
        int j=0;
        for(auto p:t){
            dp[j++]=p.first;
        }
    }
    ll ans=INFLL;
    for(int bits=0;bits<(1<<SZ(t));bits++){
        vector<bool>check(N,0);
        ll tmp=1;
        REP(i,SZ(t)){
            if(bits & (1<<i)){
                REP(j,n){
                    if(mp[j][dp[i]]>0)check[j]=1;
                }
                tmp*=dp[i];
            }
        }
        bool flag=1;
        REP(i,n){
            if(!check[i]){
                flag=0;
                break;
            }
        }
        if(flag){
            ans=min(ans,tmp);
        }

    }
    OUT(ans);

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
#define forr(i,x,n) for(int i = n;i >= x;--i)
#define Angel_Dust ios::sync_with_stdio(0);cin.tie(0)

const int N = 455;
int ans[N],top;
bool st[N];

int main()
{
	int n,k;scanf("%d%d",&n,&k);
	forn(i,1,100 + n)	st[(100 + n) * i / 100] = 1;
	forn(i,1,100 + n - 1)	if(!st[i])	ans[++top] = i;
	printf("%lld\n",ans[k % top == 0 ? top : k % top] + (k / top - (k % top == 0 ? 1 : 0)) * (100ll + n));
    return 0;
}


/*Jai Shree Ram*/
// Never Give Up
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define F(i,s,e,j)        for(int i=s;i<=e;i+=j)
#define mt19937                 rng(chrono::steady_clock::now().tjhe_since_epoch().count());
//shuffle(arr,arr+n,rng)
 void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{   c_p_c();
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b-c<<endl;
}

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
#define int long long
const int Mod = 1e9 + 7;
const int N = 1005;
char c[5];
int power[N+5],f[N+5],n;
signed main () {
	cin>>n>>c[1]>>c[2]>>c[3]>>c[4];
	f[0] = 1,f[1] = 1;
	for(int i = 2;i <= 1005;i++) {
		f[i] = (f[i-1] + f[i-2])%Mod;
	}
	power[1] = 2;
	for(int i = 2;i <= 1005;i++) {
		power[i] = power[i-1] * 2 % Mod;
	}
	if(n <= 3) {
		puts("1");
		return 0;
	}
	if(c[2] == 'A') {
		if(c[1] == 'A') {
			printf("1\n");
			return 0;
		}
		else {
			if(c[3] == 'B') {
				printf("%lld\n",power[n-3]);
			}
			else {
				printf("%lld\n",f[n-2]);
			}
		}
 	}
 	if(c[2] == 'B') {
		if(c[4] == 'B') {
			printf("1\n");
			return 0;
		}
        else {
        	if(c[3] == 'A') {
        		printf("%lld\n",power[n-3]);
			}
			else printf("%lld\n",f[n-2]);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const int HW = 30;
const int Q = 1000;

void out(string s) {
    cout << s << '\n';
    cout.flush();
}

struct route {
    pii xy;
    string r;
};

int main(void)
{
    REP(i,Q) {
        pii s,t;
        cin >> s.first >> s.second >> t.first >> t.second;
        cin.ignore();

        string ans = "";
        if (s.first < t.first) ans += string(t.first-s.first,'D');
        else ans += string(s.first-t.first,'U');
        if (s.second < t.second) ans += string(t.second-s.second,'R');
        else ans += string(s.second-t.second,'L');

        out(ans);
        int score;
        cin >> score;
        cin.ignore();
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

#define debug(x) cerr << #x << '=' << x << '\n'
#define rep(i, b, n) for (int i = b; i <= n; i++)

const int N = 512345;

int mp[2123][2123], h, w, n, m;
pair<int, int> bb[N], blk[N];
bool ilmt[2123][2123][5];

void dfs(int x, int y, const int &d) {
    ilmt[x][y][d] = true;
    if (d == 1 && !ilmt[x][y - 1][d] && mp[x][y - 1]) {
        dfs(x, y - 1, d);
    }
    if (d == 2 && !ilmt[x][y + 1][d] && mp[x][y + 1]) {
        dfs(x, y + 1, d);
    }
    if (d == 3 && !ilmt[x - 1][y][d] && mp[x - 1][y]) {
        dfs(x - 1, y, d);
    }
    if (d == 4 && !ilmt[x + 1][y][d] && mp[x + 1][y]) {
        dfs(x + 1, y, d);
    }
}

int main(void) {
    cin >> h >> w >> n >> m;
    rep (i, 1, h) {
        rep (j, 1, w) {
            mp[i][j] = 1;
        }
    }
    rep (i, 1, n) {
        scanf("%d%d", &bb[i].first, &bb[i].second);
    }
    rep (i, 1, m) {
        scanf("%d%d", &blk[i].first, &blk[i].second);
        mp[blk[i].first][blk[i].second] = 0;
    }
    rep (i, 1, n) {
        dfs(bb[i].first, bb[i].second, 1);
        dfs(bb[i].first, bb[i].second, 2);
        dfs(bb[i].first, bb[i].second, 3);
        dfs(bb[i].first, bb[i].second, 4);
    }
    int ans = 0;
    rep (i, 1, h) {
        rep (j, 1, w) {
            ans += *max_element(ilmt[i][j] + 1, ilmt[i][j] + 5);
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, x;
    vector<int> ans;
    cin >> n >> x;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a != x){
            ans.push_back(a);
        }
    }
    if(ans.empty()){
        cout << "\n";
        return 0;
    }
    cout << ans[0];
    for(int i = 1; i < ans.size(); i++){
        cout << " " << ans[i];
    }
    cout << "\n";
}

/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 61;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[201][12];

void cmemoInit(){
    rep(i, 201){
        rep(j, 12){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> ans;
    rep(i, n){
        if(a[i] != x){
            ans.push_back(a[i]);
        }
    }
    rep(i, ans.size()){
        cout << ans[i] << " ";
    }
    cout << endl;
}


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

template<typename T, typename U>
using vp = vector<pair<T,U>>;
template<typename T>
using pque = priority_queue<T>;
template<typename T>
using lpque = priority_queue<T,vector<T>,greater<T>>;

using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using vint = vector<int>;
using vll = vector<ll>;
using qint = queue<int>;
using pqint = pque<int>;
using qll = queue<ll>;
using pqll = pque<ll>;

constexpr double PI = 3.141592653589793;
constexpr int INTINF = (1<<30)-1;
constexpr ll LLINF = (1LL<<62)-1;
constexpr int MPRIME = 1000000007;
constexpr int MPRIME9 = 998244353;
constexpr ll MMPRIME = (1LL<<61)-1;
constexpr char newl = '\n';

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

template<typename T>
struct matrix{
private:
	vector<vector<T>> mat;

public:
	matrix() : matrix(0,0) {}
	matrix(int h, int w) { resize(h,w); }
	matrix(int h, int w, T init) { resize(h,w,init); }

	void resize(int h, int w) {
		mat=vector<vector<T>>(h,vector<T>(w));
	}
	void resize(int h, int w, T init) {
		mat=vector<vector<T>>(h,vector<T>(w,init));
	};

	void in() {
		for(int i=0; i<mat.size(); i++) for(int j=0; j<mat[i].size(); j++) {
			cin>>mat[i][j];
		}
	}

	void out() {
		for(int i=0; i<mat.size(); i++) {
			int wm=mat[i].size();
			for(int j=0; j<wm; j++) {
				cout<<mat[i][j]<<(wm==j+1 ? '\n' : ' ');
			}
		}
		cout<<flush;
	}

	inline vector<T> &operator[](int idx) {
		assert(0<=idx && idx<mat.size());
		return mat[idx];
	}
};

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

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

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

long long binpow(long long a, long long ex, long long p=MMPRIME) {
	long long res = 1;
	while(ex > 0) {
		if(ex & 1) (res*=a) %= p;
		ex>>=1;
		(a*=a) %= p;
	}
	return res;
}

int N;
string S,T;

void input() {
	cin>>N>>S>>T;
}

void solve() {
	ll ans=0;
	for(int i=0, j=0; i<N; i++) {
		if(S[i]==T[i]) continue;
		if(S[i]=='1') {
			for(chmax(j,i+1); j<N; j++) {
				if(S[j]=='0') continue;
				S[i]=S[j]='0';
				ans += j-i;
				break;
			}
		}
		else {
			for(chmax(j,i+1); j<N; j++) {
				if(S[j]=='0') continue;
				S[i]='1';
				S[j]='0';
				ans += j-i;
				break;
			}
		}
	}
	if(S!=T) cout<<-1<<newl;
	else cout<<ans<<newl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t--) {
		input();
		solve();
	}
}

#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define ll long long
#define pb push_back
#define mem(x, y) memset(& x, y, sizeof(x))

const int n0 = 5e5 + 123;
int n;
ll p[n0];
string s, t;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> s >> t;
	vector <int> v, u;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1') v.pb(i);
		if (t[i] == '1') u.pb(i);
	}
	if (SZ(v) < SZ(u) || (SZ(v) & 1) != (SZ(u) & 1)) return cout << -1, 0;
	ll res = 0;
	int last = -1;
	for (int i = 1; i <= SZ(v); i++) {
		p[i] = p[i - 1];
		if (i & 1) p[i] -= v[i - 1];
		else p[i] += v[i - 1];
	}
	for (int i = 0; i < SZ(u); i++) {
		int pos = lower_bound(begin(v) + (last + 1), end(v), u[i]) - begin(v);
		if (pos == SZ(v)) return cout << -1, 0;
		int x = pos - last - 1;
		if (x & 1) pos++;
		if (pos == SZ(v)) return cout << -1, 0;
		ll cur = p[pos] - p[last + 1];
		if ((last + 2) % 2 == 0) cur *= -1;
		res += v[pos] - u[i] + cur;
		last = pos;
	}
	int x = SZ(v) - last - 1;
	if (x & 1) return cout << -1, 0;
	ll cur = p[SZ(v)] - p[last + 1];
	if ((last + 2) % 2 == 0) cur *= -1;
	res += cur;
	cout << res;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,dp[100][100];
double cnt,ans;
string s[100],t;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        for(int j=0;j<n;j++){
            if(i==j)dp[i][j]=0;
            else if(s[i][j]=='0')dp[i][j]=1e9;
            else dp[i][j]=1;
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j)continue;
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        cnt=1.0;
        for(int j=0;j<n;j++){
            if(dp[j][i]!=0&&dp[j][i]!=1e9)cnt+=1.0;
        }
        ans+=1/cnt;
    }
    cout<<setprecision(15)<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
constexpr ll MOD=998244353;

int main() {
    int n;
    cin >> n;
    vector<int> a(n,0);
    vector<vector<int>> e(n,vector<int>(0));
    rep(i,n){
        string s;
        cin >> s;
        rep(j,n){
            if (s[j]=='1') e[i].push_back(j);
        }
    }
    rep(i,n){
        vector<int> b(n,0);
        b[i]=1;
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int f=q.front();
            q.pop();
            rep(j,e[f].size()){
                if (b[e[f][j]]!=1){
                    b[e[f][j]]=1;
                    q.push(e[f][j]);
                }
            }
        }
        rep(j,n){
            a[j]+=b[j];
        }
    }
    ld ans=0;
    rep(i,n){
        ld w=a[i],ww=1;
        ans+=(ww/a[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}


//GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define pb push_back
#define eb emplace_back
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
using P=pair<ll,ll>;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf =1e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p) {
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p) {
  is>>p.first>>p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v) {
  for(int i=0;i<(int)v.size();i++) {
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&v) {
  for(T &in:v)is>>in;
  return is;
}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail) {
  cin>>head;
  scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
  cout << head << ' ';
  print(tail...);
}
template<class... T>
void fin(const T &... a) {
  print(a...);
  exit(0);
}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
int main(){
  LL(n,m);
  vs a(m);
  cin>>a;
  sort(all(a));
  ll now=0;
  rep(i,0,n){
    ll cnt=0;
    while(cnt+a[now].size()<=n){
      cnt+=a[now].size();
      cout<<a[now];
      now++;
    }
    rep(i,0,n-cnt){
      cout<<".";
    }
    cout<<endl;
  }
}

#pragma region
#ifdef LOCAL
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif

// debug
template<typename ... Types>
void __read(Types& ... args) {
  ((std::cin >> args), ...);
}
#define read(type, ...) type  __VA_ARGS__; __read(__VA_ARGS__)

template <typename T>
std::istream &operator>>(std::istream &in, std::vector<T>& v) {
  int n = v.size();
  for(int i = 0; i < n; i++) in >> v[i];
  return in;
}

template <typename Type, typename... Types>
auto print(Type const &arg, Types const &... args) {
  std::cout << arg, ((std::cout << " " << args), ...), std::cout << std::endl;
}
template <typename Type, typename... Types>
auto print_debug(Type const &arg, Types const &... args) {
  std::cout << arg, ((std::cout << " | " << args), ...), std::cout << std::endl;
}
#ifdef LOCAL
#define debug(...) do{std::cout <<  __LINE__ << ": [" << #__VA_ARGS__ << "]: ", print_debug(__VA_ARGS__);}while(0)
#else
#define debug(...) 1
#endif

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& out, std::pair<T1, T2> const& a) {
  return out << "{" << a.first << ", " << a.second << "}";
}
#define __DEF_PRINTER(container)                                          \
template<typename T>                                                      \
std::ostream& operator<<(std::ostream& out, container<T> const& a)        \
{                                                                         \
  size_t len = a.size();                                                  \
  for(auto x : a) out << x << " \n"[len--==0];                            \
  return out;                                                             \
}
#define __DEF_PRINTER2(container)                                         \
template<typename T, typename T2>                                         \
std::ostream& operator<<(std::ostream& out, container<T, T2> const& a)    \
{                                                                         \
  size_t len = a.size();                                                  \
  for(auto x : a) out << x << " \n"[len--==0];                            \
  return out;                                                             \
}

__DEF_PRINTER(std::vector)
__DEF_PRINTER(std::set)
__DEF_PRINTER(std::unordered_set)
__DEF_PRINTER2(std::map)
__DEF_PRINTER2(std::unordered_map)
// end debug

#define ALL(container) std::begin(container), std::end(container)
#define RALL(container) std::rbegin(container), std::rend(container)

const char nl = '\n';

template <typename T>
void minmax(T k1, T k2, T& min, T& max) {
  min = std::min(k1, k2);
  max = std::max(k1, k2);
}

template <typename T>
void maxim(T& val, T t) {
  val = std::max(val, t);
}

template <typename T>
void minim(T& val, T t) {
  val = std::min(val, t);
}

const long long mod = 1e9+7;
long long reduce_mod(long long a) {
  return (a % mod + mod) % mod;
}
long long add(long long a, long long b) {
  return reduce_mod(a + b);
}
long long mult(long long a, long long b) {
  return reduce_mod(a * b);
}

template<class Fun>
class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) {
      return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};
template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
  return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

void yn(bool yes) {
  std::cout << (yes ? "yes" : "no") << '\n';
}

using i64 = int64_t;
using namespace std;

#pragma endregion

void run(int tt) {
  (void)tt;
}

int main() {
  cin.tie(0)->sync_with_stdio(false);

  read(i64, n, k);
  i64 q = n/200;
  i64 r = n%200;
  for(int i = 0; i < k; i++) {
    if (r==0) {
      // n = q
      r = q%200;
      q = q/200;
    } else{
      q = (1000*q+5*r+1);
      r = 0;
    }
  }
  print(200*q+r);
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define sqrt(x) pow(x,0.5)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
ll max(ll a,ll b){return (a>b ? a:b);}
ll min(ll a,ll b){return (a<b ? a:b);}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// nCkのテーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// aのmodでの逆元 非再帰拡張 Euclid の互除法
long long modinv(long long a, long long mod) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  // srand((unsigned)time(NULL));
  // set<int> st;
  // queue<ll> q;
  // map<ll, ll> mp;
  ll t,ans=0,r,l;
  string str;
  cin >> t;
  rep(i, t){
    cin >> l>>r;
    l*=2;
    cout << (r<l ? 0:(r%2 ? (r-l+1)/2*(r-l+2):(r-l+2)/2*(r-l+1))) << endl;
  }
  // vector<int> v(n);
  // cins(n, v);
  // couts(v);
  // cout << (ans==0 ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

int main() {
  int t;
  cin >> t;
  ll ans =0;
  rep(i,t){
    ll l,r;
    cin >> l >> r;
    ll sub = r-l;
    if(sub < l){
      cout << 0 << endl;
    }
    else{
      ll number = sub-l+1;
      if(number != 1){
        ans = (number + 1) * number / 2;
      }
      else if (number == 1){
        ans = 1;
      }
      cout << ans << endl;
      ans = 0;
    }
  }

  return 0;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define _GLIBCXX_DEBUG
#define reps(i, a, n) for (lint i = a; i < (lint)(n); i++)
#define rep(i, n) reps(i, 0, n)
#define repd(i, n) for (lint i = n - 1; i >= 0; i--)
#define INF (int)1e9
#define LINF (lint)1e12
#define pb push_back
#define mp make_pair
#define ALL(v) v.begin(), v.end()
using vi = vector<int>;
using vlint = vector<lint>;
using vs = vector<string>;
using vc = vector<char>;
using vvi = vector<vi>;
using vvlint = vector<vlint>;
using Graph = vector<vector<int>>;
using pii = pair<int, int>;
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; }

int main() {
	int N;
	cin >> N;
	int ans = 1;
	if (N == 1) {
		ans = 0;
	}
	else {
		ans = N - 1;
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve()
{
    int c;
    cin >> c;
    cout << c - 1 << "\n";
}

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

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int long long
#define mod 1000000007
#define all(x) x.begin() , x.end()
#define ld long double
const long long inf = 1e18 + 1LL;
void solve();
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}
void solve()
{
	ll n , m; cin >> n >> m;

	ll ctr[3][n][m] ; memset(ctr , 0 , sizeof ctr);

	ctr[0][0][0] = ctr[1][0][0] = ctr[2][0][0] = 1 ;

	string arr[n]; for (auto &x : arr) cin >> x;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (arr[i][j] == '#' or (i == 0 and j == 0)) {
				//cout << "- ";
				continue;
			}
			ll x = 0;
			if (i > 0)
			{
				x += ctr[0][i - 1][j] ;
				x %= mod;
			}
			if (j > 0)
			{
				x += ctr[1][i][j - 1] ;
				x %= mod;
			}
			if (i > 0 and j > 0)
			{
				x += ctr[2][i - 1][j - 1] ;
				x %= mod;
			}
			for (int k = 0; k < 3 ; k++) ctr[k][i][j] = x;
			if (i > 0)
			{
				(ctr[0][i][j] += ( ctr[0][i - 1][j]) ) % mod;
			}
			if (j > 0)
			{
				(ctr[1][i][j] += ( ctr[1][i][j - 1])) % mod;
			}
			if (i > 0 and j > 0)
			{
				(ctr[2][i][j] += ( ctr[2][i - 1][j - 1])) % mod;
			}
			if (i == n - 1 and j == m - 1)cout << x << " ";
		}
		//cout << "\n";
	}
	//cout << (ctr[0][n - 1][m - 1] + ctr[1][n - 1][m - 1] + ctr[2][n - 1][m - 1]) % mod;

	cout << "\n";
	return ;
}
//                                                                  🙂

#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

const int PRIME = 1e9 + 7;

ll powerMod(ll a, ll b, int mod){
    ll result = 1;
    a %= mod;
    while(b){
        if(b & 1){
            result = result * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return result;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    char aa, ab, ba, bb;
    cin >> aa >> ab >> ba >> bb;
    vector<pair<int, int>> dp(n);
    dp[0] = {1, 1};
    for(int i = 1; i < n; i++){
        dp[i].first = (dp[i-1].first + dp[i-1].second) % PRIME;
        dp[i].second = dp[i-1].first;
    }
    if(n <= 3){
        cout << "1\n";
        return 0;
    }
    ll ans = (dp[n-4].first + dp[n-4].second) % PRIME;
    if(ab == 'A'){
        if(aa == 'A'){
            ans = 1;
        }else{
            if(ba == 'B'){
                ans = powerMod(2, n-3, PRIME);
            }
        }
    }else if(ab == 'B'){
        if(bb == 'B'){
            ans = 1;
        }else{
            if(ba == 'A'){
                // cout << "i";
                ans = powerMod(2, n-3, PRIME);
            }
        }
    }

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


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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;
const ll lINF = 1e16+1;

int main(){

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

    int n;
    cin >> n;

    vector<ll> isprime = {2,3,5,7,11,13,17,19,23,29};

    ll ans = 1;
    ans*=16;
    ans*=27;
    ans*=25;
    ans*=7;
    ans*=11;
    ans*=29;
    ans*=23;
    ans*=19;
    ans*=13;
    ans*=17;
    ans++;
    // for(int i=2; i<=n; i++){
    //     cout<<(ans)%i<<' ';
    // }
    // cout<<endl;
    cout<<ans;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

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

ll mdc(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll ans = 2;
    for(int i = 2; i <= n; i++)
        ans = mdc(ans, i);
    cout << ans + 1 << endl;
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e6+7;
const int mod=1e9+7;
const int INF=1e18+7;
const double EPS=1e-12;
const int dx[]={-1,1,0,0}; // UDLR
const int dy[]={0,0,-1,1}; // UDLR
inline int maximum(int a,int b) {int c=a>b?a:b; return c;}
inline int minimum(int a,int b) {int c=a>b?b:a; return c;}

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

    int a,b; cin>>a>>b;
    a+=b;
    if(a>=15&&b>=8) cout<<"1"<<'\n';
    else if(a>=10&&b>=3) cout<<"2"<<'\n';
    else if(a>=3) cout<<"3"<<'\n';
    else cout<<"4"<<'\n';

 return 0;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
    //#include <unordered_set>
    //#include <unordered_map>

using namespace std;

const double pi = 3.141592653689793238460;
const long long inf = 0x3f3f3f3f;
const int   N = 2e5 + 5;
const int pr = 31;
#define ll long long
using ld = long double;
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define MEM(x) memset(x,0,sizeof(x))
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i< n; i++)
#define forl(i,l,u) for(int i=(int)l;i<=(int)u;++i)
#define all(v) (v).begin(), (v).end()
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int mod = 998244353;

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

}
int power(long long x, unsigned int y, int p)
{   //(x^y)%p
    int res = 1;
    x = x % p;
    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //#define int ll
    //cout << fixed << setprecision(17);

    ll m = 998244353;
    int h, w;
    cin >> h >> w;
    string s[10005];
    forn(i, h) {
        cin >> s[i];
    }
    ll ways = 1LL;
    vector<char> a[10005];
    forn(i, h) {
        forn(j, w) {
            a[i + j].pb(s[i][j]);
        }
    }
    int to = h + w - 2;
    int pow = 0;
    forl(i, 0, to) {
        int r = 0;
        int b = 0;
        forn(j, (int)a[i].size()) {
            if (a[i][j] == 'R') {
                r++;
            }
            if(a[i][j] == 'B')b++;
        }
        if (r == 0 && b == 0) {
            pow++;
        }
        else {
            if (r > 0 && b > 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << power(2,pow,m) << endl;
}