#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	vector<long long> a(n),b(n),v(1000,0);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<a[i]-1;j++)v[j]=1;
		for(int j=b[i];j<1000;j++)v[j]=1;
	}
	int count=0;
	for(int i=0;i<1000;i++)
	{
		if(v[i]==0){count++;}
	}
	cout<<count;

}

#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define mod2 998244353
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   int n;
   cin>>n;
   int a[n];
   int b[n];
   int maxim=0;
   int minim=1001;
   for(int i=0;i<n;i++){
    cin>>a[i];
    maxim=max(a[i],maxim);
   }
   for(int i=0;i<n;i++){
    cin>>b[i];
    minim=min(b[i],minim);
   }
   if(minim>=maxim){
    cout<<minim-maxim+1<<"\n";
   }else{
    cout<<0<<"\n";
   }

}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define vii vector<vi>
#define vp vector<pair<ll,ll>>
#define vpp vector<pair<ll,pair<ll,ll>>>
#define pb push_back
#define pu push
#define po pop
#define up(v,x) upper_bound(v.begin(),v.end(),x)
#define lo(v,x) lower_bound(v.begin(),v.end(),x)
#define ups(v,x) v.upper_bound(x)
#define los(v,x) v.loer_bound(x)
#define pa pair<long long int ,long long int>
#define f(a,x,b) for(int a=x;a<b;a++)
#define fr(a,x,b) for(int a=x;a>=b;a--)
#define EACH(a,x) for(auto a:x)
#define sort(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
#define sz(a) (int)a.size()
#define mod 998244353
#define F first
#define S second
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx,
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
vi v(1009),v1(1009);
vii dp(1009,vi(1009,-1));
ll sol(ll pos1,ll pos2)
{
	if(pos2==0)
	{
		return pos1;
	}
	if(pos1==0)
	{
		return pos2;
	}
	if(dp[pos1][pos2]!=-1)
	{
		return dp[pos1][pos2];
	}
	ll x=mod;
	if(v[pos1-1]==v1[pos2-1])
	{
       x=min(x,sol(pos1-1,pos2-1));
	}
	else
	{
	   x=min({x,sol(pos1-1,pos2)+1,sol(pos1,pos2-1)+1,sol(pos1-1,pos2-1)+1});
	}
	return dp[pos1][pos2]=x;
}
void solve(){
   ll n,m;
   cin>>n>>m;
   f(i,0,n)
   {
	   cin>>v[i];
   }
   f(i,0,m)
   {
	   cin>>v1[i];
   }
   cout<<sol(n,m);
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// f(i,0,t)
	// {
        //  cout<<"Case #"<<i+1<<":"<<" ";
	     solve();
	// }
	return 0;
}

#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;
string s, t;
queue<int> que;
ll ans;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++)if (s[i] == '1')que.push(i);
	for (int i = 0; i < n; i++) {
		if (!que.empty() && que.front() == i)que.pop();
		if (s[i] == t[i])continue;
		if (que.empty()) {
			cout << -1 << endl;
			return 0;
		}
		int p = que.front();
		ans += p - i;
		que.pop();
		if (s[i] == '0')s[i] = '1', s[i + 1] = '0', s[p] = '0';
		else s[i] = '0', s[i + 1] = '0', s[p] = '0';
	}
	cout << ans << endl;
}


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

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

const int mod = 1e9 + 7;
vector<pair<int, ll> > E[200001];
ll W[200001];
int kazu[60];
void dfs(int u, int mae) {
	for (auto v : E[u]) {
		if (v.first != mae) {
			W[v.first] = W[u] ^ v.second;
			dfs(v.first, u);
		}
	}
}

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

	int N;
	cin >> N;
	rep(i, N - 1) {
		int u, v;
		ll w;
		cin >> u >> v >> w;
		E[u].pb({ v,w });
		E[v].pb({ u,w });
	}
	dfs(1, 0);

	ll kotae = 0;
	rep1(i, N) {
		kotae += W[i] % mod * (N - 1) % mod;
	}
	kotae %= mod;

	rep1(i, N) {
		rep(j, 60) if (W[i] >> j & 1) {
			kazu[j]++;
		}
	}
	rep(j, 60) {
		kotae -= ((1ll << j) % mod) * kazu[j] % mod * (kazu[j] - 1) % mod;
	}

	co((kotae% mod + mod) % mod);

	Would you please return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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 ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main(){
	int n, x;
	cin >> n >> x;
	string s;
	cin >> s;
	rep(i, n) {
		if (s[i] == 'o') x++;
		else if (s[i] == 'x' && x > 0) x--;
	}
	cout << x << endl;
	return 0;
}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _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 = numeric_limits<int>::max() / 4;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
int save[30];
signed main()
{
    fio
    string s;
    cin>>s;
    int ans=0;
    int n=s.length();
    for(int i=n-1;i>0;--i)
    {
        if(s[i]==s[i-1])
        {
            ans+=n-1-i-save[s[i]-'a'];
            memset(save,0,sizeof(save));
            save[s[i]-'a']=n-i;
        }else save[s[i]-'a']++;
//        debug4(i,ans,s[i],save[0])
    }
    cout<<ans;
    return 0;
}

//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;}
template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;}
template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;}
template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;}
const ll p=998244353ll,pp=p*p;const int ps2=p-2ll;
inline void add(ll &x){if(x>= p)x-=p ;}
inline void sub(ll &x){if(x<0ll)x+=p ;}
inline void adp(ll &x){if(x>=pp)x-=pp;}
inline void sup(ll &x){if(x<0ll)x+=pp;}
inline ll expo(ll a,int b=ps2,ll m=p){
	ll s=1ll;
	while(b){
		if(b&1)s=s*a%p;
		b>>=1; a=a*a%p;
	}
	return s;
}

inline void ac();
//inline void in();int main(){in();int t;scanf("%d",&t);while(t--)ac();return 0;}
//int main(){int t;scanf("%d",&t);while(t--)ac();return 0;}
int main(){ac();return 0;}

map<ll,int>M;
inline void ac(){
	int n,a;ll S=0ll,Z=0ll;
	scanf("%d",&n);
	M[0ll]=1;
	while(n--){
		scanf("%d",&a);
		if(n&1)S+=a;else S-=a;
		Z+=(M[S]++);
	}
	printf("%lld\n",Z);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/


//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-9
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod = 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e18;
//const int inf = 2e9;
const int nmax = 1e6+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

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

    int tc;
    cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        vector<int>v(n);
        for(int &x : v) cin>>x;
        if(n%2) cout<<"Second\n";
        else{
            map<int, int>cnt;
            for(int x : v) cnt[x]++;
            bool mara = false;
            for(auto z : cnt){
                if(z.second%2) mara=true;
            }
            if(mara) cout<<"First\n";
            else cout<<"Second\n";
        }
    }
}
/*
*/

#include <bits/stdc++.h>
#include <fstream>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF=2147483647;
// 9,223,372,036,854,775,807
const ll INFL = 9223372036854775807;

int main(){

    ll n;
    cin >> n;
    vector<pair<string,int>> s(n);
    for(int i=0;i<n;i++){
        string tmp;
        cin >> tmp;
        if(tmp[0] == '!'){
            s[i] = {tmp,1};
        }
        else{
            tmp.insert(0,"!");
            s[i] = {tmp,0};
        }
    }
    sort(s.begin(),s.end());
    string ans;
    for(int i=0;i<n-1;i++){
        if(s[i].first==s[i+1].first&&s[i].second!=s[i+1].second){
            s[i].first.erase(s[i].first.begin());
            ans = s[i].first;
            cout << ans << endl;
            return 0;
        }
    }
    cout << "satisfiable " << endl;
    return 0;
}


#line 1 "main_b.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>

/* template start */

#line 2 "/home/imperi/cp-library/lib/utility/type_alias.hpp"

#line 4 "/home/imperi/cp-library/lib/utility/type_alias.hpp"

using u64 = std::uint64_t;
using u32 = std::uint32_t;
using u16 = std::uint16_t;
using u8 = std::uint8_t;

using i64 = std::int64_t;
using i32 = std::int32_t;
using i16 = std::int16_t;
using i8 = std::int8_t;

using usize = std::size_t;
using isize = std::ptrdiff_t;

constexpr i64 operator"" _i64(unsigned long long num) { return i64(num); }

constexpr u64 operator"" _u64(unsigned long long num) { return u64(num); }
#line 33 "main_b.cpp"

#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...)                                                    \
  std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
      debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
  std::cerr << " " << h;
  if (sizeof...(t) > 0) std::cerr << " :";
  debug_out(t...);
}

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

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

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

