#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}

const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
template<class T>
class Queue{
    struct node{
        T val;
        node *next,*prev;
    };
    node *head=NULL,*tail=NULL;
    public:
        bool empty(){return head==NULL;}
        void push(T v){
            node *q=new node;
            q->val=v;
            q->prev=tail;
            q->next=NULL;
            if(tail!=NULL)tail->next=q;
            tail=q;
            if(head==NULL)head=q;
        }
        T pop(){
            node *q=head;
            head=q->next;
            if(head!=NULL)head->prev=NULL;
            T v=q->val;
            delete q;
            if(head==NULL)tail=NULL;
            return v;
        }
        T front(){
            return head->val;
        }

};

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

void Main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> G(N);
  rep(i,M){
      int A,B;
      cin>>A>>B;
      A--;B--;
      G[A].push_back(B);
      G[B].push_back(A);
  }
  int K;
  cin>>K;
  int C[K];
  rep(i,K){
      cin>>C[i];
  C[i]--;
  }
  int table[K][K];
  rep(s,K){
      int dist[N];
      rep(i,N)dist[i]=INF;
      dist[C[s]]=0;
      Queue<int> q;
      q.push(C[s]);
      while(!q.empty()){
          int v=q.pop();
          for(int nv:G[v]){
              if(dist[v]+1<dist[nv]){
                  dist[nv]=dist[v]+1;
                  q.push(nv);
              }
          }
      }
      rep(t,K)table[s][t]=dist[C[t]];
  }

  int dp[1<<K][K];
  rep(i,1<<K)rep(j,K)dp[i][j]=INF;
  rep(bit,1<<K){
      if(popcnt(bit)==0){
          rep(j,K)dp[0][j]=0;
      }
      else if(popcnt(bit)==1){
          rep(j,K)dp[bit][j]=1;
      }
      else{
          rep(k,K)if((bit>>k)&1){
              int prebit=bit^(1<<k);
              rep(j,K)if((prebit>>j)&1){
                  if(dp[prebit][j]!=INF&&table[j][k]!=INF)chmin(dp[bit][k],dp[prebit][j]+table[j][k]);
              }
          }
      }
  }
  int ans=INF;
  rep(i,K)chmin(ans,dp[(1<<K)-1][i]);
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
}

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

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
	va_list args;
	va_start(args, format);
	vprintf(format, args);
	va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 105
#define EPS 1e-7

int n;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN];

int main() {
	scanf("%d", &n);
	REP (_, 0, 2) {
		int x = 0, y = 0;
		REP (i, 0, n) {
			scanf("%d%d", &a[i], &b[i]);
			x += a[i];
			y += b[i];
			a[i] *= n;
			b[i] *= n;
		}
		REP (i, 0, n) {
			a[i] -= x;
			b[i] -= y;
		}
		swap(c, a);
		swap(d, b);
	}
	if (n == 1) {
		printf("Yes\n");
		return 0;
	}
	if (a[0] == 0 && b[0] == 0) {
		swap(a[0], a[1]);
		swap(b[0], b[1]);
	}
	REP (i, 0, n) {
		if (d[i] == c[i]) continue;
		ld angle = atan2(d[i], c[i]) - atan2(b[0], a[0]);
		bool pos = 1;
		REP (j, 0, n) {
			ld x = a[j] * cos(angle) - b[j] * sin(angle);
			ld y = a[j] * sin(angle) + b[j] * cos(angle);
			bool found = 0;
			REP (k, 0, n) {
				if (abs(x - c[k]) <= EPS && abs(y - d[k]) <= EPS) {
					found = 1;
					break;
				}
			}
			if (!found) {
				pos = 0;
				break;
			}
		}
		if (pos) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

/*
3
1 0
1 1
2 0
-1 0
-1 1
-3 0
*/


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

int main() {
  int num, nuts, x = 0, y = 0;
  cin >> num;

  for (int i = 1; i <= num; i++){
    cin >> nuts;

    if (nuts > 10){
      x = nuts - 10;
      //y += x;
    }

    else{
      continue;
    }

    y += x;

  }

  cout << y << endl;

return 0;

}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  string s;
  cin>>s;
  ll n=s.size();
  map<char,ll>p;
  ll r=0;
  for(ll i=n-1;i>0;i--) {
    if(s[i-1]==s[i]){
      r+=(n-i-1-p[s[i]]);
      for (ll j=0;j<26;j++) p[('a'+j)] = 0;
      p[s[i]]=n-i;
    }else p[s[i]]++;
  }
  cout<<r<<'\n';
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
#define int long long
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define M2 1000000009
#define M1 998244353
#define inf 1e18
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n){
    	if(n==1) return false;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b){
    if (b == 0){
    	return a;
	}
    return gcd(b, a % b);

}
int power(int x,int y,int p){
    int res=1;
    if(x==0)return 0;
    while(y>0){
        if(y&1){
        	res*=x;
        	res%=p;
		}
        y=y>>1;
        x=(x*x);
		x%=p;
		res%=p;
    }
    return res;
}
int modInverse(int n, int p){
    return power(n, p-2,p);
}
struct node{
	int a,b;
};

/*    BAAP BAAP HOTA HAI
      Author : Sagar          */

signed main(){
	FAST
	int n,m;
	cin>>n>>m;
	int arr[n][m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			char x;
			cin>>x;
			if(x=='-')arr[i][j]=-1;
			else arr[i][j]=1;
		}
	}
	int dp[n][m];
	dp[n-1][m-1]=0;
	for(int i=n-1;i>=0;i--){
		for(int j=m-1;j>=0;j--){
			if(i==n-1 && j==m-1)continue;
			if((i+j)%2==0){
				dp[i][j]=INT_MIN;
				if(i+1<n)dp[i][j]=max(dp[i][j],dp[i+1][j]+arr[i+1][j]);
				if(j+1<m)dp[i][j]=max(dp[i][j],dp[i][j+1]+arr[i][j+1]);
			}
			else{
				dp[i][j]=INT_MAX;
				if(i+1<n)dp[i][j]=min(dp[i][j],dp[i+1][j]-arr[i+1][j]);
				if(j+1<m)dp[i][j]=min(dp[i][j],dp[i][j+1]-arr[i][j+1]);
			}
		}
	}
	if(dp[0][0]>0)cout<<"Takahashi";
	else if(dp[0][0]<0)cout<<"Aoki";
	else cout<<"Draw";
}

/*
  Created by: Amit Kumar at 17:50 on 15 May 21
*/
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define db(...)
#endif
using namespace std;

#define int long long
#define S(x, n) memset(x, n, sizeof(x));
#define pb(x) emplace_back(x)
#define all(x) x.begin(), x.end()
#define NIL -1

const long long MAXN = 1e5 + 1;
const long long mod = 1e18;

template <typename T>
inline istream &operator>>(istream &is, vector<T> &A);

int dp[2010][2010][2];
vector<string> arr;
int n, m;

int calc(int i, int j, int turn)
{
    int &ret = dp[i][j][turn];
    if (ret != -mod)
        return ret;

    if (turn == 0)
    {
        ret = -mod;
        if (i + 1 < n)
            ret = max(ret, (arr[i + 1][j] == '+' ? 1 : -1) + calc(i + 1, j, turn ^ 1));
        if (j + 1 < m)
            ret = max(ret, (arr[i][j + 1] == '+' ? 1 : -1) + calc(i, j + 1, turn ^ 1));
        if (ret == -mod)
            ret = 0;
    }
    else
    {
        ret = mod;
        if (i + 1 < n)
            ret = min(ret, (arr[i + 1][j] == '+' ? -1 : 1) + calc(i + 1, j, turn ^ 1));
        if (j + 1 < m)
            ret = min(ret, (arr[i][j + 1] == '+' ? -1 : 1) + calc(i, j + 1, turn ^ 1));
        if (ret == mod)
            ret = 0;
    }
    db(ret, i, j, turn);
    return ret;
}

void solve()
{

    cin >> n >> m;
    arr = vector<string>(n);
    cin >> arr;

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= m; j++)
            dp[i][j][0] = dp[i][j][1] = -mod;

    int ans = calc(0, 0, 0);
    db(ans);
    if (ans == 0)
        cout << "Draw\n";
    else if (ans > 0)
        cout << "Takahashi\n ";
    else
        cout
            << "Aoki\n";
}
int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    auto started = std::chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    t = 1;
    //cin >> t;
    for (int I = 1; I <= t; I++)
    {
#ifdef LOCAL
        cerr << "TestCase " << I << "\n";
#endif
        solve();
    }
#ifdef LOCAL
    auto done = std::chrono::high_resolution_clock::now();
    cerr << "Time = " << std::chrono::duration_cast<std::chrono::milliseconds>(done - started).count() << " ms\n";
#endif
    return 0;
}
template <typename T>
inline istream &operator>>(istream &is, vector<T> &A)
{
    for (int i = 0; i < A.size(); i++)
        is >> A[i];
    return is;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> Vll;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
    ll n,k;
    cin >> n >> k;
    vector<Vll> t(n,Vll(n));
    rep(i,n){
        rep(j,n){
            cin >> t[i][j];
        }
    }
    ll ans=0;
    vector<int> v(n-1);
    for(int i=0;i<n-1;i++)v[i]=i+1;
    do{
        int cnt=0;
       rep(i,n-1){
           if(i==n-2){
               cnt+=t[v[i-1]][v[i]];
               cnt+=t[v[i]][0];
           }
           else if(i==0){
               cnt+=t[0][v[i]];
           }
           else{
               cnt+=t[v[i-1]][v[i]];
           }
            if(cnt==k)ans++;
       }
    }while(next_permutation(v.begin(),v.end()));

    cout << ans << endl;
}

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

int N, ft[200005];
set< pair<int,int> > s;

void update (int x, int v) {
    x++;
    while (x <= N) ft[x] += v, x += x & -x;
}

int query (int x) {
    x++;
    int ans = 0;
    while (x) ans += ft[x], x -= x & -x;
    return ans;
}

