#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	bool flag=1;
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int ans;
string s;
char c='0';
signed main()
{
	cin>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i]==s[i-1]&&s[i]!=c)
		{
			if(c!='0')
				ans+=s.size()-i;
			c=s[i];
		}
		if(c=='0')
			continue;
		while(s[i]==c&&i!=s.size())
			i++;
		if(i==s.size())
			break;
		ans++;
//		cout<<i<<" "<<ans<<endl;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)

#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll fact_mod(ll n, ll mod) {
    ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

ll modpow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = modpow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}

ll modncr(ll n, ll r, ll mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    ll a = 1;
    rep(i, r) a = a * ((n-i) % mod) % mod;
    ll b = modpow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

signed main() {
	string s;
	cin >> s;
	ll r = 0;
	ll n = s.size();
	stack <char> stk;

	rep(i, n) {
		if (i && s[i] == s[i-1]) stk.push(s[i]);
	}

	if (stk.empty()) {
		mes(0);
		re0;
	}

	ll tmp = 0;
	drep(i, n) {
		if (stk.empty()) break;

		if (i && s[i] == s[i-1]) {
			stk.pop();
			r += tmp;
			tmp = 0;
			if (!stk.empty() && stk.top() != s[i-1]) tmp += n-i;
		} else {
			if (stk.top() != s[i]) tmp++;
		}
	}

	mes(r);

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int mod =  1e9+7;
#define debug(x)  cout<<"val= "<<x<<"\n";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

void solve()
{
    ll a,b,c;

    cin>>a>>b>>c;

    cout<<max(max(a+b, b+c) , c+a);
}

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

    while(t--)
    {
        solve();
    }
}

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr ll INF = 1LL << 30;
constexpr ll mod = 100000; //(ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

int main() {
    init();

    vector<int>A(3);
    rep(i, 0, 3)cin >> A[i];
    sort(all(A), greater<int>());
    cout << A[0] + A[1] << "\n";

    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;
ll mmod= 998244353;

int main(){
  ll d=1;
  ll k;
  cin >> k;
  for(ll i=2;i<=k;i++)d=d/__gcd(d,i)*i;
  d++;
  cout << d << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e9;

#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";
#define read(x)         freopen("in.txt","r",stdin);
#define write(x)        freopen("out.txt","w",stdout);
#define Fast            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define mod             1e9+7
#define sz              3000005

map< char , int > mpp;

void solve(){

    ll res=0;
    string s;
    cin>>s;

    int len=s.size();
    mpp[s[len-1]]++;
    mpp[s[len-2]]++;

    for(int i=len-3; i>=0; i--){
        mpp[s[i]]++;
        if(s[i]==s[i+1] && s[i]!=s[i+2]){
            res+=(len-i-mpp[s[i]]);
            mpp.clear();
            mpp[s[i]]=len-i;
        }
    }

    cout<<res<<endl;
}

int main(){
    Fast;///using Fast I/O

    //read(x); write(x);

    int multitest=0;
    if(multitest){
        int tc;
        cin>>tc;
        while(tc--)
            solve();
    }
    else
        solve();

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define F first
#define S second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie()

typedef long long ll;
typedef long double ld;

const int maxn = 1e2 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 20;
const int SQ = 400;

vector<int> adj[maxn];
int mark[maxn];

double cnt = 0;

void dfs(int v)
{
	cnt++;
	mark[v] = true;
	for(int u : adj[v]) if(!mark[u]) dfs(u);
}

int32_t main()
{
    FAST;

	int n;
	cin >> n;

	for(int i=1;i<=n;i++)
	{
		string s;
		cin >> s;

		for(int j=0;j<n;j++) if(s[j] == '1') adj[j+1].pb(i);
	}

	double ans = 0;
	for(int i=1;i<=n;i++)
	{
		memset(mark, 0, sizeof(mark));
		cnt = 0;

		dfs(i);
		ans += (1.0/cnt);
	}

	cout << setprecision(15) << fixed << ans << "\n";

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=107;

char mp[N][N];
int Ans=0;

int main(){
	int n=input(),m=input();

	for(int i=1;i<=n;i++){
		scanf("%s",mp[i]+1);
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(mp[i][j]=='.'){
				if(mp[i+1][j]=='.') Ans++;
				if(mp[i][j+1]=='.') Ans++;
			}
		}
	}

	printf("%d\n",Ans);
}


#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;

namespace Elaina{
    // #define NDEBUG
    #include<cassert>

    #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i)
    #define drep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i)
    #define fi first
    #define se second
    #define mp(a, b) make_pair(a, b)
    #define Endl putchar('\n')
    #define mmset(a, b) memset(a, b, sizeof a)
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    template<class T>inline T fab(T x){ return x<0? -x: x; }
    template<class T>inline void getmin(T& x, const T rhs){ x=min(x, rhs); }
    template<class T>inline void getmax(T& x, const T rhs){ x=max(x, rhs); }
    template<class T>inline T readin(T x){
        x=0; int f=0; char c;
        while((c=getchar())<'0' || '9'<c) if(c=='-') f=1;
        for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48));
        return f? -x: x;
    }
    template<class T>inline void writc(T x, char s='\n'){
        static int fwri_sta[1005], fwri_ed=0;
        if(x<0) putchar('-'), x=-x;
        do fwri_sta[++fwri_ed]=x%10, x/=10; while(x);
        while(putchar(fwri_sta[fwri_ed--]^48), fwri_ed);
        putchar(s);
    }
}
using namespace Elaina;

int n, k;

ll ans=0;

signed main(){
    n=readin(1), k=readin(1);
    rep(i, 1, n) rep(j, 1, k)
        ans=ans+100*i+j;
    writc(ans);
    return 0;
}

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

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define int long long int
#define mod(x) x%MOD

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

template <class T> void pprint(vector <T> v) {for (T i : v) {cout << i << " ";} cout << endl;}

void print(int t) {cerr << t ;}
void print(string t) {cerr << t ;}
void print(char t) {cerr << t ;}
void print(double t) {cerr << t ;}

template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.ff); cerr << ","; print(p.ss); cerr << "}" << endl;}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]" << endl;}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]" << endl;}

int power(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res *= a;
		b >>= 1;
		a *= a;
	}
	return res;
}

void solve() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c & 1) {
		c = 1;
	}
	else {
		c = 2;
	}
	if (a < 0 && c % 2 == 0) {
		a = abs(a);
	}
	if (b < 0 && c % 2 == 0) {
		b = abs(b);
	}
	if (pow(a, c) > pow(b, c)) {
		cout << ">" << endl;
	}
	else if (pow(a, c) < pow(b, c)) {
		cout << "<" << endl;
	}
	else {
		cout << "=" << endl;
	}
}

int32_t main() {

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

	solve();

}


#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
#include <queue>
#include <bitset>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n)  for(int i=0 ; i<(n) ; ++i)
typedef long long ll;
typedef pair<int,int> p;
const double PI=3.14159265358979323846;
const int MOD = 1000000000+7;
const int INF = 1001000100;

int main(){
  ll n;
  cin >> n;
  ll t[n],l[n],r[n];
  rep(i,n) cin >> t[i] >> l[i] >> r[i];

  ll ans=0;
  for(int i=1 ; i<n ; ++i){
    rep(j,i){
      if(l[i]>r[j] || l[j]>r[i]){
        continue;
      }else if(l[i]==r[j]){
        if((t[i]==1 || t[i]==2) && (t[j]==1 || t[j]==3)){
          ans++;
        }
      }else if(l[j]==r[i]){
        if((t[j]==1 || t[j]==2) && (t[i]==1 || t[i]==3)){
          ans++;
        }
      }else ans++;
    }
  }
  cout << ans;
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define rep(i, n) for(int i = 0;i < n;i++)
#define rep1(i, n) for(int i = 1;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

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

vector<vector<ll>> near8={{-1,1},{0,1},{1,1},{-1,0},{1,0},{-1,-1},{0,-1},{1,-1}};
vector<vector<ll>> near4={{0,1},{-1,0},{1,0},{0,-1}};

ll INF = INT64_MAX;

bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound)
{
	constexpr ll ll_max = numeric_limits<ll>::max();

	bool first_boost = true;

	lower_bound = 0;
	upper_bound = x;
	while (upper_bound - lower_bound > 1)
	{
		if (first_boost)
		{
			ll guess = (ll)sqrt((double)x);
			lower_bound = max(guess - 1, (ll)0);
			upper_bound = lower_bound + 3;
			first_boost = false;
		}

		ll newval = (lower_bound + upper_bound) / 2;
		if ((newval != 0) && (newval > ll_max / newval))  // newval*newval becomes overflow
			upper_bound = newval;  // because overflow means newval is too big
		else
		{
			ll newval_sqr = newval * newval;
			if (newval_sqr < x)
				lower_bound = newval;
			else
				upper_bound = newval;
		}
	}

	if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound))
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
	}
	else
	{
		if (lower_bound * lower_bound == x)
			upper_bound = lower_bound;
		else if (upper_bound * upper_bound == x)
			lower_bound = upper_bound;
	}
	bool is_exact = (lower_bound == upper_bound);
	return is_exact;
}

ll ll_ceil(ll x, int digit);
ll ll_floor(ll x, int digit);

