#include <bits/stdc++.h>

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 998244353;
const LL INF = LLONG_MAX;
const LL N = 3e5+1;

#define S second
#define F first
#define vt vector

LL binpow (LL x, LL p, LL m) {
	LL res = 1;
	x %= m;

	while (p) {
		if (p&1) {
			res = res * x % m;
		}
		x = x * x % m;
		p >>= 1;
	}
	return res;
}

int main () {
	fastio();

	LL n, k;
	cin >> n >> k;

	vt<LL> a(n);

	for (LL i = 0; i < n; ++i) {
		cin >> a[i];
	}

	vt<vt<LL>> binom(k+1, vt<LL>(k+1));
	binom[0][0] = 0;

	for (LL i = 1; i <= k; ++i) {
		binom[i][0] = binom[i][i] = 1;

		for (LL j = 1; j <= i-1; ++j) {
			binom[i][j] = binom[i-1][j-1]+binom[i-1][j];
			binom[i][j] %= MOD;
		}
	}

	vt<vt<LL>> sum(k+1, vt<LL>(n, 1));

	for (LL i = 0; i < n; ++i) {
		sum[1][i] = a[i];
	}
	for (LL i = 2; i <= k; ++i) {
		for (LL j = 0; j < n; ++j) {
			sum[i][j] = (sum[1][j]*sum[i-1][j]) % MOD;
		}
	}

	vt<LL> sumacc(k+1, 0);
	LL twoinv = binpow(2, MOD-2, MOD);
	LL tp = 2;

	for (LL i = 0; i <= k; ++i) {
		for (LL j = 0; j < n; ++j) {
			sumacc[i] = (sumacc[i] + sum[i][j])%MOD;
		}
	}

	for (LL i = 1; i <= k; ++i, tp <<= 1, tp %= MOD) {
		LL accum = 0;
		for (LL j = 0; j <= i; ++j) {
			accum = (accum + sumacc[j]*sumacc[i-j] % MOD * binom[i][j] % MOD) % MOD;
		}
		accum = ((accum - tp * sumacc[i] % MOD) % MOD + MOD) % MOD;
		accum = (accum * twoinv) % MOD;
		cout << accum << "\n";
	}

}

#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef struct edge{
	int to;
	int cost;
}Edge;
typedef pair<int,int> P;

long long INF=250000010;
int V;
vector<Edge> G[1000000];
long long d[1000000];

void dijkstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
	fill(d,d+V,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P p=que.top();que.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		for(unsigned int i=0;i<G[v].size();i++){
		  Edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
			  d[e.to]=d[v]+e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

int main(){
  int R,C;
  cin>>R>>C;
  V=R*C*2;
  vector<vector<int>> A,B;
  for(int i=0;i<R;i++){
    vector<int>tmp(C-1);
    for(int j=0;j<C-1;j++)cin>>tmp.at(j);
    A.push_back(tmp);
  }
  for(int i=0;i<R-1;i++){
    vector<int>tmp(C);
    for(int j=0;j<C;j++)cin>>tmp.at(j);
    B.push_back(tmp);
  }
  int q=R*C;
  for(int i=0;i<R;i++){
    for(int j=0;j<C;j++){
      if(j<C-1){
        G[C*i+j].push_back({C*i+j+1,A.at(i).at(j)});
      }
      if(j>0){
        G[C*i+j].push_back({C*i+j-1,A.at(i).at(j-1)});
      }
      if(i<R-1){
        G[C*i+j].push_back({C*(i+1)+j,B.at(i).at(j)});
      }
      G[C*i+j].push_back({q+C*i+j,1});
      G[q+C*i+j].push_back({C*i+j,0});
      if(i>0){
        G[q+C*i+j].push_back({q+C*(i-1)+j,1});
      }
    }
  }
  dijkstra(0);
  printf("%d\n",d[R*C-1]);
  return 0;
}


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

int T, n;
string s1, s2, s3;

int main()
{
	std::ios::sync_with_stdio(0);

	cin >> T;
	while (T--) {
		cin >> n;
		cin >> s1 >> s2 >> s3;
		for (int i = 1; i <= n; i++) cout << '0';
		for (int i = 1; i <= n; i++) cout << '1';
		cout << "0\n";
	}

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    double a = 1.08 * n;
    int r = (int)a;
    if(r < 206){
        cout<<"Yay!"<<endl;
    }else if(r == 206){
        cout<<"so-so"<<endl;
    }else{
        cout<<":("<<endl;
    }

}

#line 1 "Contests/AtCoder_abc206/abc206_a/main.cpp"
using namespace std;
#line 2 "library/bits/stdc++.h"

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#line 3 "Contests/AtCoder_abc206/abc206_a/main.cpp"
#include <unordered_set>

#define ll long long
#define MAX 9223372036854775807
#define REP(i,N) for(ll i=0; i<N; i++)

void solve(){
    // write your solution here.
}

int main() {
    ll N;
    cin >> N;
    double x=(double)108*N/100;
    x=floor(x);
    if(x<206)   cout << "Yay!" << endl;
    else if(x==206) cout << "so-so" << endl;
    else cout << ":(" << endl;
    return 0;
}


//g++ -std=c++11 -Wall test.cpp -o test -lm -g -O2

#include <bits/stdc++.h>
#include <cstdio>
#include <iterator>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vll vector<long long int>
#define vb vector<bool>
#define pb push_back
#define ll long long int
#define endl '\n'
#define pii pair<int,int>
#define pill pair<int,ll>
#define plli pair<ll,int>
#define plli pair<ll,int>
#define tlli tuple<ll,ll,int>
#define till tuple<int,ll,ll>
#define forn(b) for(int i = 0; i<b ;i++)
#define MAX 4005

int main(){
    int n;
    cin>>n;
    string ans = n%2?"Black":"White";
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
const ll maxn = 1e5 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n = 0;
  cin >> n;
  ll x = 1.08 * 1.0 * n;
  ll c = 206;
  // cout << x << " " << c << "\n";
  if (x < c)
    cout << "Yay!";
  else if (x > c)
    cout << ":(";
  else
    cout << "so-so";
}


#include <bits/stdc++.h>

long double EPS = 1e-12;

using namespace std;

vector<complex<long double>> rotate(vector<complex<long double>> points, const complex<long double>& rot) {
  for (auto& p : points) {
    p *= rot;
  }
  return points;
}

bool equals(vector<complex<long double>> points1, vector<complex<long double>> points2) {
  if (points1.size() != points2.size()) return false;

  int n = points1.size();

  sort(points1.begin(), points1.end(), [](const complex<long double>& c1, const complex<long double>& c2) {
    if (abs(c1.real() - c2.real()) < EPS) return c1.imag() < c2.imag();
    return c1.real() < c2.real();
  });

  sort(points2.begin(), points2.end(), [](const complex<long double>& c1, const complex<long double>& c2) {
    if (abs(c1.real() - c2.real()) < EPS) return c1.imag() < c2.imag();
    return c1.real() < c2.real();
  });

  for (int i = 0; i < n; i++) {
    if (abs(points1[i] - points2[i]) >= EPS) return false;
  }
  return true;
}

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

  vector<complex<long double>> S(N), T(N);

  for (int i = 0; i < N; i++) {
    double x, y;
    cin >> x >> y;
    S[i] = x + y * 1i;
  }

  for (int i = 0; i < N; i++) {
    double x, y;
    cin >> x >> y;
    T[i] = x + y * 1i;
  }

  complex<long double> gS = 0, gT = 0;

  for (int i = 0; i < N; i++) {
    gS += S[i];
    gT += T[i];
  }

  gS /= N;
  gT /= N;

  for (int i = 0; i < N; i++) {
    S[i] -= gS;
    T[i] -= gT;
  }

  for (int i = 0; i < N; i++) {
    if (S[i] == complex<long double>(0)) {
      S.erase(S.begin() + i);
      break;
    }
  }

  for (int i = 0; i < N; i++) {
    if (T[i] == complex<long double>(0)) {
      T.erase(T.begin() + i);
      break;
    }
  }

  bool able = false;

  if (S.size() == T.size()) {
    for (int i = 0; i < N; i++) {
      able |= equals(S, rotate(T, S[0] * abs(T[i]) / (T[i] * abs(S[0]))));
    }
  }

  if (able) puts("Yes");
  else puts("No");

  return 0;
}

#include<bits/stdc++.h>
#define ln puts("")
#define sp printf(" ")
using namespace std;
typedef long long ll;

inline ll read() {
	ll sum = 0, ff = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-')
			ff = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
		sum = sum * 10 + ch - '0', ch = getchar();
	return sum * ff;
}

void write(ll x) {
	if(x < 0)
		putchar('-'), x = -x;
	if(x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
}

const int N = 1e5 + 7;
int n, a[N], b[N], c[N], mp1[N], mp2[N];
ll ans;

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i++)
		a[i] = read(), mp1[a[i]]++;
	for(int i = 1; i <= n; i++)
		b[i] = read();
	for(int i = 1; i <= n; i++)
		c[i] = read(), mp2[c[i]]++;
	for(int i = 1; i <= n; i++)
		ans += (ll)mp1[b[i]] * mp2[i];
	write(ans);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int M = 100005;
#define db double
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n;db ans,a[M];
db Abs(db x) {return x>0?x:-x;}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		db x=read();
		ans+=x/2;
		a[i]=x/2;
	}
	sort(a+1,a+1+n);
	db tmp=a[(n+1)/2];
	for(int i=1;i<=n;i++)
		ans+=Abs(tmp-a[i]);
	printf("%.7f\n",ans/n);
}