int main() {
    scanf("%d", &N);
    memset(ft,0,sizeof(ft));
    for (int i = 1; i < N; ++i) update(i,1);
    for (int i = 0; i < N; ++i) {
        int x; scanf("%d", &x);
        s.emplace(x+i,i);
    }
    long long ans = 0;
    for (int i = 0; i < N; ++i) {
        int x; scanf("%d", &x);
        x += i;
        auto it = s.lower_bound(make_pair(x,-1));
        if (it == s.end()) {
            printf("-1");
            return 0;
        }
        int n = (*it).second;
        ans += query(n);
        update(n,-1);
        s.erase(it);
    }
    printf("%lld", ans);

    return 0;
}


/*One cannot escape the feeling ... that these mathematical formulae have
an independent existence and an intelligence of their own ... that they
are wiser than we are, wiser even than their discoverers ... that we get
more out of them that was originally put into them.
*/

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; id good if no two adjacent cells contain the same value, where two cells are called adjacent if they share a side. >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[52],dp[52],span[52],g[52],possible[52],fact[52];
int main(){
    ll n,x;
    cin>>n>>x;

    forn(i,n) cin>>a[i];
    forn(i,n-1){
        fact[i]=(a[i+1]/a[i])-1;
    }
    fact[n-1]=1e18;
    for(ll i=n-1;i>=0;i--){
        g[i]=x/a[i];
        x%=a[i];
    }
    for(ll i=0;i<n;i++){
        ll c=0;
        for(ll j=i+1;j<n;j++){
            if(g[j]==fact[j]) c++;
            else break;
        }
        span[i]=c;
    }
    possible[n-1]=1;
    dp[n-1]=1;
    for(ll i=n-2;i>=0;i--){
        dp[i]=0;
        ll c=0;
        if(g[i]) c+=possible[i+span[i]+1];
        dp[i]+=dp[i+1];
        dp[i]+=c;
        if(g[i]) possible[i]=dp[i];
        else possible[i]=dp[i+1]+possible[i+1+span[i]];
    }
    cout<<dp[0];
}

#include<bits/stdc++.h>
long long n,x;
long long ans[2],k[2],a,b,c,now;
int main()
{
	scanf("%lld%lld",&n,&x);
	scanf("%lld",&b);
	ans[0]=1;ans[1]=0;
	for(int i=1;i<n;++i)
	{
		scanf("%lld",&a);
		c=a/b;b=a;
		now=x%c;
		x/=c;
		k[0]=ans[0],k[1]=ans[1];
		if(now)k[1]+=ans[0];
		if(++now!=c)k[0]+=ans[1];
		ans[0]=k[0];ans[1]=k[1];
	}
	printf("%lld",ans[0]+ans[1]);
	return 0;
}


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

int main()
{
	string str;
	int a[10]={0};
	int zh(string s);
	cin >> str;

	for(int i=0;i<str.size();i++)
	{
		a[str[i]-'0']++;
	}

	if(str.size()==1)
	{
		if(zh(str) == 8)
		{
			cout << "Yes";
		}
		else
		{
			cout << "No";
		}
		return 0;
	}

	if(str.size()==2)
	{
		if(zh(str)%8==0)
		{
			cout << "Yes";
		}
		else
		{
			swap(str[0],str[1]);
			if(zh(str)%8==0)
				cout << "Yes";
			else
			    cout << "No";
		}
		return 0;
	}

	for(int i=112;i<999;i+=8)
	{
		int b,sh,g;
		b=i/100;
		sh=i/10%10;
		g=i%10;

		a[b]--;
		a[sh]--;
		a[g]--;

		if(a[b]>=0 && a[sh]>=0 && a[g]>=0)
		{
			cout << "Yes";
			return 0;
		}
		else
		{
			a[b]++;
			a[sh]++;
			a[g]++;
		}
	}

	cout << "No";
	return 0;
}

int zh(string a)
{
	int ans=0;

	for(int i=0;i<a.size();i++)
	{
		ans = ans*10+(a[i]-'0');
	}

	return ans;
}

/*    BISMILLAHIR-RAHMANIR-RAHIM
 ____________________________________
|                                    |
|      SHANTO_SUST_SWE-19__029       |
|      shanto-swe029.github.io       |
|____________________________________|
*/

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

#define ll          long long
#define fastio      ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb          push_back
#define Pi          acos(-1.0)
#define r0          return 0
#define endl        "\n"
#define show(x)     cout << x << endl
#define take(x)     cin >> x
#define debug       1

int main()
{
	string s;
	std::cin >> s;
	int sz = s.size();

	if( sz == 1 ) {
		if( s == "8" ) std::cout << "Yes";
		else std::cout << "No";
		return 0;
	}

	if( sz == 2 ) {
		int d1 = s[0] - '0';
		int d2 = s[1] - '0';
		int n1 = d1 * 10 + d2;
		int n2 = d2 * 10 + d1;
		if( ( n1 % 8 == 0 ) || ( n2 % 8 == 0 ) ) {
			std::cout << "Yes";
			return 0;
		}
		else {
			std::cout << "No";
			return 0;
		}
	}

	int counter[10] = {0};

	for( int i = 0; i < sz; i++ ) {
		int x = ( int ) ( s[i] - '0' );
		counter[x]++;
	}

	std::vector < int > v;

	for( int i = 0; i < 10; i++ ) {
		if( counter[i] > 0 ) v.push_back(i);
		if( counter[i] > 1 ) v.push_back(i);
		if( counter[i] > 2 ) v.push_back(i);
	}

	bool gotcha = false;
	for( int i = 0; i < v.size(); i++ ) {
		for( int j = i + 1; j < v.size(); j++ ) {
			for( int k = j + 1; k < v.size(); k++ ) {
				int d1 = v[i];
				int d2 = v[j];
				int d3 = v[k];

				int n1 = d1 * 100 + d2 * 10 + d3;
				int n2 = d1 * 100 + d3 * 10 + d2;
				int n3 = d2 * 100 + d1 * 10 + d3;
				int n4 = d2 * 100 + d3 * 10 + d1;
				int n5 = d3 * 100 + d1 * 10 + d2;
				int n6 = d3 * 100 + d2 * 10 + d1;

				bool pass = ( n1 % 8 == 0 ) || ( n2 % 8 == 0 ) || ( n3 % 8 == 0 )
							|| ( n4 % 8 == 0 ) || ( n5 % 8 == 0 ) || ( n6 % 8 == 0 );

				if( pass ) {
					gotcha = true;
					break;
				}
			}
			if( gotcha ) break;
		}
		if( gotcha ) break;
	}

	if( gotcha ) cout << "Yes";
	else cout << "No";

	return 0;
}

//ALHAMDULILLAH


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dd;
#define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++)
#define nl cout<<"\n";
#define forn(a,b) for(int ii=a;ii<b;ii++)
const ll MOD1=1e9+7;
const ll MOD2=998244353;
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define hhh cout<<"here"<<endl;

ll mod=MOD1;
ll po(ll x,ll y) {y%=mod;ll res=1;while(y>0){if(y&1)res=(res*x);x=(x*x);y>>=1;}return res;}
ll gcd(int a, int b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);}

void solve(){
    int n,m;cin>>n>>m;
    if(n==1 && m==0){
        cout<<"1 2\n";return;
    }
    if(!(m>=0 && m<=n-2)){cout<<"-1\n";return;}
    int inf=1e8;
    forn(1,n-m){
        cout<<ii<<" "<<ii+inf;nl;
    }int i=0;
    forn(n-m,n+1){
        cout<<ii+i<<" "<<ii+1+i;nl;
        i++;
    }
}
int main(){

    // fastio
    // ++*(int*)0;// crash
    // freopen("out.txt","r",stdin);freopen("outt.txt","w",stdout);
    // tst
    {
        solve();
    }
}
/*

*/

#include<bits/stdc++.h>

using namespace std;