ll ll_floor(ll x, int digit)
{
	if (x < 0)
		return -ll_ceil(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	return ans;
}

ll ll_ceil(ll x, int digit)
{
	if (x < 0)
		return -ll_floor(-x, digit);

	ll div = 1;
	while (digit != 0)
	{
		div *= 10;
		digit--;
	}
	ll modval = x % div;
	ll ans = x - modval;
	if (modval != 0)
		ans += div;
	return ans;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

ll H,W;
vector<vector<char>> map1(501, vector<char>(501,'#'));

bool solve(ll h, ll w){
	ll nexth=0;
	ll nextw=0;

	for(vector<ll> to:near4){
		nexth = h+to[0];
		nextw = w+to[1];
		if(nexth < 0 || nexth >=H || nextw < 0 || nextw >=W || map1[nexth][nextw] == '#'){
			continue;
		}
		if(map1[nexth][nextw] =='g'){
			return true;
		}
		map1[nexth][nextw]='#';
		if(solve(nexth, nextw)){
			return true;
		};
	}

	return false;
}

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

	ll ans = 0;
	vector<vector<ld>> k;
	ld t, l, r;

	rep(i, n){
		cin >> t >> l >> r;
		if(t==2){
			r-=0.5;
		}
		if(t==3){
			l+=0.5;
		}
		if(t==4){
			l+=0.5;
			r-=0.5;
		}

		for(ll j = 0; j < i; j++){
			if((k[j][0] >=  l && k[j][0] <= r) || (k[j][1] >= l && k[j][1] <= r)
				||  (k[j][0] < l &&  k[j][1] >= r)){
				ans++;
			}
		}
		vector<ld> tmp = {l, r};
		k.push_back(tmp);
	}

	cout << ans << endl;

  return 0;
}


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

int main() {
  long long n; cin >> n;
  string t; cin >> t;
  if (t == "1") {cout << 20000000000 << endl; return 0;}
  long long ans = 10000000000;
  for (int i = 1; i < n; ++i){
    if (t[i-1] == '0' && t[i] == '1') ans--;
  }
  string a, b, c;
  rep(i,n){
    if (i % 3 == 0) a.insert(a.begin(), '0');
    if (i % 3 == 0) b.insert(b.begin(), '1');
    if (i % 3 == 0) c.insert(c.begin(), '1');
    if (i % 3 == 1) a.insert(a.begin(), '1');
    if (i % 3 == 1) b.insert(b.begin(), '0');
    if (i % 3 == 1) c.insert(c.begin(), '1');
    if (i % 3 == 2) a.insert(a.begin(), '1');
    if (i % 3 == 2) b.insert(b.begin(), '1');
    if (i % 3 == 2) c.insert(c.begin(), '0');
  }
  if (t != a && t != b && t != c) {cout << 0 << endl; return 0;}
// cout << t << endl << a << endl << b << endl << c << endl;
  cout << ans << endl;
}

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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

bool check_cons_zeros(string t) {
  int cons_zeros = 0;
  for (auto &c : t) {
    if (c == '0') {
      cons_zeros++;
    } else {
      cons_zeros = 0;
    }
    if (cons_zeros > 1) {
      return true;
    }
  }
  return false;
}

bool check_cons_ones(string t) {
  int cons_ones = 0;
  for (auto &c : t) {
    if (c == '1') {
      cons_ones++;
    } else {
      cons_ones = 0;
    }
    if (cons_ones > 2) {
      return true;
    }
  }
  return false;
}

bool check_one_surr(string t) {
  for (int i = 1; i < t.length() - 1; i++) {
    if (t[i] == '1' && t[i - 1] == '0' && t[i + 1] == '0') {
      return true;
    }
  }
  return false;
}

int main() {
  _upgrade;
  int n;
  cin >> n;
  string t;
  cin >> t;
  if (check_cons_zeros(t) || check_cons_ones(t) || check_one_surr(t)) {
    // cerr << check_cons_zeros(t) << "\n";
    // cerr << check_cons_ones(t) << "\n";
    // cerr << check_one_surr(t) << "\n";
    cout << 0 << "\n";
    return 0;
  }
  long long res = 1e10;  // change
  if (t.length() == 1) {
    if (t[0] == '0') {
      cout << res << "\n";
    } else {
      cout << 2 * res << "\n";
    }
  } else {
    if (t[0] == '1' && t[1] == '1') {
      cout << res - (t.length() + 2) / 3 + 1 << "\n";
    } else if (t[0] == '1' && t[1] == '0') {
      long long need = 1 + (t.length() - 2 + 2) / 3;
      cout << res - (need - 1) << "\n";
    } else {
      long long need = 1 + (t.length() - 1 + 2) / 3;
      cout << res - (need - 1) << "\n";
    }
  }
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, string>> V(M);
	string s;
	rep(i, M) {
		cin >> s;
		V[i] = {s.size(), s};
	}
	sort(all(V));
	vector<vector<string>> T(8);
	rep(i, M) {
		T[(V[i].second[0]-'A')].pb(V[i].second);
	}

	int a=0, b=0, c=0, x, y, z;
	vi v(8);
	vector<string> S(20);
	rep(i, M) {
		s = T[b][v[b]];
		if (S[a].size() + s.size() > 20) a++;
		if (a == 20) break;
		if (S[a].size()) S[a] = S[a].substr(0, S[a].size()-1);
		S[a] += s;
		v[b] = (v[b]+1)%T[b].size();
		b = s[s.size()-1]-'A';
	}
	rep(i, 20) {
		rep(j, 20) {
			if (S[i].size() < 20) S[i] += 'A' + rand()%8;
		}
		std::cout << S[i] << '\n';
	}
}

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

bool contains(const std::string& s, const std::string& v)
{
  return s.find(v) != std::string::npos;
}

std::vector<std::string> erase_contained(std::vector<std::string> ss)
{
  std::sort(ss.begin(), ss.end());
  ss.erase(std::unique(ss.begin(), ss.end()), ss.end());

  std::vector<std::string> result;
  for (auto& e : ss)
  {
    bool contained = false;
    for (auto& f : ss)
    {
      if (e == f) { continue; }
      if (contains(f,e))
      {
        contained = true;
        break;
      }
    }
    if (!contained) { result.push_back(e); }
  }

  return result;
}

std::vector<std::set<std::pair<int, int>>>
connect_info(const std::vector<std::string>& ss, int len)
{
  std::vector<std::set<std::pair<int, int>>> connect(ss.size());
  for (int i = 0; i < ss.size(); i++)
  {
    for (int j = 0; j < ss.size(); j++)
    {
      if (i == j) { continue; }
      for (int n = ss[i].length() - 1; len <= n; n--)
      {
        if (ss[i].substr(ss[i].length() - n) == ss[j].substr(0, n))
        {
          connect[i].insert({ n, j });
          break;
        }
      }
    }
  }
  return connect;
}

std::vector<std::string>
merge(std::vector<std::string> ss, const std::vector<std::set<std::pair<int, int>>>& info, int len)
{
  std::vector<std::string> result;
  for (int i = 0; i < ss.size(); i++)
  {
    if (ss[i].empty()) { continue; }
    if (info[i].empty()) { continue; }
    std::vector<std::pair<int, int>> infos(info[i].begin(), info[i].end());
    std::reverse(infos.begin(), infos.end());
    for (auto& info : infos)
    {
      if (ss[info.second].empty()) { continue; }
      if (info.first < len) { continue; }
      result.push_back(ss[i].substr(0, ss[i].length() - info.first) + ss[info.second]);
      ss[i] = "";
      ss[info.second] = "";
      break;
    }
  }
  for (auto& e : ss)
  {
    if (!e.empty()) { result.push_back(e); }
  }
  return result;
}

//std::vector<std::string> merge_common_part(std::vector<std::string> ss, int len)
//{
//  std::set<std::string> sss(ss.begin(), ss.end());
//  for (int n = 12; len <= n; n--)
//  {
//    for(auto it_l = sss.begin(); it_l !=sss.end  (); it_l++)
//    {
//      if (it_l->length() <= n) { continue; }
//      auto common = it_l->substr(it_l->length()-n);
//      auto it_r = sss.upper_bound(common);
//      if (it_r == sss.end()) { continue; }
//      if (it_l == it_r) { continue; }
//      if (common != it_r->substr(0, common.length())) { continue; }
//
//      int x = 0;
//    }
//  }
//  return {};
//}

int main()
{
  int N, M;
  std::cin >> N >> M;

  std::vector<std::string> ss(M);
  for (auto& e : ss) { std::cin >> e; }
  ss = erase_contained(ss);

  int length = 100000000;
  int level = 5;
  while (true)
  {
    auto cinfo = connect_info(ss, level);
    auto ssm = merge(ss, cinfo, level);
    ss = erase_contained(ssm);
    auto len = 0;
    for (auto& e : ss)
    {
      len += e.length();
    }
    if (length == len)
    {
      if (level == 5) { break; }
      level--;
    }
    length = len;
  }

  std::vector<std::string> ans(N);
  for (auto& s : ss)
  {
    for (int i = 0; i < N; i++)
    {
      if (ans[i].length() + s.length() <= N)
      {
        ans[i] += s;
        break;
      }
    }
  }

  for (auto& e : ans)
  {
    std::cout << e << std::string(20-e.length(), '.') << std::endl;
  }

  return 0;
}


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

const int MAXN = 200200;
const int INF = 1e9 + 7;

int n, a[MAXN];
pair<int, int> b[MAXN];
map<int, vector<int> > mp;

void dfs(int dep, int x, vector<int> cur) {
    if (dep > n) return ;
    if (x && mp.count(x) && cur != mp[x]) {
        cout << "Yes" << endl;
        sort(cur.begin(), cur.end());
        cout << cur.size() << " ";
        for (auto c : cur) cout << c << " ";
        cout << endl;
        sort(mp[x].begin(), mp[x].end());
        cout << mp[x].size() << " ";
        for (auto c : mp[x]) cout << c << " ";
        cout << endl;
        exit(0);
    } else if (x) mp[x] = cur;
    dfs(dep + 1, x, cur);
    auto v = cur; v.push_back(b[dep + 1].second);
    dfs(dep + 1, (x + b[dep + 1].first) % 200, v);
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i]; a[i] %= 200;
        b[i].first = a[i], b[i].second = i;
    }
    sort(b + 1, b + n + 1);
    dfs(0, 0, vector<int>());
    cout << "No" << endl;
    return 0;
}

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