template <typename Num, typename Func = std::multiplies<Num>>
constexpr Num mypow(Num a, u64 b, Num id = 1, Func mul = Func()) {
  if (b == 0) return id;
  Num x = id;
  while (b > 0) {
    if (b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n;
  std::cin>>n;

  std::vector<i64> a(n);
  for(auto&& e:a)std::cin>>e;

  std::sort(all(a));

  long double ans = 1e18;

  long double sum = 0;

  i64 coef = n;

  chmin(ans,(long double)n*a[n-1]/2);

  for(i64 i = n-2;i>=0;i--){
    sum += a[i+1];
    coef-=2;
    chmin(ans,sum + (long double)coef*a[i]/2);
  }

  std::cout<<std::setprecision(10)<<ans/n<<"\n";

  return 0;
}

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

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

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

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


#include <bits/stdc++.h>

typedef long long ll;

const int P = 998244353;
const int N = 200000;
const int IV2 = (P + 1) >> 1;

inline int norm(int x) {if( x >= P ) x -= P; return x;}

int pw2[N + 5], ipw2[N + 5];

int a[N + 5], n;

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) scanf("%d", &a[i]); std::sort(a + 1, a + n + 1);

	pw2[0] = ipw2[0] = 1;
	for(int i=1;i<=n;i++) {
		pw2[i] = norm(pw2[i - 1] << 1);
		ipw2[i] = (ll)ipw2[i - 1] * IV2 % P;
	}

	int ans = 0, t = 0;
	for(int i=n;i>=1;i--) {
		ans = (ans + (ll)a[i] * a[i]) % P;
		ans = (ans + (ll)t * a[i] % P * ipw2[i]) % P;
		t = (t + (ll)a[i] * pw2[i - 1]) % P;
	}
	printf("%d\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
#define clr(a) memset(a, 0, sizeof(a))
#define full(a) memset(a, 0x3f, sizeof(a))
#define mset(a, b) memset(a, b, sizeof(a))
#define cpy(a,b) memcpy(a, b, sizeof(a))
#define fornext(x, i) for(signed i = hd[x], y = ver[i]; i; i = nxt[i], y = ver[i])
#define Rep(i, a, b) for(signed i = (signed)(a); i <= (signed)(b); ++i)
#define dRep(i, a, b) for(signed i = (signed)(a); i >= (signed)(b); --i)
#define IOset(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
#define pb push_back
#define It iterator
#define endl '\n'
#define un unsigned
#define int ll
#define ll long long
#define db double
#define rept cerr<<1.0*clock()/CLOCKS_PER_SEC<<endl;
#define dbg cout<<"c "
#define dbug(x) cerr << #x " = " << (x) << endl
template<typename _T> inline void _prt(_T _d) { cerr << _d << ' '; }
template <typename _T, typename ...Args> inline void _prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...); }
template <typename _T, typename ...Args> inline void prt(_T _d, Args ..._a) { _prt(_d), _prt(_a...), cerr<<endl; }
template <typename _T, typename ...Args> inline void prt(_T _d) { cerr << _d <<endl; }
template<typename _T> inline void rd(_T &_d) {
	signed _f; char _c; _f = 1,_d = 0; while (_c = getchar(), !isdigit(_c)) if(_c=='-') _f=-1;
	while (isdigit(_c)) _d = _d * 10 + _c - '0', _c = getchar();
	_d=_f*_d;
}
template <typename _T, typename ...Args> inline void rd(_T &_d, Args &..._a) { rd(_d); rd(_a...); }

const int N=2e5+5,M=998244353;
int n,a[N];

inline void ml(int &x,int v) {
	x=1LL*x*v%M;
}

inline int md(int x) {
	return x>=M?x-M:x;
}

inline void add(int &x,int v) {
	x+=v,x=x>=M?x-M:x,x=x<0?x+M:x;
}

