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

const int maxn = 2e2+8, inf  = 1e18+9, mod  = 998244353;

int n, k, a[maxn][maxn], fac[maxn], fa[maxn], sz[maxn];

int find(int u) { return u == fa[u] ? u : fa[u] = find(fa[u]); }
void solve() {
    int i, j, x, y, ans = 1;
    cin >> n >> k;
    for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) cin >> a[i][j];
    for (fac[1] = 1, i = 2; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod;
    for (i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
    for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) {
        int ok = 1;
        for (x = 1; x <= n; x++) if (a[i][x] + a[j][x] > k) { ok = 0; break; }
        if (ok) {
            int fi = find(i), fj = find(j);
            if (fi != fj) { fa[fi] = fa[fj]; sz[fj] += sz[fi]; }
        }
    }
    for (i = 1; i <= n; i++) if (fa[i] == i) ans = (ans * fac[sz[i]]) % mod;
    for (i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
    for (i = 1; i <= n; i++) for (j = i + 1; j <= n; j++) {
        int ok = 1;
        for (x = 1; x <= n; x++) if (a[x][i] + a[x][j] > k) { ok = 0; break; }
        if (ok) {
            int fi = find(i), fj = find(j);
            if (fi != fj) { fa[fi] = fa[fj]; sz[fj] += sz[fi]; }
        }
    }
    for (i = 1; i <= n; i++) if (fa[i] == i) ans = (ans * fac[sz[i]]) % mod;
    cout << ans << endl;
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15);
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

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

const long long MOD=998244353;
int N, K;

long long modmypower(long long a, long long b){
  if(b==1){
    return a;
  }else if(b%2==0){
    long long c=modmypower(a,b/2);
    return (c*c)%MOD;
  }else{
    long long c=modmypower(a,(b-1)/2);
    return (((c*c)%MOD)*a)%MOD;
  }
}

long long modfactorial(long long x){
  if(x<=1) x=1;
  else for(int i=x-1; i>0; i--) x=((x*i)%MOD);
  return x;
}

long long modinv(long long x){
  return modmypower(x,MOD-2);
}

long long fn(vector<vector<int>>& mat){
  // 交換できる行のグラフをつくる
  vector<vector<int>> g(N, vector<int>());
  for(int i=0; i<N-1; i++){
    for(int j=i+1; j<N; j++){
      bool c=true;
      for(int k=0; k<N; k++) if(mat[i][k]+mat[j][k]>K) c=false;
      if(c){
        g[i].push_back(j);
        g[j].push_back(i);
      }
    }
  }

  long long result=1;

  //連結成分ごとに見る
  vector<int> visited(N, 0);
  for(int i=0; i<N; i++){
    //連結成分を抽出
    if(visited[i]==1) continue;
    visited[i]=1;

    queue<int> q;
    q.emplace(i);

    vector<int> group;
    group.push_back(i);

    while(!q.empty()){
      int a=q.front();
      q.pop();
      for(auto dest:g[a]){
        if(visited[dest]==1) continue;
        visited[dest]=1;
        q.emplace(dest);
        group.push_back(dest);
      }
    }

    //ベクトルが一致するかどうか
    int s=group.size();
    vector<int> d(s, 0);
    for(int j=0; j<s; j++){
      for(int k=0; k<s; k++){
        if(mat[j]==mat[k]) d[j]++;
      }
    }

    map<int, int> dlist;
    for(int j=0; j<s; j++) dlist[d[j]]++;

    long long tmp=modfactorial(s);
    for(auto kv: dlist){
      int k=kv.first;
      int v=kv.second/k;
      if(k==1) continue;
      tmp=(tmp*modinv(modfactorial(v)))%MOD;
    }

    result=(result*tmp)%MOD;
  }

  return result;
}

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

  long long result=fn(A);

  vector<vector<int>> B(N, vector<int>(N));
  for(int i=0; i<N*N; i++) B[i/N][i%N]=A[i%N][i/N];
  result*=fn(B);

  cout << result%MOD << endl;
}


#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;

long long f(long long x)
{
    return x * (x+1)/2 % MOD;
}

void solve()
{
long long a,b,c;
cin >> a >> b >> c;

cout << ((f(a) * f(b))%MOD * f(c))%MOD;

}

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

/*
1
6
1 2 6 5 3 4
*/

#include <bits/stdc++.h>

using namespace std;

long long  a, b, c;