int dp[300][300];
int n;
vector<int> bucket;

bool valid(vector<int> x, vector<int> y)
{
    if (x.size() == 0 || y.size() == 0)
    {
        return false;
    }
    if (x.size() != y.size())
    {
        return true;
    }
    rep(i, x.size())
    {
        if (x[i] != y[i])
        {
            return true;
        }
    }
    return false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    rep(i, n)
    {
        int t;
        cin >> t;
        bucket.push_back(t % 200);
    }
    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, 200)
        {
            if (dp[i][j] > 0)
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][(j + bucket[i]) % 200] += dp[i][j];
            }
        }
    }
    while (true)
    {
        int s = 0, t = 0;
        bool cant = true;
        rep(i, n + 1)
        {
            rep(j, 200)
            {
                if (j == 0 && dp[i][j] > 2)
                {
                    s = i;
                    t = j;
                    cant = false;
                }
                if (j > 0 && dp[i][j] > 1)
                {
                    s = i;
                    t = j;
                    cant = false;
                }
            }
        }
        if (cant)
        {
            cout << "No" << endl;
            return 0;
        }
        int i = s;
        int j = t;
        vector<int> x;
        while (i != 0 && j != 0)
        {
            if (dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 0)
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                x.push_back(i);
                i--;
            }
            else
            {
                i--;
            }
        }
        i = s;
        j = t;
        vector<int> y;
        while (i != 0 && j != 0)
        {
            if (y.empty() && dp[i - 1][j] > 1)
            {
                i--;
            }
            else if (y.empty() && dp[i - 1][(j + 200 - bucket[i - 1]) % 200] > 1)
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                y.push_back(i);
                i--;
            }
            else if (dp[i - 1][j] > 0)
            {
                i--;
            }
            else
            {
                j = (j + 200 - bucket[i - 1]) % 200;
                y.push_back(i);
                i--;
            }
        }
        if (valid(x, y))
        {
            reverse(x.begin(), x.end());
            reverse(y.begin(), y.end());
            cout << "Yes" << endl;
            cout << x.size();
            for (auto xi : x)
            {
                cout << ' ' << xi;
            }
            cout << endl;
            cout << y.size();
            for (auto yi : y)
            {
                cout << ' ' << yi;
            }
            cout << endl;
            return 0;
        }
        else
        {
            dp[s][t] = 0;
        }
    }
}


#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
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; }
typedef long long ll;
const int INF = 1000000000;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    int ans = 0;
    for (int bit1 = 0; bit1 < (1<<h*(w-1)); ++bit1) {
        vector<vector<bool>> f(h, vector<bool> (w, false));
        bool flag = 1;
        int cnt = 0;
        REP(i, h*(w-1)) {
            if (bit1 & (1<<i)) {
                cnt++;
                if(f[i/(w-1)][i%(w-1)] == 0){
                    f[i/(w-1)][i%(w-1)] = 1;
                }
                else {
                    flag = 0;
                    break;
                }

                if(f[i/(w-1)][i%(w-1)+1] == 0){
                    f[i/(w-1)][i%(w-1)+1] = 1;
                }
                else {
                    flag = 0;
                    break;
                }
            }
        }

        if(!flag) continue;
        if(cnt > a) continue;

        int res = cnt;
        for (int bit2 = 0; bit2 < (1<<(h-1)*w); ++bit2) {
            vector<vector<bool>> f2 = f;
            cnt = res;
            flag = 1;
            REP(i, (h-1)*w){
                if (bit2 & (1<<i)) {
                    cnt++;
                    if(f2[i%(h-1)][i/(h-1)] == 0){
                        f2[i%(h-1)][i/(h-1)] = 1;
                    }
                    else {
                        flag = 0;
                        break;
                    }

                    if(f2[i%(h-1)+1][i/(h-1)] == 0){
                        f2[i%(h-1)+1][i/(h-1)] = 1;
                    }
                    else {
                        flag = 0;
                        break;
                    }
                }
            }
            if(flag == 1 && cnt == a) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


//
#include "bits/stdc++.h"
using namespace std;
#define pr1(a) for(auto b : a) cout << b << " ";cout << endl;
#define pr2(a) for(auto b : a){for(auto c:b) cout << c << " ";cout << endl;}
#define prc(...) for(auto b:{ __VA_ARGS__ }) cout << b << " ";cout << endl;

const int NN=200000;
vector<vector<int>> g(NN+1,vector<int>());
vector<bool> visited(NN+1,false);
long long ans=0;

void dfs(int p){
    for(auto e:g[p]){
        if (visited[e]==false){
            ans++;
            visited[e]=true;
            dfs(e);
        }
    }
}

void solve()
{
    fill(g.begin(),g.end(),vector<int>());
    fill(visited.begin(),visited.end(),false);
    ans=0;
    int a,b,n,val;
    cin >> n ;
    vector<int> d(n);
    for(int &i:d) cin>>i;
    for(int i=0;i<n/2;i++){
        int v1=d[i], v2=d[n-i-1];
        if (v1!=v2){
            g[v1].push_back(v2);
            g[v2].push_back(v1);
        }
    }
    for(int i=0;i<=NN;i++){
        if (visited[i]==false)
            visited[i]=true;
            dfs(i);
    }

    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);
#ifndef ONLINE_JUDGE
    stringstream in(R"(3
8
1 5 3 2 5 2 3 1
7
1 2 3 4 1 2 3
1
200000
)"); //ans 2 1 0
    std::cin.rdbuf(in.rdbuf());
#endif
    int tn = 1;
    //cin >> tn;
    while (tn--)
        solve();
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep3(i, k, n) for(int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int index_vout=0; index_vout < v.size(); index_vout++) cout<<v[index_vout]<<' '
#define blank cout<<endl
#define newvar(n) ll n; cin >> n
#define uniquify(vec) (vec).erase(std::unique((vec).begin(), (vec).end()), (vec).end())
const ll MOD = 1e9 + 7;
const ll INF = MOD*MOD+1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl M(n+1, 0);
    for(ll i = 1; i <= n; i++){
        M[i]++;
        cout << M[i] << ' ';
        for(ll j = 2*i; j <= n; j += i){
            M[j] = max(M[j], M[i]);
        }
    }

    return 0;
}


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

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    auto solve = [&]() -> long long {
        long long p = abs(c - a), q = abs(d - b);
        if (p == 0 && q == 0) return 0;
        if (p == q || p + q <= 3) return 1;
        if ((p + q) % 2 == 0 || p + q <= 6 || abs(p - q) <= 3) return 2;
        return 3;
    };
    cout << solve() << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

int main()
{
  ll x1, x2, y1, y2, ans = 0;
  cin >> x1 >> y1;
  cin >> x2 >> y2;
  if (x1 == x2 && y1 == y2)
  {
    cout << 0 << endl;
    return 0;
  }
  else if (abs(x1 - x2) + abs(y1 - y2) <= 3)
  {
    cout << 1 << endl;
    return 0;
  }
  int judge1 = (x1 + y1) % 2, judge2 = (x2 + y2) % 2;
  ll diffm1 = x1 - y1, diffp1 = x1 + y1;
  ll diffm2 = x2 - y2, diffp2 = x2 + y2;
  if ((judge1 == 0 && judge2 == 0) || (judge1 == 1 && judge2 == 1))
  {
    if ((diffm1 == diffm2) || (diffp1 == diffp2))
    {
      cout << 1 << endl;
    }
    else
    {
      cout << 2 << endl;
    }
    return 0;
  }
  else
  {
    if ((abs(diffm1 - diffm2) <= 3) || (abs(diffp1 - diffp2) <= 3))
    {
      cout << 2 << endl;
      return 0;
    }

    cout << 3 << endl;
    return 0;
  }
}


#include <iostream>
using namespace std;

void cur_char_count(string S, int chars[], int s_i) {
    if (S[s_i] == 'A')
        chars[0] += 1;
    else if (S[s_i] == 'T')
        chars[1] += 1;
    else if (S[s_i] == 'C')
        chars[2] += 1;
    else
        chars[3] += 1;
}

int main(void){
    int N;
    string S;
    cin >> N >> S;

// i:始点, j:終点
int ans_count = 0;
for (int i = 0; i < N; i++) {
        int chars[4] = {0, 0, 0, 0}; // A, T, C, G
        for (int j = i; j < N; j++) {
            cur_char_count(S, chars, j); // charsはポインタ
        if (chars[0] == chars[1] and chars[2] == chars[3])
            ans_count += 1;
    }
}
cout << ans_count << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;
const int N = 3005;

long long a[N];
int f[2][N];
int cnt[N];

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int flag = 0;
	for (int i = 1; i <= n; i++) f[flag][i] = 1;
	int res = 1;
	for (int j = 2; j <= n; j++) {
		int cur = 0;
		int old = flag;
		flag ^= 1;
		for (int i = 0; i < j; i++) cnt[i] = 0;
		for (int i = 1; i <= n; i++) {
			cur = (cur + a[i] % j) % j;
			f[flag][i] = cnt[cur];
			if (f[old][i]) {
				cnt[cur] += f[old][i];
				if (cnt[cur] >= MOD) cnt[cur] -= MOD;
			}
		}
		res += f[flag][n];
		if (res >= MOD) res -= MOD;
	}
	cout << res << "\n";
}

#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

// auto mod int
//const int mod = 1000000007;
//const int mod = 998244353;
int mod;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  //mint inv() const { return pow(mod-2);}

  //supports not prime
  mint modinv(ll a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    mint res(u);
    return res;
}
  mint& operator/=(const mint a) { return *this *= modinv(a.x);}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int N,K;
    cin>>N>>K>>mod;

    int MX=N*(N+1)*K/2+1;

    vector<vector<mint>> dp(N+1, vector<mint> (MX));
    dp[0][0]=1;
    int s=0;
    for(int i=1;i<=N;i++){
        vector<mint> ps(i);
        s+=i;
        for(int j=0;j<=s*K;j++){
            int x=j%i;
            ps[x]+=dp[i-1][j];
            if(j-i*(K+1)>=0){
                ps[x]-=dp[i-1][j-i*(K+1)];
            }
            dp[i][j]=ps[x];
        }
    }

    s=0;

    for(int i=1;i<=N;i++){
        s+=i;
        mint ans;
        for(int t=0;t<=s*K;t++){
            ans+=dp[i-1][t]*dp[N-i][t];
        }
        ans=ans*(K+1)-1;
        cout<<ans<<endl;
    }

    return 0;
}