signed main() {
	rd(n);
	Rep(i,1,n) rd(a[i]);
	sort(a+1,a+n+1);
	int ans=0,sum=0;
	Rep(i,1,n) {
		add(sum,a[i-1]);
		add(ans,a[i]*(sum+a[i])%M);
		sum=md(sum+sum);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[65540];
template<class T>inline void read(T &x){
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
int main(){
	int n,t;
	cin>>n;
	int min1=-INT_MAX,min2=-INT_MAX;
	int ans1=0,ans2=0;
	int l=pow(2,n)/2,r=pow(2,n);
	for(int i=1;i<=l;i++){
		read(t);
		if(min1<t)
			ans1=i,min1=t;
	}
	for(int i=l+1;i<=r;i++){
		read(t);
		if(min2<t)
			ans2=i,min2=t;
	}
	if(min1>min2)cout<<ans2<<endl;
	else cout<<ans1<<endl;

}

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    return x*f;
}
const int N=1e2+10,M=1e4+10;
char s[N];int a[N],b[M][N];
signed main(){
	int n=read()+1;
	scanf("%s",s+1);
	For(i,1,n)a[i]=read();
	int k=1e5;
	For(i,2,n)k=min(k,abs(a[i]-a[i-1]));
	printf("%d\n",k);
	For(i,1,k){
		For(j,1,n){
			printf("%d ",(a[j]+i-1)/k);
		}
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=3005,mod=998244353;
inline void add(int &a,int b){a+=b;if(a>=mod)a-=mod;}
int dp[N][N];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=n;j>=1;j--)
		{
			if(j) add(dp[i][j],dp[i-1][j-1]);
			if(j*2<=n) add(dp[i][j],dp[i][j*2]);
		}
	}
	printf("%d\n",dp[n][k]);
	return 0;
}

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int popcount(ll bits) {
    bits = (bits & 0x5555555555555555LL) + (bits >> 1 & 0x5555555555555555LL);
    bits = (bits & 0x3333333333333333LL) + (bits >> 2 & 0x3333333333333333LL);
    bits = (bits & 0x0f0f0f0f0f0f0f0fLL) + (bits >> 4 & 0x0f0f0f0f0f0f0f0fLL);
    bits = (bits & 0x00ff00ff00ff00ffLL) + (bits >> 8 & 0x00ff00ff00ff00ffLL);
    bits = (bits & 0x0000ffff0000ffffLL) + (bits >> 16 & 0x0000ffff0000ffffLL);
    return (bits & 0x00000000ffffffffLL) + (bits >> 32 & 0x00000000ffffffffLL);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    input(n, m);
    vector<vector<P>> lm(n);
    rep(i, 0, m) {
        int x, y, z;
        input(x, y, z);
        x--;
        lm[x].emplace_back(y, z);
    }
    int bits = 1 << n;
    vector<ll> dp(bits, 0);
    dp[0] = 1;
    rep(bit, 0, bits) {
        vector<int> cnt(n + 1, 0);
        rep(i, 0, n) {
            if ((bit >> i) & 1) cnt[i + 1]++;
        }
        rep(i, 0, n) {
            cnt[i + 1] += cnt[i];
        }

        rep(i, 0, n) {
            if ((bit >> i) & 1) continue;
            bool ok = true;
            for (auto [y, z] : lm[popcount(bit)]) {
                int c = cnt[y] + (i + 1 <= y);
                if (c > z) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                dp[bit | 1 << i] += dp[bit];
            }
        }
    }
    print(dp[bits - 1]);
    return 0;
}


// Author:   old_school
// Created:  20.02.2021 17:30:29

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define lld               long long int
#define ld                long double
#define pb                push_back
#define ppb               pop_back
#define mp                make_pair
#define F                 first
#define S                 second
#define nl                '\n'
#define all(c)            (c).begin(),(c).end()
#define rall(c)           (c).rbegin(),(c).rend()
#define sz(c)             (c).size()
#define tr(x,a)           for(auto &a : x)
#define psnt(x,a)         (x).find(a)!=(x).end()
#define vpsnt(x,a)        find(all(x),a)!=(x).end()
#define MOD               1000000007
#define tod               100005
#define pi                3.1415926536
#define itr(i,a,b)        for(lld i=a;i<=b;i++)
#define itrn(i,a,b)       for(lld i=a;i>=b;i--)
#define iot(n)            for(lld i=0;i<n;i++)
#define pls(n,arr)        lld arr[n]; iot(n)  cin>>arr[i];
#define bye               fflush(stdout)

typedef pair<lld,lld>     pii;
typedef pair<string,lld>  psi;

template <typename T>
bool mycomp(T x,T y){
   return (x==y);  //give your condition here
}
bool paircomp(const pair<lld,lld> &x,const pair<lld,lld> &y){
return x.second<y.second;
}
vector<pair<lld,pair<lld,lld> > > adj[tod];
void dijkstra(lld V,lld source,lld dist[]){
    priority_queue<pair<lld,lld> ,vector<pair<lld,lld> >,greater<pair<lld,lld> > > pq; //minheap
    for(lld i=0;i<=V;i++)
       dist[i]=-1;
    dist[source]=0;
    pq.push(make_pair(dist[source],source));
    while(!pq.empty()){
        lld u=pq.top().second;
        pq.pop();
        for(auto &p:adj[u]){
            lld v=p.first,weight=p.second.first,lx=p.second.second;
            lld z=dist[u]/lx;
               lld ex=0;
               if(dist[u]%lx){
               	 z++;
               }
               z*=lx;
               ex=z-dist[u];
            if (dist[v]==-1)
            {
                dist[v] = dist[u] + ex+weight;
                pq.push(make_pair(dist[v], v));

            }
            else if(dist[v]>dist[u]+ex+weight){
                dist[v]=dist[u]+ex+weight;
                pq.push(make_pair(dist[v], v));
            }
        }
    }
}
void solve(){
   lld n,m,x,y; cin>>n>>m>>x>>y;
   iot(m){
   	lld a,b,t,k; cin>>a>>b>>t>>k;
   	adj[a].pb({b,{t,k}});
   	adj[b].pb({a,{t,k}});
   }
   lld dist[n+1];
   dijkstra(n,x,dist);
   cout<<dist[y];
}
int main(){
       ios_base::sync_with_stdio(false);
             cin.tie(0);
            cout.tie(0);
      lld t=1;// cin>>t;
      while(t--){
            solve();
            cout<<endl;
      }
}

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

#include <bits/stdc++.h>

using namespace std;

#define ll long long

using pos = pair<int, int>;

bool canMoveWith1Move(const pos& from, const pos& to){
    return (
        (from.first + from.second == to.first + to.second) ||
        (from.first - from.second == to.first - to.second) ||
        (abs(from.first - to.first) + abs(from.second - to.second) <= 3)
    );
}

bool canMoveWith2Moves(const pos& from, const pos& to){
    auto color = [](const pos& p) -> int {
        return ((p.first + p.second) % 2 + 2) % 2;
    };

    bool flg = false;
    for (int dx = -3; dx <= 3; ++dx){
        for (int dy = -3; dy <= 3; ++dy){
            pos tmp = {from.first + dx, from.second + dy};
            flg |= (canMoveWith1Move(from, tmp) && canMoveWith1Move(tmp, to));
        }
    }

    return (
        (color(from) == color(to)) ||
        (abs(from.first + from.second - to.first - to.second) <= 4) ||
        (abs(from.first - from.second - to.first + to.second) <= 4) ||
        (flg)
    );
}

int solve(const pos& from, const pos& to){
    if (from == to) return 0;
    if (canMoveWith1Move(from, to)) return 1;
    if (canMoveWith2Moves(from, to)) return 2;
    return 3;
}

int main(void){
    int x, y;
    cin >> x >> y;
    pos from = {x, y};
    cin >> x >> y;
    pos to = {x, y};
    cout << solve(from, to) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define debarrall(arr) debarr(arr,arr.size())
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

int powersimple(int a, int b){//a^b
    int res=1;
    while(b>0){
        if(b&1)
		{res=(res*a);
		b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}

int lcm(int a,int b){
    return a*b/__gcd(a,b);
}

int ncr(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

int power(int x,int y,int p)
{
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int modInverse(int n, int p)
{
    return power(n, p - 2, p);
}

int ncrModPFermat(int n,int r, int p)
{

    if (r == 0)
		return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % p;

    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}

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

///////////////END OF TEMPLATE//////////////////

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>n>>k;
	int arr[n][n];
	for(i=0;i<n;i++)
	for(j=0;j<n;j++)
	cin>>arr[i][j];

	vi po;
	for(i=1;i<n;i++)
	{
	    po.pb(i);
	}
	do{
	    sum=0;
	    sum+=arr[0][po.front()]+arr[po.back()][0];
	    for(i=0;i+1<po.size();i++)
	    {
	        sum+=arr[po[i]][po[i+1]];
	    }
	    cnt+=(sum==k);
	}
	while(next_permutation(all(po)));

	cout<<cnt<<endl;

}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(15);
    //test
    {

        solve();

    }
    return 0;
}

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

#define ll long long int
#define ull unsigned long long int

/********************************/

void dfs(int index, vector<vector<int>>& distance, int n, int k, bool visited[], ll& ans, ll currentSum) {
	visited[index] = true;

	bool isEmpty = true;
	for (int i = 0; i < n; i++) {
		if (!visited[i]) {
			isEmpty = false;
			dfs(i, distance, n, k, visited, ans, currentSum + distance[index][i]);
		}
	}

	if (isEmpty) {
		currentSum += distance[index][0];
		if (currentSum == k) ans++;
	}

	visited[index] = false;
}

void solve(vector<vector<int>>& distance, int n, int k) {
	ll ans = 0;
	bool visited[n];
	for (int i = 0; i < n; i++) {
		visited[i] = false;
	}

	dfs(0, distance, n, k, visited, ans, 0LL);
	cout << ans << endl;
}

int main() {

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

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

	ll t = 1;
	// cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;

		vector<vector<int>> distance;
		for (int i = 0; i < n; i++) {
			vector<int> row;
			for (int j = 0; j < n; j++) {
				int a;
				cin >> a;
				row.push_back(a);
			}
			distance.push_back(row);
		}

		solve(distance, n, k);
	}
}


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

//A.at(i) = iの約数の個数 = Π(素因数の乗数+1)
//しかし1から10^5まで全て因数分解するのはたぶん間に合わない
//☆違う
//例えば6の約数の個数は4だが、A.at(2) = A.at(3) = 2なのでA.at(6) = 3
//つまり「A.at(n) = A.at(nの約数iのうち、A.at(i)がもっとも大きいもの) + 1
//DP?

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1, 2);
    A.at(1) = 1;
    for (int i = 4; i <= N; i++){
        int root = sqrt(i);
        for (int j = 2; j <= root; j++){
            if(i % j == 0 && A.at(i / j) + 1 > A.at(i)){
                A.at(i) = A.at(i / j) + 1;
            }
        }
    }

    for (int i = 1; i <= N; i++){
        cout << A.at(i);
        if(i != N){
            cout << " ";
        }else{
            cout << endl;
        }
    }
}

#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define sqr(x) ((x) * (x))
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 30;
const LL INF = 2e9;

int n, a[MX], ans;

void rec(int i, int xr)
{
    if(i == n)
    {
        ans = min(ans, xr);
        return;
    }

    int vor = 0;

    loop(j,i,n)
    {
        vor |= a[j];
        rec(j+1,vor ^ xr);
    }
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>n;
    loop(i,0,n) cin>>a[i];

    ans = INF;
    rec(0,0);

    cout<<ans<<'\n';

    return 0;
}


#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long int ll;
#define vec vector<int>
#define pb push_back
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
     ll i,j,k,l,m,t;
    {
        ll a[2][2];
        for(i=0;i<2;i++)
        {
            for(j=0;j<2;j++)
            {
                cin>>a[i][j];
            }
        }
        cout<<(a[0][0]*a[1][1])-(a[1][0]*a[0][1]);
    }
}

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

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    cin.sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll cnt[n];
    memset(cnt,0,sizeof(cnt));
    ll i,j;
    for(i=0;i<n;i++) {
        ll x;
        cin>>x;
        cnt[x]+=1;
    }
    ll boxes[k];
    memset(boxes,-1,sizeof(boxes));
    i=0;
    j=0;
    while(i<n) {
        ll flag=0;
        while(cnt[i]>0) {
            if(boxes[j]+1==i || boxes[j]==i) {
                boxes[j]=i;
                j=(j+1)%k;
                cnt[i]-=1;
            }
            else {
                j=0;
                if(boxes[j]+1==i || boxes[j]==i) {
                    boxes[j]=i;
                    j=(j+1)%k;
                    cnt[i]-=1;
                }
                else {
                    flag=1;
                    break;
                }
            }
        }
        i+=1;
        j=0;
        if(flag==1)
            break;
    }
    ll ans=0;
    for(i=0;i<k;i++)
    ans=ans+boxes[i]+1;
    cout<<ans;
}

#include<bits/stdc++.h>
#define N 300005
#define ll long long
#define rep(i, l, r) for(int i=l; i<=r; ++i)
#define per(i, r, l) for(int i=r; i>=l; --i)
using namespace std;
int n, k;
int a[N], c[N];
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, n){
		scanf("%d", &a[i]);
		++c[a[i]];
	}
	c[0]=min(c[0], k);
	int ans=c[0];
	rep(i, 1, n){
		c[i]=min(c[i], c[i-1]);
		ans+=c[i];
	}
	printf("%d", ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  bool ok=true;
  for ( int i=0; i<s.size(); i++ ) {
    if ( isupper(s[i]) ) {
      if ( i%2==0 ) ok=false;
    } else {
      if ( i%2 ) ok=false;
    }
  }
  if ( ok ) cout<<"Yes\n";
  else cout<<"No\n";
  return 0;
}