#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define ins insert
#define sz(x) (int)x.size()
#define dbg(x) cout << x << "\n";

const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
const long double Eps = 1e-9;

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

using namespace std;

#define int long long int

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

        long double ans = Inf;

        vector <int> a(n + 1);
        for(int i = 1; i<=n; i++) cin >> a[i];

        sort(a.begin() + 1, a.end());

        int sum = accumulate(a.begin() + 1, a.begin() + n + 1, 0LL);
        ans = (long double)sum / n;

        int tn = 0;
        for(int i = 1; i<=n; i++){
                long double x = (long double)a[i] / 2.0;

                long double cur = n * x + sum - tn - (n - i + 1) * a[i];

                ans = min(ans, cur / n);
                tn += a[i];
        }

        cout << fixed << setprecision(10) << ans;
}

#undef int

int main(){
        IOS;
        int T = 1;
        // cin >> T;
        while(T--){
                TestCase();
                cout << "\n";
        }
        return 0;
}


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

int main(){
    string a, b;
    cin >> a >> b;
    int ai, bi;
    ai = (a[0] - '0') + (a[1] - '0') + (a[2] - '0');
    bi = (b[0] - '0') + (b[1] - '0') + (b[2] - '0');

    if(ai >= bi) cout << ai << endl;
    else cout << bi << endl;

}

#include <bits/stdc++.h>

using namespace std;

typedef long int lint;
typedef long long int llint;

#define INF 1073741824
#define LINF 4611686018000000000
#define MOD 1000000007

int digsum(int n) {
    int ans = 0;
    while (n) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main() {
    int a, b;
    cin >> a >> b;
    cout << max(digsum(a), digsum(b)) << endl;
    return 0;
}


// Containers
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

// #include "conf.d/say.h"
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define all(v) v.begin(), v.end()
#define f first
#define s second
#define MOD 1000000007
#define vt(T) vector<T>

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORUP(i, a, b) for (int i = a; i < b; i++)
#define FORDOWN(i, a, b) for (int i = a; i > b; --i)
#define EACH(e, C) for (auto &e : C)
#define len(v) (int)v.size()
#define PQ(type) priority_queue<type>
#define PQD(type) priority_queue<type, vector<type>, greater<type>>
#define US unordered_set
#define UM unordered_map

typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef vector<pii> vpii;

template <class T> bool in(const T e, unordered_set<T> s) {
  return s.count(e) > 0;
}
template <class T> bool in(const T e, set<T> s) { return s.count(e) > 0; }
template <class K, class V> bool in(const K e, unordered_map<K, V> s) {
  return s.count(e) > 0;
}
template <class K, class V> bool in(const K e, map<K, V> s) {
  return s.count(e) > 0;
}

int dirs[5] = {-1, 0, 1, 0, -1};

// fast IO
static auto __2333__ = []() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return 0;
}();
// --------------------------------------------------------

int main() {
  int N;
  cin >> N;
  ll res = 0;
  FOR(i, N) {
    int a, b;
    cin >> a >> b;
    res += (ll)(b + a) * (1 + b - a) / 2;
  }
  cout << res << endl;
}

#include<bits/stdc++.h>
#define mod 1000000007
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 200005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef  long long ll;
typedef long double ld;
using namespace std;

signed main()
{
  ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
  ll pre[MAX];
  memset(pre,0,sizeof(pre));
  ll n,w;
  cin>>n>>w;
  ll s,t,p;
  rep(i,0,n)
  {
  	cin>>s>>t>>p;
  	pre[s]+=p;
  	pre[t]-=p;
  }
  ll f=0;
  if(pre[0]>w) f=1;
  rep(i,1,MAX)
  {
  	pre[i]+=pre[i-1];
  	if(pre[i]>w) f=1;
  }
  if(f) cout<<"No\n";
  else cout<<"Yes\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i=1,n,s=0;
    cin>>n;
    while(s<n)
    {
    s+=i;
    i++;
    }
  cout<<i-1<<endl;
  return 0;
}

#include <math.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define max(p, q) ((p) > (q) ? (p) : (q))
#define min(p, q) ((p) < (q) ? (p) : (q))
using ll = long long;
using P = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;
const ll INF = 1e18 + 1;
const ll mod = 1000000007;
int main()
{
  ll n;
  cin >> n;
  ll ans = 1;
  while(2*n>ans*(ans+1))
    ans++;
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c;cin>>a>>b>>c;
  int ans=a+b+c;
  int g;
  g=min(a,b);
  g=min(g,c);
  cout << ans-g << endl;
}

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

int main()
{
  long double r, x, y;
  cin >> r >> x >> y;

  long double cnt = sqrtl(x * x + y * y) / r;

  if (cnt < 1) {
    // ちょうどrしか動けないため、迂回して2歩
    cout << 2 << endl;
  } else {
    cout << ceil(cnt) << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
bool punched[3][3];

//using Graph = vector<vector<int>>;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

//最小公倍数
ll lcm(ll a,ll b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

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

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

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

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

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

ll powmod(ll x,ll y){
    ll res=1;
    for(ll i=0;i<y;i++){
        res=res*x%MOD;
    }
    return res;
}

bool ok(int v, int b) {
    while (v) {
        if (v % b == 7) return false;
        v /= b;
    }
    return true;
}

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

    for (int i = 0;i < s.size() - 2;i++) {
         //cout << i << endl;
        if (s.size()<3) break;
        if (s[i]== 'f' && s[i+1] == 'o' && s[i+2] == 'x') {
            //ans -= 3;
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            if (i < 3){
            i = -1;
            }
            else {
                i -= 3;
            }
        }

    }
   // cout << s << endl;
    cout << s.size() << endl;
}

#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define M 1000000007
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int N = 2e5 + 5;

int n, m, top, chose, dp[(1<<18)], group[(1<<18)], st[20];
bitset<20> mat[20];

void init(){
    for(int i = 0; i < (1<<n); i++){
        top = 0;
        for(int j = 0; j < n; j++)
            if((i>>j)&1) st[top++] = j;
        for(int j = 0; j < top; j++)
            for(int k = 0; k < j; k++)
                if(mat[st[j]][st[k]] == 0)
                    goto next;
        group[i] = 1;
        next:;
    }
}

void dfs(int now, int bit){
    if(now == top){
        if(group[bit]) dp[chose|bit] = min(dp[chose|bit], dp[chose] + 1);
        return;
    }
    dfs(now + 1, bit | (1<<st[now]));
    dfs(now + 1, bit);
}

signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        mat[a][b] = mat[b][a] = 1;
    }
    init();
    mem(dp, 0x3f);
    dp[0] = 0;
    for(int i = 0; i < (1<<n); i++){
        top = 0;
        for(int j = 0; j < n; j++)
            if(((i>>j)&1) == 0) st[top++] = j;
        chose = i;
        dfs(0, 0);
    }
    cout << dp[(1<<n)-1];
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "BIGROUP"
#define pll pair<ll, ll>
#define pii pair<pll, ll>
#define fi first
#define se second

using namespace std;
const ll mod = 998244353;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, siz, tong, a[N], b[N],  c[N];
string s;

vector<ll> adj[N], kq;

ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}
ll pw1(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % (mod-1);
        k = k * k % (mod-1);
    }
    return total;
}
void ask(int i, int j, int l)
{
    cout << i <<" "<< j << " " << l << endl ;
}
void sol()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
    }
    sort(a+1 ,a+1+n);
    for(int i = 1; i <= n; i ++)
    {
        ans = (ans + a[i] * a[i] % mod + a[i] * tong % mod) % mod;
        tong = (tong * 2 + a[i]) % mod;
    }
    cout << ans;
}
int main()
{
    if(fopen(task".INP", "r"))
    {
       freopen(task".INP", "r", stdin);
       freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1

5 7
3 3 7
7 4 8
10 5 4
13 4 3
15 2 8
16 5 2
18 3 7

https://codeforces.com/contest/791/problem/E

*/

#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n;
ll d[105][105];
double ans;

int main()
{
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            scanf("%1lld", &d[i][j]);
        }
    }
    for(ll k = 0; k < n; k++)
    {
        for(ll i = 0; i < n; i++)
        {
            for(ll j = 0; j < n; j++)
            {
                d[i][j] |= (d[i][k] & d[k][j]);
            }
        }
    }
    for(ll i = 0; i < n; i++)
    {
        ll cnt = 0;
        for(ll j = 0; j < n; j++)
        {
            if(i == j || d[j][i]) cnt++;
        }
        ans += 1.0 / cnt;
    }
    printf("%.12f", ans);
    return 0;
}


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