#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;
    v A(N);
    v sA(N,0),ssA(N,0);
    rep(i,0,N){
        cin>>A[i];
        if(i==0){sA[0]=A[0];ssA[0]=A[0]*A[0];}
        else{
            sA[i] = sA[i-1]+A[i];
            ssA[i]= ssA[i-1]+A[i]*A[i];
        }
    }
    ll ans = 0;
    rep(i,2,N+1){
        ans += (i-1)*A[i-1]*A[i-1]-2*A[i-1]*sA[i-2]+ssA[i-2];
    }
    cout<<ans;
    return 0;
}

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

int main() {

	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < (int) s.size() - 4 + 1; ++i) {
		string t = "";
		for(int j = i; j < (int) i + 4; ++j) {
			t += s[j];
		}
		//cout << t << "\n";
		if(t == "ZONe") {
			++cnt;
		}
	}
	cout << cnt << '\n';

}


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

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1.0);

const int N = 1e5 + 10;

int n, Q;
LL a[N], k;

LL query(){
	int low = 0, top = n, mid, ans = 0;
	while(low <= top){
		mid = low + top >> 1;
		if(a[mid] - mid >= k){
			top = mid - 1;
		} else {
			ans = max(ans, mid);
			low = mid + 1;
		}
	}
	return k + ans;
}

int main(){
	scanf("%d %d", &n, &Q);
	a[0] = 0;
	rep(i, 1, n + 1)	scanf("%lld", a+i);
	while(Q--){
		scanf("%lld", &k);
		if(k <= a[n] - n){
			printf("%lld\n", query());
		} else {
			printf("%lld\n", k + n);
		}
	}
	return 0;
}

// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}
int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
const int maxn = 1e5+10;
vin adj [maxn];
int c[maxn];
int vis [maxn];
mpin mp;
int n;
sint good;
void dfs (int u) {
	//cout<<u<<" "<<c[u]<<" "<<mp[c[u]]<<endl;
	if (mp[c[u]]==0) good.ins(u);
	++mp[c[u]];
	vis [u]=1;
	for (auto v : adj[u]) {
		if (vis[v]==0) dfs (v);
	}
	if (mp[c[u]]>0) --mp[c[u]];
}
int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
cin>>n;
F (i,0,n,1) cin>>c[i];
F (i,0,n-1,1) {
	int a, b; cin>>a>>b;
	--a ; --b;
	adj[a].pb (b); adj[b].pb(a);
}
dfs (0);
for (auto e : good) cout<<e+1<<endl;
return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/


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

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

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

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

#define en "\n"

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

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

int N, dp[101][100], A[100];
ll X,ans=LINF;
vector<tpl> q;

void Main(){
    cin >> N >> X;
    REP(i,N) cin >> A[i];

    FOR(x,1,N+1){
        REP(i,x+1)REP(j,x) dp[i][j] = -INF;
        dp[0][0] = 0;

        REP(i,N){
            REP(j,x)REP(k,x){
                if(dp[j][k]<0) continue;
                q.emplace_back(j+1, (dp[j][k]+A[i])%x, dp[j][k]+A[i]);
            }
            while(!q.empty()){
                auto [i,j,k] = q.back(); q.pop_back();
                chmax(dp[i][j],k);
            }
        }

        if(dp[x][X%x]>=0)
            chmin(ans, (X-dp[x][X%x])/x);
    }

    cout << ans << en;
    return;
}

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

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

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

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

char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}

void operator delete (void *ptr) { }

void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int getbiggestsum(int ele,int n,int ar[],int req)
{
    int dp[ele+1][ele];

    memset(dp,-1,sizeof dp);

    dp[0][0]=0;

    for(int k=0;k<n;k++)
    for(int i=ele-1;i>=0;i--)
    {
        for(int j=0;j<ele;j++)
        {
            if(~dp[i][j])
            {
                dp[i+1][(j+ar[k])%ele]=max(dp[i+1][(j+ar[k])%ele],dp[i][j]+ar[k]);
            }
        }
    }

    return dp[ele][req];
}

//subset sum+no.of elements +
void solve()
{
    int n,x;
    cin>>n>>x;

    int ar[n];

    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    int ans=inf;
    for(int i=1;i<=n;i++)
    {
        int k=getbiggestsum(i,n,ar,x%i);
        if(k==-1) continue;
        assert((x-k)%i==0);
        ans=min(ans,(x-k)/i);
    }

    cout<<ans;
}

int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


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

using ll = long long;
using lb = long double;
#define fi first
#define se second
#define pb push_back

ll times_cap(ll a, ll b) {
	if (log10(a) + log10(b) >= 17.0)return 1e17;
	else return a * b;
}

typedef pair<int64_t, int64_t> P;