int main() {

    cin >> a >> b >> c;
    if (a * a + b * b < c * c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
#define MOD 1000000007
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<lint, lint>;

lint zero = 0;

lint modpow(lint a, lint n, lint m = Mod){
  lint ans = 1;
  while(n>0){
    if(n%2==1) ans *= a;
    ans %= m;  a *= a;  a %= m;  n /= 2;
  }
  return ans;
}

lint inv(lint a, lint m = Mod){
  return modpow(a, m-2, m);
}

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

vi soinsu(lint n){
  vi primes(0); // 素因数
  vi nums(0); // 指数
  vector<bool> nonzero(n, false);
  lint p=2;  lint m = n;
  while(p*p<=n){
    while(m%p==0){
      if(nonzero[p]){ nums[nums.size()-1]++;  m /= p;}
      else{nonzero[p]=true; primes.PB(p); nums.PB(1); m /= p;}
    }
    p++;
  }
  if(m>1){primes.PB(m); nums.PB(1);}
  return nums; // 適宜必要なものを取り出す
}
  //  cout << fixed << setprecision(12);

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

int main(){
  lint n; cin>>n;
  vi acnt(n,0);
  for(lint i=0; i<n; i++){
    lint a; cin>>a; a--;
    acnt[a]++;
  }
  vi bs(n);
  vi bcnt(n,0);
  for(lint i=0; i<n; i++){
    cin>>bs[i]; bs[i]--;
  }
  for(lint i=0; i<n; i++){
    lint c; cin>>c; c--;
    bcnt[bs[c]]++;
  }
  lint ans = 0;
  for(lint i=0; i<n; i++){
    ans += acnt[i]*bcnt[i];
  }
  cout << ans << endl;
}

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define sz(x) ((int) (x).size())
#define dbg(x) cerr << #x << "->" << x << "\n";

int gcd(int a, int b) {if (b == 0) return a; return gcd(b, a % b);}
int mod = (int)1e9 + 7;

void solve() {
	int n; cin >> n;
	vector<int> a(n), b(n), c(n);
	forn(i, n)cin >> a[i];
	forn(i, n)cin >> b[i];
	forn(i, n)cin >> c[i];
	vector<int> bc;
	forn(i, n) {
		bc.pb(b[c[i] - 1]);
	}
	map<int, int> ma, mb;
	forn(i, n) ma[a[i]]++;
	forn(i, sz(bc)) mb[bc[i]]++;
	int ans = 0;
	for (auto i : ma) {
		ans += i.second * mb[i.first];
	}
	cout << ans;

}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	forn(i, t)
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
typedef std::vector<string> vstr;
typedef std::pair<long long, long long> pll;
#define INF 1999999999
#define INFLL std::numeric_limits<long long>::max()
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errv1(x) cerr << #x <<" "<< x << endl;
#define errv2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errv3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errv4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;

int main() {
  ll H, W;
  cin >> H >> W;
  vvll A(H, vll(W));
  rep(i,H){
    rep(j,W){
      cin >> A[i][j];
    }
  }

  ll mini = INFLL;
  rep(i,H){
    rep(j,W){
      mini = min(mini, A[i][j]);
    }
  }

  ll ans =0;
  rep(i,H){
    rep(j,W){
      ans += A[i][j] - mini;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

long long n, ans, a, b;

int main(){
    n = read();
    for (int i = 1; i <= n; i++)
        a = read(), b = read(), ans += ((a+b) * (b-a+1) / 2);
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long N, std::vector<long long> a, std::vector<long long> b, std::vector<long long> p){
  REP(N){
    if(i!=p[i]&&a[i]<=b[p[i]]){
      cout<<-1<<endl;
      return;
    }
  }
  auto cmp=[&](ll x,ll y){
    if(b[p[x]]>b[p[y]]){
      return true;
    }else if(b[p[x]]<b[p[y]]){
      return false;
    }else{
      return p[x]>p[y];
    }
  };
  set<ll,decltype(cmp)> notyet(cmp);
  REP(N){
    if(i!=p[i]){
      if(i==12660)dump(i);
      notyet.insert(i);
      if(notyet.count(i)==0)abort();
    }
  }
  vector<pll> ans;
  while(!notyet.empty()){
    ll cur1=*(notyet.begin());notyet.erase(cur1);
    if(cur1==12660)dump(cur1);
    ll cur2=p[cur1];
    if(cur2==12660)dump(cur2);
    if(notyet.count(cur2)==0)abort();
    notyet.erase(cur2);
    ans.push_back(pll(cur1,cur2));
    swap(p[cur1],p[cur2]);
    if(cur2!=p[cur2])abort();
    if(p[cur1]!=cur1){
      if(cur1==12660)dump(cur1);
      notyet.insert(cur1);
    }
  }
  REP(N){
    if(p[i]!=i)abort();
  }
  cout<<ans.size()<<endl;
  REP(ans.size()){
    cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
        --p[i];
    }
    solve(N, std::move(a), std::move(b), std::move(p));
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,b,a) for(int i=b;i>=a;i--)
#define efo(i,u,v) for(int i=BB[u],v=B[BB[u]][1];i;v=B[i=B[i][0]][1])
#define mset(a,x) memset(a,x,sizeof(a))
template<typename T> bool chkmin(T &a,const T &b) {return b<a?a=b,1:0;}
template<typename T> bool chkmax(T &a,const T &b) {return b>a?a=b,1:0;}
using namespace std;
typedef long long ll;
typedef double db;
char ch;
int read(){int n=0,p=1;for(ch=getchar();ch<'0' || '9'<ch;ch=getchar())if(ch=='-') p=-1;for(;'0'<=ch && ch<='9';ch=getchar()) n=n*10+ch-'0';return n*p;}
int main()
{
	//freopen("a.in","r",stdin);
	int a,b,x,y;
	a=read(),b=read(),x=read(),y=read();
	y=min(y,x+x);
	int t=a>b?a-b-1:b-a;
	printf("%d\n",t*y+x);
	return 0;
}


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

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 998244353;
const ll INF = (1ll << 60);

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

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

class eratosthenes_sieve
{
private:
    int n;
    vector<int> f;

public:
    vector<int> primes;

    eratosthenes_sieve(int n) : f(n + 1)
    {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++)
        {
            if (!f[i])
            {
                f[i] = i;
                primes.emplace_back(i);
                for (ll j = i * i; j <= n; j += i)
                {
                    if (!f[j])
                    {
                        f[j] = i;
                    }
                }
            }
        }
    }

    map<ll, ll> prime_factor(int x)
    {
        map<ll, ll> res;

        while (x != 1)
        {
            res[f[x]]++;
            x /= f[x];
        }

        return res;
    }
};

class factorial
{
private:
    vector<ll> fac, finv, inv;

public:
    factorial(ll n) : fac(2, 1), finv(2, 1), inv(2, 1)
    {
        for (ll i = 2; i <= n; i++)
        {
            fac.push_back(fac[i - 1] * i % MOD);
            inv.push_back(MOD - inv[MOD % i] * (MOD / i) % MOD);
            finv.push_back(finv[i - 1] * inv[i] % MOD);
        }
    }

    ll comb(ll n, ll k)
    {
        if (n < k || n < 0 || k < 0)
        {
            return 0;
        }

        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    ll perm(ll n, ll k)
    {
        if (n < k || n < 0 || k < 0)
        {
            return 0;
        }

        return fac[n] * finv[n - k] % MOD;
    }
};

int main(void)
{
    ll n, m;
    cin >> n >> m;

    eratosthenes_sieve e(m);
    factorial f(400000);

    ll ans = 0;

    for (ll i = 1; i <= m; i++)
    {
        ll tmp = 1;

        for (auto &&j : e.prime_factor(i))
        {
            tmp *= f.comb(n - 1 + j.second, n - 1) % MOD;
            tmp %= MOD;
        }

        ans += tmp % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}


#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll x, y, z;
    cin>>x>>y>>z;
    if(y%x==0)
    {
        cout<<((y/x)*z)-1<<endl;
    }
    else
    {
        ll low=0, high=(ll)1e8;
        double eps=1.0/1e6;
        ll ans=0;
        ll count=0;
        while(count++<=100)
        {
            ll mid=low+(high-low)/2;
            double hump=(1.0*mid)/z;
            double bump=(1.0*y)/x;
            if(bump-hump>eps)
            {
                ans=mid;
                low=mid;
            }
            else
            {
                high=mid;
            }
        }
        cout<<ans<<endl;
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

#line 1 "A.cpp"
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

#if defined(DONLINE_JUDGE)
	#define NDEBUG
#elif defined(ONLINE_JUDGE)
	#define NDEBUG
#endif

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

int main() {
	int x, y, z; scanf("%d%d%d", &x, &y, &z);

	for(int i = 1e6; i >= 0; i--) {
		if(y * z <= x * i) continue;
		printf("%d\n", i);
		return 0;
	}

	#ifndef NDEBUG
	cout << "test" << endl;
	#endif
	return 0;
}


#pragma GCC optimize("Ofast")
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define mod (int)(1e9+7)
#define mod2 998244353
#define flush fflush(stdout);
#define PI 3.1415926535897932384626433832795

void solve() {
    int n; cin>>n;
    int a[n],b[n];
    for(auto &it:a)
        cin>>it;
    for(auto &it:b)
        cin>>it;
    map<int,int> m;
    for(int i=0;i<n;i++){
        for(int j=min(a[i],b[i]);j<=max(a[i],b[i]);j++)
            m[j]++;
    }
    int ans=0;
    for(auto &it:m){
        if(it.second==n)ans++;
    }
    cout<<ans;
}

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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = 0; i <= (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

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

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

  if (n <= 1) {
    cout << 0 << endl;
    return 0;
  }

  const int M = 200005;

  UnionFind uf(M);
  rep(i,n) uf.unite(a[i], a[n-1-i]);

  int ans = 0;
  rep(i,M) {
    if (uf.find(i) != i) continue;
    ans += uf.size(i) - 1;
  }

  cout << ans << endl;

  return 0;
}


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

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

int main()
{
    ll n,x,ans,i;
   set<ll>s;
    cin>>n;
    for(i=2;i*i<=n;i++)
    {
        x=i*i;
        while(x<=n)
        {
            s.insert(x);
            x=x*i;
        }
    }
    ans=n-s.size();
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

const int N = 2e5+5;
ll bit[N], row[N], col[N];
vector<ll> tt[N];

void update(int pos, int val){
	while(pos < N){
		bit[pos] += val;
		pos += pos&-pos;
	}
}

int query(int pos){
	int res = 0;
	while(pos){
		res += bit[pos];
		pos -= pos&-pos;
	}
	return res;
}

signed main(){
	fastio
	ll h,w,m;
	cin >> h >> w >> m;
	fill(row,row+N,w);
	fill(col,col+N,h);
	while(m--){
		ll x,y;
		cin >> x >> y;
		x--,y--;
		row[x] = min(row[x],y);
		col[y] = min(col[y],x);
		tt[y].push_back(x);
	}
	ll ans = 0;
	for(ll i = 0;i < col[0];i++) ans += row[i];
	ll ok[h];
	fill(ok,ok+h,1);
	for(ll i=col[0];i < h;i++) ok[i] = 0, update(i,1);
	for(ll i = 0;i < row[0];i++){
		for(ll j : tt[i]){
			if(ok[j]) ok[j] = 0, update(j,1);
		}
		ans += query(col[i]-1);
	}
	cout << ans <<endl;;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;

int f(int b,int r,int c){
  return b*500*500+r*500+c;
}

int main(){
  int R,C; cin >> R >> C;
  vvi g(500*500*2);
  vvi co(500*500*2);
  rep(r,R) rep(c,C-1){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r,c+1));
    g[f(0,r,c+1)].pb(f(0,r,c));
    co[f(0,r,c)].pb(in);
    co[f(0,r,c+1)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    int in; cin >> in;
    g[f(0,r,c)].pb(f(0,r+1,c));
    co[f(0,r,c)].pb(in);
  }
  rep(r,R-1) rep(c,C){
    g[f(1,r+1,c)].pb(f(1,r,c));
    co[f(1,r+1,c)].pb(1);
  }
  rep(r,R) rep(c,C){
    g[f(0,r,c)].pb(f(1,r,c));
    co[f(0,r,c)].pb(1);
    g[f(1,r,c)].pb(f(0,r,c));
    co[f(1,r,c)].pb(0);
  }
  vector<int> D(500*500*2, -1);
  vector<bool> used(500*500*2, false);
  priority_queue<pair<int,int>,
                 vector<pair<int,int>>,
                 greater<pair<int,int>>> q;
  q.push({(int)0,f(0,0,0)});
  while(!q.empty()){
    int d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true; D[to] = d;
    rep(i,sz(g[to])){
      int nxt=g[to][i];
      if(D[nxt] != -1 && D[nxt] <= D[to] + co[to][i]) continue;
      q.push({D[to] + co[to][i], nxt});
    }
  }

  int ans = D[f(0,R-1,C-1)];
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())a
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
const int inf = 0x3f3f3f3f;
int mod = 1000000007;
bool remender(ll a , ll b){return a%b;}

void solve(){
	int m , h;
	cin>>m>>h;
	cout<<(h % m != 0 ? "No\n" : "Yes\n");
}

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

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

ll X, Y;
map<ll, ll> mp;

ll solve(ll y) {
	if (mp.count(y) > 0) return mp[y];
	if (y == 1) {
		mp[y] = abs(X-y);
	} else if (y%2 == 1) {
		mp[y] = min(min(abs(X-y), solve((y+1)/2)+2), solve((y-1)/2)+2);
	} else {
		mp[y] = min(abs(X-y), solve(y/2)+1);
	}
	return mp[y];
}

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

	cin >> X >> Y;
	cout << solve(Y) << "\n";
}


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

#include <random>
typedef long double ld;

ll n;
vector<ll> x, y, r;

const ll LIM = 10000 - 1;
const int INF = 1000000000;

struct STATE {
	vector<P> loc;
	vector<P> area;
	ll score;
};

ll calc_score(STATE &state){
	ld score = 0;
	rep(i,n){
		ll R = state.area[i].first * state.area[i].second;
		ld tmp = (ld)(min(r[i], R)) / (ld)(max(r[i], R));
		score += (ld)1 - ((ld)1 - tmp) * ((ld)1 - tmp);
	}
	score *= (ld)(1000000000);
	score = floor(score);
	ll ret = score;
	ret /= n;
	return ret;
}

void isOverlapped(STATE &state, ll j, ll X, ll Y){
	vector<P> now(4);
	now[0] = P(y[j], x[j]);
	now[1] = P(y[j], x[j] + X);
	now[2] = P(y[j] + Y, x[j] + X);
	now[3] = P(y[j] + Y, x[j]);
	rep(i,n){
		if(i == j) continue;
		ll L = x[i];
		ll R = x[i] + state.area[i].second;
		ll U = y[i];
		ll D = y[i] + state.area[i].first;
		bool ok = true;
		rep(k,4){
			if(now[k].first < U) continue;
			if(D < now[k].first) continue;
			if(now[k].second < L) continue;
			if(R < now[k].second) continue;
			ok = false;
			break;
		}
		if(x[j] <= L && R <= x[j] + X && !(D <= y[j]) && !(y[j] + Y <= U)) ok = false;
		if(y[j] <= U && D <= y[j] + Y && !(R <= x[j]) && !(x[j] + X <= L)) ok = false;
		if(!ok){
			state.loc[i] = P(LIM, i);
			state.area[i] = P(1, 1);
		}
	}
	return;
}

void modify(STATE &state){
	std::random_device rnd;
	std:: mt19937 mt(rnd());
	std::uniform_int_distribution<> randN(0,n-1);
	int j = randN(mt);
	std::uniform_int_distribution<> randH(1,r[j]);
	ll h = randH(mt);
	if(y[j] + h > LIM) return;
	ll w = r[j] / h;
	if(x[j] + w > LIM) return;
	isOverlapped(state, j, w, h);
	state.loc[j] = P(y[j], x[j]);
	state.area[j] = P(h, w);
	state.score = calc_score(state);
}

void init(STATE &state){
	state.loc.resize(n);
	state.area.resize(n);
	rep(i,n){
		state.loc[i] = P(LIM, i);
		state.area[i] = P(1, 1);
	}
	state.score = calc_score(state);
}

void solve(){
	std::random_device rnd;
	std:: mt19937 mt(rnd());
	std::uniform_int_distribution<> randINF(1,INF);
	STATE state;
	init(state);
	const ld TL = 4.8;
	const ld start_temp = 1000000000;
	const ld end_temp = 10;
	//int cnt = 0;
	while(true){
		//++cnt;
		ld terminal = (ld)clock() / (ld)CLOCKS_PER_SEC;
		if(terminal >= TL) break;
		STATE new_state = state;
		ll pre_score = state.score;
		modify(new_state);
		ll new_score = new_state.score;
		ld temp = start_temp + (end_temp - start_temp) * terminal / TL;
		ld prob = exp((new_score - pre_score) / temp);
		if(prob > (randINF(mt) % INF)/(double)INF){
			state = new_state;
		}
	}
	rep(i,n){
		ll y = state.loc[i].first;
		ll x = state.loc[i].second;
		ll dy = state.area[i].first;
		ll dx = state.area[i].second;
		cout << x << " " << y << " " << x+dx << " " << y+dy << endl;
	}
	//cout << cnt << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i,n){
		ll X, Y, R;
		cin >> X >> Y >> R;
		x.push_back(X);
		y.push_back(Y);
		r.push_back(R);
	}
	solve();
	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< string > ans;
  ans.emplace_back("AB");
  range(i, 1, n) {
    vector< string > na;
    for (auto &a : ans) {
      auto b = a;
      na.emplace_back(a + b);
      for (auto &c : b) {
        if (c == 'A') c = 'B';
        else c = 'A';
      }
      na.emplace_back(a + b);
    }

    na.emplace_back(string(ans[0].size(), 'A') + string(ans[0].size(), 'B'));
    ans = na;
  }

  cout << ans.size() << endl;
  for (auto &a : ans) cout << a << endl;
}

signed main() {
  solve();
}


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

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

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

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

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

struct P{
    int x, y, r, id;
    P(int x=0, int y=0, int r=0, int id=0) : x(x), y(y), r(r), id(id) {}
    bool operator <(const P& other) const {
        return r < other.r;
    }
};

struct S{
    int a,b,c,d,id;
    S(int a=0, int b=0, int c=0, int d=0, int id=0) :a(a),b(b),c(c),d(d),id(id) {}
};

struct Point {
    int x, y;
    Point(int x=0, int y=0) : x(x),y(y) {}
    bool operator <(const Point& other) const {
        if (y != other.y) return y < other.y;
        return x < other.x;
    }
};

auto solve (int n, V<P>& v) -> V<S> {
    // 面積が小さいほうから見る
    sort(all(v));

    V<S> ret(n);
    set<Point> st;

    // version 1: (x,y), (x+1,y+1)
    rep(i,0,n) {
        ret[i] = S(v[i].x,v[i].y,v[i].x+1,v[i].y+1,v[i].id);
        st.insert(Point(v[i].x,v[i].y));
    }

    // version 2: 横だけに伸ばす
    // => cをできるだけ大きくする
    rep(i,0,n) {
        int c = ret[i].c;
        int d = ret[i].d;
        while (!st.count(Point(c,d-1)) && c < 10000) {
            if (c - ret[i].a >= v[ret[i].id].r) break;
            c++;
        }
        ret[i].c = c;
    }

    return ret;
}

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

    // input
    int n;
    cin >> n;
    V<P> v(n);
    rep(i,0,n) {
        cin >> v[i].x >> v[i].y >> v[i].r;
        v[i].id = i;
    }

    // solve
    auto ans = solve(n, v);

    // output
    V<int> a(n),b(n),c(n),d(n);
    rep(i,0,n) {
        a[ans[i].id] = ans[i].a;
        b[ans[i].id] = ans[i].b;
        c[ans[i].id] = ans[i].c;
        d[ans[i].id] = ans[i].d;
    }
    rep(i,0,n) {
        cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int n; cin >> n; int x[n], y[n], r[n];
REP(i, n){ cin >> x[i] >> y[i] >> r[i]; }
vector<int> X, Y; unordered_map<int, int> kshtX, kshtY;
REP(i, n){
  if(!kshtX[x[i]]){ X.push_back(x[i]); kshtX[x[i]]++; }
  if(!kshtY[y[i]]){ Y.push_back(y[i]); kshtY[y[i]]++; }
}
sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
int xl=X.size(), yl=Y.size();
map<int, vector< pair<int, int> > > onX, onY;
REP(i, n){ onX[x[i]].push_back(make_pair(y[i], i)); onY[y[i]].push_back(make_pair(x[i], i)); }
REP(i, n){ sort(onX[x[i]].begin(), onX[x[i]].end()); sort(onY[y[i]].begin(), onY[y[i]].end()); }

const int cs=2;
int a[cs][n], b[cs][n], c[cs][n], d[cs][n];
REP(k, cs){ REP(i, n){ a[k][i]=x[i]; b[k][i]=y[i]; c[k][i]=x[i]+1; d[k][i]=y[i]+1; } }

int mae=0;
REP(i, xl){
  mae=0;
  REP(j, onX[X[i]].size()){
    int e=0, v=onX[X[i]][j].second;
    b[0][v]=max(d[0][v]-r[v], mae);
    if(j==(int)onX[X[i]].size()-1){ e=10000; }else{ e=b[0][onX[X[i]][j+1].second]; }
    d[0][v]=min(b[0][v]+r[v], e); mae=d[0][v];
  }
}
mae=0;
REP(i, xl){
  int sub=0;
  REP(j, onX[X[i]].size()){
    int e=0, v=onX[X[i]][j].second, h=d[0][v]-b[0][v], w=r[v]/h;
    a[0][v]=max(c[0][v]-w, mae);
    if(i==xl-1){ e=10000; }else{ e=X[i+1]; }
    c[0][v]=min(a[0][v]+w, e); sub=max(sub, c[0][v]);
  }
  mae=max(mae, sub);
}

REP(i, yl){
  mae=0;
  REP(j, onY[Y[i]].size()){
    int e=0, v=onY[Y[i]][j].second;
    a[1][v]=max(c[1][v]-r[v], mae);
    if(j==(int)onY[Y[i]].size()-1){ e=10000; }else{ e=a[1][onY[Y[i]][j+1].second]; }
    c[1][v]=min(a[1][v]+r[v], e); mae=c[1][v];
  }
}
mae=0;
REP(i, yl){
  int sub=0;
  REP(j, onY[Y[i]].size()){
    int e=0, v=onY[Y[i]][j].second, w=c[1][v]-a[1][v], h=r[v]/w;
    b[1][v]=max(d[1][v]-h, mae);
    if(i==yl-1){ e=10000; }else{ e=Y[i+1]; }
    d[1][v]=min(b[1][v]+h, e); sub=max(sub, d[1][v]);
  }
  mae=max(mae, sub);
}

int l=0, ans=0;
REP(k, cs){
  long double s, t, p, q, sc=0;
  REP(i, n){
    s=(d[k][i]-b[k][i])*(c[k][i]-a[k][i]); t=r[i]; q=min(s, t)/max(s, t); p=1-(1-q)*(1-q);
    sc+=(1e9*p)/n;
  }
  if(ans<round(sc)){ ans=round(sc); l=k; }
}
REP(i, n){ cout << a[l][i] << " " << b[l][i] << " " << c[l][i] << " " << d[l][i] << "\n"; }

}


// omae wa mou shindeiru

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define float           double
#define ll              long long
#define int             long long
#define pb              push_back
#define ppb             pop_back
#define pf              push_front
#define ppf             pop_front
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define uniq(v)         (v).erase(unique(all(v)),(v).end())
#define endl            "\n"

#define pii             pair<int,int>
#define pll             pair<ll, ll>
#define vi              vector<int>
#define vl              vector<ll>
#define vpii            vector<pii>
#define vpll            vector<pll>
#define vvi             vector<vi>
#define vvl             vector<vl>

#define rep(i,a,b)      for(int i=a;i<b;i++)
#define tr(it, l)       for(auto it = l.begin(); it != l.end(); it++)
#define max(a, b)       ((a < b) ? b : a)
#define min(a, b)       ((a > b) ? b : a)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mem1(a)         memset(a,-1,sizeof(a))
#define mem0(a)         memset(a,0,sizeof(a))
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)

#define PI              3.1415926535897932384626433832795
#define eps             1e-9
#define mod             1000000007
#define inf             1e18

mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T, typename T1>T amax(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T amin(T &a, T1 b) {if (b < a)a = b; return a;}
template<typename T>
using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;

void runtime()
{
    int n,q;
    cin >> n >> q;
    vi a(n+1);
    rep(i,1,n+1)
    cin >> a[i];
    vi pre(n+1);
    pre[1] = a[1] - 1;
    for(int i=2;i<=n;i++)
    {
        pre[i] = pre[i-1] + (a[i]-a[i-1]-1);
    }
    while(q--)
    {
        int k;
        cin >> k;
        int p = lower_bound(all(pre),k) - pre.begin();
        // cout << p << " ";
        int s = k - pre[p-1];;
        cout << a[p-1] + s<<endl;

    }

}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int TESTS = 1; // one input
    // cin >> TESTS;
    while (TESTS--) {
        runtime();
        cout << "\n";
    }
    return 0;
}

/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi>
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll ceil(const ll &a, const ll &b)
{
    if(a%b == 0)
        return a/b;
    return a/b +1;
}
ll mod=1000000007;
const ll N=100005;
int main()
{
fast;
    ll n,m;
    cin>>n>>m;
    char s[n][m];
    f(i,n)
    {
        f(j,m)
        {
            cin>>s[i][j];
        }
    }
    ll ans=0;
    f(i,n)
    {
        f(j,m)
        {
            if(s[i][j]=='.')
            {
                if(j==m-1 && i==n-1)
                {
                    continue;
                }
                else if(j==m-1)
                {
                    if(s[i+1][j]=='.')
                        ans++;
                }
                else if(i==n-1)
                {
                    if(s[i][j+1]=='.')
                        ans++;
                }
                else
                {
                    if(s[i+1][j]=='.')
                        ans++;
                    if(s[i][j+1]=='.')
                        ans++;
                }
            }
        }
    }
    cout<<ans;
    return 0;
}


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int v, t, s, d;

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> v >> t >> s >> d;
    if(v * t > d || v * s < d)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
/**

// probati bojenje sahovski ili slicno

**/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    ll X,Y;
    cin>>X>>Y;
    if(ABS(X-Y)<3) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


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

# define endl "\n"
# define io_boost std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef unsigned long long int ulli;
typedef long long int lli;
typedef unsigned int ui;

int N, K, m[805][805], bm[805][805], s[805][805];

int query(int a, int b, int c, int d){
    int res = s[c][d];
    if(a > 0) res -= s[a - 1][d];
    if(b > 0) res -= s[c][b - 1];
    if(a > 0 && b > 0) res += s[a - 1][b - 1];
    return res;
}

int get_sum(int mid){
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(m[i][j] <= mid) bm[i][j] = 1;
            else bm[i][j] = 0;
            if(i == 0) s[i][j] = bm[i][j];
        }
    }
    for(int i = 0; i < N; i++)
        for(int j = 1; j < N; j++)
            s[j][i] = s[j - 1][i] + bm[j][i];
    for(int i = 1; i < N; i++)
        for(int j = 0; j < N; j++)
            s[j][i] += s[j][i - 1];
    int maxi = 0;
    for(int i = 0; i + K - 1 < N; i++)
        for(int j = 0; j + K - 1 < N; j++){
            //cout << query(i, j, i + K - 1, j + K - 1) << endl;
            maxi = max(query(i, j, i + K - 1, j + K - 1), maxi);
        }
    return maxi;
}

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            cin >> m[i][j];
    get_sum(0);
    int lo = 0, hi = 1e9 + 5;
    while(lo < hi){
        int mid = (lo + hi) / 2;
        int sum = get_sum(mid);
        //cout << mid << " " << sum << endl;
        if(sum < (K * K + 1) / 2) lo = mid + 1;
        else hi = mid;
    }
    cout << lo << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll>vec;
vector<ll>ans;
int main()
{
    ll a,b,c,d,e,i,j,k,l,n,m,x,y,t,p;
    cin>>n>>m;
    if(m==0)
    {
        printf("1\n");
        return 0;
    }
    x=n;
    for(i=0;i<m;i++)
    {
        cin>>a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    if(vec[0]!=1)
    {
        ans.push_back(vec[0]-1);
        x=min(x,vec[0]-1);
    }
    if(vec[m-1]!=n)
    {
        ans.push_back(n-vec[m-1]);
        x=min(x,n-vec[m-1]);
    }
    for(i=1;i<m;i++)
    {
        a=vec[i]-vec[i-1];
        a--;
        if(a>0)
        {
            ans.push_back(a);
        x=min(x,a);
        }
    }
    l=ans.size();
    y=0;
    //cout<<x<<endl;
    for(i=0;i<l;i++)
    {
        a=ans[i];
        //cout<<"aa: "<<a<<endl;
        c=a/x;
        if(a%x!=0)
        {
            c++;
        }
        y+=c;
    }
    cout<<y<<endl;
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    if (N == 0) {
        cout << "Yes\n";
        return 0;
    }
    while (N % 10 == 0) N /= 10;
    string S = to_string(N), ans = "Yes\n";
    int l = S.size();
    rep(i, l) if (S[i] != S[l - 1 - i]) ans = "No\n";
    cout << ans;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll K;

int main(){
    cin>>K;

    ll ans=0;
    repn(i,K){
        repn(j,K/i){
            ans+=K/(i*j);
        }
    }

    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;}
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;}

// s.top().second;

signed main()
 {

       run;

/*
open for mod factorial

     fac[0]=1;
       for(int i=1;i<100009;i++)
      {
         fac[i]=fac[i-1]*i;
          fac[i]%=mod;
      }
 */

/*
for sieve open this and use v_prime

       int pp=pow(10,6)+100000;
          Sieve(pp);

*/

 // USE v_factor For calculating factors

int  t=1;
 //cin>>t;
 while(t--)
{
         // vector< pair <int,int> > vp;
        //  map<int,int>mp; // x.second-->frequency
       //   set<int>st;

          int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
          int  h[100009]={0};

                cin>>n>>k;
                if(k==0)
                {
                    cout<<n<<endl;
                    return 0;
                }
                string s=to_string(n);
                sort(all(s));
                x=stoi(s);
                //cout<<x<
                reverse(all(s));
                y=stoi(s);
                vector<int>a(k+2,0);

                for(i=1;i<=k;i++)
                {

                        a[i]=y-x;

                         string s1=to_string(a[i]);
                sort(all(s1));
                x=stoi(s1);
                reverse(all(s1));
                y=stoi(s1);

                }
                cout<<a[k]<<endl;

}
}

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<long double, long double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const int modd = 1000000007;
const long long modl = 1000000007LL;
const long long mod = 998244353LL;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main(){
    int n; cin >> n;
    ll w; cin >> w;
    vector<vector<ll>> ar(n,vector<ll>(3));
    rep(i,n) rep(j,3) cin >> ar[i][j];
    vector<ll> imo(200010,0LL);
    rep(i,n){
        imo[ar[i][0]] += ar[i][2];
        imo[ar[i][1]] -= ar[i][2];
    }
    bool t = true;
    ll rui = 0LL;
    rep(i,200010){
        rui += imo[i];
        if (rui > w) t = false;
    }
    if (t) yes();
    else no();
}


#include <iostream>

int main() {
  int x, y, z;
  std::cin >> x >> y;
  if (x == y) z = x;
  else z = 3 - x - y;
  std::cout << z << std::endl;
  return 0;
}

#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#define ll long long
#define pb push_back
#define forn(i,x,n) for(int i=x;i<=n;++i)
#define forr(i,x,n) for(int i=n;i>=x;--i)
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
	int x,y;
	cin>>x>>y;
	if(x==y)
	  cout<<x<<endl;
	else cout<<3-x-y<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod = 1e9 + 7;
const ll maxn = 5e6 + 5;
#define endl '\n'
#define ld long double
#define int ll
#define all(x)  (x).begin(),(x).end()
const ll md = (ll) 1e9 + 7;

inline ll add(ll a, ll b) {
  a += b;
  if (a >= md) a -= md;
  return a;
}

inline ll sub(ll a, ll b) {
  a -= b;
  if (a < 0) a += md;
  return a;
}

inline ll mul(ll a, ll b) {
  return (ll) ((long long)((a%md) * (b%md)) % md);
}

inline ll power(ll a, long long b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline ll inv(ll a) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

vector<int> fact(maxn+5);
void init (int n)
{
  fact[0] = 1;
  for(int i = 1;i<=n;i++)
  {
    fact[i] = mul(i,fact[i-1]);
  }
}
int nck(int n,int k)
{
  return mul(fact[n],mul(inv(fact[k]),inv(fact[n-k])));
}

int32_t main(){

  IOS

  init(5000000);

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

  if(m < 0){
    cout << 0 << endl;
    return 0;
  }

  int num = k - 1 + m;
  int den = k - 1;
  int ans = 1;
  for(int i = 0;i<den;i++){
    ans = mul(ans, num - i);
  }

  ans = mul(ans, inv(fact[den]));

  cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

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

  ll a, b, ans;
  cin >> a >> b;
  if(a+b >= 15 && b >= 8) ans = 1;
  else if(a+b >= 10 && b >= 3) ans = 2;
  else if(a+b >= 3) ans = 3;
  else ans = 4;
  cout << ans << newl;
  return 0;
}


#include<bits/stdc++.h>
#define pu push
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=1;i<=x;i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define BITSC(x,v) (binary_search(x.begin(),x.end(),v)
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
const double eps =1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main(){
    int n,m,k;cin>>n>>m;
    vi a(m);
    vi kukan;
    ll ans=0;

    if(m!=0){
        rep(i,m){
            int temp;cin>>temp;
            temp--;
            a[i]=temp;
        }
        sort(rng(a));
        if(a[0]==0)k=n+20;
        else {
            k=a[0];
            kukan.pb(a[0]);
        }
        rep(i,m-1){
            if(a[i+1]-a[i]==1)continue;
            k=min(k,a[i+1]-a[i]-1);
            kukan.pb(a[i+1]-a[i]-1);
        }
        if(n-1-a[m-1]>0){
            k=min(k,n-1-a[m-1]);
            kukan.pb(n-1-a[m-1]);
        }

        rep(i,kukan.size()){
            ans+=dup(kukan[i],k);
        }
    }

    if(k==n+20)ans=0;
    if(m==0)ans=1;
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, x, y; cin >> h >> w >> x >> y;
  x--; y--;
  vector<string> S(h); rep(i, h) cin >> S[i];
  int ans = 1;
  for(int i=x+1; i<h; i++) {
    if(S[i][y] == '#') break;
    ans++;
  }
  for(int i=x-1; i>=0; i--) {
    if(S[i][y] == '#') break;
    ans++;
  }
  for(int j=y+1; j<w; j++) {
    if(S[x][j] == '#') break;
    ans++;
  }
  for(int j=y-1; j>=0; j--) {
    if(S[x][j] == '#') break;
    ans++;
  }
  cout << ans << endk;
  return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define si short int
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pill pair<ll,ll>
#define f first
#define s second
#define pilc pair<ll,char>
#define all(a) (a).begin(),(a).end()
#define rep(s,e,step) for(int i = (s); i < (e) ; i += step)
#define vrep(s,e,step) for(int j = (s); j < (e) ; j += step)
#define ex exit(0)
#define sz(a) (ll)(a).size()
#define triple pair<pill, ll>
#define pinode pair<node*, node*>
#define quadra pair<pill, pill>
#define ld long double
using namespace std;

const ll N = 500 + 10;
const ll M = 1e14;
const ll big = 1e14;
const ll hsh2 = 1964325029 ;
const long long mod = 1e9 + 7;
const long double EPS = 1e-20;
const ll block = 500;
const ll shift = 2e3;
const ld pi = acos(-1.0);

ll n, m;
vector<int> g[N];
ll ans = 0;
ll glo = 1;
ll c[N];
vector<ll> cmp;

void solve(int pos) {
	if(pos == cmp.size()) {
	    ans++;
		return;
	}
	bool can[4] = {0};
	for(auto u : g[cmp[pos]]) {
		if(u > cmp[pos])
			break;
    	can[c[u]] = 1;
    }
    if(!can[1])
    	c[cmp[pos]] = 1,
    	solve(pos + 1);
    if(!can[2])
    	c[cmp[pos]] = 2,
    	solve(pos + 1);
    if(!can[3])
    	c[cmp[pos]] = 3,
    	solve(pos + 1);
    c[cmp[pos]] = 0;
}

bool us[N];

void dfs(ll v) {
	us[v] = 1;
	for(auto u : g[v])
		if(!us[u])dfs(u);
	cmp.pb(v);
}

int main() {
	speed;
	cin >> n >> m;
	for(int i = 1; i <= m; i++) {
		ll a, b;
		cin >> a >> b;
		g[b].pb(a);
		g[a].pb(b);
	}
	for(int i = 1; i <= n; i++)
		sort(all(g[i]));
	for(int i = 1; i <= n; i++) {
		if(!us[i]) {
			dfs(i);
			sort(all(cmp));
			cmp.erase(unique(all(cmp)), cmp.end());
			solve(0);
			glo = glo * ans;
			ans = 0;
			cmp.clear();
		}
	}
	cout << glo;
}
/*
4
4 6 1 9
2 5 3 2
*/

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

using ll = long long int;
using P = pair<int, int>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
#define endl '\n'
const int INF = 1001001001;
const ll mod = 1000000007;
const ll INFL = 10000000010000000;

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h); rep(i,h) cin >> s[i];
    int sx, sy, gx, gy;
    vector<pair<int, int>> tp[26];
    rep(i,h) rep(j,w) {
        if (s[i][j] == 'S') {
            sx = i;
            sy = j;
        }
        else if (s[i][j] == 'G') {
            gx = i;
            gy = j;
        }
        int d = s[i][j]-'a';
        if (0 <= d && d <= 25) tp[d].push_back({i, j});
    }

    vector<vector<int>> dist(h, vector<int>(w, INF));
    vector<pair<int,int>> dxdy = {{1,0}, {0,1}, {-1,0}, {0,-1}};
    queue<pair<int,int>> que;
    dist[sx][sy] = 0;
    que.push({sx, sy});

    while (que.size()) {
        pair<int,int> p = que.front(); que.pop();
        int cx = p.first, cy = p.second;
        for (int i = 0; i < 4; i++) {
            int nx = cx+dxdy[i].first, ny = cy+dxdy[i].second;
            if (!(0 <= nx && nx < h && 0 <= ny && ny < w)) continue;
            if (s[nx][ny] == '#') continue;
            if (dist[nx][ny] == INF) {
                dist[nx][ny] = dist[cx][cy]+1;
                que.push({nx, ny});
            }
        }
        int d = s[cx][cy]-'a';
        if (d < 0 || 25 < d) continue;
        for (auto pn : tp[d]) {
            if (dist[pn.first][pn.second] == INF) {
                dist[pn.first][pn.second] = dist[cx][cy]+1;
                que.push({pn.first, pn.second});
            }
        }
        tp[d].clear();
    }
    if (dist[gx][gy] == INF) puts("-1");
    else cout << dist[gx][gy] << endl;
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>

using ll = long long;
#define fast_io                                                                                \
    ios::sync_with_stdio(false);                                                                                \
    cin.tie(0)

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

void solve(ll t) {
	ll a,b,c;
	cin >> a>>b>>c;
	ll ans = 0;

	if (a * a + b * b < c * c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	//cout << ans << endl;

}

int main(void)
{
	ll t = 0;
	//cin >> t; for (ll i = 1; i <= t; i++) {solve(i);}
	solve(t);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;

void solve(){
  double n,D,H;
cin >> n >> D >> H;
vector<double> d(n),h(n);
double ans = INF;
rep(i,n){
  cin >> d[i] >> h[i];
  chmin(ans,(H-h[i])/(D-d[i]));
}
double aa = H-ans*(D);
if(aa<=0)aa = 0;
cout << aa << endl;
    return;
}

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

  solve();
    return 0;
}


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

using namespace std;

#define R (long long)(1e9 + 7)

string s;

bool valid(int a, int b, int c, int d) {
	return (s[a] != 'x' && s[b] != 'x' && s[c] != 'x' && s[d] != 'x');
}

int main() {
	cin >> s;
	set<int> definite;
	for(int i = 0; i < 10; i++) {
		if(s[i] == 'o')
			definite.insert(i);
	}
	set<vector<int>> ans;
	for(int a = 0; a < 10; a++) {
		for(int b = 0; b < 10; b++) {
			for(int c = 0; c < 10; c++) {
				for(int d = 0; d < 10; d++) {
					if(valid(a, b, c, d)) {
						set<int> temp = definite;
						temp.erase(a);
						temp.erase(b);
						temp.erase(c);
						temp.erase(d);
						if(temp.empty())
							ans.insert({a, b, c, d});
					}
				}
			}
		}
	}
	cout << ans.size() << '\n';
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	string s;
	cin >> s;
	int a = 0, b = 0, c = 0;
	for (int i=0; i<s.size(); i++) {
		if (s[i] == 'o') a++;
		if (s[i] == 'x') b++;
		if (s[i] == '?') c++;
	}
	if (a > 4) {
		cout << 0 << '\n';
		return 0;
	}

	int res = 0;
	for (int p=0; p<10000; p++) {
		vec<bool> use(10);
		for (int x=p, i=0; i<4; i++, x/=10) {
			use[x%10] = 1;
		}
		bool poss = 1;
		for (int i=0; i<10; i++) {
			if (s[i] == 'o' && !use[i]) poss = 0;
			if (s[i] == 'x' && use[i]) poss = 0;
		}
		res += poss;
	}
	cout << res << '\n';
}


#include <bits/stdc++.h>
#define LL long long

using namespace std;

int a1, a2, a3;

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> a1 >> a2 >> a3;
  cout << (a1 - a2 == a2 - a3 || a1 - a3 == a3 - a2 || a2 - a1 == a1 - a3 || a2 - a3 == a3 - a1 || a3 - a1 == a1 - a2 || a3 - a2 == a2 - a1 ? "Yes" : "No") << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  vector<int> a(3);
  REP(i, 3) cin >> a[i];
  SORT(a);
  if (a[2] - a[1] == a[1] - a[0]) cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


#include<bits/stdc++.h>
#define PI 3.141592653589793238462
#define eps 1e-20
#define fi first
#define se second
using namespace std;
using cd = complex<double>;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdd;
int main(){
    ll n,ans=2e18;cin>>n;
    for(ll i=0;i<=60;i++){
        ll v=((ll)1<<i);
        ll a=n/v,c=n%v;
        ans=min(ans,a+c+i);
    }
    cout<<ans<<endl;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
using ll = long long;
using Graph = vector<vector<int> >;
using P = pair<int, int>;
#define INF 2000000000

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


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ri register int
#define ll long long
#define ui unsigned int
il ll read(){
    bool f=true;ll x=0;
    register char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();}
    while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
    if(f) return x;
    return ~(--x);
}
il int read(char *s){
    int len=0;
    register char ch=getchar();
    while(ch==' '||ch=='\n') ch=getchar();
    while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar();
    return len;
}
il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');}
il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');}
il ll max(const ll &a,const ll &b){return a>b?a:b;}
il ll min(const ll &a,const ll &b){return a<b?a:b;}
ll n,ans;
struct hmap{
    static const int P=2e6+3,M=3e6+10;
    int hed[M],nxt[M],cnt;ll val[M];ll as[M];
    bool count(ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return 1;
            c=nxt[c];
        }return 0;
    }
    ll& operator [](ll x){
        int c=hed[x%P];
        while(c){
            if(val[c]==x) return as[c];
            c=nxt[c];
        }
        ++cnt;val[cnt]=x;nxt[cnt]=hed[x%P];hed[x%P]=cnt;
        return as[cnt];
    }
    int size(){return cnt;}
}M;
int main(){
    ans=n=read();
    for(ll i=2;i*i<=n;++i){
        ll res=i*i;
        while(res<=n){
            if(!M[res]) M[res]=1,--ans;
            res*=i;
        }
    }
    print(ans);
    return 0;
}

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
#define ll long long
#define int long long
//#define double long double
#define eps 1e-8
//#define mod 1e9+7
using namespace std;
const int mod=1e9+7;
const int M=2e3+5;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
int prime[N],v[N];
int ans;
map < int , bool > mp;
signed main()
{
//	ios::sync_with_stdio(false);
	cin>>n;
	m=sqrt(n);
	for(int i=1;i<=m;i++)
	{
		if(mp[i])  continue;
		int j=i;
		mp[i]=1;
		if(i==1)  continue;
		while(j<=n)
		{
			j=i*j;
			if(j>n)  break;
			ans++;
			mp[j]=1;
		}
	}
	cout<<n-ans;
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define INF 1<<30
#define all(x) x.begin(),x.end()
#define ms(a,v) memset(a,v,sizeof a)
#define II ({int a; scanf("%d", &a); a;})
#define LL  ({ll  a; scanf("%lld", &a); a;})
#define EPS 1e-10
#define pi acos(0.0)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<int> vi ;
typedef vector<ll> vl;

#define FOR(i,n) for( __typeof(n)i = 0 ; i < n ; i++)
#define FORL(i,a, b) for( __typeof(a)i = a ; i <= b ; i++)
#define FORR(i,a, b) for( __typeof(a)i = a ; i >= b ; i--)
#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++)
#define forstl(i,n) for(__typeof(n.begin())i = n.begin();i!=n.end();i++)
#define forab(i,a,b) for( __typeof(b) i = a ; i <= (b) ; i++ )
#define forba(i,b,a) for( __typeof(b) i = b ; i >= (a) ; i-- )
#define sz(v)               ((int)((v).size()))
const ll OO = 1e8;

int x[4] = {0 , 0 , -1, 1};
int y[4] = {1, -1, 0  , 0};

ll dp[3005][3005];

ll count(ll n , ll k)
{
    if (k < 0 || n < k) return 0LL;

    if (n <= 0 || k <= 0)
    {
        if (n == 0 && k == 0)
        {
            return 1LL;
        }
        return 0LL;
    }

    if (dp[n][k] >= 0)
        return dp[n][k];

    dp[n][k] = (count(n - 1, k - 1) + count(n , 2 * k) ) % 998244353LL;
    return (dp[n][k]);
}

void solve()
{
    ll n, k;
    cin >> n >> k;

    FOR(i, n + 3)
    {
        FOR(j, n + 3)
        {
            dp[i][j] = -1;
        }
    }
    cout << count(n, k) << endl;
}

int main()
{

    int T = 1;
    //cin >> T;
    // cin.ignore(); must be there when using getline(cin, s)

    //freopen("input.txt", "r", stdin);

    // Printing the Output to output.txt file
    //freopen("output.txt", "w", stdout);

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

    return 0;
}

#include <bits/stdc++.h>

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
using ll = long long;
using namespace std;
const double PI = acos(-1);
// const int M = 1000000007;
const int M = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k, int m = M) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2, m);
  ax = mod(ax * ax, m);
  if (k % 2) ax = mod(ax * n, m);
  return ax;
}

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

int dp[3123][3123];

//#define MULTIPLE_TEST_CASE
void solution() {
  int n, k;
  cin >> n >> k;
  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 1; j--) {
      dp[i][j] = dp[i - 1][j - 1] + (2 * j <= n ? dp[i][2 * j] : 0);
      dp[i][j] = mod(dp[i][j]);
      // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
    }
  }
  cout << dp[n][k] << endl;
}

int32_t main() {
  DESYNC;
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define F(i,a,b) for(i=a;i<b;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781641;
const ll M=1e16;
const ll MAXN=200200;
ll i,j,mask;
void solve()
{
   ll x,y;
   cin>>x>>y;
   if(x>=y)
   {
       cout<<x-y;
       return ;
   }
   queue<ll> q;
   q.push(y);
   ll lvl=-1;
   ll ans=y-x;
   set<ll> st;
   st.insert(y);
   while(!q.empty())
   {
       lvl++;
       if(lvl>=ans)break;
       ll s=q.size();
       F(i,0,s)
       {
           ll p=q.front();
           q.pop();
           if(p<=x)
           {
               ans=min(ans,lvl+x-p);
           }
           else
           {
               ans=min(ans,lvl+p-x);
               if(p%2)
               {
                   if(st.count(p+1)==0)
                   {st.insert(p+1);q.push(p+1);}
                   if(st.count(p-1)==0)
                   {st.insert(p-1);q.push(p-1);}
               }
               else
               {
                   if(st.count(p/2)==0)
                   {st.insert(p/2);q.push(p/2);}
               }
           }
       }
   }
   cout<<ans;
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#*/
/*ll t,test;
cin>>test;
F(t,1,test+1)
{
    //cout<<"Case #"<<t<<": ";
    solve();
    nl
}*/
solve();
return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=2005;

int vis[N + 100][N + 100];

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

void solve(){
	int h,w;
	cin >> h >> w;
	string s[h];

	int x,y;

	vector<pii> v[26];

	for(int i = 0; i < h; i++){
		cin >> s[i];
		for(int j = 0; j < w; j++){
			if(s[i][j] == 'S'){
				x = i;
				y = j;
			}
			if(s[i][j] >= 'a' && s[i][j] <= 'z'){
				v[s[i][j] - 'a'].pb({i,j});
			}
		}
	}

	set<pair<int, pii>> q;
	q.insert({0,{x,y}});

	while(!q.empty()){
		auto tmp = *q.begin();
		q.erase(tmp);
		int X = tmp.sc.fr, Y = tmp.sc.sc;
		if(X == N+5){
			if(vis[X][Y]){
				continue;
			}
			vis[X][Y] = 1;
			// we are on a character
			for(pii z:v[Y]){
				q.insert({tmp.fr+1,z});
			}
			continue;
		}
		if(X < 0 || Y < 0 || X >= h || Y >= w || vis[X][Y] || s[X][Y] == '#'){
			continue;
		}
		vis[X][Y] = 1;
		if(s[X][Y] == 'G'){
			cout << tmp.fr / 2;
			return;
		}

		for(int i = 0; i < 4; i++){
			q.insert({tmp.fr + 2, {X+dx[i], Y+dy[i]}});
		}
		if(s[X][Y] >= 'a' && s[X][Y] <= 'z'){
			q.insert({tmp.fr+1,{N+5,s[X][Y] - 'a'}});
		}
	}

	cout << -1;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

/**templates**/
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sull(x) scanf("%llu",&x)
#define sf(x) scanf("%lf",&x)
#define ss(x) scanf(" %s",x)
#define sc(x) scanf(" %c",&x)
#define pi acos(-1.0)
#define pb push_back
#define aa first
#define bb second
#define sz(x) (ll)(x).size()
#define cas printf("Case %lld: ",++t)
#define casline printf("Case %lld:\n",++t)
//#define cas cout<<"Case "<<++t<<": "
//#define casline cout<<"Case "<<++t<<":"<<endl;
#define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
#define endl "\n"
#define bug cout<<"bugggggggggggg "<<endl;
#define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf
#define clean fflush(stdout)

const ll mod = 1000000007;
const ll inf = 1LL<<62;
const ll mx = 100005;
const double eps = 1e-10;

ll dx[10]={1,0,-1,0};
ll dy[10]={0,-1,0,1};
///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction
///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction

ll power(ll a,ll b)
{
    if(b==0)return 1;
    ll x=power(a,b/2);
    x=x*x;
    if(b%2)x=x*a;
    return x;
}

ll bigmod(ll a,ll b)
{
    if(b==0)return 1;
    ll x=bigmod(a,b/2)%mod;
    x=(x*x)%mod;
    if(b%2)x=(x*a)%mod;
    return x;
}

ll Set(ll N,ll pos){return N=N | (1LL<<pos);}
ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);}
bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));}

/**
        ...ENDING OF TEMPLATE...
*/

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

int main()
{
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    fast; ///no printf/scanf
    /** Use "long double"(%Lf) instead of double for precision safety*/
    ll tst,a,b,c,k,s,n,m,mm,res=0,ans=0,t=0;
    sl(tst);
    while(tst--)
    {
        sl(n),sl(s),sl(k);
        c=__gcd(k,n);
        if(c!=1)
        {
            if(s%c)
            {
                cout<<-1<<endl;
                continue;
            }
        }
        s/=c;
        n/=c;
        k/=c;
        egcd(k,n,res,ans);
        if(res<0)
            res+=n;
        res=(res*(n-s))%n;
        cout<<res<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
  pair<lli,lli>,
  null_type,
  less<pair<lli,lli>>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
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) {lli f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
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(abs(a), abs(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;
}
void solve(){
    lli n,s,k;
    cin>>n>>s>>k;
    lli x,y,g;
    g = __gcd(n,s);
    if(find_any_solution(n,-k,s,x,y,g)){
       // debug(y,n/g);
        cout<<(y%(n/g)+(n/g))%(n/g)<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }
}
int main(){
    /* freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout); */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /*  for(lli i = 1; i<MAX-5; i++){
        fact[i] = i*fact[i-1]%MOD;
        invfact[i] = binpow(fact[i],MOD-2);
    } */
    lli t;
    t = 1;
    cin>>t;
    while(t--)
        solve();
}


#include <bits/stdc++.h>

using namespace std;

template <int MOD=998'244'353>
struct Modular {
  int value;
  static const int MOD_value = MOD;

  Modular(long long v = 0) { value = v % MOD; if (value < 0) value += MOD;}
  Modular(long long a, long long b) : value(0){ *this += a; *this /= b;}

  Modular& operator+=(Modular const& b) {value += b.value; if (value >= MOD) value -= MOD; return *this;}
  Modular& operator-=(Modular const& b) {value -= b.value; if (value < 0) value += MOD;return *this;}
  Modular& operator*=(Modular const& b) {value = (long long)value * b.value % MOD;return *this;}

  friend Modular mexp(Modular a, long long e) {
    Modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
    return res;
  }
  friend Modular inverse(Modular a) { return mexp(a, MOD - 2); }

  Modular& operator/=(Modular const& b) { return *this *= inverse(b); }
  friend Modular operator+(Modular a, Modular const b) { return a += b; }
  friend Modular operator-(Modular a, Modular const b) { return a -= b; }
  friend Modular operator-(Modular const a) { return 0 - a; }
  friend Modular operator*(Modular a, Modular const b) { return a *= b; }
  friend Modular operator/(Modular a, Modular const b) { return a /= b; }
  friend std::ostream& operator<<(std::ostream& os, Modular const& a) {return os << a.value;}
  friend bool operator==(Modular const& a, Modular const& b) {return a.value == b.value;}
  friend bool operator!=(Modular const& a, Modular const& b) {return a.value != b.value;}
};

int main(){
    Modular<998244353> a, b, c, ans;
    int a1, b1, c1;
    cin >> a1 >> b1 >> c1;
    a = a1; b = b1; c = c1;
    ans = (a * (a + 1))/2 * (b * (b + 1))/2 * (c * (c + 1))/2;
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
    while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 1e5 + 5;

int a[N], b[N], f[2][N];
int n, len[2];
ll ans;

int main() {
    memset(f, -0x3f, sizeof(f));
    read(n);
    for (int i = 1; i <= n; i++) read(a[i]), ans += a[i];
    for (int i = 1; i <= n; i++) read(b[i]), b[i] -= a[i];
    for (int i = 1; i <= n; i++) f[i & 1][++len[i & 1]] = b[i];
    sort(f[0] + 1, f[0] + len[0] + 1); reverse(f[0] + 1, f[0] + len[0] + 1);
    sort(f[1] + 1, f[1] + len[1] + 1); reverse(f[1] + 1, f[1] + len[1] + 1);
    for (int i = 1; i <= n / 2; i++) {
        if (f[0][i] + f[1][i] < 0) break;
        ans += f[0][i] + f[1][i];
    }
    print(ans, '\n');
    return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define loop(i, n) for (int i = 0; i < n; ++i)
#define read(a, n) loop($, n) cin >> a[$];
#define show(a, n)                  \
    loop($, n) cout << a[$] << " "; \
    cout << endl;

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

/*	// RANDOM NUMBER GENERATOR
// rng() generates u.a.r. from [0, 2^32 - 1]
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/

/* // TIME
auto start = chrono::high_resolution_clock::now();
// ...
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
cout << duration.count() << endl;
*/

struct con{
    ull d, k, t;
};

void dijkstra(int n, int s, vector<con> G[], ll d[]){
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > H;
    H.push({0, s});
    while(n && !H.empty()){
        int v = H.top().s;
        ll t = H.top().f;
        H.pop();
        if(d[v] == -1){
            --n;
            d[v] = t;
            for(con c : G[v]){
                if(d[c.d] == -1){
                    H.push({t + (c.k - t % c.k) % c.k + c.t, c.d});
                }
            }
        }
    }
}

int main(){
	/*	// IO
	ios_base::sync_with_stdio(false);	// unsync C- and C++-streams (stdio, iostream)
	cin.tie(NULL);	// untie cin from cout (no automatic flush before read)
	*/
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s; --t;
    vector<con> G[n];
    loop(i, m){
        int u, v, l, k;
        cin >> u >> v >> l >> k;
        G[u - 1].push_back({v - 1, k, l});
        G[v - 1].push_back({u - 1, k, l});
    }
    ll d[n];
    loop(i, n){
        d[i] = -1;
    }
    dijkstra(n, s, G, d);
    cout << d[t] << endl;
    return 0;
}

#include<bits/stdc++.h>
#define MAX 100000
#define MOD 1000000007
using namespace std;
vector<pair<int,pair<int,int>>> v[MAX+10];
long long sp[MAX+10];
set<pair<long long,int>> st;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	while(m--)
	{
		int a, b,t,k;
		cin>>a>>b>>t>>k;
		v[a].push_back({b,{t,k}});
		v[b].push_back({a,{t,k}});
	}
	for(int i=1;i<=n;++i)
		sp[i] = LLONG_MAX;
	sp[x] = 0;
	st.insert({0,x});
	while(!st.empty())
	{
		pair<long long,int> p = *(st.begin());
		st.erase(st.begin());
		for(pair<int,pair<int,int>> x:v[p.second])
		{
			long long tm = x.second.first;
			if(sp[p.second]%x.second.second)
				tm += x.second.second*1LL-1LL*(sp[p.second]%x.second.second);
			if(tm+sp[p.second]<sp[x.first])
			{
				set<pair<long long,int>>::iterator it = st.find({sp[x.first],x.first});
				if(it!=st.end())
					st.erase(it);
				sp[x.first] = tm+sp[p.second];
				st.insert({sp[x.first],x.first});
			}
		}
	}
	cout<<(sp[y]==LLONG_MAX?-1:sp[y])<<endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
int n,m;
int sa;
int ans1,ans2;
int ksm(ll ta,int tp){
    int s=1;
    for(;tp;ta=ta*ta%mod,tp>>=1) if(tp&1) s=ta*s%mod;
    return s;
}
int main(){
    scanf("%d %d",&n,&m);
    m+=n;
    for(int i=1,a;i<=n;i++){
        scanf("%d",&a); sa+=a;
    }
    sa+=n;
    ans1=ans2=1;
    if(m<sa){
        printf("0\n");
        return 0;
    }
    for(int i=1;i<=sa;i++) ans1=1ll*ans1*i%mod;
    for(int i=1;i<=sa;i++) ans2=1ll*ans2*(m-i+1)%mod;
    printf("%lld\n",1ll*ans2*ksm(ans1,mod-2)%mod);
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first
#define S second
#define PB push_back
#define MP make_pair
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int  gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll N;
    cin >>N;
    vl A(N);
    ll ans=0;
    rep(i,N){
        cin >>A[i];
    }
    sort(all(A));
    ll pas=0;
    rep(i,N){
        ans = ans + ( (A[i]*A[i])%998244353+ (A[i]*pas)%998244353)%998244353;
        ans %=998244353;
        pas = (pas*2+A[i])%998244353;
    }
    cout<<ans<<endl;
}


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

#define int long long
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, m;
vector<int> ans;
vector<vector<P>> g;

void dfs(int v, int p, int k) {
    ans[v] = k;
    for(auto e: g[v]) {
        int nv = e.fr, c = e.sc;
        if(nv == p) continue;
        if(ans[nv] != -1) continue;
        if(k == c) {
            dfs(nv, v, (k == n ? 1 : k + 1));
        } else {
            dfs(nv, v, c);
        }
    }
}

void solve() {
    cin >> n >> m;
    g.assign(n, vector<P>());
    rep(i, m) {
        int u, v, c; cin >> u >> v >> c;
        -- u, -- v;
        g[u].push_back({v, c});
        g[v].push_back({u, c});
    }
    ans.assign(n, -1);
    dfs(0, -1, 1);
    rep(i, n) {
        if(ans[i] == -1) {
            cout << "No" << endl;
            return;
        }
    }
    rep(i, n) {
        cout << ans[i] << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

vector<ll> parent, rk;

void make_set(ll v) {
    parent[v] = v;
    rk[v] = 0;
}

ll find_set(ll v) {
    if (v == parent[v]) return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rk[a] < rk[b])  swap(a, b);
        parent[b] = a;
        if (rk[a] == rk[b])      rk[a]++;
    }
}

struct Edge {
    ll u, v, weight;
    bool operator<(Edge const& other) {
        return weight < other.weight;
    }
};

vector<pair<ll, ll> > adj[100010];
ll vis[100010], a[100010];
ll n, m;
    vector<Edge> edges;
    vector<Edge> result;

void dfs(ll x){
    vis[x] = 10;
    for(auto &i: adj[x]) if(!vis[i.first]) {
        if(a[x] == i.second) a[i.first] = (a[x]+1)%n;
        else a[i.first] = i.second;
        dfs(i.first);
    }
}

void solve(){
    cin >> n >> m;
    for(ll i = 0; i < m; i++){
        Edge x;
        cin >> x.u >> x.v >> x.weight;
        --x.u, --x.v, --x.weight;
        edges.push_back(x);
    }
    parent.resize(n);
    rk.resize(n);
    for (ll i = 0; i < n; i++)  make_set(i);
    sort(edges.begin(), edges.end());
    for (Edge e : edges) {
        if (find_set(e.u) != find_set(e.v)) {
            //cost += e.weight;
            result.push_back(e);
            union_sets(e.u, e.v);
        }
    }
    //cout << "here " << endl;
    for(ll i = 0; i < n; i++) a[i] = -1;
    for(Edge e: result){
        //cout << e.u << " - " << e.v << e.weight << endl;
        adj[e.u].push_back({e.v, e.weight});
        adj[e.v].push_back({e.u, e.weight});
    }
    a[0] = 1;
    dfs(0);
    for(ll i = 0; i < n; i++) cout << a[i] + 1 << endl;
}

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


#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 2e5+10;

int n,f[N],p=998244353,fa[N],ans;

ll quickpow(ll a,ll b)
{
	ll ans = 1;
	while(b){
		if(b&1) ans *= a;
		a *= a;
		ans %= p; a %= p;
		b>>=1;
	}
	return ans;
}

int find_fa(int x)
{
	if(fa[x] == x) return x;
	else return fa[x] = find_fa(fa[x]);
}

void merge(int x,int y)
{
	int fx=find_fa(x),fy=find_fa(y);
	if(fx != fy){
	 	fa[x] = y; ans--;
	}
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%lld",&f[i]);
		fa[i] = i;
	}
	ans = n;
	for(int i=1;i<=n;i++){
		merge(i,f[i]);
	}
	cout<<quickpow(2,ans)-1;

	return 0;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	bool flag=1;
	int x=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int n,ans=1,fa[200001],sz[200001];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		int x=read();
		fa[find(i)]=find(x);
	}
	for(int i=1;i<=n;i++)
		sz[(find(i))]++;
	for(int i=1;i<=n;i++)
		if(sz[i])
			ans=(ans<<1)%998244353;
	cout<<(ans+998244352)%998244353;
	return 0;
}


//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
struct Init { Init(){
    cin.tie(0); ios::sync_with_stdio(false);
} } init;
//}}}

ll n, x;
vector<ll> as;
unordered_map<ll, ll> memo[50];
ll solve(int idx, ll rem){
    if(idx == n - 1){
        return 1;
    }
    if(memo[idx].count(rem)){ return memo[idx][rem]; }
    ll rem2 = rem / as[idx + 1] * as[idx + 1];
    ll rem3 = (rem + as[idx + 1] - 1) / as[idx + 1] * as[idx + 1];
    // ll rem2 = rem - rem % as[idx + 1];
    ll ret = 0;
    if(rem != rem2){
        ret += solve(idx + 1, rem2);
    }
    ret += solve(idx + 1, rem3);
    printde(idx, rem, ret);
    return memo[idx][rem] = ret;
    // return ret;
}

int main(){
    cin >> n >> x;
    as.resize(n); cin >> as;
    ll ans = solve(0, x);
    cout << ans << '\n';
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int a[maxn];
int b[maxn];
ll pre[maxn];

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    sort(a+1,a+1+n);
    sort(b+1,b+1+m);
    for(int i=n;i;i--){
        if(i&1)pre[i]=pre[i+1]-a[i];
        else pre[i]=pre[i+1]+a[i];
    }
    int po=0;
    ll ans=LLONG_MAX,sum=0;
    for(int i=1;i<=m;i++){
        while(a[po+1]<=b[i]&&po<n){
            if(po&1)sum+=a[po+1];
            else sum-=a[po+1];
            po++;
            // cout<<po<<' '<<sum<<endl;
        }
        if(po&1)ans=min(sum+b[i]+abs(pre[po+1]),ans);
        else ans=min(sum-b[i]+abs(pre[po+1]),ans);
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define INF 1e15+7
#define eps 1e-8
#define DIV 998244353
#define pi 3.14159265

using namespace std;

double sx, sy, gx, gy, res;

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

	cin >> sx >> sy >> gx >> gy;
	gy = -gy;
	res = -sy * (sx - gx) / (sy - gy) + sx;
	printf("%.6lf", res);
	return 0;
}

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

int main()
{
    double Sx,Sy,Gx,Gy;
    cin >> Sx >> Sy >> Gx >> Gy;
    double ans=double((Gx*Sy+Gy*Sx)/(Sy+Gy));
    cout << setprecision(10) << double(ans) << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	string n;
	cin >> n;
	ll count = 0;
	int len = n.length();
	size_t sz = 0;
	count = stoll(n, &sz, 10);
	int maxcom = (len - 1) / 3;

	ll x = 1;
	for (int i = 0; i < maxcom; i++) x *= 1000;
	count = count - x + 1;
	count *= maxcom;

	x = 1;
	for (int i = 0; i < maxcom; i++) {
		count += 999 * x * i;
		x *= 1000;
	}
	cout << count << '\n';

	return 0;
}