#define SIZE 101

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  double dp[SIZE][SIZE][SIZE] = { 0 };

  dp[a][b][c] = 1;

  for (int i = a; i < SIZE; i++) {
    for (int j = b; j < SIZE; j++) {
      for (int k = c; k < SIZE; k++) {
        if (i + j + k <= 1)continue;
        if (i > 0 && j != SIZE - 1 && k != SIZE - 1) {
          dp[i][j][k] += dp[i - 1][j][k] * (i - 1) / (i + j + k - 1);
        }
        if (j > 0 && i != SIZE - 1 && k != SIZE - 1) {
          dp[i][j][k] += dp[i][j - 1][k] * (j - 1) / (i + j + k - 1);
        }
        if (k > 0 && j != SIZE - 1 && i != SIZE - 1) {
          dp[i][j][k] += dp[i][j][k - 1] * (k - 1) / (i + j + k - 1);
        }
      }
    }
  }

  double ans = 0;
  int first = a + b + c;
  for (int i = a; i < SIZE; i++) {
    for (int j = b; j < SIZE; j++) {
      for (int k = c; k < SIZE; k++) {
        if (i == SIZE - 1 || j == SIZE - 1 || k == SIZE - 1) {
          ans += dp[i][j][k] * (i + j + k - first);
        }
      }
    }
  }

  printf("%.8f", ans);
}

#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

#define f first
#define s second
#define ll long long
#define mp make_pair
#define ull unsigned long long
#define p push
#define pb push_back

double r, x, y;

int main() {
	cin >> r >> x >> y;
	double dist = sqrt((x * x) + (y * y));
	double ans = dist / r;
	int out = 0;
	if (ceil(ans)!=ans) {
		out = ceil(ans);
	}
	else {
		out = (int)ans;
	}
	if (r > dist) {
		cout << "2\n";
	}
	else {
		cout << out << "\n";
	}

}


//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")

//#include <immintrin.h>
//#include <emmintrin.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,h,t) for (int i=h;i<=t;i++)
#define dep(i,t,h) for (int i=t;i>=h;i--)
#define ll long long
#define me(x) memset(x,0,sizeof(x))
#define IL inline
#define rint register int
inline ll rd(){
	ll x=0;char c=getchar();bool f=0;
	while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
char ss[1<<24],*A=ss,*B=ss;
IL char gc()
{
	return A==B&&(B=(A=ss)+fread(ss,1,1<<24,stdin),A==B)?EOF:*A++;
}
template<class T>void maxa(T &x,T y)
{
	if (y>x) x=y;
}
template<class T>void mina(T &x,T y)
{
	if (y<x) x=y;
}
template<class T>void read(T &x)
{
	int f=1,c; while (c=gc(),c<48||c>57) if (c=='-') f=-1; x=(c^48);
	while(c=gc(),c>47&&c<58) x=x*10+(c^48); x*=f;
}
const int mo=1e9+7;
ll fsp(int x,int y)
{
	if (y==1) return x;
	ll ans=fsp(x,y/2);
	ans=ans*ans%mo;
	if (y%2==1) ans=ans*x%mo;
	return ans;
}
struct cp {
	ll x,y;
	cp operator +(cp B)
	{
		return (cp){x+B.x,y+B.y};
	}
	cp operator -(cp B)
	{
		return (cp){x-B.x,y-B.y};
	}
	ll operator *(cp B)
	{
		return x*B.y-y*B.x;
    }
    int half() { return y < 0 || (y == 0 && x < 0); }
};
const int N=3e5;
struct re{
	int a,b,c;
}a[N],b[N];
bool cmp1(re x,re y)
{
	return x.a<y.a;
}
bool cmp2(re x,re y)
{
	return x.b<y.b;
}
int main()
{
   ios::sync_with_stdio(false);
   int n;
   cin>>n;
   int mx1,mx2,mx3,mx4;
   rep(i,1,n)
   {
     cin>>a[i].a>>a[i].b;
     b[i].a=a[i].a; a[i].c=b[i].c=i;
     b[i].b=a[i].b;
   }
   sort(a+1,a+n+1,cmp1);
   sort(b+1,b+n+1,cmp2);
   int ans=0;
   if (a[1].c==b[1].c&&a[n].c==b[n].c)
   {
   	ans=max(a[n].a-a[2].a,a[n-1].a-a[1].a);
   	ans=max(ans,max(b[n].b-b[2].b,b[n-1].b-b[1].b));
   } else
   {
   	 if (a[n].a-a[1].a>b[n].b-b[1].b)
   	 {
   	 	ans=max(max(a[n].a-a[2].a,a[n-1].a-a[1].a),b[n].b-b[1].b);
   	 } else
   	 {
   	 	ans=max(max(b[n].b-b[2].b,b[n-1].b-b[1].b),a[n].a-a[1].a);
   	 }
   }
   cout<<ans<<endl;
   return 0;
}

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

int main(){
    ll n;
    cin >>n;
    vl x(n);
    vl y(n);
    rep(i,n){
        cin >> x[i];
        cin >> y[i];
    }
    rep(i,n){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                ll e=(x[i]-x[j])*(y[k]-y[i])-(y[i]-y[j])*(x[k]-x[i]);
                if(!e){
                    print("Yes");
                    return 0;
                }
            }
        }
    }
    print("No");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mp(x,y) make_pair(x,y)
#define lc (x<<1)
#define rc (x<<1|1)
#define fi first
#define se second
#define mid ((l+r)>>1)
#define fan(x) (((x-1)^1)+1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

inline void write(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x/10) write(x/10);
	putchar((char)(x%10)+'0');
}

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

const int mod=998244353;
int n,m,k,ans;

inline int q_pow(int a,int b);

signed main()
{
	n=read();m=read();k=read();
	if(n==1)
	{
		printf("%lld\n",q_pow(k,m));
		return 0;
	}
	if(m==1)
	{
		printf("%lld\n",q_pow(k,n));
		return 0;
	}
	for(int i=1;i<=k;++i)
		ans+=((q_pow(i,n)-q_pow(i-1,n)+mod)%mod)*q_pow(k-i+1,m)%mod,ans%=mod;
	printf("%lld\n",ans);
	return 0;
}

inline int q_pow(int a,int b)
{
	int c=1;
	while(b)
	{
		if(b&1) c=a*c%mod;
		a=a*a%mod;b>>=1;
	}
	return c;
}

#pragma GCC optimize("O3")

#include "bits/stdc++.h"

#define sz(x) (int)(x).size()
using namespace std;
const int64_t INV = int64_t(332748118);
const int64_t MOD = int64_t(998244353);
const int mxN = int(5e3) + 5;
int64_t dp[mxN][mxN];
char arr[mxN][mxN];
int h,w,k;

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

    cin >> h >> w >> k;
    for(int i=0; i<k; i++) {
        int r,c; char val;
        cin >> r >> c >> val;
        arr[r][c] = val;
    }
    dp[1][1] = 1;
    for(int i=1; i<=h; i++)
        arr[i][0] = 'X';
    for(int j=1; j<=w; j++)
        arr[0][j] = 'X';
    for(int i=1; i<=h; i++) {
        for(int j=1; j<=w; j++) {
            if(i==1 && j==1) continue;
            switch(arr[i-1][j]) {
                case 0:
                    dp[i][j] += (2 * INV * dp[i-1][j]) % MOD;
                    break;
                case 'X':
                case 'D':
                    dp[i][j] += dp[i-1][j];
                    break;
            }
            switch(arr[i][j-1]) {
                case 0:
                    dp[i][j] += (2 * INV * dp[i][j-1]) % MOD;
                    break;
                case 'X':
                case 'R':
                    dp[i][j] += dp[i][j-1];
                    break;
            }
        }
    }
    int times = h * w - k;
    int64_t mul = 1;
    while(times--) {
        mul *= 3;
        mul %= MOD;
    }
    cout << (dp[h][w] * mul) % MOD << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;

#define INF INT_MAX
#define LLINF LLONG_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

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

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

    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) {
        cin >> A[i];
    }

    ll ans = INF;
    rep (bit, (1<<(N-1))) {
        ll xored = 0;
        ll ored = 0;

        rep (i, N+1) {
            if (i < N) {
                ored |= A[i];
            }
            if ((bit & (1<<i)) || (i == N)) {
                xored ^= ored;
                ored = 0;
            }
        }

        ans = min(ans, xored);
    }

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