int main(){
  ll x,y;
  cin>>x>>y;
  if(x>=y){
    cout<<x-y<<endl;
    return 0;
  }
  map<ll,ll> dis;
  priority_queue<P,vector<P>,greater<P>> pq;
  pq.push({0,y});
  ll ans=y-x;
  dis[x]=ans;
  ll A=1,D=1;
  while(!pq.empty()){
    auto tmp=pq.top(); pq.pop();
    ll v=tmp.second,cst=tmp.first;
    dis[x]=min(cst+abs(v-x),dis[x]);
    ans=min(dis[x],ans);
    if(cst>dis[v])continue;
    if(cst>ans)continue;
    if(v==x){
      ans=min(ans,cst);
      continue;
    }
    if(v<=x){
      ans=min(ans,cst+x-v);
      continue;
    }

    if(v%2==0){
      if(dis[v/2]==0||dis[v/2]>dis[v]+1){
        dis[v/2]=cst+1;
        pq.push({dis[v/2],v/2});
      }
      /*if(dis[v+1]==0||dis[v+1]>dis[v]+1){
        dis[v+1]=cst+1;
        pq.push({dis[v+1],v+1});
      }*/
      /*if(dis[v-1]==0||dis[v-1]>dis[v]+1){
        dis[v-1]=cst+1;
        pq.push({dis[v-1],v-1});
      }*/
    }
    else{
      if(dis[v+1]==0||dis[v+1]>dis[v]+1){
        dis[v+1]=cst+1;
        pq.push({dis[v+1],v+1});
      }
      if(dis[v-1]==0||dis[v-1]>dis[v]+1){
        dis[v-1]=cst+1;
        pq.push({dis[v-1],v-1});
      }
    }
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main () {
  int a, b;
  cin >> a >> b;
  ll K;
  cin >> K;
  ll cmp[63][63];
  for (int i = 0; i <= 60; i ++) {
    cmp[i][0] = cmp[i][i] = 1;
    for (int j = 1; j < i; j ++) {
      cmp[i][j] = cmp[i - 1][j] + cmp[i - 1][j - 1];
    }
  }
  int s = a + b;
  for (int i = 0; i < s; i ++) {
    if (a == 0) {
      cout << 'b';
      b --;
    } else if (b == 0) {
      cout << 'a';
      a --;
    } else {
      if (K <= cmp[a + b - 1][a - 1]) {
        cout << 'a';
        a --;
      } else {
        cout << 'b';
        K -= cmp[a + b - 1][a - 1];
        b --;
      }
    }
  }
  cout << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

/*
1. If you cannot approach a problem
directly in the way it is proposed
then try to think from backwards
2. Have you checked the implementation
before starting to write the code?
3. Have you read the question carefully ?
4. Keep the names of variable descriptive.
5. Check the types and range of the values properly
6. Erase a iterator in the set or map only after using its value.
7. 1 bitset of 1e9 size only takes 256 mb.
8. Try to use global variables in case of recursion
9. Short and precise exectutes faster
*/

void solve()
{
    int n,s,d;
    cin >>n >> s >> d;
    F(int, i, 0, n - 1,1 ){
        int x, y;
        cin >> x >> y;
        if((x < s) && (y > d)){
            cout << "Yes\n";
            return;
        }
    }
    cout <<"No\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // freopen("Debug.txt", "w", stderr);
    #else
    #endif
    // cout << fixed << setprecision(10);
    // int _t;
    // cin>>_t;
    // while(_t --)
        solve();
}

/*                 -> Bismillahir Rahmanir Rahim <-                */

#include <bits/stdc++.h>
using namespace std;
//Some Hints
//Find odd and even return 1 || 0
// __builtin_parity() if x is ll use __builtin_parityll(x)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * (b / gcd(a, b)))
// count how many 0 in a bynary number
#define NumOf0(x) __builtin_popcount(x)
// count how many 1 in a bynary number
#define NumOf1(x) __builtin_ctz(x)
#define pi acos(-1)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned un;
#define Bismilla                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
bool isPrime(int n)
{
    if (n < 2)
    {
        return false;
    }
    if (n == 2 || n == 3)
    {
        return true;
    }
    if (n % 2 == 0)
    {
        return false;
    }
    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define In insert
#define mini(a, b) a = min(a, (b))
#define maxi(a, b) a = max(a, (b))
#define si(a) scanf("%d", &a)
#define si2(a, b) scanf("%d %d", &a, &b)
#define si3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sl2(a, b) scanf("%lld %lld", &a, &b)
#define sl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define ln "\n"
#define pf printf
#define endl "\n"
#define pfi(a) printf("%d\n", a)
#define pf2(a, b) printf("%d %d\n", a, b)
// Now Start.....:)

void solve()
{
    ll n, m, k, q, l, r, x, y, z;
    cin >> x >> y >> z;
    bool ok=false;
    for (int  i = 0; i < x; i++)
    {
        cin>>n>>m;
        if(n<y and m>z){
            ok = true;
        }
    }
    cout<<((ok)?"Yes":"No")<<ln;
}

int main()
{
    Bismilla;
    solve();
}


#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli __int128
#define ldouble long double
using namespace std;

/*
(2x + 2y)n + x <= t < (2x + 2y)n + x + y
  range = y (max 500)
(p + q)n + p <= t < (p + q)(n + 1)
  range = q (max 500)

try all combinations of mod (500^2)

t - (2x + 2y)n - x == remY
t - (2x + 2y)n = remY + x
t = remY + x + (2x + 2y)n1

t - (p + q)n - p == remQ
t - (p + q)n = remQ + p
t = remQ + p + (p + q)n2

remQ + p + (p + q)n2 = remY + x + (2x + 2y)n1
(p + q)n2 - (2x + 2y)n1 = remY + x - remQ - p

*/

lli read() {
    lli 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 * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
void print(lli x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

lli abslol(lli num)
{
  return num < 0 ? -num : num;
}

lli gcd(lli a, lli b, lli& x, lli& y)
{
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  lli x1, y1;
  lli d = gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}

bool find_any_solution(lli a, lli b, lli c, lli &x0, lli &y0, lli &g)
{
  g = gcd(abslol(a), abslol(b), x0, y0);
  if (c % g) {
    return false;
  }

  x0 *= c / g;
  y0 *= c / g;
  if (a < 0) x0 = -x0;
  if (b < 0) y0 = -y0;
  return true;
}

const lli inf = LONG_LONG_MAX;
lli x, y, p, q;

lli findMinSolution(lli remY, lli remQ)
{
  // t - (2x + 2y)n - x == remY
  // t - (2x + 2y)n = remY + x
  // t = remY + x + (2x + 2y)x0

  // t - (p + q)n - p == remQ
  // t - (p + q)n = remQ + p
  // t = remQ + p + (p + q)y0

  // remQ + p + (p + q)y0 = remY + x + (2x + 2y)x0
  // -(2x + 2y)x0 + (p + q)y0 = remY + x - remQ - p
  lli x0, y0, g;
  lli a = -(2*x + 2*y), b = p + q, c = remY + x - remQ - p;
  if (find_any_solution(a, b, c, x0, y0, g))
  {
    lli t1 = remY + x + (2*x + 2*y)*x0, t2 = remQ + p + (p + q)*y0;
    bool isNegative = a / g < 0;

    // lli lo = 0, hi = 1e18;
    // while (lo < hi)
    // {
    //   lli mid = (lo + hi + 1) >> 1;
    //   if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q))
    //     hi = mid - 1;
    //   else
    //     lo = mid;
    // }
    // lli maxHi = lo;

    // lo = -1e18, hi = 0;
    // while (lo < hi)
    // {
    //   lli mid = (lo + hi) >> 1;
    //   if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q))
    //     lo = mid + 1;
    //   else
    //     hi = mid;
    // }
    // lli minLo = lo;

    lli lo = -1e18, hi = 1e18;
    while (lo < hi)
    {
      lli mid = (lo + hi + isNegative) >> 1;
      lli e = remQ + p + (p + q)*(y0 + mid*(a / g));

      // DEBUG printf("\t\t%lld %lld\n", mid, e);
      if (isNegative)
      {
        if (e >= 0) lo = mid;
        else hi = mid - 1;
      }
      else
      {
        if (e >= 0) hi = mid;
        else lo = mid + 1;
      }
    }

    x0 -= lo * b / g;
    y0 += lo * a / g;

    // DEBUG printf("\t%lld %lld - %lld %lld | %lld %lld\n", remY, remQ, t1, t2, 0LL, b / g);
    return remQ + p + (p + q)*y0;
  }
  else
    return inf;
}

int main()
{
  int t; scanf("%d", &t);
  for (int tt = 1; tt <= t; tt++)
  {
    // scanf("%lld %lld %lld %lld", &x, &y, &p, &q);
    x = read();
    y = read();
    p = read();
    q = read();
    lli ans = inf;
    for (int i = 0; i < y; i++)
      for (int j = 0; j < q; j++)
        ans = min(ans, findMinSolution(i, j));

    if (ans == inf) printf("infinity\n");
    else
    {
      print(ans);
      printf("\n");
    }
  }

  return 0;
}

#include<iostream>
#include<utility>
using namespace std;
typedef long long ll;

int T;
ll X,Y,Q,P;
ll A,B,ans;
ll ext_gcd(ll p,ll q,ll& x, ll& y) { // get px+qy=gcd(p,q)
	if(q==0) return x=1,y=0,p;
	ll g=ext_gcd(q,p%q,y,x);
	y-=p/q*x;
	return g;
}

pair<ll,ll> crt(ll a1,ll mo1,ll a2,ll mo2) { // return (x,y) y=lcm(a1,a2),x%mo1=a1,x%mo2=a2
	ll g,x,y,z;
	g=ext_gcd(mo1,mo2,x,y);
	a1=(a1%mo1+mo1)%mo1;a2=(a2%mo2+mo2)%mo2;
	if(a1%g != a2%g) return pair<ll,ll>(-1,0); // N/A
	__int128_t lcm=mo1*(mo2/g);
	if(lcm<mo1) return pair<ll,ll>(-2,0); // overflow

	__int128_t v=a1+((a2-a1)%lcm+lcm)*x%lcm*(mo1/g);
	return make_pair(((v%lcm)+lcm) % lcm,lcm);
}

int main(){
	cin>>T;
	while(T--){
		ans=1LL<<60;
		cin>>X>>Y>>P>>Q;
		for(int i=X;i<X+Y;i++){
			ll tmp=crt(i,2*(X+Y),P,P+Q).first;
			if(tmp>=0){
				if(ans>tmp) ans=tmp;
			}
		}
		for(int i=P;i<P+Q;i++){
			ll tmp=crt(i,P+Q,X,2*(X+Y)).first;
			if(tmp>=0){
				if(ans>tmp) ans=tmp;
			}
		}
		if(ans==1LL<<60) cout<<"infinity"<<endl;
		else cout<<ans<<endl;
	}
}


#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

const ll MOD = 998244353;
ll modPow(ll a, ll n){
  if (n == 0) return 1;
  if (n == 1) return a % MOD;
  if (n % 2 == 1) return (a * modPow(a, n-1)) % MOD;
  ll t = modPow(a, n/2);
  return (t * t) % MOD;
}

int main(){
  ll n; cin >> n;
  vector<ll> f(n);
  rep(i, n){
    cin >> f[i];
    f[i]--;
  }
  ll num = 0;
  vector<bool> flag(n, false);
  rep(i, n){
    if (flag[i]) continue;
    multiset<ll> st;
    ll now = i;
    st.insert(now);
    rep(j, n){
      flag[now] = true;
      now = f[now];
      st.insert(now);
      if (flag[now]) break;
    }
    if (st.count(now) == 2) num++;
  }
  cout << modPow(2, num)-1 << endl;;

  return 0;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define nl '\n'
#define endl '\n'
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
#define pcnt(x) __builtin_popcountll(x)
#define df(x) ll x = in();
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 (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vs = vector<string>;
using P = pair<ll, ll>;
using gt = greater<P>;
using minq = priority_queue<P, vector<P>, gt>;
using vP = vector<P>;
inline ll in() {
  ll x;
  scanf("%lld", &x);
  return x;
}
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
template <class T> void print(const initializer_list<T> &il) {
  for (auto x : il) {
    cout << x << " ";
  }
  cout << "\n";
}
inline void priv(vll a) {
  rep(i, (int)a.size() - 1) cout << a[i] << " ";
  cout << a.back() << nl;
}
inline void priv(vi a) {
  rep(i, (int)a.size() - 1) cout << a[i] << " ";
  cout << a.back() << nl;
}
const ll LINF = 8e18L + 1;
const int INF = 8e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// g++ -std=c++17 -stdlib=libc++
#define _GLIBCXX_DEBUG
// This slows down the execution; even the time complexity, since it checks if
// std funcs such as lower_bound meets prereqs
int mod = 1e9 + 7;
int n, p;
ll f(ll nn) {
  if (nn == 0)
    return 1;
  ll ret = f(nn / 2);
  (ret *= ret) %= mod;
  if (nn & 1)
    (ret *= (p - 2)) %= mod;
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(16);
  cin >> n >> p;
  ll ans = p - 1;
  ans *= f(n - 1);
  cout << ans % mod << nl;
  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

// string N;

int main() {
	int x = 0;
	cin >> x;

	if (x < 0) {
		cout << 0;
	}
	else {
		cout << x;
	}

	//int k = N.length();

	//const char* N_ch = N.c_str();
	//int mod0 = 0;
	//int mod1 = 0;
	//int mod2 = 0;
	//for (int i = 0; i < k; i++) {
	//	int num = (int)N_ch[i] - '0';
	//	if (num % 3 == 0)mod0++;
	//	else if (num % 3 == 1)mod1++;
	//	else if (num % 3 == 2)mod2++;
	//}
	//if ((mod2 < 3 && mod1 == 0 && mod0 == 0) || (mod2 == 0 && mod1 < 3 && mod0 == 0))cout << -1;
	//else {
	//	if ((mod1 * 1 + mod2 * 2) % 3 == 2)cout << 2;
	//	else if ((mod1 * 1 + mod2 * 2) % 3 == 1)cout << 1;
	//}

}

#include <iostream>
//#include <string>
//#include <algorithm>

using namespace std;

int main()
{
	int X;

	cin >> X;

	cout << 100 - X%100;
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

typedef long long ll;
typedef pair<ll,ll> P;

template<typename T>
void show_vector(vector<T> v) {
	for (auto ele: v)cout << ele << " " ;cout << endl;
}

template<typename T>
void show_vector(vector<vector<T>> v) {
	for (auto ele: v)show_vector(ele);
}

template<typename T>
void show_vector(vector<vector<vector<T>>> v) {
	for (auto ele: v) {
		show_vector(ele);
		cout << endl;
	}
}

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

	vector<ll> fib(88);
	fib[0] = 0;
	fib[1] = 1;
	for (ll i = 2;i < fib.size();i++) {
		fib[i] = fib[i-1] + fib[i-2];
	}

	ll n;cin >> n;
	vector<ll> v(2);
	vector<ll> ans;
	REP(i, fib.size() - 1) {
		if (n >= fib[fib.size() - 1 - i]) {
			n -= fib[fib.size() - 1 - i];
			v[i%2]++;
			ans.PB(i % 2);
		}
		v[(i+1)%2] += v[i%2];
		ans.PB(2 + (1 - (i % 2)));
		//cout << v[0] << " " << v[1] << endl;
	}

	cout << ans.size() << endl;
	REP(i, ans.size()) {
		cout << ans[i]+1 << endl;
	}

	// cout << "ans: " << v[0] << endl;

	return 0;
}

#include <bits/stdc++.h>
#include <cstdlib>
#include <pthread.h>
#include <sstream>
#include <string>

using namespace std;
#define mem1(a) memset(a,-1,sizeof(a))
#define mem0(a) memset(a,0,sizeof(a))
#define ln "\n"
#define ll long long int
#define Mod 1000000007
#define lld long double

template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
	if (start < 0) start = 0;
	if (end < 0) end = int(v.size());

	for (int i = start; i < end; i++)
		cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}

ll sttoll(string s)
{
	stringstream hel(s);
	ll x = 0;
	hel >> x;
	return x;
}

string lltostr(ll x)
{
	string s;
	s = to_string(x);
	return s;
}

void solve(int tc) {
	ll n, k; cin >> n >> k;
	ll b = n;
	while (k > 0)
	{
		if (b % 200 == 0) b /= 200;
		else {
			string t = lltostr(b);
			t += "200";
			b = sttoll(t);
		}
		k--;
	}
	cout << b << ln;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << setprecision(15) << fixed;
	ll t = 1;
	// cin >> t;
	for (ll i = 0; i < t; i++)
	{
		solve(i);
	}
	return 0;
}


#include <bits/stdc++.h>

#define MAX 50
#define SQRDMAX 2500
#define K 1

using namespace std;

int si, sj, tiles[SQRDMAX], weights[SQRDMAX];
list<tuple<int, int>> path;
bitset<SQRDMAX> visited;
const int directions[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

void setTile(int i, int j) {
  visited.flip(i * MAX + j);
  for (const int* dir : directions) {
    int i_ = i + dir[0];
    int j_ = j + dir[1];
    int cell;
    cell = i_ * MAX + j_;
    if (0 <= i_ && i_ < MAX && 0 <= j_ && j_ < MAX && tiles[cell] == tiles[i * MAX + j]) {
      visited.flip(cell);
      break;
    }
  }
}

tuple<int, list<tuple<int, int>>> dfs(int i, int j) {
  priority_queue<tuple<int, int, int>> q;
  //get valid adj
  for (const int* dir : directions) {
    int i_ = i + dir[0];
    int j_ = j + dir[1];

    int cell;
    cell = i_ * MAX + j_;
    if (0 <= i_ && i_ < MAX && 0 <= j_ && j_ < MAX && tiles[cell] != tiles[i * MAX + j] && !visited.test(cell)) {
      q.push(make_tuple(weights[i_ * MAX + j_], i_, j_));
    }
  }
  //dfs
  int bestPathWeight = 0;
  list<tuple<int, int>> bestPath;
  //get k best choices
  for (int k = 0; k < K && !q.empty(); ++k) {
    int weight, i_, j_;
    tie(weight, i_, j_) = q.top();
    q.pop();
    setTile(i_, j_);
//    cout<<visited.count()<<endl;
    int pathWeight;
    list<tuple<int, int>> path;
    tie(pathWeight, path) = dfs(i_, j_);
    setTile(i_, j_);
    if (weight + pathWeight > bestPathWeight) {
      bestPathWeight = weight + pathWeight;
      bestPath = path;
    }
//    cout<<visited.count()<<endl;
  }
  bestPath.push_front(make_tuple(i, j));
  return make_tuple(weights[i * MAX + j] + bestPathWeight, bestPath);
}

int main(void) {
  scanf("%d%d", &si, &sj);
  for (int i = 0; i < SQRDMAX; ++i)
    scanf("%d", &tiles[i]);
  for (int i = 0; i < SQRDMAX; ++i)
    scanf("%d", &weights[i]);
  setTile(si, sj);
  int pathWeight;
  list<tuple<int, int>> path;
  tie(pathWeight, path) = dfs(si, sj);
  setTile(si, sj);
  tuple<int, int> prev = make_tuple(si, sj);
  string res = "";
  for (const tuple<int, int>& t : path) {
    int i, j, i_, j_;
    tie(i, j) = t;
    tie(i_, j_) = prev;
//    if (abs(i - i_) > 1 || abs(j - j_) > 1 || visited.test(i * MAX + j))
//      cout<<"Error"<<endl;
    if (i > i_)
      res += "D";
    else if (i < i_)
      res += "U";
    else if (j < j_)
      res += "L";
    else if (j > j_)
      res += "R";
    setTile(i, j);
    prev = t;
//    cout<<i<<" "<<j<<endl;
  }
  cout<<res<<endl;
  return 0;
}

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();

	int res = 2000000000;
	for (int i = 0; i < 1 << (n - 1); i++) {
		int xored = 0;
		int ored = 0;
		for (int j = 0; j <= n; j++) {
			if (j < n) ored |= a[j];
			if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
		}
		res = std::min(res, xored);
	}

	printf("%d\n", res);
	return 0;
}


#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define BACK(x) x.rbegin(),x.rend()
#define MOD 1000000007
#define INF INT_MAX
#define FLOAT_ANS setprecision(30)
#define elif else if

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(void){
	string s;
	cin>>s;
	rep(i,s.length()){
		if(i%2){
			if(s[i]>'Z'){
				cout<<"No";
				return 0;
			}
		}
		else{
			if(s[i]<'a'){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
}

/*

*/

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
#include <assert.h>
#include <climits>

using namespace std;
#define int long long

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

  int sum = 0;
  for (int i = 1;; i++) {
    sum += i;
    if (sum >= n) {
      cout << i << '\n';
      return 0;
    }
  }
}


#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,X;
    cin >> N >> X;
    string S;
    cin >> S;
    REP(i, N){
        if(S[i] == 'o') X++;
        else X = max(0, X-1);
    }
    pr(X);
}

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

using namespace std;

clock_t timeStart, timeFinish;

void timeBegin() {
    timeStart = clock();
}

void timeEnd() {
    timeFinish = clock();
}

void timeDuration() {
    double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
    cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    cout << " sec " << endl;
}

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

const int MAXN = 1000;
const int MOD = 1000000007;

int dp[1 + MAXN][2];

int main() {
    //timeBegin();
    //ifstream cin("input.txt");
    //ofstream cout("papagali.out");
    int n;
    char aa, ab, ba, bb;
    cin >> n >> aa >> ab >> ba >> bb;
    if (n <= 3) {
        cout << "1\n";
        return 0;
    }
    if ((ab == 'A' && aa == 'A') || (ab == 'B' && bb == 'B')) {
        cout << "1\n";
        return 0;
    }
    if ((ab == 'A' && aa == 'B' && ba == 'B') || (ab == 'B' && bb == 'A' && ba == 'A')) {
        int answer = 1;
        for (int i = 1; i <= n - 3; i++) {
            answer *= 2;
            if (answer >= MOD) {
                answer -= MOD;
            }
        }
        cout << answer << "\n";
        return 0;
    }
    dp[1][0] = dp[1][1] = 1;
    for (int i = 2; i <= n - 3; i++) {
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
        if (dp[i][0] >= MOD) {
            dp[i][0] -= MOD;
        }
        dp[i][1] = dp[i - 1][0];
    }
    int answer = dp[n - 3][0] + dp[n - 3][1];
    if (answer >= MOD) {
        answer -= MOD;
    }
    cout << answer << "\n";
    return 0;
}


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

int main(){
int n,k,right=1000000000,left=-1; cin >> n >> k;
int lim = k*k/2 + 1;
bool a;
vector<vector<int>> park(n,vector<int>(n));
vector<vector<int>> s(n+1,vector<int>(n+1));
for(int i=0;i<n;i++){
   for(int j=0;j<n;j++){
      cin >> park.at(i).at(j);
   }
}
while(right - left > 1){
     int mid = (left + right)/2;
     for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
           s.at(i+1).at(j+1) = s.at(i).at(j+1) + s.at(i+1).at(j) - s.at(i).at(j);
           if(park.at(i).at(j) > mid) s.at(i+1).at(j+1)++;
        }
    }
    a = false;
    for(int i=0;i<n-k+1;i++){
       for(int j=0;j<n-k+1;j++){
          if(s.at(i+k).at(j+k) - s.at(i).at(j+k) - s.at(i+k).at(j) + s.at(i).at(j) < lim)a = true;
       }
    }
if(a) right = mid;
else left = mid;
//cout << left << " " << right <<  endl;
}
cout << right << endl;
}

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

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    vector<map<ll,ll>> dp(n+1);
    dp[0][x]=1;
    rep(i,n) cin >> a[i];
    a.push_back(INF);
    reverse(all(a));
    rep(i,n){
        for (auto it=dp[i].begin();it!=dp[i].end();it++){
            if (it->first>=0){
                dp[i+1][(it->first)%a[i+1]]+=it->second;
                if ((it->first)%a[i+1]!=0 && it->first+a[i+1]<a[i]) dp[i+1][-(a[i+1]-(it->first)%a[i+1])]+=it->second;
            }
            else{
                dp[i+1][-((-it->first)%a[i+1])]+=it->second;
                if ((-it->first)%a[i+1]!=0 && it->first-a[i+1]>-a[i]) dp[i+1][a[i+1]-((-it->first)%a[i+1])]+=it->second;
            }
        }
    }
    cout << dp[n][0] << endl;
}


#include <iostream>
#include<string>
using namespace std;
string nyu,totyu,kekka;
int main() {
	cin >> nyu;
    char totyu = nyu[0];
    string kekka = nyu + totyu;
    kekka = kekka.erase(0,1);
    cout <<kekka;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define all(a)      (a).begin(),(a).end()

#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long   M = 1e9 + 7;

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

int mod(int x) {
	return (x % M + M) % M;
}
int  add(int a, int b)
{
	return mod(mod(a) + mod(b));
}
bool isRoaring(int n)
{
	string s = to_string(n);
}
void solve()
{
	string s;
	cin >> s;
	int c = 0;
	int n = s.size();
	int i;
	for (i = 0; i < n - 3; i++)
	{
		if (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e')
			c++;
	}
	cout << c << endl;
}
int32_t main()
{

	c_p_c();

	FIO;

	int tt = 1;
	solve();

}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-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(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

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

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

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

void solve(){
  int n, m, q;
  cin >> n >> m >> q;
  pi wv[55];
  pi x[55];
  rep(i, n) {
    int w, v;
    cin >> w >> v;
    wv[i] = make_pair(v, w);
  }
  rep(i, m) {
    int t;
    cin >> t;
    x[i] = make_pair(t, i);
  }

  sort(wv, wv + n);
  sort(x, x + m);

  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--; r--;
    bool used[55] = {};
    rep(i, m) {
      if(l <= x[i].second && x[i].second <= r) {
        used[i] = true;
      }
    }

    int ans = 0;
    rrep(i, n) {
      int v = wv[i].second;
      rep(j, m) {
        if(x[j].first >= v && !used[j]) {
          ans += wv[i].first;
          used[j] = true;
          break;
        }
      }
    }
    cout << ans << endl;
  }
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

int n,m,q;
int w[52],v[52];
int x[52];

int main(){
	scanf("%d%d%d",&n,&m,&q);
	for(int i=0;i<n;i++){
		scanf("%d%d",&w[i],&v[i]);
	}
	for(int i=0;i<m;i++)scanf("%d",&x[i]);
	vector<pair<int,int>> vec;
	for(int i=0;i<n;i++){
		vec.push_back(mp(v[i],w[i]));
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i=0;i<n;i++){
		v[i]=vec[i].fr;
		w[i]=vec[i].sc;
	}

	for(;q>0;q--){
		int l,r;
		scanf("%d%d",&l,&r);
		vector<int> X;
		for(int i=0;i<m;i++){
			if(l-1<=i&&i<=r-1){}
			else X.push_back(x[i]);
		}
		sort(X.begin(),X.end());
		bool used[52]; memset(used,false,sizeof used);
		int ret=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<X.size();j++){
				if(!used[j]&&X[j]>=w[i]){
					used[j]=true;
					ret+=v[i];
					break;
				}
			}
		}
		cout<<ret<<endl;
	}
}


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

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

    int p[N];
    vector<tuple<int,int,int>> vec(N);

    rep(i,N) cin >> get<0>(vec.at(i)) >> get<1>(vec.at(i)) >> get<2>(vec.at(i)) ;

    sort(vec.begin(),vec.end());
    vector<P> vec2(2*N);
    rep(i,N){
        vec2.at(i).first = get<0>(vec.at(i));
        vec2.at(i).second = get<2>(vec.at(i));
    }
    rep(i,N){
        vec2.at(N+i).first = get<1>(vec.at(i));
        vec2.at(N+i).second = -get<2>(vec.at(i));
    }

    sort(vec2.begin(),vec2.end());

    ll now = 0;
    bool over = false;
    int time=0;
    int before_time=0;
    rep(i,2*N){
        time = vec2.at(i).first;
        if ((before_time|=time)&&(now > W)){
            over = true;
        }
        now += vec2.at(i).second;
        before_time = time;
    }

    if(over){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
}

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

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

    int n,m; cin >> n >> m;
    vector<ll> h(n); rep(i,n) cin >> h[i];
    vector<ll> w(m); rep(i,m) cin >> w[i];
    sort(h.begin(), h.end());
    sort(w.begin(), w.end());

    if(n == 1){
        ll ans = 1e17;
        rep(i,m) ans = min(ans, abs(h[0]-w[i]));
        cout << ans << endl;
        return 0;
    }

    vector<ll> ev(n/2+10,0LL), od(n/2+10,0LL);
    rep(i,n/2){
        ev[i+1] = ev[i] + h[2*i+1] - h[2*i];
        od[i+1] = od[i] + h[2*i+2] - h[2*i+1];
    }

    ll ans = 1e17;
    rep(i,m){

        int j = upper_bound(h.begin(), h.end(), w[i]) - h.begin();
        --j;

        if(j >= n-1){
            ans = min(ans, ev[n/2] + abs(w[i] - h[n-1]));
            continue;
        }

        if(j%2){
            ans = min(ans, od[n/2]-od[(j+1)/2] + ev[(j+1)/2] + abs(h[j+1] - w[i]));
        }else{
            ans = min(ans, ev[j/2] + od[n/2] - od[j/2] + abs(w[i] - h[j]));
        }
    }

    cout << ans << endl;

}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll mod = (ll)1e9 + 7;

int main(){
    speed;
    int n, h; cin >> n >> h;
    int matrix[n][n];
    rep(i, 0, n) {
        rep(j, 0, n) {
            cin >> matrix[i][j];
        }
    }
    vector<int> path;
    rep(i, 0, n) {
        path.push_back(i);
    }
    int cnt = 0;
    do {
        int sum = 0;
        rep(i, 0, n) {
            sum += matrix[path[i]][path[(i + 1) % n]];
        }
        if(sum == h && path[0] == 0) cnt++;
    } while(next_permutation(all(path)));
    cout << cnt;
    return 0;
}

#include<bits/stdc++.h>
typedef long long  ll;
using namespace std;
int main()
{

    ll a,b;
    cin>>a>>b;
    if(a==b)
    {
        vector<ll>v;
        for(ll i=1; i<=a; i++)
        {
            v.push_back(i);
            v.push_back(i*-1);
        }
        ll si=v.size();
        for(ll i=0; i<si-1; i++)
        {
            cout<<v[i]<<" ";
        }
        cout<<v[si-1]<<endl;
    }
    else
    {

        if(a>b)
        {
            vector<ll>v;
            for(ll i=1; i<=a; i++)
            {
                v.push_back(i);
            }

            for(ll i=1; i<b; i++)
            {
                v.push_back(i*-1);
            }
            ll res=(a*(a+1))/2;
            ll res1=(b*(b-1))/2;
            ll finalres=(res-res1)*-1;
            v.push_back(finalres);
            ll si=v.size();
            for(ll i=0; i<si-1; i++)
            {
                cout<<v[i]<<" ";
            }
            cout<<v[si-1]<<endl;
        }
       else if(b>a)
        {
            vector<ll>v;
            for(ll i=1; i<=b; i++)
            {
                v.push_back(i*-1);
            }

            for(ll i=1; i<a; i++)
            {
                v.push_back(i);
            }
            ll res=(b*(b+1))/2;
            ll res1=(a*(a-1))/2;
            ll finalres=(res-res1);
            v.push_back(finalres);
            ll si=v.size();
            for(ll i=0; i<si-1; i++)
            {
                cout<<v[i]<<" ";
            }
            cout<<v[si-1]<<endl;
        }

    }

}


#include<bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define ll                long long
using namespace std ;
ll i , j , c ;
ll dp[61][61] ;
void solve()
{

    ll a , b ,  k ; cin >> a >> b >> k ;
    memset(dp,0l,sizeof(dp)) ;
    dp[0][0] = 1 ;
    for(i=1;i<=61;i++){
        dp[i][0] = 1 ;
        for(j=1;j<i;j++){
            dp[i][j] = dp[i-1][j] + dp[i-1][j-1] ;
        }
        dp[i][i] = 1 ;
    }
    ll n = a+b ;
    while(n--){
        ll value = dp[a-1+b][b] ;
        if(value>=k){
            cout << 'a';
            a-- ;
        }else {
           cout << 'b' ;
           b-- ;
           k-= value ;
        }
    }
}

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

#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
#include <cassert>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
#define ALL(a)  (a).begin(),(a).end()

int main() {
  ll A,B,K,W,ans1=0,ans2=10000000,sum=0,x,y,z,ans=0;
  string s, s2, s3;
  char S1,S2,S3[11];
  vector<ll> v,v1,v2;
  map<ll,ll> f,g;

  cin >> A >> B >> K;

  if(A==B && B==K){
    cout << A;
    return 0;
  }
  if(A==B && A!=K){
      cout << K;
      return 0;
  }if(B==K && A!=B){
    cout << A;
    return 0;
  }if(A==K && B!=A){
    cout << B;
    return 0;
  }
  cout << 0;

}


#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) LL((a).size())

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL LARGE_INT = 1e9+100;
const LL INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const LL MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n,s,d;cin>>n>>s>>d;
    REP(i,n){
        LL x,y;cin>>x>>y;
        if(x<s && y>d){
            cout<<"Yes"<<endl;
            return;
        }
    }
    cout<<"No"<<endl;

	return;
}

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

#ifdef GCC_VERSION
#include<bits/stdc++.h>
#endif

#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <tuple>
#include <algorithm>
#include <functional>
#include <deque>
#include <queue>
#include <cstring>
#include <chrono>
#include <numeric>

#ifdef _DEBUG
#define DEBUG_INPUT
#endif

#ifdef DEBUG_INPUT
#include "../__common/Helper.h"
#endif

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

static const ll INF = 6'000'000'000'000'000'000; // -INF for min value

template<typename T> using Vec = std::vector<T>;
template<typename T> using VecVec = std::vector<std::vector<T>>;

#define fe(e,cont) for(auto& e : cont) // others loop types by snippets
#define all(v) std::begin(v),std::end(v)

// only for md-arrays
template<class T> void unsafe_clear(T& val) { auto sz = sizeof(val); std::memset(&val, 0, sz); }
template<class T1, class T2> bool isMemEqual(const T1& v1, const T2& v2) { static_assert(sizeof(v1) == sizeof(v2)); return std::memcmp(&v1, &v2, sizeof(v1)) == 0; }

ll ipow(ll v, ll p) { ll res = 1; while (p--) { res *= v; } return res; }
ll div_ceil(ll a, ll b) { ll res = a / b; if (res * b != a) res++; return res; }

class Timer { // Sometimes measurement is required...
    using sc = std::chrono::steady_clock;  sc::time_point start;
public:
    Timer() :start(sc::now()) {}
    ll elapsedMs() { return std::chrono::duration_cast<std::chrono::milliseconds>(sc::now() - start).count(); }
};

extern const char* INPUT_DATA;

#ifdef DEBUG_INPUT
static Helper helper(INPUT_DATA);
#endif

template<class T>
T __get() {
#ifdef DEBUG_INPUT
    return helper.get<T>();
#else
    T val; std::cin >> val; return val;
#endif
}

ll get() { return __get<ll>(); }
std::string gets() { return __get<std::string>(); }
std::tuple<ll, ll> get2() { return { get(), get() }; } std::tuple<ll, ll, ll> get3() { return { get(), get(), get() }; } std::tuple<ll, ll, ll, ll>
get4() { return { get(), get(), get(), get() }; } std::tuple<ll, ll, ll, ll, ll> get5() { return { get(), get(), get(), get(), get() }; }

template<class T> void print(const T& val) { std::cout << val << " "; }
template<class T, class ... Types> void print(const T& var, const Types&...var2) { print(var); print(var2...); }
void endl() { std::cout << "\n"; }

void onetime(); void prepare() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);  std::cout.tie(nullptr); onetime(); }
void task(); void tcase() { ll t = get(); while (t--) task(); }

int main() {
    Timer timer; prepare();
    //tcase();
    task();
#ifdef DEBUG_INPUT
    while (helper.hasInput()) task();
    //print("Execution time:", timer.elapsedMs());
#endif
    return 0;
}

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

void onetime()
{
}

const char* INPUT_DATA = R"(
4 9 9
5 5
15 5
5 15
15 15

)";

void task()
{
    auto [n, S, D] = get3();
    bool f = false;
    for (ll i = 0; i < n; i += 1)
    {
        ll s = get();
        ll d = get();

        if (s < S && d > D)
        {
            f = true;
        }
    }

    print(f?"Yes":"No");

}


#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)
vi cs(10, 0), ct(10, 0);
ll comp(ll x)
{
	ll ans = 0;
	if (x == 0)
	{
		fr(i, 1, 10)
		{
			ans += i * pow(10, cs[i]);
		}
	}
	else
	{
		fr(i, 1, 10)
		{
			ans += (i * pow(10, ct[i]));
		}
	}
	return ans;
}
void solve()
{
	ll k;
	cin >> k;
	string s, t;
	cin >> s >> t;
	fr(i, 0, 4)
	{
		ll x = s[i] - '0';
		cs[x]++;
	}
	fr(i, 0, 4)
	{
		ll x = t[i] - '0';
		ct[x]++;
	}
	vlli ans1(10, 0), ans2(10, 0);
	ll tot = 0;
	fr(i, 1, 10)
	{
		tot += k - (cs[i] + ct[i]);
		if (cs[i] + ct[i] < k)
		{
			cs[i]++;
			ans1[i] = comp(0);
			cs[i]--;
			ct[i]++;
			ans2[i] = comp(1);
			ct[i]--;
		}
		// if (ct[i] < k)
		// {
		// 	ct[i]++;
		// 	ans2[i] = comp(1);
		// 	ct[i]--;
		// }
	}
	// fr(i, 1, 10)
	// {
	// 	cout << ans1[i] << " " << ans2[i] << endl;
	// }
	tot = tot * (tot - 1);
	ll sum = 0;
	fr(i, 1, 10)
	{
		fr(j, 1, 10)
		{
			if (ans1[i] > ans2[j])
			{
				if (i != j)
					sum += ((k - (cs[i] + ct[i])) * (k - (cs[j] + ct[j])));
				if (i == j)
				{
					ll x = cs[i] + ct[i];
					x = k - x;
					sum += (x * (x - 1));
				}
			}
		}
	}
	// cout << sum << " " << tot << endl;
	double fina = (double)sum / tot;
	cout << fixed << setprecision(9);
	cout << fina << 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);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}

	return 0;
}