int main()
{
//	freopen("1.in","r",stdin);

	int n,m;
	scanf("%d %d",&n,&m);

	if(n==1)
	{
		if(m==0)printf("1 2\n");
		else puts("-1");
	}
	else
	{
		if(m<0 || m>n-2)puts("-1");
		else
		{
			int nn=n,r=0;
			if(m>=1)
			{
				printf("1 %d\n",n*2);
				--nn;r=1;

				for(int i=1;i<=m+1;++i)
				{
					printf("%d %d\n",r+1,r+2);
					--nn;r+=2;
				}

				r=n*2;
			}
			while(nn)
			{
				printf("%d %d\n",r+1,r+2);
				--nn;r+=2;
			}

			puts("");
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#define _GLIBCXX_DEBUG
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
const ll INF = 50000000000000000;
const ll dx[8] = {1,0,-1,0,1,1,-1,-1};
const ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll mod(ll x,ll m){return x & m;}
ll modinv(ll a,ll m){
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}
ll npow(ll a, ll n){
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
ll yaku(ll x){
    ll cnt = 0;
    for(int i = 1; i * i <= x; i++){
        if(x % i == 0){
            if(i == x / i) cnt++;
            else cnt += 2;
        }
    }
    return cnt;
}
ll modwaru(ll a, ll b, ll m){
    a %= m;
    return a * modinv(b, m) % m;
}
ll gcd(ll x, ll y){
    if(x % y == 0)return y;
    else return gcd(y, x % y);
}
struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll K, N, M, wa = 0;
    cin >> K >> N >> M;
    vector<ll> A(K), ans(K);
    vector<pair<ll,ll>> C(K);
    for(int i = 0; i < K; i++) cin >> A[i];
    for(int i = 0; i < K; i++){
        ll s = M * A[i] / N;
        ans[i] = s;
        C[i].first = s * N - M * A[i];
        C[i].second = i;
    }
    for(int i = 0; i < K; i++) wa += ans[i];
    sort(ALL(C));
    for(int i = 0; i < M - wa; i++){
        ans[C[i].second]++;
    }
    for(int i = 0; i < K; i++){
        cout << ans[i];
        if(i != K - 1) cout << ' ';
    }
    cout << endl;
}

//ye moh moh ke dhaage,tere ungliyon se ja uljhe

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define dbug(x) cout<<#x<<"="<<x<<endl;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll fr[3*100002];
ll mex[3*100002];

int main(){
    ll n,k,ans=0;
    cin>>n>>k;

    forn(i,n){
        ll te;
        cin>>te;
        fr[te]++;
    }

    forn(i,n){
        for(ll j=0;j<(min(fr[i],k));j++){
            if(mex[j]==i) mex[j]++;
        }
    }

    forn(i,k) ans+=mex[i];
    cout<<ans;
}


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

#define int long long
#define pii pair<int,int>
const int M=1e9+7;
const int N=200005;

signed main(){
  int t1=1;
  //cin>>t1;
  while(t1--){
    string s;
    cin>>s;

    reverse(s.begin(),s.end());
    for(int i=0;i<s.length();i++){
      if(s[i]=='6') s[i]='9';
      else if(s[i]=='9') s[i]='6';
    }

    cout<<s<<endl;
  }
}


	#include "bits/stdc++.h"
	using namespace std;
	#define mod 1000000007
	#define pie  3.14159265
	#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++)

	void solve()
	{
		ll a, b;
		cin >> a >> b;
		ll m = -1;
		fr(i, 1, b)
		{
			ll x = (a - 1) / i;
			ll y = b / i;
			if (y - x >= 2)
				m = max(m, i);

		}
		cout << m << endl;
	}

	int main() {
	//#ifndef ONLINE_JUDGE
	#ifdef yogi23
		freopen("input.txt", "r", stdin);
		freopen ("output.txt", "w", stdout);
	#endif
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		int t;
		t = 1;
		//cin >> t;
		while (t--)
		{
			solve();
		}

		return 0;
	}

#include <iostream>
#include <cmath>
using namespace std;
int getMaxGCD(int arr[], int n) {
   int high = 0;
   for (int i = 0; i < n; i++)
   high = max(high, arr[i]);
   int divisors[high + 1] = { 0 }; //array to store all gcd values
   for (int i = 0; i < n; i++) {
      for (int j = 1; j <= sqrt(arr[i]); j++) {
         if (arr[i] % j == 0) {
            divisors[j]++;
         if (j != arr[i] / j)
            divisors[arr[i] / j]++;
         }
      }
   }
   for (int i = high; i >= 1; i--)
   if (divisors[i] > 1)
   return i;
}
int main() {
    int a,b;
    cin >> a >> b;
    int arr[b-a+1];
    int t=0;

    for(int i=a;i<=b;i++){
        arr[t] = i;
        t++;
    }

    int n = sizeof(arr) / sizeof(arr[0]);
    cout << getMaxGCD(arr,n);

}


#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;

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; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){

  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//cout<<""<<endl;
int main(){
 ll N;cin>>N;
 set<ll> a;
  a.insert(1);
 for( ll i=1;i*i<=N;i++){
    if(N%i==0){
      a.insert(i);
      a.insert(N/i);
    }
 }
  for(auto x: a)cout<<x<<endl;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#define int long long
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define fcout cout << fixed << setprecision(20)
using namespace std;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

signed main() {
  int n;
  cin >> n;
  vector<int> v = divisor(n);
  rep(i, 0, (int)v.size()) cout << v[i] << "\n";
}


#include<bits/stdc++.h>
#include<string>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mod (ll)(1e9+7)
#define nax (ll)(1e5 + 10)
#define INFL LLONG_MAX
#define NINFL LLONG_MIN
#define INF INT_MAX
#define disp(a,n,arr) for(int i=a;i<(ll)n;i++) cout << arr[i] << " "; cout << "\n";
#define check cout << "Working\n";
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpl vector<pl>
#define vpi vector<pi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
using namespace std;

void code(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a < 0 && c%2 == 0) a = -a;
    if(b < 0 && c%2 == 0) b = -b;
    if(a < 0 && b >= 0) cout << "<\n";
    else if(a >= 0 && b < 0) cout << ">\n";
    else{
        if(a == b) cout << "=\n";
        else if(a > b) cout << ">\n";
        else cout << "<\n";
    }
}

int main() {
    FIO;

    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif

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

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int64_t a, b, c;
    cin >> a >> b >> c;
    if (c & 1 == 1) c = 1;
    else c = 2;
    if (pow(a, c) > pow(b, c))
        cout << ">\n";
    else if (pow(a, c) < pow(b, c))
        cout << "<\n";
    else
        cout << "=\n";
}


#include <stdio.h>
#include <string.h>

int ans[110][10010];
int a;
char x[110];
int y[110];

void func(int k)
{
	printf("%d\n",k);
	for(int i=0;i<=a;i++)
	{
		int s = y[i]/k;
		int t = y[i]%k;
		for(int j=1;j<=t;j++) ans[i][j] = s+1;
		for(int j=t+1;j<=k;j++) ans[i][j] = s;
	}

	for(int j=1;j<=k;j++)
	{
		for(int i=0;i<=a;i++) printf("%d ",ans[i][j]);
		printf("\n");
	}
}

int main()
{
	scanf("%d",&a);
	scanf("%s",x+1);
	for(int i=0;i<=a;i++) scanf("%d",&y[i]);

	int limit = 10000;
	for(int i=limit;i>=1;i--)
	{
		int s = y[0]/i;
		int t = y[0]%i;
		for(int j=1;j<=a;j++)
		{
			int s2 = y[j]/i;
			int t2 = y[j]%i;
			if(x[j]=='<')
			{
				if(t<t2)
				{
					if(s+1 < s2+1 && s < s2+1 && s<s2);
					else goto u;
				}
				else if(t>t2)
				{
					if(s+1 < s2+1 && s+1 < s2 && s<s2);
					else goto u;
				}
				else
				{
					if(s+1 < s2+1 && s<s2);
					else goto u;
				}
			}
			else
			{
				if(t<t2)
				{
					if(s+1 > s2+1 && s > s2+1 && s>s2);
					else goto u;
				}
				else if(t>t2)
				{
					if(s+1 > s2+1 && s+1 > s2 && s>s2);
					else goto u;
				}
				else
				{
					if(s+1 > s2+1 && s>s2);
					else goto u;
				}
			}
			s = s2;
			t = t2;
		}

		func(i);
		return 0;
		u:;
	}
}

#include<bits/stdc++.h>

using namespace std;

#define endl "\n"
#define lln long long int
#define ld long double
#define all(x) (x).begin(),(x).end()
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int MOD = 1e9 + 7;
const int N = (int)2e5 + 5;

int main(){
    IOS;

    int TT = 1;
    //cin >> TT;
    for(int tt = 1; tt <= TT; tt++){
        string s;
        cin >> s;
        int n = s.length();
        reverse(all(s));
        for(int i = 0; i < n; i++){
            if(s[i] == '9') s[i] = '6';
            else if(s[i] == '6') s[i] = '9';
        }
        cout << s << endl;
    }
    return 0;
}


//  /Applications/Geany.app/Contents/MacOS/geany
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define pairii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

const int N = 10000000;
vector<int> lp(N+1,0);
vector<int> pr;
void primefactor();
int binpow(int a, int b);
int binpow(int a, int b, int mod);
int gcd(int a, int b);
int lcm (int a, int b);
bool comp(int a, int b);
int inversemod(int a, int mod);

void test()
{
	int n,x,i,j;
	cin>>n>>x;
	x*=100;
	vector<pairii> pre(n);
	for(i=0;i<n;i++) cin>>pre[i].ff>>pre[i].ss;

	double sum=0;
	for(i=0;i<n;i++)
	{
		sum+=pre[i].ss*pre[i].ff;
		if(sum>x)
		{
			cout<<i+1<<endl;
			return;
		}
	}
	cout<<-1<<endl;

}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--) test();
	return 0;
}

void primefactor()
{
	for (int i=2; i<=N; ++i) {
		if (lp[i] == 0) {
			lp[i] = i;
			pr.push_back (i);
		}
		for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
			lp[i * pr[j]] = pr[j];
	}
}

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

int binpow(int a, int b, int mod)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}

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

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

bool comp(int a, int b)
{
	return a>b;
}