#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(false), cin.tie(0);
#define et cout<<endl;
using namespace std;
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
const int N = 2e5+5;
const int M = 2e5+5;
const int mod = 1e9+7;
int t, n, k;
int g[N];
char s[N];
void solve()
{
    cin >> s + 1;
    int len = strlen(s+1);
    bool even = true, odd = true;
    for(int i = 1; i <= len; i ++)
    {
        if(i & 1)
        {
            if(s[i] >= 'a' && s[i] <= 'z') ;
            else even = false;
        }
        if(!(i & 1))
        {
            if(s[i] >= 'A' && s[i] <= 'Z') ;
            else odd = false;
        }
    }
    if(even && odd) cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main()
{
    ios
    bool multi = 0;   // 0 for single and 1 for multi
    if(multi) cin >> t;
    else t = 1;
    while(t--)
    {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
// rep
#define rep(i,n)    for(decltype(n) i = 0; i < (n) ; ++i)
#define orep(i,n)   for(decltype(n) i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(auto  i = (n)-1; i >= static_cast<decltype(i)>(0); --i) // down rep
#define srep(i,s,t) for(auto  i = (s); i < (t); ++i)  // set rep

// func
#define rng(x)  (x).begin(),(x).end() // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) <= (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define sz(x) int((x).size()) // size

// replace
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)
#define LL_MIN std::numeric_limits<long long>::min()
#define LL_MAX std::numeric_limits<long long>::max()

// type
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vvp = vector<vp>;
using vl  = vector<ll>;
using rpq = priority_queue<int,vi,less<int>>;   // 大きい順
using pq  = priority_queue<int,vi,greater<int>>;// 小さい順

const int INF = 1001001001;
const ll LINF = 1010010011001001001;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

int main() {
  float d; int t,s,v;cin >> v >> t >> s >> d;
  Yes(not isin(d / v, t, s));

  return 0;
}

#include <iostream>

using namespace std;

int main(void) {
    int V, T, S, D;
    cin >> V >> T >> S >> D;
    if (D > V*S || T*V > D)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}


#include<iostream>
#include<cstring>
#include<set>

using namespace std;

int n;
string ss;
set<string> s;

int main()
{
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>ss;

    if(ss[0]=='!'){
        string t=ss;
        t.erase(t.begin());
        if(s.count(t)){
            cout<<t;
            return 0;
        }

    }
    else {
        string t="!"+ss;
        if(s.count(t))
        {
            cout<<ss<<endl;
            return 0;
        }
    }
    s.insert(ss);
    }
    cout<<"satisfiable"<<endl;
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    map<string, int> mp;
    REP(i, N) {
        string t;
        cin >> t;
        mp[t]++;
    }
    for (auto &x : mp) {
        if (x.first[0] != '!') {
            if (mp["!" + x.first] > 0) {
                cout << x.first << endl;
                return;
            }
        }
    }
    cout << "satisfiable\n";
}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
  ll p, q, r;
  ll inf = 1e8 + 7;
  inf = inf * inf;
  p = -inf;
  q = inf;
  r = 0;
  int N;
  cin >> N;
  for (int i = 0; i < N; i ++) {
    ll a, t;
    cin >> a >> t;
    ll al, bt, gm;
    if (t == 1) {
      gm = a;
      al = -inf;
      bt = inf;
    }
    if (t == 2) {
      al = a;
      bt = inf;
      gm = 0;
    }
    if (t == 3) {
      bt = a;
      al = -inf;
      gm = 0;
    }
    ll nep = max(al, min(p + gm, bt));
    ll neq = min(q + gm, bt);
    ll ner = r + gm;
    p = nep;
    q = neq;
    r = ner;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i ++) {
    ll x;
    cin >> x;
    cout << max(p, min(x + r, q)) << endl;
  }
}

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION cout << fixed << setprecision(20);

using namespace std;

const int mod = 998244353;

struct Mint {
    ll v; explicit operator ll() const { return v; }
    Mint() { v = 0; }
    Mint(ll _v) {
        v = (-mod < _v && _v < mod) ? _v : _v % mod;
        if (v < 0) v += mod;
    }
    friend bool operator==(const Mint& a, const Mint& b) { return a.v == b.v; }
    friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
    friend bool operator<(const Mint& a, const Mint& b) { return a.v < b.v; }

    Mint& operator+=(const Mint& m) { if ((v += m.v) >= mod) v -= mod; return *this; }
    Mint& operator-=(const Mint& m) { if ((v -= m.v) < 0) v += mod; return *this; }
    Mint& operator*=(const Mint& m) { v = v*m.v%mod; return *this; }
    Mint& operator/=(const Mint& m) { return (*this) *= inv(m); }

    friend Mint pow(Mint a, ll p) {
        Mint ans = 1; assert(p >= 0);
        for (; p; p /= 2, a *= a) if (p & 1) ans *= a;
        return ans;
    }

    friend Mint inv(const Mint& a) { assert(a.v != 0); return pow(a, mod-2); }

    Mint operator-() const { return Mint(-v); }
    Mint& operator++() { return *this += 1; }
    Mint& operator--() { return *this -= 1; }
    Mint operator++(int) { Mint temp; temp.v = v++; return temp; }
    Mint operator--(int) { Mint temp; temp.v = v--; return temp; }

    friend Mint operator+(Mint a, const Mint& b) { return a += b; }
    friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
    friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
    friend Mint operator/(Mint a, const Mint& b) { return a /= b; }

    friend ostream& operator<<(ostream& os, const Mint& m) {
        os << m.v; return os;
    }

    friend istream& operator>>(istream& is, Mint& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};

const int N = 200000 + 100;

Mint fact[N];

int ff[N];

void pre() {
    fact[0] = Mint(1);
    for (int i = 1; i < N; i++) fact[i] = Mint(i) * fact[i - 1];

    for (int i = 2; i < N; i++) {
        if (!ff[i]) {
            for (int j = i; j < N; j += i) {
                if (!ff[j]) ff[j] = i;
            }
        }
    }
}

Mint ncr(int n, int r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] / (fact[n - r] * fact[r]);
}

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

    Mint ans = 0, ans2 = 0;

    // vector<Mint> dp(m + 1, 1);
    // for (int itr = 2; itr <= n; itr++) {
    //     vector<Mint> ndp(m + 1, 0);
    //     for (int i = 1; i <= m; i++) {
    //         for (int j = i; j <= m; j += i) {
    //             ndp[j] += dp[i];
    //         }
    //     }

    //     dp.swap(ndp);
    // }

    for (ll i = 1; i <= m; i++) {
        ll x = i;
        Mint curr = 1;
        while (x > 1) {
            int cnt = 0;
            int f = ff[x];
            while (x % f == 0) {
                x /= f;
                cnt++;
            }
            curr *= ncr(cnt + n - 1, n - 1);
        }
        ans += curr;
    }

    cout << ans << "\n";
}