#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
#define PR(x) cout << (x) << "\n"
#define PS(x) cout << (x) << " "
#define PRYES(x) PR((x) ? "Yes" : "No")
const long long INF          = numeric_limits<long long>::max();
const long long DP_INF       = 1 << 29;
template <class T> using arr = vector<vector<T> >;
using vint                   = vector<int>;
using vll                    = vector<ll>;
// SourceTest用出力マクロ
#ifdef SOURCE_TEST
#define SPR(x) PR(x)
#define SPS(x) PS(x)
#define STRACE(var) cout << #var << "=" << var << endl;
#define SMAPTRACE(var)  \
    cout << #var << "=" \
         << "{" << var.first << "," << var.second << "}" << endl;
#else
#define SPR(x) \
    {}
#define SPS(x) \
    {}
#define STRACE(var) \
    {}
#define SMAPTRACE(var) \
    {}
#endif
template <class T> void dump(const vector<T>& vec) {
#ifdef SOURCE_TEST
    for (ll i = 0; i < vec.size(); ++i) {
        cout << vec[i] << ",";
    }
    cout << endl;
#endif
}

vector<vll> orNums;

int main() {
    ll N;
    cin >> N;
    vll values(N);
    REP(i, N) {
        cin >> values[i];
    }
    orNums.resize(N);
    vector<vll> xorNums(N);
    orNums[0].resize(N);
    for (ll s = 0; s < N; ++s) {
        orNums[0][s] |= values[s];
    }
    for (ll i = 1; i < N; ++i) {
        orNums[i].resize(N, 0);
        for (ll s = 0; s < N; ++s) {
            ll n = s + i;
            if (n >= N) continue;
            orNums[i][s] = orNums[i - 1][s] | orNums[0][n];
        }
    }

    SPR("orList");
    for (const auto& ss : orNums) {
        dump(ss);
    }

    struct INFO {
        ll value;
        ll remainNum;
        ll next;

        void dump() const {
            SPS(value);
            SPS(remainNum);
            SPR(next);
            SPR("---");
        }
    };
    queue<INFO> infos;
    for (ll i = 0; i < N; ++i) {
        infos.push({orNums[i][0], N - 1 - i, i + 1});
    }

    ll ans = INF;
    while (!infos.empty()) {
        auto info = infos.front();
        infos.pop();
        SPR("------dumpInfomation");
        info.dump();
        if (info.remainNum == 0) {
            ans = min(ans, info.value);
        } else {
            for (ll i = 0; i < N; ++i) {
                ll nextValue = orNums[i][info.next];
                ll nextR     = info.remainNum - i - 1;
                if (nextR >= 0) {
                    INFO infomation;
                    infomation.value     = info.value ^ nextValue;
                    infomation.remainNum = nextR;
                    infomation.next      = info.next + 1 + i;
                    STRACE(i);
                    STRACE(nextValue);
                    infomation.dump();
                    infos.push(infomation);
                }
            }
        }
    }

    PR(ans);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll mod = 998244353;
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; }

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> h(n), w(m);
	rep(i, 0, n)cin >> h[i];
	rep(i, 0, m)cin >> w[i];
	sort(all(h));
	sort(all(w));
	ll ans = 1ll << 60;
	ll t = 0;
	for (int i = 0; i < n; i += 2) {
		auto it = lower_bound(all(w), h[i]);
		ll w1 = 1ll << 60, w2 = 1ll << 60;
		if (it != w.begin())w1 = *(it - 1);
		if (it != w.end())w2 = *it;
		ll temp = min(abs(h[i] - w1), abs(h[i] - w2));
		t += temp;
		if (i == 0) {
			for (int j = 1; j < n; j += 2) {
				t += h[j + 1] - h[j];
			}
		}
		else {
			t -= h[i] - h[i - 1];
			t += h[i - 1] - h[i - 2];
		}
		ans = min(ans, t);
		t -= temp;
	}
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

const int INF = 1001001001;