int inversemod(int a, int mod)
{
	return binpow(a,mod-2, mod);
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){//cout<<fixed<<setprecision(20);
  ll n,x;
  cin>>n>>x;
  x*=100;
  rep(i,0,n){
    ll v,p;
    cin>>v>>p;
    x-=v*p;
    if(x<0){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<string> S(n);
  vector<vector<int>> A(n, vector<int>(m)), B(n, vector<int>(m)), C(n, vector<int>(m)), D(n, vector<int>(m));
  int K = 0;
  for (int i = 0; i < n; ++i) cin >> S[i], K += count(S[i].begin(), S[i].end(), '.');
  int64 md = 1e9 + 7;
  vector<int64> two(max(100, K + 2));
  two[0] = 1;
  for (int i = 1; i < SZ(two); ++i) two[i] = two[i - 1] * 2 % md;
  int64 res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (S[i][j] == '.') {
        A[i][j] = 1;
        if (i - 1 >= 0) A[i][j] += A[i - 1][j];
        B[i][j] = 1;
        if (j - 1 >= 0) B[i][j] += B[i][j - 1];
      }
    }
  }
  for (int i = n - 1; i >= 0; --i) {
    for (int j = m - 1; j >= 0; --j) {
      if (S[i][j] == '.') {
        C[i][j] = D[i][j] = 1;
        if (i + 1 <= n - 1) C[i][j] += C[i + 1][j];
        if (j + 1 <= m - 1) D[i][j] += D[i][j + 1];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j)
      if (S[i][j] == '.') {
        int tot = A[i][j] + B[i][j] + C[i][j] + D[i][j] - 3;
        (res += (two[tot] + md - 1) * two[K - tot] % md) %= md;
      }
  }
  cout << res;
  return 0;
}
//14.10.2020 04:31:12 CST

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define P pair<int,int>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vi (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define sz(x) int(x.size())
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

ll p=1e9+7;

ll f(ll n){
  if(n==0)return 1;
  if(n==1)return 2;
  if(n%2)return 2*f(n-1)%p;
  ll res=f(n/2);
  return res*res%p;
}
int main(){
  cci(h,w);

  int k=0;
  vvi v(h+2,vi(w+2,-1));
  rep(i,0,h){
    rep(j,0,w){
      char c;ci(c);
      if(c=='.')v[i+1][j+1]=0,k++;
    }
  }

  vvi tt=v,yk=v;
  rep(i,1,h+1){
    int now=0;

    rep(j,1,w+1){
      if(v[i][j]==0)yk[i][j]=++now;
      else now=0;
    }
    rev(j,w,1){
      if(yk[i][j]==-1)continue;
      chmax(yk[i][j],yk[i][j+1]);
    }
  }

  rep(i,1,w+1){
    int now=0;

    rep(j,1,h+1){
      if(v[j][i]==0)tt[j][i]=++now;
      else now=0;
    }
    rev(j,h,1){
      if(tt[j][i]==-1)continue;
      chmax(tt[j][i],tt[j+1][i]);
    }
  }

  ll ans=0;
  ll k2=f(k);
  map<int,int>mp;

  rep(i,1,h+1){
    rep(j,1,w+1){
      ll now=max(-1,yk[i][j]+tt[i][j]-1);
// cout<<now<<" ";
      mp[now]++;
    }
// co("");
  }

  for(auto x:mp){
    if(x.first==-1)continue;
    ll now=k2-f(k-x.first);
    ans+=now*x.second%p;
    ans%=p;
  }

  ans=(ans+p)%p;
  co(ans);
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#define IO  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define req(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define fi first
#define se second
using namespace std;

const int inf=0x3f3f3f3f;
typedef long long ll;
const int N = 1e5+7;
const ll mod = 1e9+7;
int a[N];
int main()
{
    IO;
    string s;
    cin>>s;
    if(s.size()==1){
    	cout<<((s[0]=='8')?"Yes":"No")<<endl;return 0;
    }
    if(s.size()==2){
    	if(((s[0]-'0')*10+(s[1]-'0'))%8==0||((s[0]-'0')+(s[1]-'0')*10)%8==0)cout<<"Yes"<<endl;
    	else cout<<"No"<<endl;
    	return 0;
    }
    for(char i:s)a[i-'0']++;
    rep(i,1,9){
    	if(!a[i])continue;
    	int k=(i*100+7)/8*8;
    	while(k<(i+1)*100){
    		int p=k;
    		if(k%10>0&&k/10%10>0){
    			if(a[p%10]>0){
    				int x=p%10;
    				p/=10;
    				a[x]--;
    				if(a[p%10]>0){
    					int y=p%10;
    					p/=10;
    					a[y]--;
    					if(a[p%10]>0){
    						cout<<"Yes"<<endl;
    						return 0;
    					}a[y]++;
    				}a[x]++;
    			}
    		}
    		k+=8;
    	}
    }
    cout<<"No"<<endl;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <limits.h>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll MOD=1000000007;
ll INF=1000000011;
ll MOD2=998244353;
ll LINF = 1001002003004005006ll;
ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

string S;
ll A[10];

signed main(){
  cin >> S;
  rep(i,S.size()){
    A[ctoi(S[i])]++;
  }
  if(S.size()==2){
    string V=S;
    reverse(ALL(V));
    if(stoi(S)%8==0 || stoi(V)%8==0){
      cYes;return 0;
    }
  }
  else if(S.size()==1){
    if(stoi(S)%8==0){
      cYes;return 0;
    }
  }
  else{
    for(int i=0;i<1000;i+=8){
      vector<ll> B(10,0);
      ll K=i;
      rep(j,3){
        B[K%10]++;
        K/=10;
      }
      ll Z=1;
      rep(j,10){
        if(B[j]>A[j]){
          Z=0;
        }
      }
      if(Z){
        //cout << i << endl;
        cYes;return 0;
      }
    }
  }
  cNo;
}


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

void seive(ll n)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p = 2; p <= n; p++)
        if (prime[p])
        	pr.pb(p);
}

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

ll gcd(ll x, ll y){
    if (y == 0)
    return x;
    else
    return gcd(y, x % y);
}

ll nck(ll n, ll k){
    ll C[k + 1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++) {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = (C[j]%M + C[j - 1]%M)%M;
    }
    return C[k]%M;
}

void call(vll &primefactor,int N){
    for(int i=1;i<N;i++)
    {
        primefactor[i]=i;
    }
    for(int i=2;i<N;i++)
    {
        if(primefactor[i]!=i)
            continue;
        for(int j=i;j<N;j+=i)
            primefactor[j]=i;
    }
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
    //cin>>t;
    while(t--){
        ll n; cin>>n;
        vll v(n);
        ll s=0;
        fo(i,n){
            cin>>v[i];
            s+=v[i];
        }
        sort(v.begin(),v.end());
        vll run(n);
        ll ss=0;
        fo(i,n){
            ss+=v[i];
            run[i]=ss;
        }
        ld ans=1e18;
        fo(i,n){
            ld x=(ld)v[i]/2.0;
            while(i<n && v[i]==x*2)
            i++;
            i--;
           // cout<<i<<"   "<<v[i]<<endl;
            ld num=n*x+s-(n-i-1)*v[i]-run[i];
            ld an=num/n;
            if(an<ans)
            ans=an;
        }
        cout<<setprecision(8)<<ans<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
inline int qr(){
	int x=0,f=0;char ch=0;
	while(!isdigit(ch)){f|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return f?-x:x;
}
const int N=1e5+100;
int n;
double a[N];
int main(){
	n=qr();
	for(reg int i=1;i<=n;i++){
		scanf("%lf",&a[i]);
	}
	sort(a+1,a+n+1);
	int mid=(1+n)/2;
	double x=a[mid]/2;
	double ans=0;
	for(reg int i=1;i<=n;i++){
		ans+=x+a[i]-min(x*2,a[i]);
	}
	printf("%.7f",ans/n);
	return 0;
}


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

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

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int x, y; cin >> x >> y;
    if(x > y) swap(x, y);
    if(y - x < 3) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

/* @memendra_singh */
#include<bits/stdc++.h>
using namespace std;
#define m7          1000000007
#define m9          1000000009
#define ll          long long
#define boost       ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define F           first
#define S           second
#define pb          push_back
#define f1(i,n)     for(int i=0;i<n;i++)
#define all(c)      c.begin(),c.end()
#define ldb         long double
#define pi          acos(-1);

bool check(int x,vector<vector<int>> &vec,int n)
{
	set<int> st;
	for(int i=0;i<n;i++)
	{
		int bit = 0;
		for(int j=0;j<5;j++)
		{
			if(vec[i][j] >= x)
			{
				bit = bit|(1<<j);
			}
		}
		st.insert(bit);

	}
	for(auto a : st)
		for(auto b : st)
			for(auto c : st)
				if((a|b|c) == 31)
					return 1;

   return 0;
}

int main()
{
	boost;
	int t = 1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		vector<vector<int>> vec(n,vector<int>(5));
		f1(i,n)
		{
			f1(j,5)
			{
				cin>>vec[i][j];
			}
		}
		int low = 0,high = 1000000000;
		int mid;
		while(low < high)
		{
			mid = (low+high+1)/2;
			if(check(mid,vec,n))
			{
				low = mid;
			}
			else
			{
				high = mid-1;
			}

		}
		cout<<low<<'\n';

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll i,j,n,m;
	scanf("%lld%lld",&n,&m);
	pair<ll,ll>p[m+1];
	for(i=0;i<m;++i)
		scanf("%lld%lld",&p[i].first,&p[i].second);
	sort(p,p+m);
	set<ll>s;
	s.insert(n);
	p[m].first=1e10;
	queue<ll>q1,q2;
	for(i=0;i<m;++i){
		if(s.find(p[i].second)!=s.end())
			q1.push(p[i].second);
		if(s.find(p[i].second+1)!=s.end()||s.find(p[i].second-1)!= s.end())
			q2.push(p[i].second);
		if(p[i].first!=p[i+1].first){
			while(q1.size())
				s.erase(q1.front()),q1.pop();
			while(q2.size())
				s.insert(q2.front()),q2.pop();
		}
	}
	printf("%lld",s.size());
	return 0;
}

#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
typedef long long LL;
const int N=1007;
int n,m,c,a,vH[N],vL[N];
char G[N][N];
void flyL(int);
void flyH(int u) {
	if(vH[u]) return;
	vH[u]=c;
	For(v,1,m) if(G[u][v]=='#') flyL(v);
}
void flyL(int u) {
	if(vL[u]) return;
	vL[u]=c;
	For(v,1,n) if(G[v][u]=='#') flyH(v);
}
int main() {
	scanf("%d%d",&n,&m);
	For(i,1,n) scanf("%s",G[i]+1);
	G[1][1]=G[n][1]=G[1][m]=G[n][m]='#';
	For(i,1,n) if(!vH[i]) ++c,flyH(i);
	For(i,1,n) vH[i]=0;
	For(i,1,m) vL[i]=0;
	a=c,c=0;
	For(i,1,m) if(!vL[i]) ++c,flyL(i);
	printf("%d",min(c-1,a-1));
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l); i<(r); ++i)
using ll = long long int;
using namespace std;
const int INF = 1234567890;

int main(){
    //入力
    int x, y;
    cin >> x >> y;

    //処理
    if(x>y) cout << (x<y+3?"Yes":"No") << endl;
    else cout << (x+3>y?"Yes":"No") << endl;

    //出力

    return 0;
}

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void solve(){
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<a<<endl;
    }else{
        cout<<3-a-b<<endl;
    }
    return;
}
int main() {
    int test =1;
    // cin>>test;
    while(test--){
        solve();
    }
    return 0;
}


/**
*
* @Author : Sindys
* Language  : C++
*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <limits>//numeric_limits<int>::max() ... numeric_limits<int>::min()
#include <cmath>
#include <bitset>
#include <tuple>
#include <deque>
#include <stack>

using namespace std;
#define ll                  long long
#define pii                 pair<int, int>
#define vpii                vector<pii>
#define vi                  vector<int>
#define vd                  vector<double>
#define vll                 vector<ll>
#define INF                 1000000000
#define pb                  push_back
#define FOR(i,a,b,p)          for (int i = a; i < b; i += p)
#define ROF(i,b,a,p)          for (int i = b-1; i >= a; i -= p)
#define mp                  make_pair
#define f                   first
#define s                   second
#define FORX(a,b,n)         for (; a < b; a += n)//for every +n operation
#define ROFX(a,b,n)         for (; a > b; a -= n)//for every -n operation
const int M = 1000000007;

//memset(memo, -1, sizeof memo); // initialize DP memoization table with -1
//memset(arr, 0, sizeof arr); // to clear array of integers
// index = (index + 1) % n; // index++; if (index >= n) index = 0;
// index = (index + n - 1) % n; // index--; if (index < 0) index = n - 1;
// int ans = (int)((double)d + 0.5); // for rounding to nearest integer

void solve() {
    long double x, y, r;
    cin>>x>>y>>r;
    ll res = 0;
    ll highestPointY = floor( y + r );
    ll lowestPointY = ceil( y - r);
    r = nextafter(r, INFINITY);
    for(ll i = highestPointY; i >= lowestPointY; i--) {
        long double width = sqrt( r * r - abs(i - y) * abs(i - y));
        res += floor(x + width) - ceil(x - width) + 1;
    }
    cout<<res<<'\n';

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
/*stuff you should look for:
-->overflow,array bounds
-->special cases n=1..
-->use printf for precision or setprecision on cout*/


#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define vlint vector<lint>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
#define GEts(s) getline(cin,s);
#define UNIQUE(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())

using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a * b / gcd(a, b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}

static const double pi = 3.141592653589793;
int modpow(int a,int n,int p){if (n==0)return 1%p; if(n==1)return a%p;if(n%2==1)return (a*modpow(a,n-1,p))%p;lint t=modpow(a,n/2,p);return (t*t)%p;}//a^n%p
lint MOD=1e9+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**/int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	void init(int size){
		table.resize(size);
		rep(i,size)table[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
	int getsize(){
		set<int> ma;
		rep(i,table.size())ma.insert(root(i));
		int re=ma.size();
		return re;
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(16);
	int a,b;
	in(a,b);
	arep(x,-100,101)arep(y,-100,101){
		if(x+y==a&&x-y==b){
			out(x,y);
			break;
		}
	}
	return 0;
}

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

vector<ll> prime_numbers = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};
int n = prime_numbers.size();

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

	ll A, B;
	cin >> A >> B;
	ll N = B-A+1;

	vector<vector<ll>> dp(N+1, vector<ll>(1<<n, 0LL));
	dp[0][0] = 1LL;

	vector<int> pre(N);
	for (ll i=A;i<=B;i++) {
		int ret = 0;
		for (int j=0;j<n;j++) {
			if (i%prime_numbers[j] == 0) {
				ret += (1<<j);
			}
		}
		pre[i-A] = ret;
	}

	for (ll i=A;i<=B;i++) {
		for (int j=0;j<(1<<n);j++) {
			if (dp[i-A][j] == 0) continue;
			dp[i-A+1][j] += dp[i-A][j];
			if ((j&pre[i-A]) != 0) continue;
			dp[i-A+1][j|pre[i-A]] += dp[i-A][j];
		}
	}

	ll ans = 0LL;
	for (int j=0;j<(1<<n);j++) ans += dp[N][j];
	cout << ans << "\n";
	return 0;
}


// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)  cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1000005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll  b) {
    return (ceil(1.0 * a / b * 1.0));
}
ll binexp(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinvfermat(ll a, ll m)
{
    return binexp(a, m - 2, m);
}
void task(bool flag)
{
    if (flag)
        cout << "YES\n";
    else
        cout << "NO\n";
}
ll lcm(ll a, ll b)
{
    return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    ll n, m;
    cin >> n >> m;
    vector<vector<char>> grid(n, vector<char>(m));
    loop(i, n)   loop(j, m)   cin >> grid[i][j];
    ll ans = 0;
    loop(i, n)
    {
        ll len = 0, j = 0;
        while (j < m)
        {
            if (grid[i][j] == '.')
            {
                len = 0;
                while (j < m && grid[i][j] == '.')
                    ++j , ++len;
                ans += len - 1;
            }
            else
                ++j;
        }
    }
    loop(j, m)
    {
        ll len = 0, i = 0;
        while (i < n)
        {
            if (grid[i][j] == '.')
            {
                len = 0;
                while (i < n && grid[i][j] == '.')
                    ++i , ++len;
                ans += len - 1;
            }
            else
                ++i;
        }
    }
    cout << ans << END;

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
    return 0;
}

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

#define endl "\n"
#define int long long int
#define mod 1000000007
#define vi vector<int>
#define pint pair<int,int>
#define vint vector<vector<int>>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int N = 1e6+5;
int A[N], B[N], P[N], Q[N][3], D[N][3];
string S[105];

int mat[5005][5005];
pint edges[N];
unordered_map<int, set<int>> m;

bool compare(vi a, vi b)
{
    return a[0] < b[0];
}

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

int mypow(int a, int x)
{
    if(a<=1 || x==1) return a;
    if(x==0) return 1;

    int temp = mypow(a,x/2);
    if(x%2==0) return ((temp%mod) * (temp%mod))%mod;
    else return (a%mod * ((temp%mod) * (temp%mod))%mod)%mod;
}

int count_bits(int n)
{
    int cnt = 0;
    while(n)
    {
        n = n & (n-1);
        cnt++;
    }return cnt;
}

void bfs(int src, int n)
{
    unordered_map<int, bool> visited;
    for(int i=0;i<n;i++) visited[i] = false;
    queue<int> q;
    q.push(src);
    visited[src] = true;

    while(!q.empty())
    {
        int curr = q.front();
        q.pop();
        B[curr] -= min(B[curr], A[src]);
        //cout<<curr<<" "<<endl;

        for(auto neigh: m[curr])
        {
            if(visited[neigh] == false)
            {
                //cout<<neigh<<endl;
                q.push(neigh);
                visited[neigh] = true;
                m[src].erase(neigh);
                m[neigh].erase(src);
            }
        }
    }
}

int length_of_lis(int n)
{
    if(n<=1) return n;
    vector<int> res;

    res.push_back(A[0]);
    int i;

    for(i=1;i<n;i++)
    {
        if(A[i] > res.back()) res.push_back(A[i]);
        else
        {
            int index = lower_bound(res.begin(), res.end(), A[i]) - res.begin();
            res[index] = A[i];
        }
    }return res.size();
}

int solve(int h, int w)
{
    int i,j,k;
    int ans = 0;

    for(i=0;i<h;i++)
    {
        for(j=0;j<w-1;j++)
        {
            if(S[i][j] == '.' && S[i][j+1] == '.')
                ans++;
        }
    }

    for(i=0;i<w;i++)
    {
        for(j=0;j<h-1;j++)
        {
            if(S[j][i] == '.' && S[j+1][i] == '.')
                ans++;
        }
    }
    return ans;
}

int32_t main()
{
    //code
	IOS;

    int t,n,m,a,b,x,y,i,j,z;
    //cin>>t;
    t = 1;
    while(t--)
    {
        int h,w;
        cin>>h>>w;
        for(i=0;i<h;i++)
            cin>>S[i];
        cout<<solve(h,w)<<endl;
    }

	return 0;
}


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

using   ll  =       long long int;
using   pll =       pair<ll, ll>;
using   vll =       vector<ll>;
#define endl        "\n"
#define space       " "
#define TLE_na_ho   ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MAX_SIZE    1024
#define MOD         1000000007
#define pb          push_back
#define fi          first
#define se          second
#define all(v)      v.begin(),v.end()
#define f(n)        for(ll i=0;i<n;i++)
#define rep(i,a,n)  for(ll i=a;i<n;i++)
#define repe(i,a,n) for(ll i=a;i<=n;i++)
#define repr(i,a,n) for(ll i=a;i>=n;i--)
#define ain(arr,n)  for(ll i1=0;i1<n;i1++ ) cin>>arr[i1]
#define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space

ll testcases;

int fact(int n);

int nCr(int n, int r)
{
    return fact(n) / (fact(r) * fact(n - r));
}

// Returns factorial of n
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
int main()
{
    TLE_na_ho;
    //READ THE QUESTION PROPERLY!!
    testcases = 1;
    //cin>>testcases;

    ll n;
    cin >> n;
    char s[n];
    ain(s, n);
    ll ans = 0, cont1 = 0, cont2 = 0;
    rep(i, 0, n - 1)
    {
        if(s[i] == 'A')
        {
            if(s[i + 1] == 'T')
            {
                ans++;
            }
        }
        else if(s[i] == 'T')
        {
            if(s[i + 1] == 'A')
            {
                ans++;
            }
        }
        else if(s[i] == 'C')
        {

            if(s[i + 1] == 'G')
            {
                ans++;
            }
        }
        else if(s[i] == 'G')
        {

            if(s[i + 1] == 'C')
            {
                ans++;
            }
        }
    }
    for(ll i = 1; i < n; i++)
    {
        if(s[i] == 'A')
        {
            if(s[i - 1] == 'T')
            {
                cont1++;
                i++;
            }
        }
        if(s[i] == 'T')
        {
            if(s[i - 1] == 'A')
            {
                cont1++;
                i++;
            }
        }
        if(s[i] == 'C')
        {
            if(s[i - 1] == 'G')
            {
                cont2++;
                i++;
            }
        }
        if(s[i] == 'G')
        {
            if(s[i - 1] == 'C')
            {
                cont2++;
                i++;
            }
        }
    }
    ll ans2 = 0;
    map<ll, ll>cnt;
    rep(i, 0, n)
    {
        //cout << "##" << i << space << cnt[0] << space << cnt[19] << space << cnt[2] << space << cnt[6] << endl;
    	if(cnt[0] == cnt[19] && cnt[2] == cnt[6])
            {
                if(cnt[0] + cnt[2] >= 2)
                    ans2++;
            }
        cnt.clear();
        rep(j, i, n)
        {
            if(cnt[0] == cnt[19] && cnt[2] == cnt[6])
            {
                if(cnt[0] + cnt[2] >= 2)
                    ans2++;
            }
            cnt[s[j] - 'A']++;
        }
    }

    cout << ans + ans2;

}


#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
typedef int int_;
#define int long long
#define maxn 400010
const int inf=1e9+7;
queue<int> q;
inline int read(){
	int ret=0,ff=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') ff=-ff;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		ret=ret*10+ch-'0';
		ch=getchar();
	}
	return ret*ff;
}
struct Edge{
	int u,v,w,next;
}E[maxn<<1];
int ecnt=0,head[maxn];
int in[maxn];
void addedge(int u,int v){
	++in[v];
	E[++ecnt].u=u;
	E[ecnt].v=v;
	E[ecnt].next=head[u];
	head[u]=ecnt;
}
void Addedge(int u,int v){
	addedge(u,v);
	addedge(v,u);
}
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
int ksm(int a,int b,int p){
	int ret=1;
	while(b){
		if(b&1) ret=ret*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ret%p;
}
bool cmp(int x,int y){
	return x>y;
}
int a[10010];
int G2(int x){
	int cnt=0;
	while(x){
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt);
	int ret=0;
	for(int i=1;i<=cnt;++i) ret=ret*10+a[i];
	return ret;
}
int G1(int x){
	int cnt=0;
	while(x){
		a[++cnt]=x%10;
		x/=10;
	}
	sort(a+1,a+1+cnt,cmp);
	int ret=0;
	for(int i=1;i<=cnt;++i) ret=ret*10+a[i];
	return ret;
}
int F(int x){
	return G1(x)-G2(x);
}
char X[10010];
bool ck(int Mid,int len,int m){
	int sum=0,tmp=1;
	for(int j = len; j;--j){
		sum+=tmp*(X[j]-'0');
		tmp*=Mid;
	}
	return sum>m;
}
int dp[2][110][110][110];
int_ main(){
	int n=read(),x=read();
	for(int i=1;i<=n;++i) a[i]=read();
	memset(dp, -1, sizeof dp);
	for(int i=1;i<=n;i++) dp[0][i][0][0] = 0;
	for(int i=0;i<n;i++){
		int qwq=i&1;
		for(int j =1;j<=n;j++){
			for(int qaq =0;qaq<=i;qaq++){
				for(int res=0;res<j;res++){
					if(dp[qwq][j][qaq][res]==-1) continue;
					dp[qwq^1][j][qaq+1][(res+a[i+1])%j]=max(dp[qwq^1][j][qaq+1][(res+a[i+1])%j],dp[qwq][j][qaq][res]+a[i+1]);
					dp[qwq^1][j][qaq][res]=max(dp[qwq^1][j][qaq][res], dp[qwq][j][qaq][res]);
				}
			}
		}
	}
	int qwq=n&1,ans=x;
	for(int qaq=1;qaq<=n;qaq++){
		if(dp[qwq][qaq][qaq][x%qaq]>0&&x>=dp[qwq][qaq][qaq][x%qaq])ans=min(ans,(x-dp[qwq][qaq][qaq][x%qaq])/qaq);
	}
	printf("%lld",ans);
	return 0;
}
/*
1
6 3
*/
/*
111111111111111111111111111111111111111111111111111111111111
1000000000000000000

100000000000000000000000000000000000000000000000000000000000

1000000000000000000
2
1000000000000000000
*/

#include<bits/stdc++.h>

typedef   long long  int ll;
typedef  long double ld;
typedef std::vector<ll> vi;
typedef std::vector<std::vector<ll> > vv;
typedef std::vector<std::pair<ll,ll> > pii;
typedef std::pair<ll,ll> pi;

#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,b) for(i=a;i<b;i++)
#define forr(i,a,b) for(i=a;i>=b;i--)
#define mp make_pair
#define pb(x) push_back(x)
#define fi first
#define se second
#define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl;
#define all(a) a.begin(),a.end()
#define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i];
#define ms(a,val) memset(a,val,sizeof(a))
using namespace std;

const int N = 2e5+ 5;

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

ll modInverse(ll a, ll m = mod) {
	return expo_pow(a, m - 2);
}

ll dp[2001][2001];
bool done[2001][2001];
string s[2001];
ll h,w;
ll cal(ll i, ll j)
{
    if(done[i][j])
     return dp[i][j];

    if(i >= h || j >= w)
     return INT_MAX;
    if(i == h-1 && j == w-1)
    {

        dp[i][j] =  0;
        done[i][j] = 1;
        return dp[i][j];
    }
    ll down = INT_MAX, right = INT_MAX;
    if(i+1 < h)
        down = cal(i+1,j) + (s[i+1][j] == '+' ? -1:1);
    if(j+1 < w)
        right = cal(i,j+1) + (s[i][j+1] == '+' ? -1:1);

    done[i][j] = 1;
    dp[i][j] = -min(down, right);
    return dp[i][j];
}
void solve(){
            ll i,j,n,m,k;

            cin>>h>>w;

            fo(i,0,h)
             cin>>s[i];

            if(cal(0,0) > 0)
            {
                cout<<"Takahashi"<<endl;
            }
            else if(cal(0,0) < 0)
            {
                cout<<"Aoki"<<endl;
            }
            else
            cout<<"Draw"<<endl;

}

int main()
{
     IO;
      ll t=1,i;
     // cin>>t;

      while(t--)
      {

          solve();
      }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+3;
template <typename T>
inline void read(T &x){
    x=0;char ch=getchar();bool f=false;
    while(!isdigit(ch)) f|=ch=='-',ch=getchar();
    while(isdigit(ch))  x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    x=f?-x:x;
}
template <typename T>
inline void print(T x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10^48);
}
int a,b;

int main(){
    read(a),read(b);
    a=a+b;
    if(a>=15&&b>=8){
        putchar('1');return 0;
    }
    if(a>=10&&b>=3){
        putchar('2');return 0;
    }
    if(a>=3){
        putchar('3');return 0;
    }
    putchar('4');
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>
ostream &operator<<(ostream &os, const vector<T> &x){
    os << "{";
    for(size_t i = 0; i < x.size(); i++){
        if(i < x.size()-1) os << x[i] << ", ";
        else os << x[i];
    }
    os << "}";
    return os;
}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

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

    vector<ll> A(2*N);
    rep(i, 2*N) cin >> A[i];

    vector<int> p(2*N);
    vector<int> v(2*N);
    iota(all(v), 0);
    sort(all(v), [&](int i, int j){
        return A[i] > A[j];
    });

    set<int> s1[2], s2[2];
    vector<int> u(2*N, 0);

    rep(i, N){
        s1[v[i]&1].emplace(v[i]);
        u[v[i]] = 1;
    }
    rep(i, N){
        s2[v[N+i]&1].emplace(v[N+i]);
    }

    vector<bool> used(2*N, false);

    rep(i, 2*N){
        if(used[i]) continue;
        if(u[i] == 0){
            int j = *s1[(i&1)^1].begin();
            s2[(i&1)].erase(i);
            s1[(i&1)^1].erase(j);
            p[i] = j, p[j] = i;
            used[i] = true, used[j] = true;
        }
        else{
            int j = *s2[(i&1)^1].begin();
            s1[(i&1)].erase(i);
            s2[(i&1)^1].erase(j);
            p[i] = j, p[j] = i;
            used[i] = true, used[j] = true;
        }
    }

    //rep(i, 2*N) cout << u[i] << ' '; cout << '\n';
    //rep(i, 2*N) cout << p[i] << ' '; cout << '\n';

    string ans(2*N, ')');
    rep(i, 2*N){
        if(i < p[i]) ans[i] = '(';
    }

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

#include <bits/stdc++.h>
using namespace std;
const int N=4e5+2;
int stk[N],top;
int n,m,p,e,a[N],b[N];
int main()
{
	scanf("%d",&n);
	m=n<<1;
	for(int i=1;i<=m;++i)
	{
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+m+1);
	for(int i=1;i<=m;++i)
		if(a[i]<b[n])++p;
		else if(a[i]>b[n])++e;
	for(int i=1;i<=m;++i)
	{
		int fl=0;
		if(a[i]>b[n])fl=1;
		else if(a[i]==b[n]&&p<n)++p;
		else if(a[i]==b[n]&&p==n)fl=1,++e;
		//else if(a[i]==b[n]&&!top)fl=1,++e;
		if(top&&stk[top]!=fl)putchar(')'),--top;
		else stk[++top]=fl,putchar('(');
	}
}


#include <bits/stdc++.h>
using namespace std;
////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros">
#define mod 1000000007
#define endl "\n"
#define long long long
#define all(v) (v).begin(),(v).end()
#define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin())
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define filein freopen("input.txt", "r", stdin);
#define fileout freopen("output.txt", "w", stdout);
#define getLine(x) getline(cin,x)
#define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower)
bool sortby(pair<int, int> a, pair<int, int> b) {
    double x = (double) a.first / a.second;
    double y = (double) b.first / b.second;
    return x < y;
}
long powUnderMod(long x, long y) {
    if(y == 0)return 1;
    long res = powUnderMod(x, y / 2) % mod;
    res = (res * res) % mod;
    if(y & 1)res = (res * x) % mod;
    return res;
}
#define printcase(x)  cout<<"Case "<<in++<<": "<<x<<endl
#define memset(a, b) memset(a,b,sizeof(a))
#define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl;
#define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;}
#define pi acos(-1)
#define esp 1e-9
////////////////////////////////////////////////////////////////////////////</editor-fold>
long n, m, f = 0, q, ans;
long tmp, flag = 0;

int main() {
///<editor-fold desc="ios">
    //IOS
#ifdef _AD_
    filein //fileout
#endif
///</editor-fold>
    int in = 1, o;
    cin>>n;
    vector<long> v;
    double sum=0;
    for(int i = 0; i < n; ++i){
        cin>>tmp;
        v.push_back(tmp);
        sum+=tmp;
    }
    double avg=sum/2;
    sort(all(v));
    long mx=0;
    for(int i = v.size()-1; i >=0 ; --i){
        long count=0;
        for(int j = i; j >=0 ; --j){
            if(count+v[j]<=avg)count+=v[j];
        }
        mx=max(count,mx);
    }
    cout<<(long)sum-mx<<endl;

}

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

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

void solve(long long N, std::vector<long long> A){
    ll ans = 1E18;
    rep(i,1<<N){
        if(i == 0) continue;
        ll r = 0;
        vector<ll> d;
        rep(j,N){
            ll js = i >> j & 1;
            r |= A[j];
            if(js) {
                d.push_back(r);
                r = 0;
            }
        }
        if(~ i >> (N-1) & 1) d.push_back(r);
        ll t = d[0];
        for(ll j = 1; j<d.size(); j++){
            t ^= d[j];
        }
        ans = min(ans,t);
    }
    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
    long n, a[100000], i; cin >> n;
    double dn = n, x2 = 2;
    for(i = 0; i < n; i++) cin >> a[i];

    if(n == 1) cout << fixed << setprecision(15)
                    << a[0] / x2 << endl;
    else if(n == 2) cout << fixed << setprecision(15)
                         << max(a[0], a[1]) / x2 << endl;
    else{
        sort(a, a + n);
        long hsum = 0; x2 = a[int(n / 2)] / x2;
        for(i = n / 2; i < n; i++) hsum += a[i];

        if(n % 2 == 0){
            cout << fixed << setprecision(15)
                 << hsum / dn << endl;
        }
        else{
            cout << fixed << setprecision(15)
                 << x2 + (hsum - int((n + 1)/ 2) * a[int(n / 2)]) / dn << endl;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int, int> P;
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    double a[n];
    double sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    double ans = sum / n;

    rep(i, n) {
        sum -= a[i];
        double tmp = sum - a[i] * (n - 1 - i) + a[i] * n / 2;
        tmp /= n;
        ans = min(ans, tmp);
    }

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


/*    BISMILLAHIR-RAHMANIR-RAHIM
 ____________________________________
|                                    |
|      SHANTO_SUST_SWE-19__029       |
|      shanto-swe029.github.io       |
|____________________________________|
*/

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

#define ll          long long
#define fastio      ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb          push_back
#define Pi          acos(-1.0)
#define r0          return 0
#define endl        "\n"
#define show(x)     cout << x << endl
#define take(x)     cin >> x
#define debug       1

int main()
{
	int n;
	std::cin >> n;
	std::vector < pair < int, int > > v;
	std::pair < int, int > p;
	for( int i = 0; i < n; i++ ) {
		int x, y;
		std::cin >> x >> y;
		p.first = x;
		p.second = y;
		v.push_back(p);
	}
	bool gotcha = false;
	for( int i = 0; i < n; i++ ) {
		for( int j = i + 1; j < n; j++ ) {
			for( int k = j + 1; k < n; k++ ) {
				int det = v[i].first * v[j].second + v[j].first * v[k].second + v[k].first * v[i].second;
				det -= v[i].second * v[j].first + v[j].second * v[k].first + v[k].second * v[i].first;
				if( det == 0 ) {
					gotcha = true;
					break;
				}
			}
			if( gotcha ) break;
		}
		if( gotcha ) break;
	}
	if( gotcha ) std::cout << "Yes";
	else std::cout << "No";

    r0;
}

//ALHAMDULILLAH

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    bool ok = false;
    for (int i = 0; i < n-2; i++) {
        for (int j = i+1; j < n-1; j++) {
            for (int k = j+1; k < n; k++) {
                if ((y[i]-y[j]) * (x[i]-x[k])  == (y[i]-y[k]) * (x[i]-x[j])) ok = true;
            }
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector <int> vi;
typedef vector <vi> vii;
typedef vector <string> vs;
typedef vector <ll> vll;

#define LSB(x) x&(-x)
#define endl "\n"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define fi(a,b,c) for(ll (a)= (b);(a)<=(c);++(a))
#define fe(a,b) for(auto &(a) : (b))
#define fr(i,a,b) for(ll (i)=(a);(i)>(b);(i)--)
#define r(a,b) f(a,0,b)
#define v vector
#define SUM(x,s) for(ll i=0;i<(x).size();i++)(s)+=(x)[i];
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ALL(x) x.begin(),x.end()
#define SORT(x) sort(ALL(x))
#define TC(t) while(t--)
#define unS unordered_set
#define unM unordered_map
#define oS set
#define oM map
#define eb emplace_back
#define pq priority_queue
#define print(x) cout<<(x)<<endl

///////////////////// I/O shortcuts ////////////////////////////////
template <typename D>
istream& operator>> (istream &in , vector <D> &arr) {
    ll n = arr.size();
    r(i, n) {
        in >> arr[i];
    }
    return in;
}

template <typename D>
ostream& operator<< (ostream &in , vector <D> &arr) {
    for (auto x : arr) in << x << " ";
    in << endl;
    return in;
}
template <typename D, typename B>
ostream& operator<< (ostream &in , pair <D, B> &p) {
    in << p.F << " " << p.S << endl;
    in << endl;
    return in;
}

////////////////////////////Global Variables////////////////////////////////
ll i, j, k, l, x, y, z, m, n, a, b, c, r, d, t = 1;

string s;
template<typename A, typename B> A max(A a, B b) {return (a > b) ? a : b;}
template<typename A, typename B> A min(A a, B b) {return (a < b) ? a : b;}
/////////// The Code Starts Here ///////////////////////////////////////

void solve(int tc) {
    cin >> n;
    ll ans = 0;
    f(i, 1, n) {
        ll s = n - i;
        if (s > 0) ans++;
        else break;
    }
    cout << ans << endl;

}

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

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

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

    TC(t) solve(k++);

}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int n;
int main() {
    cin >> n;
    double res = 0;
    for (int i = 1; i <= n-1; i++) {
        res += 1.0 * n / i;
    }
    printf("%.10lf\n", res);
    return 0;
}


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

#define int long long
using ll = long long;
using P = pair<int,int>;

int n,m;

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

  map<int,int> cnt;
  vector<P> p(m);
  for(int i=0;i<m;i++){
    cin >> p[i].first;
    cin >> p[i].second;
    cnt[p[i].first]++;
  }

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

  //for(int i=0;i<m;i++){
  //  cout << "i=" << i << ":" << p[i].first << "," << p[i].second << endl;
  //}

  vector<int> d(2*m+1,0);

  d[m] = 1;

  int j = 0;
  map<int,int> manip;
  for(auto it = cnt.begin(); it != cnt.end(); it++){
    int v = it->first;
    // cout << "it->first=" << it->first << endl;
    // int c = it->second;
    manip.clear();
    int j2 = j;
    while( p[j].first == v ){
      int y = p[j].second;    // n座標系
      int y2 = ( y - n ) + m; // m座標系
      if( y2 >= 0 && y2 <= 2*m ){
        manip[y2] = 0;
      }
      j++;
    }
    j = j2;
    while( p[j].first == v ){
      int y = p[j].second;     //
      int y2 = ( y - n ) + m;  // m
      if( y2 >= 0 && y2 <= 2*m && y2-1 >= 0 && y-1>=0 && d[y2-1]==1 ){
        manip[y2]=1;
      }
      if( y2 >= 0 && y2 <= 2*m && y2+1 <=2*m && y+1<=2*n && d[y2+1]==1 ){
        manip[y2]=1;
      }
      j++;
    }
    for(auto x: manip){
      d[x.first] = x.second;
    }
    //for(int j=0;j<2*m+1;j++){
    //  cout << "," << d[j];
    //}
    //cout << endl;
  }
  int res = 0;
  for(int i=0;i<=2*m;i++){
    if(d[i]!=0) res++;
  }
  cout << res << endl;

}

#pragma GCC optimize("fast-math")
// begin "cp-lib/boilerplate.hpp"
#include <bits/stdc++.h>

#define _choose(_1, _2, _3, chosen, ...) chosen
#define _rep(i, l, r)     for (int i = l; i < r; ++i)
#define _rep0(i, r)       _rep(i, 0, r)
#define _repr(i, r, l)    for (int i = r; i >= l; --i)
#define _repr0(i, r)      _repr(i, r, 0)
#define rep(...)          _choose(__VA_ARGS__, _rep, _rep0, suppress_warning)(__VA_ARGS__)
#define repr(...)         _choose(__VA_ARGS__, _repr, _repr0, suppress_warning)(__VA_ARGS__)
#define all(a)      ::begin(a),::end(a)
#define sz(c)       int(::size(c))
#define trav(a, b)  for(auto& a : b)

using namespace std;

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

[[maybe_unused]] static constexpr int INF = int(1e9 + 5);
[[maybe_unused]] static constexpr ll INFL = ll(INF) * INF;
[[maybe_unused]] static mt19937 rng(u32(chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()));

namespace cp_lib {}
// end "cp-lib/boilerplate.hpp"

using namespace cp_lib;

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

    map<int, int> m;
    int n; cin >> n;
    rep(_, n) {
        int ai; cin >> ai;
        m[ai]++;
    }

    ll ans = 0;
    for (auto& [a1, c1] : m) {
        for (auto& [a2, c2] : m) {
            if (a1 <= a2)
                continue;
            ans += ll(c1) * c2 * (a2 - a1) * (a2 - a1);
        }
    }

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


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

bool localTest = false;

long long readLongLong()
{
    long long t;
    cin >> t;
    return t;
}

std::vector<ll> readVector(long long size)
{
    std::vector<ll> v(size);
    for (long long i = 0; i < size; i++)
    {
        cin >> v[i];
    }
    return v;
}

class CodeForcesPrint
{
public:
CodeForcesPrint operator<<(string x)
    {
        CodeForcesPrint tmp;
        std::cout << x << std::endl;
        return tmp;
    }
    CodeForcesPrint operator<<(long long x)
    {
        CodeForcesPrint tmp;
        std::cout << x << std::endl;
        return tmp;
    }
    CodeForcesPrint operator<<(std::vector<std::vector<long long>> finalAnswer)
    {
        CodeForcesPrint tmp;
        if (localTest)
        {
            cout << "--final answer--" << endl;
        }
        for (long long i = 0; i < finalAnswer.size(); i++)
        {
            for (long long k = 0; k < finalAnswer.at(i).size(); k++)
            {
                cout << finalAnswer.at(i).at(k) << " ";
            }
            cout << endl;
        }
        return tmp;
    }
    CodeForcesPrint operator<<(std::vector<string> finalAnswer)
    {
        CodeForcesPrint tmp;
        if (localTest)
        {
            cout << "--final answer--" << endl;
        }
        for (long long i = 0; i < finalAnswer.size(); i++)
        {
            cout << finalAnswer[i] << endl;
        }
        return tmp;
    }
    CodeForcesPrint operator<<(std::vector<long long> v)
    {
        CodeForcesPrint tmp;
        for (long long i = 0; i < v.size(); i++)
        {
            cout << v[i] << " ";
        }
        cout << endl;
        return tmp;
    }
};

long long readTestcaseSize()
{
    ll t;
    cin >> t;
    return t;
}

#define inTest                 \
    ll t = readTestcaseSize(); \
    for (ll testcase = 0; testcase < t; testcase++)

class OddNumber
{
};

class EvenNumber
{
};

bool operator==(OddNumber oddNumber, long long n)
{
    return n % 2 == 1;
}

bool operator==(EvenNumber evenNumber, long long n)
{
    return n % 2 == 0;
}

bool operator==(long long n, OddNumber oddNumber)
{
    return oddNumber == n;
}

bool operator==(long long n, EvenNumber evenNumber)
{
    return evenNumber == n;
}

template <class T, class U>
std::vector<U> permutation(std::vector<T> vec, std::vector<T> before_list, std::vector<U> after_list)
{
    std::vector<U> res(vec.size());
    for (ll i = 0; i < vec.size(); i++)
    {
        for (ll k = 0; k < before_list.size(); k++)
        {
            if (vec[i] == before_list[k])
            {
                res[i] = after_list[k];
            }
        }
    }
    return res;
}

template <class T, class U>
vector<U> permutationRead(long long size, std::vector<T> before_list, std::vector<U> after_list)
{
    vector<T> t(size);
    for (ll i = 0; i < size; i++)
    {
        cin >> t[i];
    }
    return permutation<T, U>(t, before_list, after_list);
}

#define ll(name) long long name = readLongLong()
#define llV(name, size) std::vector<long long> name = readVector(size)

OddNumber Odd;
EvenNumber Even;
CodeForcesPrint print;

//________________________________________________________________________________

#define INF (1ll) << 60
#define rep(i, n) for (long long i = 0; i < n; i++)
#define yes print<<"Yes"
#define no print<<"No"
#define all(v) v.begin(),v.end()
#define ld long double

int main()
{
    ll A,B,C;cin>>A>>B>>C;
    if(A*A+B*B<C*C){
        yes;
    }else{
        no;
    }
}

#include <iostream>
#include <vector>
#include <cmath>
#include <unordered_set>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	vector<vector<char>> mat;
	cin >> n >> m;
	mat.resize(n + 1, vector<char>(m + 1));
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> mat[i][j];

	// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(2)));
	const int inf = 1e9;
	vector<vector<int>> dp(n + 1, vector<int>(m + 1, -inf));

	for (int i = n - 1; i >= 0; i--) {
		for (int j = m - 1; j >= 0; j--) {
			if ((i == n - 1) && (j == m - 1)) dp[i][j] = 0;
			else if (j == m - 1) dp[i][j] = ((mat[i + 1][j] == '+') ? 1 : -1) - dp[i + 1][j];
			else if (i == n - 1) dp[i][j] = ((mat[i][j + 1] == '+') ? 1 : -1) - dp[i][j + 1];
			else {
				int v1 = ((mat[i + 1][j] == '+') ? 1 : -1) - dp[i + 1][j];
				int v2 = ((mat[i][j + 1] == '+') ? 1 : -1) - dp[i][j + 1];
				dp[i][j] = max(v1, v2);
			}
		}
	}

	if (dp[0][0] > 0) cout << "Takahashi" << endl;
	else if (dp[0][0] < 0) cout << "Aoki" << endl;
	else cout << "Draw" << endl;

	return 0;
}


#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define qll queue<ll>
#define sll set<ll>
//(a/b)%mod = (a%mod*powermod(b,mod-2,mod))%mod
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                    //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
    int p = (int)log2(n);
    return (int)pow(2, p);
}
ll powermod(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
return res;
}
vector<string>s(70);
ll n;
ll dp[70][70];
ll trav(ll i,bool x,bool prev){
	if(i==n && prev) return 1;
	if(i==n) return 0;
	if(dp[i][prev]!=-1) return dp[i][prev];
	if(s[i]=="AND"){
		return dp[i][prev]=trav(i+1,true,prev&true)+trav(i+1,false,prev&false);
	}
	else{
		return dp[i][prev]=trav(i+1,true,prev|true)+trav(i+1,false,prev|false);
	}
}

int main(){
    memset(dp,-1,sizeof(dp));
	cin>>n;
	for(ll i=0;i<n;i++) cin>>s[i];
	ll sum=trav(0,true,true);
	memset(dp,-1,sizeof(dp));
	sum+=trav(0,false,false);
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<string> str(n);
    vector<pair<long long, long long>> tbl;
    for (int i = 0; i < n; i++) {
        cin >> str[i];
    }
    tbl.emplace_back(make_pair(1, 1));
    for (int i = 0; i < n; i++) {
        long long t_count, f_count;
        if (str[i] == "AND") {
            t_count = tbl[i].first;
            f_count = tbl[i].first + tbl[i].second * 2;
        } else {
            t_count = tbl[i].first * 2 + tbl[i].second;
            f_count = tbl[i].second;
        }
        tbl.emplace_back(make_pair(t_count, f_count));
    }

    cout << tbl.back().first << endl;
    return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef __int128 it;
typedef long double ldb;
int main(){
	ll s,p;
	scanf("%lld%lld",&s,&p);
	it sqt=it(s)*s-it(p<<2);
//	if(p*4<(s*2-1)){
//		puts("No");
//		return 0;
//	}
	ldb tmp=sqrt(ldb(s)*s-(p<<2));
	for(it i=max(tmp-1000000,ldb(0)),ed=tmp+1000000; i<=ed; ++i)
		if(i*i==sqt){
			if((i+s)&1){
				puts("No");
				return 0;
			}
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
/* * * *   * * *   	* * * */
/* *
 *
 * Too many mind, no mind.
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b; cin >> a >> b;
	vector <ll> g, l;
	for (int i = 1; i <= min(a, b); ++i) {
		g.push_back(i);
		l.push_back(-i);
	}
	if (a > b) {
		for (int  i = b + 1; i <= a; ++i) {
			g.push_back(i);
			l.back() -= i;
		}
	} else if (b > a) {
		for (int  i = a + 1; i <= b; ++i) {
			l.push_back(-i);
			g.back() += i;
		}
	}
	for (auto &i : g) cout << i << ' ';
	for (auto &i : l) cout << i << ' ';
	cout << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T> ostream &operator<<(ostream &os, multiset<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]"; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) { dump_func(__VA_ARGS__) }
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int A[3000][5];
int main() {
    int N;
    cin >> N;
    rep(i,N){
        rep(j,5){
            cin >> A[i][j];
        }
    }
    auto check = [&](ll x) -> bool{
        vector<int> mask(N,0);
        int sz = bit(5);
        vector<int> mp(sz,0);
        rep(i,N){
            rep(j,5){
                if(A[i][j] >= x)mask[i] += bit(j);
            }
            mp[mask[i]]++;
        }
        // dump(x, mp);
        rep(k,sz){
            if(mp[k] == 0)continue;
            if((k) == sz-1 && mp[k] >= 3){
                return true;
            }
            rep(j,k){
                if(mp[j] == 0)continue;
                if((k|j) == sz-1 && mp[k]+mp[j] >= 3){
                    return true;
                }
                rep(i,j){
                    if(mp[i] == 0)continue;
                    if((i|j|k) == sz-1 && mp[i]+mp[j]+mp[k] >= 3){
                        // dump(i,j,k);
                        // dump((i|j|k));
                        // dump(mp[i],mp[j],mp[k]);
                        return true;
                    }
                }
            }
        }
        return false;
    };
    ll ok = 0;
    ll ng = INF+1;
    while(ng - ok > 1){
        ll mid = (ok + ng) / 2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(5, 0));
    for(int i = 0; i < N; ++i) for(int j = 0; j < 5; ++j) cin >> A.at(i).at(j);

    int ok = 0, ng = 1000000001;
    while(abs(ok-ng) > 1) {
        int cen = (ok + ng) / 2;

        set<int> S;
        for(int i = 0; i < N; ++i) {
            int bit = 0;
            for(int j = 0; j < 5; ++j) {
                bit = bit << 1;
                bit |= A.at(i).at(j) >= cen;
            }
            S.insert(bit);
        }
        bool flg = false;
        for(auto x : S) {
            for(auto y : S) {
                for(auto z : S) {
                    if((x | y | z) == 31) {
                        flg = true;
                    }
                }
            }
        }
        if(flg) ok = cen;
        else ng = cen;
    }

    cout << ok << endl;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef vector<int> vi;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define allrev(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())

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

    vi arr(n), b(n);
    forn(i, n)
    {
        cin >> arr[i];
    }
    forn(i, n)
    {
        cin >> b[i];
    }

    map<int, int> m;

    forn(i, n)
    {
        int x;
        cin >> x;
        --x;
        int val = b[x];
        m[val]++;
    }

    ll cnt = 0;

    forn(i, n)
    {
        if (m.find(arr[i]) != m.end())
        {
            cnt += m[arr[i]];
        }
    }

    cout << cnt << ln;
}
int main()
{
    fast_cin();
    ll t = 1;
    // cin >> t;
    for (int it = 0; it < t; it++)
    {
        // cout << "Case #" << it + 1 << ": ";
        solve();
    }
    return 0;
}

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

int main(){
  int n;cin>>n;
  vector<ll>ae(n+1,0),be(n+1,0),b(n+1);
  int tmp;
  for(int i=0;i<n;i++){
    cin>>tmp;
    ae.at(tmp)++;
  }
  for(int i=1;i<=n;i++){
    cin>>b.at(i);
    be.at(b.at(i))=1;
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>tmp;
    ans+=ae.at(b.at(tmp))*be.at(b.at(tmp));
  }
  cout<<ans<<endl;
}