int main() {
    FASTIO;
    PRECISION;

    pre();

    int t = 1;
    // cin >> t;

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


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

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

bool solve(long long N, std::vector<long long> &a, std::vector<long long> &b, std::vector<long long> &p) {
	map<int, int> m;
	vector<int> seq(N);
	iota(seq.begin(), seq.end(), 0);
	sort(seq.begin(), seq.end(), [&](int lhs, int rhs) {
		return a[lhs] < a[rhs];
	});
	for (int i = 0; i < N; ++i) {
		if (p[i] != i && a[i] <= b[p[i]]) {
			return false;
		}
		m[p[i]] = i;		// 荷物p[i]はiが持っている
	}
	vector<II> ans;
	for (int i = 0; i < N; ++i) {
		int j = seq[i];
		if (m[j] == j) continue;
		int target = m[j];
		ans.emplace_back(II(j + 1, target + 1));
		m[p[j]] = target;
		m[j] = j;
		swap(p[j], p[target]);
	}
	cout << ans.size() << endl;
	for (auto kv : ans) {
		cout << kv.first << " " << kv.second << endl;
	}
	return true;
}

int main() {
    long long N;
	std::cin >> N;
	std::vector<long long> a(N), b(N), p(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		std::cin >> b[i];
	}
	for (int i = 0; i < N; i++) {
		std::cin >> p[i]; p[i]--;
	}
	if (!solve(N, a, b, p)) {
		cout << -1 << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b)for(ll i=a;i<=b;i++)
#define loopr(i,a,b)for(ll i=b;i>=a;i--)
#define vll vector<ll>
#define vvl vector<vll>
#define pii pair<ll,ll>
#define F first
#define S second
#define endl "\n"
#define M 1000000007
ll max(ll a,ll b){if (a>b) return a; else return b;}
ll min(ll a,ll b){if(a<b) return a; return b;}

ll po(ll x, ll y){
    if(y==0)
    return 1;
    if(y%2){
        return ((x)*(po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
    }
   return ((po(x,y/2)%M)*(po(x,y/2)%M) + M)%M;
}

void seive(bool prime[]){
    //bool prime[100002];

    for (ll p=2; p*p<=1000001; p++)
    {
        if (prime[p])
        {
            for (ll i=p*p; i<=1000001; i+=p)
                prime[i] = false;
        }
    }
}

ll powermod(ll x,ll y,ll p)
{   ll res = 1;
    x = x % p;
 if (x == 0) return 0;
    while (y > 0)
    {     if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

ll gcd(ll x, ll y){
    if (y == 0)
    return x;
    else
    return gcd(y, x % y);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
    //cin>>t;
    while(t--){
        ll n; cin>>n;
        vll a(n),b(n);
        vll mx(n);
        fo(i,n){
            cin>>a[i];
            if(i==0)
            mx[i]=a[i];
            else
            mx[i]=max(a[i],mx[i-1]);
        }
        fo(i,n)
        cin>>b[i];
        vll c(n);
        c[0]=a[0]*b[0];
        for(ll i=1; i<n; i++){
            c[i]=max(c[i-1],b[i]*mx[i]);
        }
        fo(i,n)
        cout<<c[i]<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
const ll MAX = 1000000000000000000LL;
const ll md = 998244353;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)

ll pw(ll a, ll n)
{
	ll result = 1;
	while (n)
	{
		if (n&1) result = (result*a)%md;
		a = (a*a)%md;
		n >>= 1;
	}
	return result;
}

vector<int> primes;
void sieve(int n)
{
	bool *isp = new bool[n+1];
	for(int i=0; i<=n; ++i)
		isp[i] = i>1;
	for(int i=2; i*i <= n; ++i)
	{
		if (isp[i])
		{
			for(int j=i*i; j<=n; j+=i)
			{
				isp[j] = false;
			}
		}
	}
	for(int i=0; i<=n; ++i)
	{
		if (isp[i])
		{
			primes.push_back(i);
		}
	}

}

inline ll ad(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod)%mod;
}

inline ll ml(ll a, ll b, ll mod = md) {
    return ((a%mod) * (b%mod))%mod;
}

vl fac(2,1), ifac(2,1);
ll C(ll n, ll r, ll mod = md) {
	if(n < r) return 0;
    return ml(fac[n], ml(ifac[r], ifac[n-r], mod), mod);
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

int main()
{
	FAST_IO;

	int n, m;
	cin >> n >> m;
	cachefact(m+n);
	sieve(sqrt(m)+2);
	ll result = 0;
	int ps = primes.size();
	for (int i=1; i<=m; ++i)
	{
		ll I = i, run = 1;
		for(int j=0; j < ps && primes[j]*primes[j] <= I; ++j)
		{
			int e=0;
			while (I%primes[j] == 0)
			{
				I /= primes[j];
				e++;
			}
			run = ml(run, C(n+e-1, e));
		}
		if (I > 1) run = ml(run, n);
		result = ad(result, run);
	}

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

// Problem: D - Powers
// Contest: AtCoder - AtCoder Regular Contest 106
// URL: https://atcoder.jp/contests/arc106/tasks/arc106_d
// Memory Limit: 1024 MB
// Time Limit: 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

const int N = 2e5+7,M = 305,MOD = 998244353;
ll fx[M],fc[M],fsa[M],fsb[M];
int a[N],b[N];
ll fa[N][M],fb[N][M];
ll qmul(ll a, ll b, ll P)
{
  	ll L = a * (b >> 25LL) % P * (1LL << 25) % P;
  	ll R = a * (b & ((1LL << 25) - 1)) % P;
  	return (L + R) % P;
}
ll qpow(ll a,ll b,ll p)
{
	ll res = 1 % p;
	while(b)
	{
		if(b & 1)	res = qmul(res,a,p);
		a = qmul(a,a,p);
		b >>= 1;
	}
	return res;
}
ll C[M][M];
int main()
{
	int n,k,rev2 = qpow(2,MOD - 2,MOD);scanf("%d%d",&n,&k);
    forn(i,1,n)	scanf("%d",&a[i]),b[i] = 2 * a[i];
	C[0][0] = 1;
    forn(i,1,k)	forn(j,0,i)	C[i][j] = (!j) ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	fsa[0] = n,fsb[0] = n;
	forn(i,1,n)
	{
		ll _a = 1,_b = 1;
		forn(j,1,k)
		{
			_a = _a * a[i] % MOD,_b = _b * b[i] % MOD;
			fsa[j] = (fsa[j] + _a) % MOD,fsb[j] = (fsb[j] + _b) % MOD;
		}
	}

    forn(x,1,k)
    {
		ll lf = 0;
		forn(i,0,k)
		{
			ll t = fsa[i] * fsa[x - i] % MOD;
			t = t * C[x][i] % MOD;
			lf = (lf + t) % MOD;
		}
		// cout << lf << endl;
		lf = ((lf - fsb[x]) % MOD + MOD) % MOD;
		printf("%lld\n",rev2 * lf % MOD);
    }
    return 0;
}


#pragma comment(linker, "/STACK:128777216")
#pragma GCC optimize("fast-maths")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#include <complex>
#include <functional>
#ifdef ORSET
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, std::less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;
#endif
using namespace std;

#define forx(_name, _from, _to, _value) for (int _name = _from; _name < _to; _name += _value)
#define rforx(_name, _from, _to, _value) for (int _name = _from; _name > _to; _name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST, _SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-7;
mt19937_64 rndm;

void start() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.precision(8); cout.setf(ios::fixed);
    string FILENAME = "\-__-/";
    rndm.seed(time(0));
#ifdef _DEBUG
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#else
    //freopen((FILENAME + ".in").c_str(), "rt", stdin);
    //freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}
#ifdef NEEDFFAST
inline int FastIn() {
    int val = 0;
    char c = ' ';
    while (!isdigit(c))
        c = _getchar_nolock();
    while (isdigit(c)) {
        val *= 10;
        val += c - '0';
        c = _getchar_nolock();
    }
    return val;
}

inline void FastOut(int val) {
    bool fst = true;
    const int degree = 1000000000;
    //const ll degree = 10000000000000000ll;
    for (int i = degree; i > 0; i /= 10) {
        int dl = val / i;
        if (dl || !fst) {
            _putchar_nolock('0' + dl);
            fst = false;
        }
        val %= i;
    }
    if (fst)
        _putchar_nolock('0');
}
#endif

const ll mod = 1000000007;
ll binpow(ll val, ll deg) {
    ll res = 1;
    ll dg = val;
    while (deg) {
        if (deg & 1) res = (res * dg) % mod;
        deg >>= 1;
        dg = (dg * dg) % mod;
    }
    return res;
}

int main() {
    start();
    /* (P - 1) * (P - 2) ^ (N - 1) */
    ll n, p;
    cin >> n >> p;
    cout << (p - 1) * binpow(p - 2, n - 1) % mod;
#ifdef _DEBUG
    cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <cmath>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double EPS = 1e-10;
constexpr ll mod = 1000000007;
// constexpr ll 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};
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; }
const char eol = '\n';
// --------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,p;
    cin >> n >> p;
    ll ans = p-1;
    n--;
    ll sum = p-2;
    for(ll k=0; k<40; k++){
        if(n & (1LL<<k)){
            ans *= sum;
            ans %= mod;
        }
        sum = sum*sum;
        sum %= mod;
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define Time (double)clock()/CLOCKS_PER_SEC
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pi;
template <class T> void chmax(T &x,T y) {x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y) {x=x<y?x:y;return;}
template <class T> T sqr(T x) {return x*x;}
template <class T> T gcd(T x,T y) {return y==0?x:gcd(y,x%y);}
template <class T> T lcm(T x,T y) {return x/gcd(x,y)*y;}
const int inf=1000000000,mod=1000000007;
const ll infll=1000000000000000000ll,modll=ll(mod);
const db maxdb=db(infll),eps=1e-14,PI=acos(-1.0);
//#define mydef
//#define LOCAL
#ifdef mydef
#define foreach(v,it) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#endif
#define debug
#define putnum(x) cout<<#x<<": "<<x<<endl
#define putvec(v) cout<<#v<<": ";REP(i,0,sz(v)) cout<<v[i]<<" ";cout<<endl
template <class T> inline void read(T &x){
	T w=1;x=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')w=-1;c=getchar();}
	while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+(c&15);c=getchar();}
	x*=w;
}
template <class T> inline void write(T x) {
	if(x<0) putchar('-'),x=~x+1;
	if(x) write(x/10),putchar(x%10+'0');
}

const int maxn=700005;
int n,ans;
int a[maxn],l[maxn],r[maxn];
set<pi,greater<pi> > num;

void Get(int f,int *arr) {
	num.clear();
	for(int i=(f==1?1:n);i&&i<=n;i+=f) {
		while(!num.empty()&&(*num.begin()).fi>a[i]) {
			arr[(*num.begin()).se]=f==1?i-1:i+1;
			num.erase(num.begin());
		}
		num.insert(mp(a[i],i));
	}
	while(!num.empty()) {
		arr[(*num.begin()).se]=(f==1?n:1);
		num.erase(num.begin());
	}
//	if(f==-1) cout<<arr[2]<<endl;
}

int main() {
	#ifdef LOCAL
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	Get(1,r);
	Get(-1,l);
	for(int i=1;i<=n;i++)
		ans=max(ans,(r[i]-l[i]+1)*a[i]);
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  int N, ret = 0; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int m = 0;
  for (int i = 0; i < N; i++) {
    m = A[i];
    for (int j = i; j < N; j++) {
      m = min(m, A[j]);
      ret = max(ret, m * (j - i + 1));
    }
  }

  cout << ret << endl;
  return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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 <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

void solve()
{
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	ll ans=0;
	int pos=0;
	rep(i,n){
		chmax(pos,i+1);
		if(s[i]=='1'&&t[i]!='1'){
			for(;pos<n;++pos){
				if(s[pos]=='1'){
					s[i]='0';
					s[pos]='0';
					ans+=pos-i;
					break;
				}
			}
		}
		else if(s[i]!='1'&&t[i]=='1'){
			for(;pos<n;++pos){
				if(s[pos]=='1'){
					s[i]='1';
					s[pos]='0';
					ans+=pos-i;
					break;
				}
			}
		}
	}
	if(s==t){
		cout<<ans;
	}
	else{
		cout<<-1;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, j, k) for(int i = j; i < k; i++)
#define print(x) cout << x
#define newline cout << endl
#define space cout << ' '
#define INF 1000000000007
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

int main(){
    int h,w,x,y;
    cin >> h >>w >>x>>y;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans=1;
    for(int i=x;i<h;i++){
        if(s[i][y-1]=='#') break;
        ans++;
    }
    for(int i=x-2;i>-1;i--){
        if(s[i][y-1]=='#') break;
        ans++;
    }
    for(int i=y;i<w;i++){
        if(s[x-1][i]=='#') break;
        ans++;
    }
    for(int i=y-2;i>-1;i--){
        if(s[x-1][i]=='#') break;
        ans++;
    }
    print(ans);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

    int n;
    cin>>n;

    pair<int,int> points[n];
    for(int i=0;i<n;i++){
        cin>>points[i].first>>points[i].second;
    }
    int freq=0;
    for(int i=0;i<n;i++){
            int j=n-1;
      while(j>i){
            float a=(points[j].second)-(points[i].second);
      float b=(points[j].first)-(points[i].first);
        float s=a/b;

        if(s<=1&&s>=-1){freq++;}
        j--;}}

        cout<<freq;

    return 0;}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ans += (ll)(a + b) * (b - a + 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define endl '\n'
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

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

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    s<<endl;
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    ll x,y;
    cin>>x>>y;
    Yes(abs(x-y)<3);
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
//    ll T;
//    cin>>T;
//    while(T--)
    solve();
}

#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#include<queue>
//#include<atcoder/segtree>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
using T = tuple<int,int,int>;
const int INF = 1e9;
//using namespace atcoder;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<P> > alp(30);
    string a[h];
    P s, g;
    int cost[h][w];
    queue<P> q;
    rep(i,h) cin >> a[i];
    rep(i,h)rep(j,w){
        if(a[i][j]=='S'){ s.first=i; s.second=j;}
        else if(a[i][j]=='G'){
            //P g(i,j);
            g.first=i; g.second=j;
            }
        else if(a[i][j]=='#') cost[i][j]=-2;
        else if(a[i][j]=='.') continue;
        else{
            alp[a[i][j]-'a'].push_back(P(i,j));
        }
    }
    rep(i,h)rep(j,w) cost[i][j]=-1;

    P tmp;
    q.push(s);
    cost[s.first][s.second] = 0;
    int already[30]={};
    while(!q.empty()){
        tmp = q.front(); q.pop();
        int x = tmp.first, y = tmp.second;
        if(x>0){
            if(cost[x-1][y]==-1){
                if(a[x-1][y]!='#'){
                    cost[x-1][y] = cost[x][y]+1;
                    q.push(P(x-1,y));
                    }
            }
        }
        if(x<h-1){
            if(cost[x+1][y]==-1){
                if(a[x+1][y]!='#'){
                    cost[x+1][y] = cost[x][y]+1;
                    q.push(P(x+1,y));
                    }
            }
        }
        if(y>0){
            if(cost[x][y-1]==-1){
                if(a[x][y-1]!='#'){
                    cost[x][y-1] = cost[x][y]+1;
                    q.push(P(x,y-1));
                    }
            }
        }
        if(y<w-1){
            if(cost[x][y+1]==-1){
                if(a[x][y+1]!='#'){
                    cost[x][y+1] = cost[x][y]+1;
                    q.push(P(x,y+1));
                    }
            }
        }
        if(a[x][y]!='S' && a[x][y]!='.' && a[x][y]!='#' && a[x][y]!='G'){
            if(already[a[x][y]-'a']==0){
                already[a[x][y]-'a']=1;
                rep(i, alp[a[x][y]-'a'].size()){
                    P teleport = alp[a[x][y]-'a'][i];
                    if(cost[teleport.first][teleport.second]==-1){
                        cost[teleport.first][teleport.second] = cost[x][y]+1;
                        q.push(P(teleport.first,teleport.second));
                    }
                }
            }
        }
    }
    //cout <<g.first<<" " <<g.second << endl;
    cout << cost[g.first][g.second] << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int mod = 998244353;
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    n *= 2;
    int a[n], tag[n];
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) cin >> a[i], v.push_back({a[i], i});
    sort(v.begin(), v.end());
    for (int i = 0; i < n / 2; i++) tag[v[i].se] = 1;
    for (int i = n / 2; i < n; i++) tag[v[i].se] = -1;
    int ans[n]{}, pre[n + 1]{};
    map<int, queue<int>> v2;
    for (int i = 0; i < n; i++) pre[i + 1] = pre[i] + tag[i], v2[pre[i + 1]].push(i);
    for (int i = 0; i < n; i++){
        if (ans[i]) continue;
        ans[i] = 1;
        v2[pre[i + 1]].pop();
        int p = v2[pre[i]].front();
        v2[pre[i]].pop();
        ans[p] = 2;
        //cout << pre[i] << ' ' << p << '\n';
    }
    for (int i = 0; i < n; i++) cout << (ans[i] == 1 ? '(' : ')');
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()

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

int main(){
    ll N;
    cin>>N;
    N*=2;
    v A(N);
    rep(i,0,N)cin>>A[i];
    v As=A;
    sort(all(As));
    ll mid = -1;
    ll midl = 0, midr = 0;
    if(As[N/2] == As[N/2-1]){
        mid = As[N/2];
    }
    map<ll,ll> m;
    rep(i,0,N){
        if(As[i]!=mid){
            if(i<N/2)m[As[i]]--;
            else m[As[i]]++;
        }
        else{
            m[As[i]] = 999999;
            if(i<N/2)midl++;
            else midr++;
        }
    }
    //cout<<m[1]<<m[4]<<endl;
    ll now = 0;
    ll nowL = 0;
    rep(i,0,N){
        //cout<<A[i]<<m[A[i]]<<endl;
        if(m[A[i]] == 999999){
            if(now > 0){
                if(midl > 0){
                    cout<<")";
                    nowL--;
                    if(nowL == 0)now = 0;
                    midl--;
                }
                else{
                    now = 1;
                    cout<<"(";
                    nowL++;
                    midr--;
                }
            }
            else if(now < 0){
                if(midr > 0){
                    cout<<")";
                    nowL--;
                    if(nowL == 0)now = 0;
                    midr--;
                }
                else{
                    now = -1;
                    cout<<"(";
                    nowL++;
                    midl--;
                }
            }
            else{
                cout<<"(";
                nowL++;
                if(midr==0){
                    now = -1;
                    midl--;
                }
                else if(midl == 0){
                    now = 1;
                    midr--;
                }
                else{
                    if(m[A[i+1]] == 999999 || m[A[i+1]] > 0){
                        now = -1;
                        midl--;
                    }
                    else{
                        now = 1;
                        midr--;
                    }
                }
            }

        }
        else if(m[A[i]] < 0){
            if(now <= 0){
                now = -1;
                cout<<"(";
                nowL++;
            }
            else{
                cout<<")";
                nowL--;
                if(nowL == 0)now = 0;
            }
        }
        else{
            if(now >= 0){
                now = 1;
                cout<<"(";
                nowL++;
            }
            else {
                cout<<")";
                nowL--;
                if(nowL == 0)now = 0;
            }
        }

    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll inv_mod(ll x){
    return pow_mod(x,mod-2);
}

const ll N=(ll)3e5;
ll inv[N];
ll fac[N];

ll ncr(ll n,ll r){
    if(n<r)
    return 0;

    if(n==r||r==0)
    return 1LL;

    ll x=fac[n];
    ll y=inv[n-r];
    ll z=inv[r];

    return ((x*y)%mod*z)%mod;
}
void solve()
{
    ll n;
    cin>>n;
    double ans=0.00;
    double prev=0.00;

    for(ll i=1;i<n;i++){
    	 ans= prev+(double)n/(double)i;
    	 prev=ans;
	}
    cout<<fixed<<setprecision(6)<<ans<<endl;
}
int main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

//Start from Here.

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

  fac[0]=1;

  for(ll i=1;i<N;i++)
  fac[i]=(i*fac[i-1])%mod;

  for(ll i=0;i<N;i++)
  inv[i]=inv_mod(fac[i]);
//Good Bye!
    return 0;
}

        // Umang_US

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 2*100005
#define sec second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

void init_code(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
}

void solve()
{
    ll x,y;
    cin>>x>>y;
    if(x==y)
    {
        cout<<x<<endl;
    }
    else
    {
        map<ll,ll>m;
        m[x]++;
        m[y]++;
        for(int i=0;i<=2;i++)
        {
            if(m[i]==0)
            {
                cout<<i<<endl;
                return;
            }
        }
    }
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD ll(998244353)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> board(h, vector<ll>(w));
    vector<vector<ll>> score(h, vector<ll>(w));

    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < w; j++){
            board[i][j] = s[j] == '+' ? 1 : -1;
        }
    }

    score[h-1][w-1] = 0;
    for(int i = h-1; i >= 0; i--){
        for(int j = w-1; j >= 0; j--){
            if(i == h-1 && j == w-1){continue;}
            if((i+j)%2==1){//aoki
                if(i<h-1 && j<w-1){
                    score[i][j] = min(score[i+1][j] - board[i+1][j], score[i][j+1] - board[i][j+1]);
                }else if(i<h-1 && j==w-1){
                    score[i][j] = score[i+1][j] - board[i+1][j];
                }else if(i==h-1 && j<w-1){
                    score[i][j] = score[i][j+1] - board[i][j+1];
                }
            }else{
                if(i<h-1 && j<w-1){
                    score[i][j] = max(score[i+1][j] + board[i+1][j], score[i][j+1] + board[i][j+1]);
                }else if(i<h-1 && j==w-1){
                    score[i][j] = score[i+1][j] + board[i+1][j];
                }else if(i==h-1 && j<w-1){
                    score[i][j] = score[i][j+1] + board[i][j+1];
                }
            }

        }
    }

    if(score[0][0] > 0){
        cout << "Takahashi" << endl;
    }else if(score[0][0] == 0){
        cout << "Draw" << endl;
    }else{
        cout << "Aoki" << endl;
    }
    return 0;

}

#include<iostream>
#include<algorithm>
using namespace std;
int H,W;
string A[2000];
int dp[2000][2000];
main()
{
	cin>>H>>W;
	for(int i=0;i<H;i++)cin>>A[i];
	int ans;
	for(int i=H;i--;)for(int j=W;j--;)
	{
		int L=-1e9,R=-1e9;
		if(i<H-1)
		{
			L=-dp[i+1][j];
		}
		if(j<W-1)
		{
			R=-dp[i][j+1];
		}
		ans=dp[i][j]=max(L,R);
		if(i==H-1&&j==W-1)ans=dp[i][j]=0;
		if(A[i][j]=='+')dp[i][j]--;
		else dp[i][j]++;
	}
	cout<<(ans>0?"Takahashi":ans<0?"Aoki":"Draw")<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int a1,a2,a3;
int main(){
    cin>>a1>>a2>>a3;
    if(a1>a2)swap(a1,a2);
    if(a1>a3)swap(a1,a3);
    if(a2>a3)swap(a2,a3);
    cout<<(a3-a2==a2-a1?"Yes":"No");
}

#include <math.h>

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,L=10000000000;
string s,t;
int main(void){
    cin>>n>>s;
    for(int i=0;i<n;i++)t+="110";
    if(s=="1")cout<<L*2<<endl;
    else if(n%3==1 && t.substr(0,n)==s)cout<<L-((n-1)/3)<<endl;
    else if(n%3==2 && t.substr(0,n)==s)cout<<L-((n-2)/3)<<endl;
    else if(n%3==0 && t.substr(0,n)==s)cout<<L-((n-3)/3)<<endl;
    else if(n%3==0 && t.substr(1,n)==s)cout<<L-(n/3)<<endl;
    else if(n%3==1 && t.substr(1,n)==s)cout<<L-((n-1)/3)<<endl;
    else if(n%3==2 && t.substr(1,n)==s)cout<<L-((n-2)/3)<<endl;
    else if(n%3==2 && t.substr(2,n)==s)cout<<L-((n+1)/3)<<endl;
    else if(n%3==0 && t.substr(2,n)==s)cout<<L-(n/3)<<endl;
    else if(n%3==1 && t.substr(2,n)==s)cout<<L-((n-1)/3)<<endl;
    else cout<<0<<endl;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <array>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
using ll = long long;
using std::cin;
using std::cout;
using std::endl;
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; }
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

template<int mod>
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      std::swap(a -= t * b, b);
      std::swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend std::ostream &operator<<(std::ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend std::istream &operator>>(std::istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

constexpr int mod = (int)1e9 + 7;
using mint = ModInt<mod>;
void solve()
{
  ll n, P; cin >> n >> P;
  if(P == 2)
  {
    if(n == 1)
    {
      cout << 1 << "\n";
    }
    else
    {
      cout << 0 << "\n";
    }
  }
  else
  {
    mint res = mint(P - 1) * mint(P - 2).pow(n - 1);
    cout << res << "\n";
  }
}
int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int kkt = 1;
  //cin >> kkt;
  while(kkt--)
    solve();
  return 0;
}


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

int main(){
  int n; cin >> n;
  int ans = n*108;
  ans = ans/100;
  if(ans<206) cout << "Yay!" << endl;
  if(ans==206) cout << "so-so"<<endl;
  if(ans>206) cout << ":(" << endl;
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (int)(a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;
using VII = vector<VI>;
using VLL = vector<VL>;
using VDD = vector<VD>;
using P = pair<int, int>;
using PL = pair<ll, ll>;

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

void solve(long long N) {
  ll tmp = double(N) * 1.08;
  ll price = 206;
  string ans;
  if(tmp > price) ans = ":(";
  if(tmp == price) ans = "so-so";
  if(tmp < price) ans = "Yay!";
  cout << ans << endl;
}

int main() {
  long long N;
  std::scanf("%lld", &N);
  solve(N);
  return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807ll
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define N  100005

ll n;
ll dp[17][(1<<17)];
ll x[17],y[17],z[17];
ll dps(ll cur,ll mask)
{
    if(mask==((1<<n)-1))
    {
        return abs(x[0]-x[cur])+abs(y[0]-y[cur])+max(0ll,z[0]-z[cur]);
    }
    if(dp[cur][mask]!=-1)
        return dp[cur][mask];
    ll ans=hell;
    rep(i,0,n)
    {
        if(((1<<i)&mask)==0)
        {
            ll c=abs(x[i]-x[cur])+abs(y[i]-y[cur])+max(0ll,z[i]-z[cur]);
            ans=min(ans,c+dps(i,mask|(1<<i)));
        }
    }
    return dp[cur][mask]=ans;
}
void solve()
{
    cin>>n;
    rep(i,0,n)
    {
        cin>>x[i]>>y[i]>>z[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<dps(0,1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 1e5+5;
int l[maxn], r[maxn];
int p[maxn];
bool ok[205][205];
void build(int L,int R) {
    int sz = (R - L + 1) / 2;
    for (int i = L, j = i + sz ; j <= R ; i++,j++) {
        if (p[i] && p[j] && p[i] + p[j]) return;
        if (p[i] > 0)return;
        if (p[j] < 0) return;
    }
    ok[L][R] = 1;
}
void go() {
    int n;
    cin >> n;
    f1(n) {
        cin >> l[i] >> r[i];
        if (~l[i] && ~r[i] && l[i] > r[i]) {
            cout << "No\n";
            exit(0);
        }
        if (~l[i]) {
            if (p[l[i]]) {
                cout << "No\n";
                exit(0);
            }
            p[l[i]] = -i;
        }
        if (~r[i]) {
            if (p[r[i]]) {
                cout << "No\n";
                exit(0);
            }
            p[r[i]] = i;
        }
    }
    n *= 2;
    for (int i = 1 ; i <= n ; i += 2) {
        for (int j = i + 1 ; j <= n ; j++) {
            build(i,j);
            //cout << i <<' '<<j<<' '<<ok[i][j] << '\n';
        }
    }
    int dp[n+5] = {};
    dp[0] = 1;
    for (int i = 2 ; i <= n ; i+= 2) {
        for (int j = 1 ; j <= i ; j += 2) {
            if (ok[j][i] && dp[j-1]) dp[i]= 1;
        }
    }
    if (dp[n]) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<pll> vp;
typedef priority_queue<pll,vp,greater<pll> > pqpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) (a.begin(), a.end())

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

#define SEG_LEN (1 << 19)

ll seg[SEG_LEN*2];

void add(ll ind,ll v){
    ind += SEG_LEN;
    seg[ind] ^= v;
    while(1){
        ind /= 2;
        if(ind <= 0) break;
        seg[ind] = seg[ind*2] ^ seg[ind*2+1];
    }
    return;
}

ll sum(ll l, ll r){
    l += SEG_LEN; r += SEG_LEN;
    ll res = 0;
    while(l < r){
        if(l % 2 == 1){
            res ^= seg[l];
            l++;
        }
        l /= 2;

        if(r % 2 == 1){
            res ^= seg[r-1];
            r--;
        }
        r /= 2;
    }
    return res;
}

int main(){
    ll n,q;
    cin >> n >> q;
    vll a(n);
    rep(i,0,n) cin >> a[i];
    rep(i,0,n) add(i+1,a[i]);

    ll t,x,y;
    rep(i,0,q){
        cin >> t >> x >> y;
        if(t == 1){
            add(x,y);
        }
        else{
            cout << sum(x,y+1) << endl;
        }
    }
}

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

int main() {
	long long N, Q; cin >> N >> Q;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<pair<long long, long long>> vec;
	for (int i = 0; i < N; i++) {
		vec.emplace_back(A[i], i);
	}
	sort(vec.begin(), vec.end());

	for (int i = 0; i < Q; i++) {
		long long K; cin >> K;
		long long left = 0, right = 1100000000000000000;
		while (right - left > 1) {
			long long mid = left + (right - left) / 2;
			long long left_ = -1, right_ = N;
			bool flag = false;
			while (right_ - left_ > 1) {
				long long mid_ = left_ + (right_ - left_) / 2;
				if (A[mid_] > mid) right_ = mid_;
				else if (A[mid_] < mid) left_ = mid_;
				else {
					flag = true;
					right_ = mid_; left_ = mid_;
				}
			}
			if (!flag) {
				if (right_ + K > mid) left = mid;
				else right = mid;
			}
			else {
				if (right_ + K >= mid) left = mid;
				else right = mid;
			}
		}
		cout << right << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<(1<<n)-1<<endl;
    for(int i=1;i<(1<<n);i++)
    {
        for(int j=0;j<(1<<n);j++)
            putchar('A'+(__builtin_popcount(i&j)&1));
        puts("");
    }
    return 0;
}

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

int main() {
    ll N; cin>>N;
    ll sum = 0;

    for(ll i=1; i<1e9; i++){
        sum +=  i;
        if(sum >= N){
            cout << i << endl;
            return 0;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
long long dp1[200010],dp2[200010],tr[200010],n,m,t,ans=0,vis[200010];
vector<long long>f[200010];
void change(long long x){
    for(long long i=x;i<=m;i+=i&-i)
    tr[i]++;
}
long long ask(long long x){
    long long s=0;
    for(long long i=x;i;i-=i&-i)
    s=s+tr[i];
    return s;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m>>t;
    long long s1=n+1,s2=m+1;
    for(long long i=1;i<=n;i++)
    dp1[i]=m+1;
    for(long long i=1;i<=m;i++)
    dp2[i]=n+1;
    for(long long i=1;i<=t;i++){
        long long x,y;
        cin>>x>>y;
        dp1[x]=min(dp1[x],y);
        dp2[y]=min(dp2[y],x);
        f[x].push_back(y);
    }
    for(long long i=1;i<dp2[1];i++)
    ans=ans+dp1[i]-1;
    for(long long j=1;j<dp1[1];j++)
    ans=ans+dp2[j]-1;
    for(long long i=1;i<dp2[1];i++){
        for(long long j=0;j<f[i].size();j++){
            long long tt=f[i][j];
            if(!vis[tt]){
                vis[tt]=true;
                change(tt);
            }
        }
        long long tt=min(dp1[i],dp1[1]-1);
        ans=ans-(tt-ask(tt));
    }
    cout<<ans<<"\n";
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

struct Edge{
    ll to, cost;
    Edge(ll t, ll c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;

ll MODpow(ll x, ll n, ll mod){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n >>= 1;
	}
	return res;
}

const ll MOD=1e9+7;
const ll nmax=200000+10;

ll N;
Graph G(nmax);

ll solve(){
	vvl color(nmax,vl(60,-1));
	vl cnt1(60,0);
	vl seen(nmax,0);
    queue<ll> q;
    q.push(0);
	REP(i,60) color[0][i]=0;

    while(!q.empty()){
        ll v=q.front();
        q.pop();
        seen[v]=1;

        for(auto e:G[v]){
            if(seen[e.to]) continue;

			ll et=e.to, ec=e.cost;
			q.push(e.to);
			REP(i,60){
				bool eci=ec&1;
				ec>>=1;
				color[et][i]=color[v][i]^eci;
				if(color[et][i]) cnt1[i]++;
			}
        }
    }

	ll res=0,rec=1;
	REP(i,60){
		ll mid1=rec;
		rec=rec*2%MOD;
		ll mid2=(N-cnt1[i])*cnt1[i]%MOD;
		ll mid=mid1*mid2%MOD;
		res+=mid;
		res%=MOD;
	}

    return res;
}

int main(void){
    cin>>N;
    REP(i,N-1){
        ll u,v,w; cin>>u>>v>>w;
        u--,v--;
        G[u].push_back(Edge{v,w});
        G[v].push_back(Edge{u,w});
    }

    ll res=solve();
    cout<<res<<endl;

    return 0;
}


#ifdef _LOCAL
    #include "local_include.hpp"
#else
    #include <bits/stdc++.h>
    using namespace std;
#endif
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define bc __builtin_popcountll
#define endl '\n'
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl

template<typename T>
void bug(T const &var) { cout << var << endl; }

template<typename T, typename... Args>
void bug(T const &var, Args const &... args) {
    cout << var << ' ';
    bug(args...);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 2e5+3;

int n;
int vmin[maxn], vmax[maxn];

#define multi_test 0
void _main() {
    cin >> n;
    fto (c, 1, 2e5) vmin[c] = oo, vmax[c] = -oo;
    set<int> a;
    fto (i, 1, n) {
        int x, c;
        cin >> x >> c;
        vmin[c] = min(vmin[c], x);
        vmax[c] = max(vmax[c], x);
        a.insert(c);
    }
    ii cur = {0, 0};
    ll fmin = 0, fmax = 0;
    fat (c, a) {
        ll dt = vmax[c] - vmin[c];
        ll fmin2 = dt + min(fmin + abs(cur.first - vmax[c]), fmax + abs(cur.second - vmax[c]));
        ll fmax2 = dt + min(fmin + abs(cur.first - vmin[c]), fmax + abs(cur.second - vmin[c]));
        fmin = fmin2; fmax = fmax2;
        cur = {vmin[c], vmax[c]};
    }
    bug(min(fmin + abs(cur.first), fmax + abs(cur.second)));
}

int main() {
    #ifdef _LOCAL
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
    if (multi_test) cin >> t;
    while (t--) {
        _main();
    }

    #ifdef _LOCAL
        cerr << 0.001*clock() << endl;
    #endif
    return 0;
}

//sudo apt install bcmwl-kernel-source
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef  long double ld;
ll P=1e9+7;
ll mmod=998244353;

vector<ll> tenx(11);

/*----------------------------------------------------------------------------------------------------------------------------*/

bool comp(pair<int,int> a,pair<int,int> b){
    if(a.first==b.first)
        return a.second<b.second;
    return a.first<b.first;

}

int  find_mmn(vector<int> &arr,int n,int start,int end){
    int i;int mmn=INT_MAX;
    for(i=start;i<=end;i++){
        mmn=min(mmn,arr[i]);
    }
    return mmn;
}

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

int n;
cin>>n;
vector<ll> arr(n);
ll i,j;
for(i=0;i<n;i++){
    cin>>arr[i];
}
i=0;j=0;int mmn;
ll ans=LLONG_MIN;ll now;ll k;
for(i=0;i<n;i++){
    j=i;now=0;k=i-1;
    while(j<n && arr[j]>=arr[i]){
        now+=arr[i];
        j++;
    }
    while(k>=0 && arr[k]>=arr[i]){
        now+=arr[i];
        k--;
    }
    ans=max(ans,now);
}
cout<<ans<<"\n";

}


#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b){
	lli res =1;
	while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
	return res;
}

vvc<int> graph(int n, int m, bool dir=1){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		if(dir)v[b].pb(a);
	}
	return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7

void solve(){
	int n,m; cin>>n>>m;
	vc<string>s(n);
	fore(i,0,n)cin>>s[i];
	vv(int,v,n,m,0);
	fore(i,0,n)fore(j,0,m)v[i][j]=s[i][j]=='#';
	int tot = 0;
	fore(i,0,n-1)fore(j,0,m-1)tot+=(v[i][j]+v[i][j+1]+v[i+1][j]+v[i+1][j+1])%2;
	cout<<tot<<ENDL;
}

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

#include <iostream>
#include <cmath>
using namespace std;
long long N, M;

long long calc_expand_mod(long long n, long long b, long long m){

    long long ans = 1;

    while (n > 0) {
       if ((n & 1) == 1) ans = (ans * b) % m;
       n >>= 1;
       b = (b * b) % m;
    }

    return ans;
}

int main(){
  cin >> N >> M;
  long long a = calc_expand_mod(N,10,M*M);
  long long b = calc_expand_mod(N,10,M)%(M*M);

  cout << (a - b) /M;

}