auto solve(int64_t A, int64_t B, int64_t W) {
    // TODO: edit here
    W *= 1000;

    int l = 0, r = 0, ans_min = INF, ans_max = -1, cnt = 0;
    while (1) {
        cnt++;
        l += A;
        r += B;
        if (l <= W && W <= r) {
            ans_min = min(ans_min, cnt);
            ans_max = max(ans_max, cnt);
        }
        if (W < l) break;
    }

    if (ans_min == INF && ans_max == -1) {
        cout << "UNSATISFIABLE" << endl;
        exit(0);
    }

    vector<int> ans = {ans_min, ans_max};
    return ans;
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t A, B, W;
    cin >> A >> B >> W;
    auto ans = solve(A, B, W);
    REP (i, 2) { cout << ans[i] << endl; }
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n, m;
	cin >> n >> m;
	if (n == m || n == m + 1 && m != 0 || m < 0) {
		cout << -1 << endl;
		return 0;
	}
	V a, b;
	m++;
	int pos = 2;
	while (m) {
		m--;
		a.push_back(pos), b.push_back(pos + 1);
		pos += 2;
	}
	a.push_back(1), b.push_back(pos);
	int N = n - a.size();
	int over = 100000000;
	while (N > 0) {
		N--;
		a.push_back(over), b.push_back(over + 1);
		over += 2;
	}
	rep(i, n) {
		cout << a[i] << " " << b[i] << endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5;
int main(){
	vector<pair<int,int>>ans;
	int n,m;cin>>n>>m;
	int x=m;
	if((m>0&&x+2>n)||m<0){
		cout<<"-1\n";
		return 0;
	}
	ans.emplace_back(1,4*x+3);
	for(int i=0;i<n-1;i++){
		ans.emplace_back(4*i+2,4*i+4);
	}
	for(auto& i:ans){
		cout<<i.first<<' '<<i.second<<'\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(auto& x:a)
    cin>>x;
    for(auto& x:b)
    cin>>x;
    reverse(a.begin(),a.end());
    priority_queue<int,vector<int>,greater<int>> q;
    for(int i=0;i<n;i++)
    {
        q.push(a[i]);
        q.push(b[i]);
        q.pop();
    }
    int res=0;
    while(!q.empty())
    {
        res+=q.top();
        q.pop();
    }
    cout<<res;
    return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

constexpr i32 mod   = 1e9 + 7;
// constexpr i32 mod   = 998244353;

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

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

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input();
  vector< int > as(n), bs(n);
  cin >> as >> bs;
  whole(reverse, as);

  vector< int > vs;
  for (auto &a : as) vs.emplace_back(a);
  for (auto &b : bs) vs.emplace_back(b);
  whole(sort, vs);

  range(i, 0, n) {
    if (as[i] > bs[i]) swap(as[i], bs[i]);
  }

  i64 ans = 0;
  using P = pair<i64, i64>;
  priority_queue<P, vector< P >, greater< P >> pq;
  range(i, 0, n) {
    if (not pq.empty() and pq.top().first < as[i]) {
      ans += bs[i] + as[i] - pq.top().first;
      pq.emplace(pq.top().second, infll);
      pq.emplace(as[i], bs[i]);
      pq.pop();
    } else {
      ans += bs[i];
      pq.emplace(bs[i], infll);
    }
  }

  cout << ans << endl;
}

signed main() {
  solve();
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define NEXT(i, u) for (int i = h[u]; i; i = e[i].u)
const int INF = 2e9;
const int K = 1e5 + 7;

int Max(const int &a, const int &b) {return a > b ? a : b;}
int Min(const int &a, const int &b) {return a > b ? b : a;}

int sum[20], tot[20];
int k, n;
double sy;
double ans, sm;
char s[20], t[20];

int po(int x){
    int ans = 1;
    FOR (i, 1, x) ans *= 10;
    return ans;
}

int main(){
    scanf("%d", &k);
    sy = 9 * k - 8;
    scanf(" %s %s", s, t);
    n = strlen(s);
    FOR (i, 0, 3){
        int c = s[i] - '0', cc = t[i] - '0';
        ++sum[c];
        ++tot[cc];
    }
    FOR (i, 1, 9){
        FOR (j, 1, 9){
            if (i == j){
                if (sum[i] + tot[j] + 2 <= k) ++sum[i], ++tot[j];
                else continue;
            }
            else {
                if (sum[i] + tot[i] + 1 <= k && sum[j] + tot[j] + 1 <= k) ++sum[i], ++tot[j];
                else continue;
            }
            int sc1 = 0, sc2 = 0;
            FOR (l, 1, 9){
                sc1 += l * po(sum[l]);
                sc2 += l * po(tot[l]);
            }
            --sum[i];
            --tot[j];
            if (sc1 > sc2){
                if (i == j) ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j] - 1) / (sy - 1));
                else ans += (1.0 * (1.0 * k - sum[i] - tot[i]) / sy) * (1.0 * (1.0 * k - sum[j] - tot[j]) / (sy - 1));
            }
        }
    }
    printf("%.16lf\n", ans);
    return 0;
}

#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>

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

using namespace std;
using ll = long long;

int score(const string &s) {
    auto cnt = vector<int>(10);
    iota(ALL(cnt), 0);
    for (auto c : s) cnt[c - '0'] *= 10; // 所持カードの点数を10^ci倍していく
    return accumulate(ALL(cnt), 0);      // 点数の総和を求める
}

int main() {
    ll k{};
    string s{}, t{};
    cin >> k >> s >> t;

    auto cards = vector<ll>(10, k); // カードの枚数を保持する（インデックス0は使用しない）
    for (const auto &c : s + t) {
        if (c != '#') --cards[c - '0'];
    }

    ll win = 0; // 高橋くんが勝つ組み合わせの総和

    for (int si = 1; si <= 9; ++si) {
        for (int ti = 1; ti <= 9; ++ti) {
            s.back() = '0' + si;
            t.back() = '0' + ti;
            if (score(s) <= score(t)) continue;          // 青木くんが勝つ、もしくは引き分ける場合
            win += cards[si] * (cards[ti] - (si == ti)); // 5枚目のカードの残り枚数から、そのカードの組み合わせを求める
        }
    }

    ll p = (9 * k - 8) * (9 * k - 9); // 組み合わせの総数

    cout << fixed << setprecision(5) << static_cast<double>(win) / p << endl;

    return 0;
}


// C - Collinearity
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int n; cin>>n;
	vi X, Y;
	rp(i, 0, n){
		int x, y; cin>>x>>y;
		X.push_back(x);
		Y.push_back(y);
	}
	rp(a, 0, n-1) rp(b, a+1, n) rp(c, 0, n){
		if(c == a || c == b) continue;
		int dx = X[b] - X[a];
		int dy = Y[b] - Y[a];
		ll dx_y = dx*Y[c];
		ll dx_fx = dy*(X[c] - X[a]) + dx*Y[a];
		if(dx_y == dx_fx){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n, k, m; cin >> n >> k >> m;
    int sum = 0;
    vector<int> a(n);
    rep(i,n-1){
        cin >> a[i];
        sum+= a[i];
    }

    if(n*m < sum) dunk(0);
    else if(n*m > sum + k) dunk(-1);
    else dunk(n*m-sum);
}


#include<bits/stdc++.h>

using namespace std;

const int N = 105;

int n, k, MOD;

void sub(int& x, int y){
    x-=y;
    if(x<0)x+=MOD;
}

void add(int& x, int y){
    x+=y;
    if(x>MOD)x-=MOD;
}

int dp[N][N*N*N];

void solve(){
    dp[0][0]=1;
    for(int i=1;i<=n;++i){
        int up=k*(i+1)*i/2;
        for(int j=0;j<=up;++j){
            dp[i][j]=dp[i-1][j];
            if(j>=i){
                add(dp[i][j],dp[i][j-i]);
            }
        }
        for(int j=up;j>=(k+1)*i;--j){
            sub(dp[i][j],dp[i][j-(k+1)*i]);
        }
    }
}

void getAns(){
    for(int i=1;i<=n;++i){
        int ans=0;
        int l=i-1, r=n-i;
        int up=min(k*l*(l+1)/2,k*r*(r+1)/2);
        for(int j=0;j<=up;++j){
            add(ans,1ll*dp[l][j]*dp[r][j]%MOD);
        }
        ans=1ll*ans*(k+1)%MOD;
        add(ans,-1);
        cout<<ans<<endl;
    }
}

int main(){
    cin>>n>>k>>MOD;

    solve();

    getAns();

    return 0;
}

#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>
#include <iomanip>

#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp"

class range {
  struct iter {
    std::size_t itr;
    constexpr iter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { ++itr; }
    constexpr bool operator != (iter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  struct reviter {
    std::size_t itr;
    constexpr reviter(std::size_t pos) noexcept: itr(pos) { }
    constexpr void operator ++ () noexcept { --itr; }
    constexpr bool operator != (reviter other) const noexcept { return itr != other.itr; }
    constexpr std::size_t operator * () const noexcept { return itr; }
  };

  const iter first, last;

public:
  constexpr range(std::size_t first, std::size_t last) noexcept: first(first), last(std::max(first, last)) { }
  constexpr iter begin() const noexcept { return first; }
  constexpr iter end() const noexcept { return last; }
  constexpr reviter rbegin() const noexcept { return reviter(*last - 1); }
  constexpr reviter rend() const noexcept { return reviter(*first - 1); }
};

/**
 * @title Range
 */
#line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

#include <type_traits>
#include <iterator>
#line 6 "/Users/kodamankod/Desktop/cpp_programming/Library/other/rev.cpp"

template <class T>
class rev_impl {
public:
  using iterator = decltype(std::rbegin(std::declval<T>()));

private:
  const iterator M_begin;
  const iterator M_end;

public:
  constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { }
  constexpr iterator begin() const noexcept { return M_begin; }
  constexpr iterator end() const noexcept { return M_end; }
};

template <class T>
constexpr decltype(auto) rev(T &&cont) {
  return rev_impl<T>(std::forward<T>(cont));
}

/**
 * @title Reverser
 */
#line 17 "main.cpp"

using i32 = std::int32_t;
using i64 = std::int64_t;
using u32 = std::uint32_t;
using u64 = std::uint64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

constexpr i32 inf32 = (u32) ~0 >> 2;
constexpr i64 inf64 = (u64) ~0 >> 2;

template <class T>
using Vec = std::vector<T>;

using f80 = long double;

int main() {
  usize N, M, K;
  std::cin >> N >> M >> K;
  Vec<bool> ok(N + 1, true);
  while (K--) {
    usize i;
    std::cin >> i;
    ok[i] = false;
  }
  Vec<std::pair<f80, f80>> dp(N + 1);
  std::pair<f80, f80> sum;
  const f80 invM = 1.0L / (double) M;
  for (auto i: rev(range(0, N))) {
    if (!ok[i]) {
      dp[i].first = 1.0L;
    }
    else {
      dp[i].first = sum.first * invM;
      dp[i].second = sum.second * invM + 1;
    }
    sum.first += dp[i].first;
    sum.second += dp[i].second;
    if (i + M <= N) {
      sum.first -= dp[i + M].first;
      sum.second -= dp[i + M].second;
    }
  }
  std::cout << std::fixed << std::setprecision(10);
  if (std::abs(1.0L - dp[0].first) < 1e-9) {
    std::cout << -1 << '\n';
  }
  else {
    std::cout << dp[0].second / (1.0L - dp[0].first) << '\n';
  }
  return 0;
}


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

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
  int n, m, k; cin >> n >> m >> k;
  mint ans = 0, sum = 0;
  for(int i = 1; i <= k; i++){
    mint a = i, b = k-i+1;
    mint x = a.pow(n) - (a-1).pow(n);
    mint y = b.pow(m);
    if(n == 1){
      y = mint(k).pow(m) - mint(k-i).pow(m);
      y -= sum;
      sum += y;
    }
    if(m == 1) y = 1;
    ans += x * y;
    // cout << i << "-------------" << endl;
    // cout << x << "," << y << endl;
    // cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

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

// 2の27乗＝１億３千万
#define rep(i, n, N) for (int i = n; i < (int)(N); i++)
#define ascending(array) sort(array.begin(), array.end());
#define descending(array) sort(array.rbegin(), array.rend());
#define log(name, message) cout << name << " = " << message << endl
#define out(content) cout << content << endl
#define max(array) *max_element(array.begin(), array.end())
#define min(array) *min_element(array.begin(), array.end())

int main() {
  int n;
  string s;
  int q;
  cin >> n >> s >> q;
  vector<int> t(q), a(q), b(q);
  rep(i, 0, q) { cin >> t[i] >> a[i] >> b[i]; }
  bool reverse = false;
  rep(i, 0, q) {
    if (t[i] == 1) {
      if (reverse) {
        if (a[i] > n) {
          a[i] = a[i] - n;
        } else {
          a[i] = a[i] + n;
        }
        if (b[i] > n) {
          b[i] = b[i] - n;
        } else {
          b[i] = b[i] + n;
        }
      }
      int order1 = a[i] - 1;
      int order2 = b[i] - 1;
      string first = {s[order1]};
      string second = {s[order2]};
      int last = s.size() - 1;
      string test = {s[last]};
      s.pop_back();
      s += test;
      s.replace(order1, 1, second);
      s.replace(order2, 1, first);
    } else {
      reverse = !reverse;
    }
  }
  if (reverse) {
    s = s.substr(n) + s.substr(0, n);
  }
  out(s);
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf=1e18+3;
const int mix=1e6+5;
int n,m,fx,ty,cn;
int hea[mix],nxt[mix],tor[mix];
int len[mix],kai[mix],dis[mix];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
bool vis[mix];
inline void Build(){
    int a, b, t, k;
    scanf("%lld%lld%lld%lld", &a, &b, &t, &k);
	nxt[++cn]=hea[a],tor[hea[a]=cn]=b,len[cn]=t,kai[cn]=k;
	nxt[++cn]=hea[b],tor[hea[b]=cn]=a,len[cn]=t,kai[cn]=k;
}
#undef int
int main() {
    #define int long long
    scanf("%lld%lld%lld%lld", &n, &m, &fx, &ty);
	for(int i=1;i<=m;++i)Build();
	for(int i=1;i<=n;++i)dis[i]=inf;
	q.push(make_pair(dis[fx]=0,fx));
	while(!q.empty()){
		int x=q.top().second;
		q.pop();
		if(vis[x])continue;
		for(int t,i=hea[x];i;i=nxt[i])
		if(!vis[t=tor[i]]){
			int tim=dis[x]+kai[i]-(dis[x]+kai[i]-1)%kai[i]-1+len[i];
			if(tim<dis[t])q.push(make_pair(dis[t]=tim,t));
		}
	}
	printf("%lld\n", dis[ty]<inf?dis[ty]:-1);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M, K;
  cin >> N >> M >> K;
  unordered_set<i64> A;
  REP(0, K, i) {
    i64 a;
    cin >> a;
    A.insert(a);
  }

  for(auto a: A) {
    bool f = true;
    REP(a, a+M, i) {
      if(!IN(A, i)) {
        f = false;
      }
    }
    if(f) {
      printf("-1\n");
      return 0;
    }
  }

  vector<double> a(N+M+1), b(N+M+1);
  REP(N, N+M+1, i) {
    a[i] = 0;
    b[i] = 0;
  }
  double b_sum = 0;
  double a_sum = 0;
  for(j=N-1;j>=0;--j) {
    if(IN(A, j)) {
      b[j] = 0;
      a[j] = 1;
    }
    else {
      b[j] = b_sum / M + 1;
      a[j] = a_sum / M;
    }
    b_sum -= b[j+M];
    b_sum += b[j];
    a_sum -= a[j+M];
    a_sum += a[j];
  }
  printf("%.10f\n", double(b[0]) / double(1 - a[0]));

  /*
  REP(0, N+M+1, i) {
    cerr << a[i] << " " << b[i] << endl;
  }
  */

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  char mp[h][w];
  rep(i,h){
    rep(j,w){
      cin>>mp[i][j];
    }
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(mp[i][j]=='.'){
	if(i!= h-1 && mp[i+1][j]=='.') ans++;
	if(j!= w-1 && mp[i][j+1]=='.') ans++;
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}

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

//solution:
#define int int64_t
#define span(a) begin(a), end(a)

void hike() {
  int n, k; cin >> n >> k;
  int cost[n + 1][n + 1];
  for(int i = 1; i <= n; ++i) {
    for(int j = 1; j <= n; ++j) cin >> cost[i][j];
  }
  vector<int> path(n - 1);
  iota(span(path), 2);
  int count = 0;
  do {
    int i = 1, sum = 0;
    for(int& j: path) {
      sum += cost[i][j], i = j;
    }
    sum += cost[i][1];
    count += (sum == k);
  } while(next_permutation(span(path)));
  cout << count << "\n";
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int t = 1; //cin >> t;
  while(t--) hike();
  return 0;
} //farewell, until we meet again..


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

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

try all combinations of mod (500^2)

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

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

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

*/

lli read() {
    lli x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
void print(lli x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return 0;
}

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <utility>
#include <set>
#include <tuple>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

const ll INF = __LONG_LONG_MAX__/2;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

tuple<ll, ll, ll> extGCD(ll a, ll b){
  if(b==0){
    return {1, 0, a};
  }
  auto [y, x, xygcd] = extGCD(b, a%b);
  y -= a/b * x;
  return {x, y, xygcd};
}

pair<ll, ll> ChineseRem(pair<ll, ll>x, pair<ll, ll>y){
  auto [b1, m1] = x;
  auto [b2, m2] = y;
  auto [p, q, mgcd] = extGCD(m1, m2);
  if((b2-b1)% mgcd !=0) return make_pair(0, -1);
  ll m_lcm = m1 * (m2/mgcd);
  ll tmp = (b2 - b1) / mgcd * p % (m2/mgcd);
  ll r = mod(b1 + m1 * tmp, m_lcm);
  return make_pair(r, m_lcm);
}

void solve(int X, int Y, int P, int Q){
  ll ans = INF;
  for (int i = X; i < X + Y; i++)
  {
    for (int j = P; j < P + Q; j++)
    {
      auto [t, lcm] = ChineseRem({i, 2*X+2*Y}, {j, P+Q});
      if(lcm == -1) continue;
      ans = min(ans, t);
    }
  }
  if(ans==INF) cout << "infinity" << endl;
  else cout << ans << endl;
}

int main(){
  int T; cin >> T;
  while(T--){
    int X, Y, P, Q; cin >> X >> Y >> P >> Q;
    solve(X, Y, P, Q);
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const int MX = 100001;

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

    // int a, b;
    // cin >> a >> b;
    // a = a + b;
    // int ans;
    // if(a >= 15 && b >= 8) ans = 1;
    // else if(a >= 10 && b >= 3) ans = 2;
    // else if(a >= 3) ans = 3;
    // else ans = 4;
    // cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll T = 1;
    //cin>>T;
    while(T--) solve();
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
const int mod=1000000007;
using namespace std;
void A(){
int a,b;cin>>a>>b;
int x=0;
if(b>=8&&a+b>=15){cout<<1;return;}
if(b>=3&&a+b>=10){cout<<2;return;}
if(a+b>=3){cout<<3;return;}
cout<<4;
}
void B(){

}
void C(){

}
void D(){

}
int main(){
 	A();
 //	B();
 //	C();
 //	D();
}


#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383
#define pb push_back
#define all(s) s.begin(),s.end()

int main (){
    fast;

    int h,w;
    cin>>h>>w;
    string arr[h];

    for(int i=0;i<h;i++){
        cin>>arr[i];
    }

    int ans = 0;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(arr[i][j] == '.'){
                  if(j+1 < w and arr[i][j+1] =='.') ans++;
                if(i+1 < h and arr[i+1][j] == '.') ans++;
            }

        }
    }

    cout<<ans<<endl;

}

/*************************************************************************
	> File Name: 1.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com
	> Blog: https://blog.csdn.net/Pig_cfbsl
	> Created Time: 2020/10/10 20:03:44
 ************************************************************************/
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define pb push_back
#define pr pair<int,int>
#define fi first
#define se second
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int n,m,ans=0;
char s[250][250];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	n=read(); m=read();
	For(i,1,n) scanf("%s",s[i]+1);
	For(i,1,n) For(j,1,m){
		if(s[i][j]=='.'){
			if(s[i+1][j]=='.') ++ans;
			if(s[i][j+1]=='.') ++ans;
		}
	}
	printf("%d\n",ans);
	return 0;
}


//****************************Template Begins****************************//

// Header Files
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// Header Files End

using namespace std;
#define HARI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define all1(v) (v).begin()+1,(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define allr1(v) (v).rbegin()+1,(v).rend()
#define sort0(v) sort(all(v))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define inf 9999999999999
const ll mod = 1e9 + 7;

ll inv(ll i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}

ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}

ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}

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

ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}

ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
//****************************Template Ends*******************************//

int main() {
    HARI;
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t, n, i, j, ans, temp, sum;
    string sans;
    t = 1;
    // cin >> t;
    while (t--)
    {
        sans = "NO";
        ans = temp = sum = 0;
        cin >> n;
        vll a(n + 1, 0), psum(n + 1, 0);
        fo(i, 1, n)
        {
            cin >> a[i];
            psum[i] = psum[i - 1] + a[i];
        }
        vector<vll>dp(n + 1, vll(n + 1, 0));
        vector<vll>pre(n + 1, vll(n + 1, -1));
        vector<vll>idx(n + 1, vll(n + 1, -1));
        fo(i, 1, n)
        {
            fo(j, 1, n)
            {
                if (j == 1)
                {
                    idx[i][j] = i - 1;
                }
                else idx[i][j] = pre[j][psum[i] % j];
                pre[j][psum[i] % j] = i;
            }
        }
        dp[0][0] = 1;
        fo(i, 1, n)
        {
            fo(j, 1, n)
            {
                temp = idx[i][j];
                if (temp == -1)continue;
                dp[i][j] = mod_add(dp[temp][j - 1], dp[temp][j]);
            }
        }
        fo(i, 1, n)
        {
            ans = mod_add(ans, dp[n][i]);
        }
        cout << ans;
    }
    return 0;
}

#include<bits/stdc++.h>
#define int long long
const int p=1e9+7;
using namespace std;

int n,a[4000],sum[4000],f[3008][3008],cnt[3008][3008],ans;

signed main() {
	scanf("%lld",&n);
	for(int i=1; i<=n; i++) {
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	cnt[1][0]=1;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=i; j++) {
			f[i][j]+=cnt[j][sum[i]%j];
			f[i][j]%=p;
		}
		for(int j=1; j<=i; j++) {
			cnt[j+1][sum[i]%(j+1)]+=f[i][j];
		}
	}
	for(int i=1; i<=n; i++)
		ans=(ans+f[n][i])%p;
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll V[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, 2 * N) cin >> V[i];
	ll res = accumulate(V, V + 2 * N, 0ll);
	priority_queue<ll, vector<ll>, greater<ll>> que;
	for(int i = 0; i < N; i++) {
		que.push(V[N - 1 - i]);
		que.push(V[N + i]);
		res -= que.top(); que.pop();
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)(1e18)

signed main(){
	int N, i, ans = 0;
	scanf("%lld", &N);
	vector<int> V(2 * N);
	for(i = 0; i < 2 * N; i++){
		scanf("%lld", &V[i]);
		ans += V[i];
	}
	priority_queue<int, vector<int>, greater<int>> pq;
	for(i = 0; i < N; i++){
		pq.push(V[N - 1 - i]);
		pq.push(V[N + i]);
		ans -= pq.top();
		pq.pop();
	}
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=2e18;
ll clamp(ll x,ll min,ll max)
{
	if(x>max)
	{
		return max;
	}
	if(x<min)
	{
		return min;
	}
	return x;
}
int main()
{
	ll n;
	cin>>n;
	ll low=-INF;
	ll high=INF;
	ll bias=0;
	for(ll i=1;i<=n;i++)
	{
		ll a,t;
		cin>>a>>t;
		if(1==t)
		{
			low+=a;
			high+=a;
			bias+=a;
		}
		else if(2==t){
				low=max(low,a);
				high=max(high,a);
			}else{
				low=min(low,a);
				high=min(high,a);
			}
	}
	ll q;
	cin>>q;
	for(ll i=1;i<=q;i++)
	{
		ll x;
		cin>>x;
		cout<<clamp(x+bias,low,high)<<"\n";
	}
}

#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>
#define vc vector<char>
#define vs vector<string>
#define np(vec) next_permutation(vec.begin(),vec.end())==true
#define en endl
#define vvl vector<vector<int64_t>>
#define stl stack<int64_t>
#define qul que<int64_t>
#define ms(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pq priority_queue
#define pql priority_queue<int64_t>
#define pu push
#define pop pop()
#define top top()
#define pqr priority_queue<ll,vector<ll>,greater<ll>>
#define co cout
#define ci cin
#define wh while
#define size size()
#define front front()

int main() {
  ll n;
  ll a=0;
  char c;
  cin>>n;
  vl v1;
  vl v2;
  fo(i,n){
    cin>>c;
    if(c=='0'){v1.push_back(i);}
  }
  fo(i,n){
    cin>>c;
    if(c=='0'){v2.push_back(i);}
  }
 if(v1.size!=v2.size){cout<<-1<<en;}
  else{
    sor(v1);
    sor(v2);
    fo(i,v1.size){
      if(v1.at(i)!=v2.at(i)){a++;}
    }
    cout<<a<<en;
  }
}


#include <iostream>

using namespace std;
unsigned long long n,cn;
int s,cnt,nrcif,cf[19],i,r,j;
int main()
{
    cin>>n;
    cn=n;
    while(cn)
    {
        cf[++cnt]=(cn%10)%3;
        s+=cf[cnt];
        cn/=10;
        nrcif++;
    }
    r=s%3;
    if(r==0)
    {
        cout<<0;
        return 0;
    }
    int cnt1=1;
    if(cnt1<nrcif)
    {
        for(i=1; i<=cnt; i++)
        {
            if(r==cf[i])
            {
                cout<<cnt1;
                return 0;
            }
        }
        cnt1++;
        if(cnt1<nrcif)
        {
            for(i=1; i<=cnt; i++)
                for(j=i+1; j<=cnt; j++)
                {
                    if(r==cf[i]+cf[j])
                    {
                        cout<<cnt1;
                        return 0;
                    }
                }
            for(i=1; i<=n; i++)
            {
                if(cf[i]%3==0)
                {
                    cout<<nrcif-1;
                    return 0;
                }
            }
        }
    }
    cout<<-1;
    return 0;
}

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

int main() {
  ll n;
  cin >> n;
  vector<int> num(3);

  while (n) {
    num[n % 10 % 3]++;
    n /= 10;
  }
  int x = (num[1] + num[2] * 2) % 3;
  int k = num[0] + num[1] + num[2];
  if(x == 0){
    cout << 0 << endl;
  } else if (x == 1) {
    if (num[1]) {
      if (k == 1) {
        cout << -1 << endl;
      } else {
        cout << 1 << endl;
      }
    } else {
      if (k == 2) {
        cout << -1 << endl;
      } else {
        cout << 2 << endl;
      }
    }
  } else {
    if (num[2]) {
      if (k == 1) {
        cout << -1 << endl;
      } else {
        cout << 1 << endl;
      }
    } else {
      if (k == 2) {
        cout << -1 << endl;
      } else {
        cout << 2 << endl;
      }
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
  int H, W;
  while(scanf("%d%d", &H, &W) > 0){
    char S[H][W+1];
    for(int i = 0; i < H; i++){
      scanf("%s", S[i]);
    }

    int ans = 0;

    for(int i = 1; i < H; i++){
      bool at_side = false;
      for(int j = 0; j < W; j++){
	if(S[i-1][j] == '.' and S[i][j] == '#'){
	  if(!at_side) ans++;
	  at_side = true;
	} else {
	  at_side = false;
	}
      }
    }

    for(int i = H-2; i >= 0; i--){
      bool at_side = false;
      for(int j = 0; j < W; j++){
	if(S[i+1][j] == '.' and S[i][j] == '#'){
	  if(!at_side) ans++;
	  at_side = true;
	} else {
	  at_side = false;
	}
      }
    }

    for(int j = 1; j < W; j++){
      bool at_side = false;
      for(int i = 0; i < H; i++){
	if(S[i][j-1] == '.' and S[i][j] == '#'){
	  if(!at_side) ans++;
	  at_side = true;
	} else {
	  at_side = false;
	}
      }
    }

    for(int j = W-2; j >= 0; j--){
      bool at_side = false;
      for(int i = 0; i < H; i++){
	if(S[i][j+1] == '.' and S[i][j] == '#'){
	  if(!at_side) ans++;
	  at_side = true;
	} else {
	  at_side = false;
	}
      }
    }

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


 #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
#include <cstring>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1e9 + 7;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int main() {
    ll N;
    cin >> N;
    int x[N];
    int y[N];
    int ans = 0;
    rep(i,N) cin >> x[i] >> y[i];
    for(int i=0; i<N; i++) {
	for(int j=i+1; j<N; j++){
	    for(int k=j+1; k<N; k++) {
		int a,b,c,d;
		a = x[i] - x[k];
		b = y[i] - y[k];
		c = x[j] - x[k];
		d = y[j] - y[k];
		if(a*d == b*c) ans++;
	    }
	}
    }
    if(ans > 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

    vector<ll>v1;
    ll n;
    cin>>n;
    ll a[n],b[n];
    for(ll i=0;i<n;i++){
        cin>>a[i];
        cin>>b[i];
        ll res=a[i]+b[i];
        v1.push_back(res);
    }
    ll res1=*min_element(a,a+n);
    ll res2=*min_element(b,b+n);
    ll store1,store2;
    for(ll i=0;i<n;i++){
        if(a[i]==res1){
            store1=i;
            break;
        }
    }

    for(ll i=0;i<n;i++){
        if(b[i]==res2){
            store2=i;
            break;
        }
    }
    ll finalres;
    if(store1!=store2){
        finalres=max(res1,res2);
    }
    else{
        sort(b,b+n);
        res2=b[1];
        finalres=max(res1,res2);
    }

    v1.push_back(finalres);

    ll check=*min_element(v1.begin(),v1.end());
    cout<<check<<endl;

}


// Problem: B - Many 110
// Contest: AtCoder - AtCoder Regular Contest 110（Sponsored by KAJIMA CORPORATION）
// Time: 2020-12-05 17:30:21

// 私に忍び寄るのをやめてください、ありがとう

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define mod 1000000007 //998244353
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define nl "\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define x first
#define y second
#define vc vector
#define pb push_back
#define ar array
#define all(a) (a).begin(), (a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(v,n,x) fill(v,v+n,x);
#define init(c,a) memset(c,a,sizeof(c))
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define vpll vector<pll>
#define inf 9e18
#define cases ll T;cin>>T;while(T--)
#define BLOCK 500
//const double PI = 3.141592653589793238460;
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
// void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N=1<<20;
// 110 110 110 110 ...
int32_t main()
{

	fast
	cout << fixed << setprecision(12);
	ll n;
	string s;
	cin>>n>>s;

	ll big=(ll)1e10;

	string ans="110";

	ll pos=0,sz=0;

	if(n==1){

		if(s[0]=='1'){
			cout<<2*big;
		}
		else
		cout<<big;

		return 0;
	}

	if(n==2){
		if(s[0]=='0'){
			if(s[1]=='1')
			cout<<big-1;
			else
			cout<<0;
		}

		else
		cout<<big;

		return 0;

	}

	// 3 cases

	// 110
	if(s[0]=='1' and s[1]=='1'){
		pos=0;

		sz=((n-3)+2)/3+1;

	}

	//10
	else if(s[0]=='1' and s[1]=='0'){
		pos=1;

		sz=((n-2)+2)/3+1;

	}

	//0
	else{
		pos=2;

		sz=((n-1)+2)/3+1;

	}

	f(i,n){
		if(s[i]!=ans[pos%3]){
			cout<<0;
			return 0;
		}

		pos++;
	}

	cout<<(big-sz+1);

	return 0;

}

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

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

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

int main2() {
  ll t = nextLong();
  ll N = nextLong();

  ll hi = 1e16;
  ll lo = 0;
  while (hi - lo > 1) {
    ll m = (hi + lo) / 2;

    ll d = (m*(100+t)/100) - m;
    if (d >= N) hi = m; else lo = m;
  }
  ll ans = hi * (100 + t) / 100 - 1;
  cout << ans << endl;
  return 0;
}

int main() {

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


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

using namespace std;

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

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

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

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

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

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

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

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

vector<pair<ll,ll>> factorize(ll n) {
    vector<pair<ll,ll>> res;
    for (ll i = 2; i*i <= n; ++i) {
        if (n%i) continue;
        res.emplace_back(i,0);
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n,1);
    return res;
}

int solve(){
    ll s,p;
    cin>>s>>p;
    Vec div = divisor(p);
    bool ok = false;
    Each(d, div){
        ll n = d;
        ll m = p/d;
        if(n+m == s){
            ok = true;
        }
    }
    Yes(ok);
    return  0;
}

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

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

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = 1e18;

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

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

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

int main() {
    ll s, p;    cin >> s >> p;
    ll ans = 0;
    for (ll x = 1; x * x <= p; x++) {
        if (p % x == 0) {
            if (x + p/x == s)
                ans++;
        }
    }
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI 3.14159265359
#define pb push_back
#define mp make_pair
#define MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define IG cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define ll long long int
#define ull unsigned long long int
#define N 1378
#define maxn 1000001
#define FP ff.open("output.txt")
#define FR ff.open("input.txt")
#define valid(a,b) if(a>=1 && a<row-1 && b>=1 && b<col-1)
fstream ff;
ll a, q, b, c, d, k, h, e, f, t, m, n, i, j, x, y, tcase = 0, l, r;
string s1, s2, s;
int A[100][100];
void process(){
}
int main(){
	long double a,b;
	cin>>a>>b;
	printf("%.10Lf",(1-b/a)*100);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

ll ans = 0;

void judge(ll a, ll b, ll c) {
  if(a == b && b == c) ans ++;
  else if(a == b || b == c || c == a) ans += 3;
  else  ans += 6;
}

void solve() {
  int a, b;
  cin >> a >> b;
  cout <<((double)a-(double)b)/double(a)*100 << endl;
}

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


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define Endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//const long long INF=1e15;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//auto dist=uniform_int_distribution<int>(0,INF);
//const long double pi = acos(-1);
//primes for hashing 937, 1013
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
void shikhar7s(int cas)
{
    int n,i;
    cin>>n;
    int s[n],a[n];
    fr(i,n)
    {
        cin>>a[i];
        if(!i)
            s[i]=a[i];
        else
            s[i]=s[i-1]+a[i];
    }
    int l[n+5][n+5];
    memset(l,0,sizeof(l));
    rep(i,1,n+1)
    {
        vi v[i];
        int j;
        fr(j,n)
        {
            v[s[j]%i].pb(j);
        }
        fr(j,i)
        {
            int k;
            rep(k,1,sz(v[j]))
            {
                l[v[j][k]+1][i]=v[j][k-1]+1;
            }
        }
    }
    int dp[n+5][n+5],j;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,1,n+1)
    {
        rep(j,1,n+1)
        {
            int la=l[i][j];
            dp[i][j]=(dp[la][j-1]+dp[la][j])%mod;
        }
    }
    int ans=0;
    rep(i,1,n+1)
    {
        ans=(ans+dp[n][i])%mod;
    }
    cout<<ans;
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    //cout<<"Case #"<<cas<<": ";
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define vec vector
#define pii pair<int, int>
using namespace std;

const long long MAXVAL = (long long) 1e18 + 1;
//const long long MOD = 1000000007ll;
const long long MOD = 998244353ll;
const int INF = 1000000001;

long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  //cin >> q;
  while (q-- >0) {
    int h,w;
    cin >> h >> w;
    int k;
    cin >> k;

    vec<vec<int>> dyn(h, vec<int>(w));
    map<pii, char> pre;
    for (int i = 0; i < k; ++i) {
      int x, y;
      cin >> x>> y;
      --x;
      --y;
      char c;
      cin >> c;
      pre[(make_pair(x,y))] = c;
    }
    ll inv3 = poww(3, MOD - 2);
    dyn[0][0] = poww(3, w * h - k);
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (pre.count(make_pair(i, j))) {
          char c = pre[make_pair(i, j)];
          if (c == 'X') {
            if (i < h - 1) {
              dyn[i + 1][j] = (dyn[i + 1][j] + dyn[i][j]) % MOD;
            }
            if (j < w - 1) {
              dyn[i][j + 1] = (dyn[i][j + 1] + dyn[i][j]) % MOD;
            }
          } else if (c == 'D') {
            if (i < h - 1) {
              dyn[i + 1][j] = (dyn[i + 1][j] + dyn[i][j]) % MOD;
            }
          } else {
            if (j < w - 1) {
              dyn[i][j + 1] = (dyn[i][j + 1] + dyn[i][j]) % MOD;
            }
          }
        } else {
            if (i < h - 1) {
              dyn[i + 1][j] = (dyn[i + 1][j] +  2ll * inv3  * dyn[i][j]) % MOD;
            }
            if (j < w - 1) {
              //cout << " I J " << i << " " << j << endl;
              //cout << " inv3 " << inv3 << endl;
              //cout << " dyn i j " << dyn [i][j] << endl;
              dyn[i][j + 1] = (dyn[i][j + 1] + 2ll * inv3 * dyn[i][j]) % MOD;
            }
        }
      }
    }
    cout << dyn[h - 1][w - 1] << "\n";
  }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n";
#define rep(i, a, b) for (int i=a; i<b; i++)
#define pre(i, a, b) for (int i=a; i>=b; i--)

const int MAX_N = 2e5+5;
const int MOD = 1e9 + 7;
const int INF = 1e9;

#define pb push_back
#define fi first
#define se second
#define sz size()
#define bg begin()
#define ed end()
#define bk back()
#define pii pair<int, int>
#define mp map<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define si set<int>

/* #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cout << vars << " = ";
    string delim = "";
    (..., (cout << delim << values, delim = ", "));
} */

int ans = 0;
int parent[MAX_N], siz[MAX_N];

int findParent(int i){
	if(parent[parent[i]]!=parent[i]){
		parent[i] = findParent(parent[i]);
	}

	return parent[i];
}

void unionNodes(int a, int b){
	int parent_a = findParent(a);
	int parent_b = findParent(b);

	if(parent_b==parent_a){
		return;
	}

	ans++;

	if(siz[parent_a]>=siz[parent_b]){
		swap(parent_a,parent_b);
	}

	siz[parent_b] += siz[parent_a];

	parent[parent_a] = parent_b;
	return;
}

void cleardsu(int n){
	rep(i,1,n+1){
		parent[i] = i;
		siz[i] = 1;
	}
}

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

	cleardsu(MAX_N-2);

	vi a(n);

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

	rep(i,0,n){
		int j = n - 1 - i;
		unionNodes(a[i],a[j]);
	}

	cout<<ans;
}

signed main() {
    fast

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

    cout.precision(10);
    cout<<fixed;

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

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

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

using namespace std;
using ll = long long;

struct UnionFind {
    vector<int> par;
    UnionFind (int n) : par(n, -1){}
    int root(int x){
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y){
        x = root(x), y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x,y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int size(int x) {
        return -par[root(x)];
    }
};

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    UnionFind uf(200005);
    for(int i = 0; i < n; i++) uf.unite(a[i], a[n-1-i]);
    int ans = 0;
    for(int i = 0; i < 200005; i++) if(uf.root(i) == i) ans += uf.size(i)-1;
    cout << ans << endl;
    return 0;
}