#include<bits/stdc++.h>
// #include<atcoder/all>
#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; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef long long lint;
const ll INF=(1LL<<62);
const ll LINF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
    ll num=1000+10;
    vector<ll>count(num,0);
    ll n,m;cin>>n>>m;

    rep(i,n){
        ll a;cin>>a;count[a]++;
    }
    rep(i,m){
        ll a;cin>>a;count[a]++;
    }

    rep(i,num){
        if(count[i]==1)cout<<i<<" ";
    }
    cout<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    // ll T;cin>>T;
    // rep(i,T){
    //     cout<<"Case #"<<i+1<<" : ";solve();
    // }
    solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    double n,x0,y0,xn2,yn2;
    cin>>n>>x0>>y0>>xn2>>yn2;

    double cx=(x0+xn2)/2;
    double cy=(y0+yn2)/2;
    x0-=cx;
    y0-=cy;
    double PI=acos(-1);
    double th=2*PI/n;
    double x1=x0*cos(th)-y0*sin(th)+cx;
    double y1=x0*sin(th)+y0*cos(th)+cy;

    cout<<setprecision(10)<<x1<<" "<<y1<<endl;
}

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

#define For(i,n) for(ll i = 0; i < n; i++)
#define For1(i,n) for(ll i = 1; i < n; i++)
#define Forn(i,n) for(int i = n-1; i >=0 ; i--)
#define FOR(i,f,n) for(ll i = f; i < n; i++)
#define Forit(it,v) for(auto it = v.begin(); it != v.end(); it++)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define sz size()
#define dbg(a) For(i,a.sz){cout<<a[i]<<' ';}cout<<'\n';
#define Sort(a) sort(a.begin(), a.end());
#define Rev(a) reverse(a.begin(), a.end());
typedef long long int ll;
typedef pair<ll, ll> pl;
typedef pair<int,int> pi;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pl> vpl;
typedef vector<vll> vvll;
const long double PI = 3.1415926535;
int t,m,k,n,X,s,idx,ct1,ct0;

//const int N = 1e5;

void solve() {
    cin>>n;
    vector<long double> a,b;
    For(i,2){
        cin>>k>>m;
        a.pb(k); b.pb(m);
    }
    a.pb((a[0]+a[1]) /2); b.pb((b[0]+b[1])/2);
    long double vx, vy, l, ax, ay, Vx, Vy, L;
    vx = a[0] - a[1];
    vy = b[0] - b[1];
    l = pow(vx, 2.0)+pow(vy, 2.0);
    l = sqrt(l);
    vx /= l;
    vy /= l;
//    long double angle = (360/n) * PI;
    ax = cos((2*PI)/n);
    ay = sin((2*PI)/n);

    Vx = ax*vx - ay*vy;
    Vy = ay*vx + ax*vy;

    L = sqrt(pow(abs(a[0]-a[1]), 2.0)+pow(abs(b[0]-b[1]), 2.0)) /2;

//    cout<<ax<<' '<<ay<<' '<<L<<' '<<a[2]<<' '<<b[2]<<' '<<Vx*L<<' '<<Vy*L<<'\n';
    cout<<setprecision(20)<<a[2]+Vx*L<<' '<<b[2]+Vy*L<<'\n';
}

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

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

    return 0;
}