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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

const lint mod = MOD9;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a;
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend istream& operator>>(istream& is, mint& m){
        long long x; is >> x; m = x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

mint fac[MAX], facinv[MAX], inv[MAX];
void minit(){
    fac[0] = fac[1] = 1;
    facinv[0] = facinv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = -mint(mod / i)*inv[mod % i];
        facinv[i] = facinv[i - 1] * inv[i];
    }
}
mint mcomb(lint a, lint b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * facinv[b] * facinv[a - b];
}
mint mperm(lint a, lint b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * facinv[a - b];
}

int main(){
    lint N,K; cin>>N>>K;
    vector<vector<mint> > a(N, vector<mint>(K+1));
    rep(i, N) cin >> a[i][1];
    rep(i, N) rep(k, K+1){
        if(k==0) a[i][k] = 1;
        else if(k==1) continue;
        else a[i][k] = a[i][k-1] * a[i][1];
    }

    minit();
    vector<mint> b(K+1, 0);
    rep(k, K+1){
        rep(i, N) b[k] += a[i][k];
        b[k] /= fac[k];
    }

    mint d = 2;
    repn(x, K){
        mint c(0), ans(0);
        rep(i, N) c += d * a[i][x]; d *= 2;
        rep(k, x+1) ans += b[k] * b[x-k];
        ans = (ans * fac[x] - c) / mint(2);
        out(ans);
    }
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n,l;cin >> n >> l;l++;
  ll left=0;
  vl a(n+1),b(n+1);
  rep(i,n){
    ll t;cin >> t;
    a[i]=t-left-1;left=t;
  }
  a[n]=l-left-1;
  left=0;
  rep(i,n){
    ll t;cin >> t;
    b[i]=t-left-1;left=t;
  }
  b[n]=l-left-1;
  left=0;
  //rep(i,n+1)cout << a[i] <<" ";cout << endl;
  //rep(i,n+1)cout << b[i] <<" ";cout << endl;
  ll ans=0;
  ll start=0;
  rep(i,n+1){
    if(b[i]==0)continue;
    ll sum=0;
    ll left=-1,right=-1;
    for(int j=start;j<=n;j++){
      if(a[j]){
        if(left==-1)left=j;
        sum+=a[j];
        if(sum>b[i])break;
        if(sum==b[i]){
          right=j;break;
        }
      }
    }
    //cout << left <<" " << right <<endl;
    if(right==-1)cout << -1 <<endl,exit(0);
    if(left<=i&&i<=right)ans+=right-left;
    else if(i<left){
      ans+=right-i;
    }
    else{
      ans+=i-left;
    }
    start=right+1;
  }
  cout << ans <<endl;

}


#include <bits/stdc++.h>

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

int main(){
   ll n,m;
   cin >> n >>m;
   Vll a(m);
   rep(i,m)cin >> a[i];
   sort(a.begin(),a.end());
   if(m==0){
       cout << 1 << endl;
   }
   else if(n==m)cout << 0 << endl;
   else{
       ll stmp=MM;
       Vll d;
       if((a[0]-1)!=0){
           stmp=min(stmp,a[0]-1);
            d.push_back(a[0]-1);
       }

       for(int i=1;i<m;i++){
           if((a[i]-a[i-1]-1)!=0){
               stmp=min(stmp,(a[i]-a[i-1]-1));
               d.push_back(a[i]-a[i-1]-1);
           }
       }
       if(n-a[m-1]!=0){
           stmp=min(stmp,n-a[m-1]);
           d.push_back(n-a[m-1]);
       }
    ll num=d.size();
    ll ans=0;
    rep(i,num){
        if(d[i]%stmp==0){
            ans+=d[i]/stmp;
        }
        else{
            ans+=(d[i]/stmp)+1;
        }

    }
    cout << ans << endl;
   }

}

#include <bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pii pair <long long ,long long >
#define bug(x)  cerr<<"passed "<<x<<"\n";
#define debug(x) cerr<<"---> "<<x<<"\n" ;
#define kill(x) cout<<x<<"\n" ; return 0 ;
#define ppi pair <pair <int, long long > , long long >
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ordered_set tree<long long , null_type,less<long long , rb_tree_tag,tree_order_statistics_node_update>
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
long long const mxn =4e5+10 ;
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

int main(){
	long long n , m ;
	cin>>n>>m ;
	if (m==0){
		cout<<1 ;
		return 0 ;
	}
	vector <int > vec ;
	for (int i = 1 ; i <= m ; i++){
		int a ;
		cin>>a ;
		vec.push_back(a) ;
	}
	vec.push_back(n+1) ;
	sort(vec.begin(), vec.end()) ;
	int p = 0 ;
	int kk = linf;
	vector <int > vec2 ;
	for (auto u : vec){
		if(u-p-1!=0)
			kk=min(kk , u-p-1) ;
		vec2.push_back(u-p-1) ;
		p = u ;
	}
	long long ans = 0 ;
//	cout<<vec2.size();
	for (auto u : vec2){
	///	cout<<u<<" " ;
		ans+= u/kk + ((u%kk)!=0) ;
	}
	cout<<ans ;
}


//{{{
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VLL = vector<LL>;
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

const int N = 2e2 + 10;
LL n;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    while (cin >> n)
    {
        LL ans = 0;
        for (LL i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                if (i % 2 == 1) ans++;

                if (i * i != n && (n / i) % 2 == 1)
                {
                    ans++;
                }
            }
        }
        ans *= 2;
        cout << ans << endl;
    }

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <set>
#include <map>
#include <cassert>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200010
#define LIMIT2 500010
#define LIMIT3 1000010
#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef long double ld;
typedef const void cv;
typedef pair<ll,ll> P;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define ALL(a) (a).begin(),(a).end()
#define ALL2(a, n) (a),(a)+(n)
template<class T,class C> T max(T a,C b){ return std::max(a, (T)b); }
template<class T,class C> T min(T a,C b){ return std::min(a, (T)b); }
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
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;}
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){

}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  string s;

  cin >> n;
  for(i=1;i*(i+1)/2<=n;i++){
    ll tmp = i*(i+1)/2;
    if(abs(tmp-n)%i==0) result+=2;
  }

  cout << result << endl;
  return 0;
}


#include<iostream>
#include<array>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int n,m,k;
int a[210],b[210],c[20],d[20];

void solve(){
    cin >> n >> m;
    rep(i,m){
        cin >> a[i] >> b[i];a[i]--;b[i]--;
    }
    cin >> k;
    rep(i,k){
        cin >> c[i] >> d[i];c[i]--;d[i]--;
    }
    int U=((1<<k)-1);
    int ans=0;
    rep(S,U+1){
        vector<bool> v(n,false);
        rep(i,k){
            if(S&(1<<i))v[c[i]]=true;
            else v[d[i]]=true;
        }
        int res=0;
        rep(i,m){
            if(v[a[i]] && v[b[i]]) res++;
        }
        chmax(ans,res);
    }
    cout << ans << endl;
}

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define inf 1e9
#define linf 1e18
#define BASE 1000000
#define EPS 1e-10
#define PI acos(-1)
#define pii pair<int,int>
#define pdi pair<double,int>
#define vi vector<int>
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define ms(x,val_add) memset(x, val_add, sizeof(x))
#define pb(x) push_back(x)
#define make_unique(x) sort(ALL(x)) ; x.erase( unique(ALL(x)), x.end()) ;
#define dbg(x) do { cout << #x << " = " << x << endl; } while(0)
#define mp(x, y) make_pair(x, y)
#define minimize(x, y) x = min(x, y)
#define maximize(x, y) x = max(x, y)

/*** IMPLEMENTATION ***/
bool exitInput = false;
int ntest = 1, itest = 1 ;

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

const ll Mod = 1000000007LL;
const int maxn = 10000 + 5;
const int maxv = 500 + 5;
const int maxe = 10000 + 5;

int n, a[maxn];

int main()
{
    #ifdef HOME
    freopen( "input.txt", "r", stdin );
    freopen( "output.txt", "w", stdout );
    #endif // HOME
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << setprecision(10);
    cout << fixed;

    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    int res = 0;
    for(int i = 1; i <= n; ++i)
    {
        int m = a[i];
        res = max(res, a[i]);
        for(int j = i+1; j <= n; ++j)
        {
            m = min(m, a[j]);
            res = max(res, (j - i + 1) * m);
        }
    }
    cout << res;

    return 0;
}


//مبتسمون رغم الخرا
#include <bits/stdc++.h>
#define int long long int
#define ZaZo ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ceil1(a,b)   (a+(b-1))/b
#define all(v)  v.begin(),v.end()
using namespace std;
int32_t main()
{
	ZaZo
	double a,b;
	cin>>a>>b;
	cout<<(double)(((a-b)/a)*(double)100);
}

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll f=0;
ll pre[500];
ll nCr(int n, int r)
{

    ll p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);
            p /= m;
            k /= m;

            n--;
            r--;
        }

    }

    else
        p = 1;

 return p;
}
int main() {
    ll dp[200];
    dp[0] =1;
    ll n;
    cin>>n;
    for(ll i=1;i<200;i++)
    {
        dp[i] = dp[i-1]*11;
        // cout<<dp[i]<<endl;
    }
    // n-=12;
    ll ans =0;
    n--;
    cout<<nCr(n,11)<<endl;

}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
template<class T1> void sortA_L(int N, T1 a[], void *mem = wmem){
  sort(a, a+N);
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
long long T;
long long A[40];
int n1;
int n2;
long long a1[2000000];
long long a2[2000000];
int main(){
  int mask;
  wmem = memarr;
  int i;
  int j;
  long long res = 0;
  rd(N);
  rd(T);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  n1 = N / 2;
  n2 = N - n1;
  for(mask=(0);mask<(1<<n1);mask++){
    for(i=(0);i<(n1);i++){
      if(((mask) &(1<<(i)))){
        a1[mask] += A[i];
      }
    }
  }
  for(mask=(0);mask<(1<<n2);mask++){
    for(i=(0);i<(n2);i++){
      if(((mask) &(1<<(i)))){
        a2[mask] += A[i+n1];
      }
    }
  }
  n1 = (1<<n1);
  n2 = (1<<n2);
  sortA_L(n1, a1);
  sortA_L(n2, a2);
  j = n2 - 1;
  for(i=(0);i<(n1);i++){
    while(j >= 0 && a1[i] + a2[j] > T){
      j--;
    }
    if(j == -1){
      break;
    }
    chmax(res, a1[i] + a2[j]);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20201121-1

// --- original code ---
// int N; ll T, A[40];
// int n1, n2;
// ll a1[2d6], a2[2d6];
// {
//   int i, j;
//   ll res = 0;
//   rd(N,T,A(N));
//   n1 = N / 2;
//   n2 = N - n1;
//   rep(mask,1<<n1) rep(i,n1) if(BIT_ith(mask,i)) a1[mask] += A[i];
//   rep(mask,1<<n2) rep(i,n2) if(BIT_ith(mask,i)) a2[mask] += A[i+n1];
//   n1 = (1<<n1);
//   n2 = (1<<n2);
//   sortA(n1, a1);
//   sortA(n2, a2);
//   j = n2 - 1;
//   rep(i,n1){
//     while(j >= 0 && a1[i] + a2[j] > T) j--;
//     if(j == -1) break;
//     res >?= a1[i] + a2[j];
//   }
//   wt(res);
// }

#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define MOD 998244353
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int h,w,k,dp[5010][5010],val[5010][5010],sum[5010][5010],pw[5010];

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

signed main()
{
	ios::sync_with_stdio(false);
	cin>>h>>w>>k;
	pw[0]=1;
	for(int i=1;i<=5000;i++){
		pw[i]=(1ll*pw[i-1]*3%MOD);
	}
	for(int i=1;i<=k;i++){
		int x,y;char c;cin>>x>>y>>c;
		if(c=='X') val[x][y]=1;
		if(c=='R') val[x][y]=2;
		if(c=='D') val[x][y]=3;
	}
	for(int i=1;i<=h;i++){
		sum[i][0]=0;
		for(int j=1;j<=w;j++) sum[i][j]=sum[i][j-1]+(val[i][j]==0);
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i==1&&j==1){
				dp[i][j]=1;continue;
			}
			dp[i][j]=0;
			if(i>1){
				int num=sum[i-1][w]-sum[i-1][j]+sum[i][j-1];
				if(val[i-1][j]==0) add(dp[i][j],1ll*dp[i-1][j]*2%MOD*pw[num]%MOD);
				if(val[i-1][j]==1) add(dp[i][j],1ll*dp[i-1][j]*pw[num]%MOD);
				if(val[i-1][j]==3) add(dp[i][j],1ll*dp[i-1][j]*pw[num]%MOD);
			}
			if(j>1){
				if(val[i][j-1]==0) add(dp[i][j],1ll*dp[i][j-1]*2%MOD);
				if(val[i][j-1]==1) add(dp[i][j],dp[i][j-1]);
				if(val[i][j-1]==2) add(dp[i][j],dp[i][j-1]);
			}
		}
	}
	if(val[h][w]==0) add(dp[h][w],1ll*dp[h][w]*2%MOD);
	cout<<dp[h][w]<<endl;
	return 0;
}


 /*

                              Jai Shree Krishna !!
                                 Radhe Radhe !!

             उद्यमेन हि सिद्ध्यन्ति कार्याणि न मनोरथैः। नहि सुप्तस्य सिंहस्य मुखे प्रविशन्ति मृगाः।।

*/

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

#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
#define ins insert
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define repd(i,s,e)  for(int i=e;i>=s;i--)
#define vb vector<bool>
#define read2(n,m) int n,m; cin >> n >> m;
#define range(v) v.begin(),v.end()
#define sortd(v) sort(v.begin(),v.end(),greater<int>())
#define sorti(v) sort(v.begin(),v.end())

const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{

    fast;
    read(n);
    int  x = sqrt(n);
    int ans=0;
    rep(i,1,x){
    	if(n%i==0 && i%2==1)
    	ans+=2;
    	int k = n/i;

    	if(k!=i && n%k==0 && k%2==1)
    	ans+=2;
    }
    cout<<ans<<endl;

    return 0;
}

/* Pooja Yadav */

#include <algorithm>
#include <iostream>
#include <iterator>
#include <list>
#include <memory>
#include <vector>

using namespace std;

struct ConnectedComponent {
  long long sum;
  list<int> vertices;
};

int main() {
  int vertex_cnt;
  int edge_cnt;

  cin >> vertex_cnt >> edge_cnt;

  vector<int> diffs;
  diffs.reserve(vertex_cnt);

  for (int i = 0; i < vertex_cnt; ++i) {
    int a;
    cin >> a;
    diffs.push_back(a);
  }

  for (auto iter = diffs.begin(); iter != diffs.end(); ++iter) {
    int b;
    cin >> b;
    *iter -= b;
  }

  vector<shared_ptr<ConnectedComponent>> conn_comps;
  conn_comps.reserve(vertex_cnt);
  for (int i = 0; i < vertex_cnt; ++i) {
    shared_ptr<ConnectedComponent> comp(new ConnectedComponent);
    comp->sum = diffs[i];
    comp->vertices.push_back(i);
    conn_comps.push_back(comp);
  }

  for (int i = 0; i < edge_cnt; ++i) {
    int c, d;
    cin >> c >> d;
    --c;
    --d;
    auto comp_p = conn_comps[c];
    auto comp_q = conn_comps[d];
    if (comp_p->vertices.size() < comp_q->vertices.size()) {
      comp_p = conn_comps[d];
      comp_q = conn_comps[c];
    }
    if (comp_p.get() != comp_q.get()) {
      for (auto vertex : comp_q->vertices) {
        conn_comps[vertex] = comp_p;
      }
      comp_p->sum += comp_q->sum;
      comp_p->vertices.splice(comp_p->vertices.end(), comp_q->vertices);
    }
  }

  for (auto comp : conn_comps) {
    if (comp->sum != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

/*

[-905371741, -999219903, 969314057, -989982132, -87720225, -175700172, -993990465, 929461728, 895449935, -999016241, 782467448, -906404298, 578539175, 9684413, -619191091, -952046546, 125053320]
[-440503430, -997661446, -912471383, -995879434, 932992245, -928388880, -616761933, 929461728, 210953513, -994677396, 648190629, -530944122, 578539175, 9684413, 595786809, -952046546, 125053320]

2 10
6 12
9 11
11 5
7 6
3 15
3 1
1 9
10 4

diffs:
[-464868311, -1558457, 1881785440, 5897302, -1020712470, 752688708, -377228532, 0, 684496422, -4338845, 134276819, -375460176, 0, 0, -1214977900, 0, 0]

Connected Components:
1 3 5 9 11 15
2 4 10
6 7 12
8
*/


#include <iostream>
using namespace std;

int main()
{
	int x,y; cin >> x >> y;
	cout <<x/y<<endl;
}

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1e9+7;
ll mul(ll a,ll b){return ((a%mod)*(b%mod))%mod;}
ll sum(ll a,ll b){return ((a%mod)+(b%mod))%mod;}
ll sub(ll a,ll b){return ((a%mod)-(b%mod))%mod;}
ll power(ll a,ll b){
	ll res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N,W; cin >> N >> W;
	cout << N/W << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename A, typename B = A> using pr = pair<A, B>;
#define vec vector
#define ar array
#define len(a) ((int)((a).size()))
#define all(a) (a).begin(), (a).end()

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

    vec<int> primes;
    for (int i = 2; i <= 50; i++) {
        bool prime = true;
        for (int j = 2; j < i; j++)
            if (i % j == 0)
                prime = false;
        if (prime)
            primes.push_back(i);
    }

    int n;
    cin >> n;
    vec<int> a(n);
    for (auto &x : a)
        cin >> x;

    ll ans = 1e18;
    for (int mask = 0; mask < (1 << len(primes)); mask++) {
        vec<char> good(51);
        ll prod = 1;
        for (int i = 0; i < len(primes); i++)
            if ((mask >> i) % 2) {
                prod *= primes[i];
                for (int j = primes[i]; j <= 50; j += primes[i])
                    good[j] = 1;
            }

        bool ok = true;
        for (auto x : a)
            ok &= good[x];
        if (ok)
            ans = min(ans, prod);
    }
    cout << ans << '\n';
}

//#pragma optimization_level 3
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordset;
*/
#define fr first
#define sc second
#define vec vector
#define pb push_back
#define pii pair<int, int>
#define forn(x,y) for(int x = 1 ; x <= (int)y ; ++x)
#define all(x) (x).begin(),(x).end()
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll,ll> pll;
typedef complex<int> point;
const int nmax = 300005;
const ll linf = 1e18;
const ll mod = 998244353;
const int inf = 1e9;
const int sq = 5000;

int n;
char s[nmax];
int a[nmax];
int b[nmax];
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> s[i];
	}
	for(int i = 0; i <= n; i++){
		cin >> a[i];
	}
	int k = inf;
	for(int i = 0; i < n; i++){
		k = min(k,abs(a[i+1]-a[i]));
	}
	cout << k << '\n';
	for(int i = 0 ; i < k; i++){
		for(int j = 0; j <= n; j++){
			cout << (a[j]/k) + (a[j]%k > i) << ' ';
		}
		cout << '\n';
	}

	// a[i] - a[j] >= k*(dist(i,j))
}


#include <bits/stdc++.h>

#define ull unsigned long long int
#define ll long long int
#define vll vector<ll>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define itr vll::iterator
#define all(c) c.begin(),c.end()
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define inf 1000000000000000001

#define rep(i, n)      for(ll i = 0; i <  n; ++i)
#define repA(i, a, n)  for(ll i = a; i <= n; ++i)
#define repD(i, a, n)  for(ll i = a; i >= n; --i)

using namespace std;

bool func(const pll &a, const pll &b){
    return a.s < b.s;
}

ll power(ll x, ll y)
{
    if (y == 0)
        return 1;
    else if (y % 2 == 0)
        return ((power(x, y / 2)%mod) * (power(x, y / 2)%mod)%mod);
    else
        return (x * ((power(x, y / 2)%mod) * (power(x, y / 2)%mod)%mod))%mod;
}

ll modInverse(ll a, ll m){
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1) return 0;
    while (a > 1){
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0) x += m0;
    return x;
}

void solve(int t){
    ll n,k,  m;
    cin >> n  >> k >> m;
    ll sm = 0;
    rep(i, n-1){
        ll tmp;
        cin >> tmp;
        sm += tmp;
    }
    ll er = n*m-sm;
    if(er >= 0 && er <= k) cout << er;
    else if(er < 0) cout << 0;
    else cout << -1;
}

int main(){

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

    int t, tmp = 0;
    // cin >> t;
    t = 1;
    while(tmp++ < t){
        // cout << "Case #" << tmp << ": ";
        solve(tmp-1);
        if(t-tmp) cout << "\n";
    }
    return 0;
}

#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()
{
    vl a(4);
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(all(a));
    if(a[3]==a[0]+a[1]+a[2]||a[3]+a[0]==a[1]+a[2])
    	cout<<"Yes";
    else
    	cout<<"No";
}
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";
}


#include<bits/stdc++.h>
typedef uint64_t u64;
typedef int64_t i64;
typedef long double f128;
using namespace std;

template<u64 mod>
struct modint{
  u64 val;
  constexpr modint(const i64 x=0) noexcept:val((x%i64(mod)+i64(mod))%i64(mod)){}
  constexpr u64 &value() noexcept{
    return val;
  }
  constexpr modint operator+(const modint rhs) const noexcept{
    return modint(*this)+=rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept{
    return modint(*this)-=rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept{
    return modint(*this)*=rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept{
    return modint(*this)/=rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept{
    val+=rhs.val;
    val-=((val>=mod)?mod:0);
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept{
    val+=((val<rhs.val)?mod:0);
    val-=rhs.val;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept{
    val=val*rhs.val%mod;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept{
    u64 exp=mod-2;
    while(exp){
      if(exp&1){
        (*this)*=rhs;
      }
      rhs*=rhs;
      exp>>=1;
    }
    return *this;
  }
  friend constexpr ostream &operator<<(ostream &os,const modint &x) noexcept{
    return os<<(x.val);
  }
  friend constexpr istream &operator>>(istream &is,modint &x) noexcept{
    u64 t;
    is>>t;
    x=t;
    return is;
  }
};

template<typename T>
void scan(T& n){
  cin>>n;
}

void scan(){}

template<typename T,class... Args>
void scan(T& n,Args&... args){
  scan(n);
  scan(args...);
}

template<typename T>
void scanall(T start,T end){
  for(;start!=end;++start){
    scan(*start);
  }
}

template<typename T>
void print(T n){
  cout<<n;
}

void print(){}

template<typename T,class... Args>
void print(T n,Args... args){
  print(n);
  print(args...);
}

template<typename T>
void println(T n){
  print(n);
  cout<<endl;
}

template<typename T,class... Args>
void println(T n,Args... args){
  print(n,' ');
  println(args...);
}

template<typename T>
void printall(T start,T end){
  if(start!=end){
    print(*start);
    for(++start;start!=end;++start){
      print(' ',*start);
    }
  }
  cout<<endl;
}

template<typename T>
void chmax(T& n,T m){
  n=max(n,m);
}

template<typename T>
void chmin(T& n,T m){
  n=min(n,m);
}

template<typename T,typename U>
T power(T a,U n){
  T res=1;
  while(n){
    res*=(n&1)?a:1;
    a*=a;
    n>>=1;
  }
  return res;
}

template<typename T>
struct combination{
  vector<T> fact;
  combination(const int Max=3000000):fact(Max+1,1){
    for(int i=2;i<=Max;++i){
      fact[i]=fact[i-1]*i;
    }
  }
  template<typename U>
  T nCk(U n,U k){
    if(n<k||n<0||k<0){
      return 0;
    }
    return fact[n]/fact[k]/fact[n-k];
  }
};

void solve();

int main(){
  cout<<fixed<<setprecision(15);
  bool is_multicase=true;
  int T=1;
  if(is_multicase){
    scan(T);
  }
  for(int i=0;i<T;++i){
    solve();
  }
  return 0;
}

template<typename T>
inline T f(T n){
  return n*(n+1)/2;
}

void solve(){
  typedef modint<1000000007> mint;
  mint N,A,B;
  scan(N,A,B);
  if(A.val+B.val>N.val){
    println(0);
    return;
  }
  if(A.val<B.val){
    swap(A,B);
  }
  mint ans=0;
  ans+=(N-A+1)*(A-B+1)*f(N-A-B+1)*4;
  ans+=f(N-A-B+1)*f(N-A)*2*4;
  ans-=f(N-A-B+1)*f(N-A-B+1)*4;
  println(ans);
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int T;
  cin>>T;
  ll N, A, B;
  ll ans[T];
  ll tmp;
  ll zero = 0;
  for(int i=0;i<T;++i) {
    cin>>N>>A>>B;
    ans[i] = 0;
    if(N<A+B) continue;
    if(A<B) swap(A, B);
    tmp = (N-A-B+1)*(N-A-B+2)/2%mod;
    ans[i] += 4*tmp%mod*((N-A+1)*(N-B+1)%mod-tmp+mod)%mod;
  }
  for(int i=0;i<T;++i) cout<<ans[i]<<endl;
}


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

long long md = 1000000007;

long long fp(long long n, long long k)
{
	long long s = 1;
	while (k) {
		if (k & 1) s = (s * n) % md;
		k /= 2; n = (n * n) % md;
	}
	return s;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	int s = n;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		s += a;
	}
	int p = n + m;
	long long ns = 1, rs = 1;
	for (int i = 0; i < s; i++) {
		ns = (ns * (p - i)) % md;
		rs = (rs * (i + 1)) % md;
	}
	rs = fp(rs, md - 2);
	cout << (ns * rs) % md << '\n';
	return 0;
}

// Problem: B - 200th ABC-200
// Contest: AtCoder - KYOCERA Programming Contest 2021（AtCoder Beginner Contest 200）
// URL: https://atcoder.jp/contests/abc200/tasks/abc200_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: abhidot

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define w(x)  int x; cin>>x; while(x--)
using namespace std;
const long long N=200005, INF=2000000000000000000;

/*------------- Modular exponentiation -------------*/
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

/*------------- Sieve --------------*/
vector <int> prime;
bool is_composite[N];

void sieve (int n) {
	fill (is_composite, false);
	for (int i = 2; i < n; ++i) {
		if (!is_composite[i]) prime.push_back (i);
		for (int j = 0; j < prime.size () && i * prime[j] < n; ++j) {
			is_composite[i * prime[j]] = true;
			if (i % prime[j] == 0) break;
		}
	}
}

/*------------ Utitlity function ---------------*/
void print(bool n){
    if(n){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int cnt=0;
    while(k&&n%200==0){
    	n/=200;
    	k--;
    }

    for(int i=0;i<k-1;i+=2){
    	n*=10;
    	n+=2;
    	n/=2;
    }
    string s = to_string(n);
    if(k%2) s+="200";
    cout<<s;
}

// Written by abhidot


#include <iostream>
#include <string.h>
#include <string>
#include <cmath>
#include<vector>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include<numeric>
#include <iomanip>
#include <set>
#define ul unsigned long long int
#define sll signed long long int
#define ll long long int
#define pb push_back
#define db double

using namespace std;
ll meh=1000000000+7;
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

ll levi(ll n , ll k)
{
    if (n%k==0)
    {
        return n/k;
    }
    else
    {
        return (((n-(n%k))/k)+1);
    }

}
ll mex(ll a,ll b){
    if (a>=b)
    {
        return a;
    }
    else{
        return b;
    }

}
ll men(ll a,ll b){
    if (a<=b)
    {
        return a;
    }
    else{
        return b;
    }

}

ll diff(ll a,ll b){
    if (a>=b)
    {
        return a-b;
    }
    else{
        return b-a;
    }

}
ll expoi(ll a,ll n){
    if (n==0)
    {
        return 1;
    }
    else{
        return a*expoi(a,n-1);
    }

}
ll asb(ll n){
    if (n>=0)
    {
        return n;
    }
    else{
        return -n;
    }

}

ll sumdi(ll n){
    if (n<10)
    {
        return n;
    }
    else{
        return n%10+sumdi((n-n%10)/10);
    }

}

int main()
{
    ll n;
    cin>>n;
    vector<ll> arr(n+1);
    for (ll i = 0; i < n; i++)
    {
        cin>>arr[i+1];
    }
    if (n==1)
    {
        cout<<arr[1]%meh<<endl;
    }
    else if (n==2)
    {
        cout<<(2*arr[1])%meh<<endl;
    }
    else
    {
        vector<ll> ans(n+1),calc(n+1);
        ans[1]=arr[1]%meh,calc[1]=1,calc[2]=2,ans[2]=(2*arr[1])%meh;
        for (ll i = 2; i <= n; i++)
        {
            calc[i]=(calc[i-1]+calc[i-2])%meh;
        }
        for (ll i = 2; i <= n; i++)
        {
            ans[i]=(ans[i-1]+calc[i-2]*arr[i]+ans[i-2]+arr[i-1]*(calc[i-1]))%(meh);
        }
        ll r=ans[n]%(meh);
        cout<<r<<endl;
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}
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 (a > b) { a = b; return 1; }
	return 0;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	REP(i, N) {
		int x, y, r;
		cin >> x >> y >> r;
		cout << x << " " << y << " " << x + 1 << " " << y + 1 << endl;
	}
	return 0;
}


#include<cstdio>
const int mod=1e9+7;
long long ans;
int n,m,mp[2010][2010],row[2010],col[2010],dia[5010];
char str[2010];
int add(long long a,long long b)
{
	if(a+b>=mod)	return (a+b)%mod;
	else	return a+b;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",str+1);
		for(int j=1;j<=m;++j)
		{
			if(str[j]=='.')	mp[i][j]=0;
			else	mp[i][j]=1;
		}
	}
	int lay=2e3;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(mp[i][j])
			{
				row[i]=0;
				col[j]=0;
				dia[i-j+lay]=0;
			}
			else
			{
				int tmp=add(add(row[i],col[j]),dia[i-j+lay]);
				if(i==1&&j==1)	++tmp;
				row[i]=add(row[i],tmp);
				col[j]=add(col[j],tmp);
				dia[i-j+lay]=add(dia[i-j+lay],tmp);
				ans=tmp;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define REP(i, n) for(int(i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int(i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int(i) = (n); (i) < (m); ++(i))

// clang-format off
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; }
// clang-format on
constexpr int INF = 1e9;

class Timer {
  chrono::time_point<chrono::system_clock> start;

public:
  Timer() { start = chrono::system_clock::now(); }
  double duration() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now() - start).count();
    // return chrono::duration<chrono::milliseconds>(chrono::system_clock::now()- start).count();
  }
};
class xorShift {
  uint32_t x, y, z, w;
  static const double TO_DOUBLE;

public:
  xorShift() {
    x = 123456789;
    y = 362436069;
    z = 521288629;
    w = 88675123;
  }
  xorShift(uint32_t seed) {
    x = seed = 1812433253u * (seed ^ (seed >> 30));
    y = seed = 1812433253u * (seed ^ (seed >> 30)) + 1;
    z = seed = 1812433253u * (seed ^ (seed >> 30)) + 2;
    w = seed = 1812433253u * (seed ^ (seed >> 30)) + 3;
  }
  uint32_t nextInt(uint32_t n) {
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
    return w % n;
  }
  uint32_t nextInt() {
    uint32_t t = x ^ (x << 11);
    x = y;
    y = z;
    z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
  }
  double nextDouble() { return nextInt() * TO_DOUBLE; }
};
const double xorShift::TO_DOUBLE = 1.0 / (1LL << 32);

Timer T;
xorShift rnd;
constexpr double TIME_LIMIT = 1800;
constexpr int N = 20;
int M;
vector<string> s;

struct Solver {
  void first_method() {
    string all_string;
    REP(i, M) { all_string += s[i]; }
    REP(i, N) {
      string line;
      REP(j, N) { line += all_string[i * N + j]; }
      cout << line << endl;
    }
  }
};
int main() {
  int n;
  cin >> n >> M;
  s.resize(M);
  REP(i, M) { cin >> s[i]; }
  Solver solver;
  solver.first_method();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 105, mod = 1000000;
int n, m, a[N];
void read (int &x) {
    char ch = getchar(); x = 0; while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
struct ll {
    int p[550], len;
    ll() { memset (p, 0, sizeof (p)); len = 0; }
    void print() {
        printf ("%d", p[len]);
        for (int i = len - 1; i > 0; --i) {
            if (!p[i]) { printf ("0000"); continue; }
            for (int k = 10; k * p[i] < mod; k *= 10)
                putchar (48);
            printf ("%d", p[i]);
        } putchar ('\n');
    }
    // ll operator + (const ll &a) const {
    //     ll t; t.len = max (len, a.len); int q = 0;
    //     for (int i = 1; i <= t.len; ++i) {
    //         t.p[i] = p[i] + a.p[i] + q;
    //         q = t.p[i] / mod; t.p[i] %= mod;
    //     }
    //     if (q > 0) t.p[++t.len] = q; return t;
    // }
    // ll operator + (const int &a) const {
    //     ll t; t.len = max (len, 10); int q = 0;
    //     for (int i = 1; i <= t.len; ++i) {
    //         t.p[i] = p[i] + a % mod + q;
    //         q = t.p[i] / mod; t.p[i] %= mod, a /= mod;
    //     }
    //     if (q > 0) t.p[++t.len] = q; return t;
    // }
    ll operator * (const int &a) const {
        ll t; t.len = len; int q = 0;
        for (int i = 1; i <= len; ++i) {
            t.p[i] = p[i] * a + q;
            q = t.p[i] / mod, t.p[i] %= mod;
        }
        while (q) t.p[++t.len] = q % mod, q /= mod;
        return t;
    }
} res; int lim = 10000, tot, cnt[100000], tp, t[100000];
int is (int x) {
    if (x == 1) return 0;
    for (int i = 2; i * i <= x; ++i)
        if (x % i == 0) return 0; return 1;
}
signed main() {
    read (n); res.len = 1, res.p[1] = 1;
    for (int i = 1; i <= n; ++i) read (a[i]);
    for (int i = 1; i <= n; ++i)
        if (is (a[i])) t[++tp] = a[i], res = res * a[i];
    for (int i = 1; i <= n; ++i) {
        if (is (a[i])) continue;
        int tag = 0;
        for (int j = 1; j <= tp; ++j)
            if (a[i] % t[j] == 0) {  tag = 1; break; }
        if (tag) continue; ++tot;
        for (int j = 1; j <= lim; ++j)
            if (__gcd (j, a[i]) != 1) ++cnt[j];
    }
    for (int i = 1; i <= lim; ++i)
        if (cnt[i] == tot) { res = res * i; break; }
    return res.print(), 0;
}

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

long long int n;
cin>>n;
long long int arr[n];
for (long long int i = 0; i < n; ++i)
{
    cin>>arr[i];
}
if (n==1)
{
    cout<<arr[0]<<"\n";
    return 0;
}

for (int i = 0; i < n; ++i)
{
    for (int j = 0; j < n; ++j)
    {
            if (__gcd(arr[i],arr[j])!=1)
            {
                arr[i]=arr[j]=__gcd(arr[i],arr[j]);
            }
    }
}
set <int>s(arr,arr+n);
std::vector<int> v2(s.begin(), s.end());
std::vector<int> v3;
for (int i = 0; i < v2.size(); ++i)
{
    for (int j = 2; j <= 50; ++j)
    {
            if (v2[i]%j==0)
            {
                v3.push_back(j);
                break;
            }
    }
}
long long int h=1;
for (int i = 0; i < v3.size(); ++i)
{
        h*=v3[i];
}
cout<<h<<"\n";
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int n,mi,ans;
map<int,int> md;
int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
int main()
{
	int a;
	scanf("%d",&n);
	mi=1<<30;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		mi=min(mi,a);
		for(int j=1;j*j<=a;j++)
			if(a%j==0)md[j]=gcd(md[j],a),md[a/j]=gcd(md[a/j],a);
	}
	for(map<int,int>::iterator i=md.begin();i!=md.end();i++)
		if(i->first==i->second&&i->first<=mi)ans++;
	printf("%d",ans);
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int ans = 0;
	int kazu = 0;
	for(int j = 2; j <=1000; j++){
		int counts = 0;
		rep(i,n){
			if(a[i]%j == 0) counts++;
		}
		if(ans < counts) {
			kazu = j;
			ans = counts;
		}
	}
	cout << kazu << endl;
	return 0;
}

// cout << fixed << setprecision(15) <<  << endl;


#include<bits/stdc++.h>
using namespace std;
#define hi ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef int64_t ll;
typedef long double ld;
typedef long long unsigned llu;
#define test				int test; cin>>test; while(test--)
#define loop(i,n,k) 		for(int i=n;i<k;i++)
#define rloop(i,n,k) 		for(int i=n;i>=k;i--)
#define INT(a) 				int a;scanf("%d",&a);
#define intin(temp)			scanf("%d",&temp);
#define longin(temp)		scanf("%lld",&temp);
#define LLI(a) 				ll a;scanf("%lld",&a);
#define DOUBLE(a) 			double a;scanf("%f",&a);
#define LD(a) 				long double a;scanf("%lf",&a);
#define pb(i) 				push_back(i)
#define sz(i) 				i.size()
#define mkp(i,j)			make_pair(i,j)
#define ip 					pair<int,int>
#define lp					pair<ll,ll>
#define FOR(i,n)			for(i=0;i<n;i++)
#define range(v)			v.begin(),v.end()
#define bye					return 0;
#define file				freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

template<class c>
c gcd (c a,c b){
	if(b==0)
		return a;
	gcd(b,a%b);
}
template<class c>
c lcm(c a,c b){
    return a/gcd(a,b)*b;
}
template<class a>
bool prime(a n){
	for(a i=2;i<=sqrt(n);i++){
		if(n%i==0)
			return 0;
	}
	return 1;
}
bool bigger(pair<int,int>picachu,pair<int,int> qicachu){
	return (picachu.first<qicachu.first);
}void printarr(int arr[],int n){
	for(int i=0;i<n;i++)
		cout<<arr[i]<<' ';
	cout<<endl;
}
int chartoint(char c) {
    if (c >= 'a' && c <= 'z') return c - 'a';
    if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
    return 52;
}
int kadane(int arr[],int n){
	int maximum= arr[0];
	int max_so_far = 0;
	for(int i=0;i<n;i++){
		max_so_far+=arr[i];
		if(max_so_far>maximum)
			maximum = max_so_far;
		if(max_so_far<0)
			max_so_far = 0;
	}
	return maximum;
}

void run(){
	int n,x;
		cin >> n >> x;
		int temp;
		for(int i = 0;i<n;i++){
			cin >> temp;
			if(temp!=x ){
				cout << temp << ' ';
			}
		}
		cout << endl;
}
int main(){
	hi;
	#ifndef ONLINE_JUDGE
   	freopen("input.txt", "r", stdin);
  	freopen("error.txt", "w", stderr);
  	freopen("output.txt", "w", stdout);
   	#endif

   	{
      	run();
   	}
  	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
 	bye;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <chrono>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,a) rrepi(i,a,0)
#define rrepi(i,a,b) for(int i=a-1;i>=b;--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
typedef string::const_iterator State;
const ll MAX = 105;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};

int main(){
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n),ans;
    cins(all(a));
    rep(i,n){
        if (a[i] == x) continue;
        ans.push_back(a[i]);
    }
    array_output(all(ans));
}


#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr ll KINF = 1e18;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	ll x;
	cin >> n >> x;
	VI a(n);
	_rep(i, 0, n) cin >> a[i];
	auto check = [&](int k){
		int rem = x % k;
		int b[n];
		_rep(i, 0, n) b[i] = a[i] % k;
		int dp[n + 1][k + 1][k + 1];
		memset(dp, -0x3f, sizeof dp);
		_rep(i, 0, n + 1) dp[i][0][0] = 0;
		_rep(i, 1, n + 1)
			_rep(j, 1, k + 1)
				_rep(z, 0, k){
					dp[i][j][z] = dp[i - 1][j][z];
					if(z - b[i - 1] >= 0) dp[i][j][z] = max(dp[i][j][z], dp[i - 1][j - 1][z - b[i - 1]] + a[i - 1]);
					else dp[i][j][z] = max(dp[i][j][z], dp[i - 1][j - 1][z + k - b[i - 1]] + a[i - 1]);
					if(dp[n][k][rem] == x) return 0;
				}
		return dp[n][k][rem];
	};
	int res = -1;
	vector<PII> ans;
	_dep(k, n, 1){
		res = check(k);
		if(res > 0) {
			ans.eb(res, k);
		}
		if(res == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	if(ans.empty()) {
		sort(all(a));
		// auto  it = lb(all(a), x);
		// if(it != a.end()) cout << x - *it << endl;
		// else cout << x - a[n - 1] << endl;
		cout << x - a[n - 1] << endl;
		return 0;
	}
	else{
		ll res = KINF;
		for(auto& [ini, div] : ans){
			res = min(res, (x - ini) / div);
		}
		cout << res << endl;
	}
	return 0;
}
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline

#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define st first
#define nd second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>b;i--)
#define endl "\n"
#define fre freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)
#define start ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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

//2 4 4 +1
//

ll yen[20][1<<20];
queue<pair<int,int>> q;
vector<int> v[N];
ll vis[N];
ll dp[20][20];
ll k;
int idx[N];
vector<int> c;
ll sum=0;
bool check=true;

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

rep(i,0,m)
{
	int a,b;
	cin>>a>>b;
	v[a].pb(b);v[b].pb(a);
}

cin>>k;
memset(idx,-1,sizeof(idx));
rep(i,0,k)
{
	int a;
	cin>>a;
	c.pb(a);
	idx[c[i]]=i;
}

rep(i,0,k)
{
	memset(vis,0,sizeof(vis));
	q.push(make_pair(c[i],0));

	rep(j,0,k)
	{
		dp[i][j]=N;
	}
	while(!q.empty())
	{
		ll temp=q.front().st;
		ll cur=q.front().nd;
		q.pop();
		if(vis[temp])
			continue;
		vis[temp]=1;
		if(idx[temp] != -1) dp[i][idx[temp]] = cur;
		rep(j,0,v[temp].size())
		{
			if(vis[v[temp][j]])
				continue;
			q.push({v[temp][j],cur+1});
		}
	}
}

memset(yen, N, sizeof(yen));
    for (int i=0; i<k; i++) yen[i][1<<i] = 0;

    for (int j=0; j<(1<<k); j++) {
        for (int i=0; i<k; i++) if (j & (1<<i)) {
            int cur = j & ~(1<<i);
            for (int l=0; l<k; l++) if (cur & (1<<l)) {
                yen[i][j] = min(yen[i][j], yen[l][cur] + dp[l][i]);
            }
        }
    }

    ll ans = N;
    for (int i=0; i<k; i++) ans = min(ans, yen[i][(1<<k)-1]);

    if (ans == N) cout<<-1<<endl;
    else cout<<ans+1<<endl;

}

int main(){
	start

	int t=1;
	//cin>>t;
	rep(i,0,t)
	solve();
}


/*
    I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
/*-------typedefs------*/
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
/*---- FAST I/O and file read ---*/
void go() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif
}
/*-------- test-case stuff--------------*/
#define ssolve solve();
#define msolve int T;cin >> T;while(T--) {solve();}
#define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
int h, w, ans;
void dfs(int i, int bit, int a, int b) {
    if(i == h * w) {
		ans++;
		return;
	}

	if(bit & 1 << i) dfs(i + 1, bit, a, b);
	if(b) dfs(i + 1, bit | 1 << i, a, b - 1);

    if(a) {
		if((i % w) != (w - 1) && ~bit & 1 << (i + 1)) dfs(i + 2, bit | 1 << i | 1 << (i + 1), a - 1, b);
		if((i + w) <= (h * w) && ~bit & 1 << (i + w)) dfs(i + 1, bit | 1 << i | 1 << (i + w), a - 1, b);
	}
}

void solve() {
    int a, b;
    cin >> h >> w >> a >> b;
    ans = 0;
    dfs(0, 0, a, b);
    pf(ans);
}

int main() {
    go();
    ssolve
    return 0;
}


#include <cstdio>
using namespace std;
#define ll long long

ll r, x, y;

ll read() {
	ll X = 0, F = 1; char C = getchar();
	while(C < '0' || C > '9') {if(C == '-')F=-1; C = getchar();}
	while(C >= '0' && C <= '9') {X = X*10+C-'0'; C = getchar();}
	return X * F;
}

int main() {
	r = read(); x = read(); y = read();
	ll dis = x * x + y * y;
	r = r * r;
	for(ll i = 0;; ++i)
		if(i * i * r >= dis) {
			printf("%lld\n", i == 1 ? (i * i * r == dis ? 1 : 2) : i);
			break;
		}
	return 0;
}

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

int main() {
  long long R, X, Y, ans;
  double k;
  cin >> R >> X >> Y;
  k = sqrt(X * X + Y * Y);

  ans = ceil(k / R);
  if(k < R) ans++;

  cout << ans << endl;
}


#include<bits/stdc++.h>

#define fill(arr,c) memset(arr,c,sizeof(arr))
#define perm(r) next_permutation(all(r))
//it gives bool value ans permute the string lexoggraphically
#define sortdesc greater<int>()
#define ll long long int
//std::setfill('0') << std::setw(5) << 25; it adds leaing zeroes;
#define f(i,a) for(ll i=0;i<a;i++)
#define fo(i,a) for(ll i=1;i<=a;i++)
#define foo(i,x,n,c) for(ll i=x;i<n;i+=c)
#define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)
#define fauto(i,m) for(auto i:m)
#define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)
#define ld long double
#define in push_back
#define mll map<ll,ll>
#define mcl map<char,ll>
#define msl map<string,ll>
#define vi vector<int >
#define vl vector<ll >
#define vp vector< pair<int,int> >
#define vs vector <string>
#define vc vector <char>
#define o(a) cout<<a
#define os(a) cout<<a<<" "
#define en cout<<"\n";
#define testcase ll t ;cin>>t; while(t--)
#define ff first
#define ss second
#define pl pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a).begin(), (a).end()

#define sz(a)  (a).size()
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
#define bitcount  __builtin_popcountll
#define imin o("imin");en;
using namespace std;
bool comp(const pair<int,int> &a , const pair<int,int> &b){
    if(a.first == b.first)  return a.second < b.second;
     return a.first < b.first;
}
bool comps(const pair<int,int> &a , const pair<int,int> &b){
    if(a.second == b.second)  return a.first< b.first;
     return a.second < b.second;
}
bool compmx(int a, int b)
{
    return (a < b);
}
//ll pi=acos(0.0)*2;
void fastio()
{
    	ios::sync_with_stdio(0);
cin.tie(0);

}
void inout()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

     freopen("output.txt", "w", stdout);
     #endif
}

int main()
{
fastio();
inout();
ll n;
cin>>n;
ll a[n];
f(i,n)
cin>>a[i];
ll ans=0;

f(i,n)
{
   // os(1);
ll cur=a[i];
    foo(j,i+1,n,1)
    {
if(a[j]>=a[i])
{
cur+=a[i];
}
else
break;
    }
    foi(j,i-1,0,-1)
    {
if(a[j]>=a[i])
{
cur+=a[i];
}
else
break;
    }
    ans=max(ans,cur);
}
o(ans);
return 0;
}

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n;
int a[10001];
int mn[10001][10001];

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

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

	cin>>n;
	forn(i,0,n)
		cin>>a[i];
	forn(i,0,n){
		mn[i][i]=a[i];
		forn(j,i+1,n)
			mn[i][j]=min(mn[i][j-1],a[j]);
	}
	int res=-1;
	forn(i,0,n){
		int mx=-1;
		forn(j,i,n)
			mx=max(mx,mn[i][j]*(j-i+1));
		res=max(res,mx);
	}
	cout<<res<<endl;
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define endl "\n"
using ll = long long;
const int MOD = 1e9 + 7;

void solve() {
	int n, m; cin >> n >> m;
	if (m == 0) {
		cout << 1 << endl;
		return;
	}
	vector<int> a(m);
	for (int &x : a) cin >> x;
	sort(a.begin(), a.end());
	a.push_back(n + 1);
	int ans = 0;
	int cur = 1;
	vector<int> gaps;
	for (int i = 0; i < m + 1; i++) {
		int w = a[i] - cur;
		if (w) gaps.push_back(w);
		cur = a[i] + 1;
	}
	int k = n;
	for (int w : gaps) k = min(k, w);
	for (int w : gaps) ans += (w + k - 1) / k;
	cout << ans << endl;

}

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

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

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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, M;
    cin >> N >> M;
    V<ll> A(M);
    REP(i, M) cin >> A[i];

    A.push_back(0);
    A.push_back(N+1);
    sort(ALL(A));
    M += 2;

    ll mi = INF;
    REP(i, M-1){
        if(A[i+1]-A[i]-1 > 0) chmin(mi, A[i+1]-A[i]-1);
    }

    if(mi == INF){
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;
    REP(i, M-1){
        res += (A[i+1]-A[i]-1+mi-1)/mi;
    }

    cout << res << endl;

    return 0;
}


//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
// static const ll MOD = (1LL << 61LL) - 1LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

map<ll, ll> get_prime_factors(ll a, const vector<bool>& is_primes){
	ll sqrt_a = sqrt(double(a));
	while ((sqrt_a + 1) * (sqrt_a + 1) <= a) ++sqrt_a;
	while (sqrt_a * sqrt_a > a) --sqrt_a;

	map<ll, ll> prime_factors;
	REPD(p, 2, sqrt_a + 1) {
		if (!is_primes[p]) continue;
		while (a % p == 0LL) {
			if (prime_factors.count(p) == 0) prime_factors[p] = 0;
			++prime_factors[p];
			a /= p;
		}
	}
	if (a != 1LL) prime_factors[a] = 1;

	return prime_factors;
}

// computational complexity: o(log(max(a, b)))
inline ull get_gcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return get_gcd(b, a % b);
}

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

	vector<ll> as(n);
	REPD(i, 0, n) cin >> as[i];
	ll max_a = *max_element(as.begin(), as.end());
	ll min_a = *min_element(as.begin(), as.end());

	ll sqrt_a = sqrt(double(max_a));
	while ((sqrt_a + 1) * (sqrt_a + 1) <= max_a) ++sqrt_a;
	while (sqrt_a * sqrt_a > max_a) --sqrt_a;

	vector<bool> is_primes(sqrt_a + 1, true);
	is_primes[1] = is_primes[0] = false;
	REPD(p, 2, sqrt_a + 1) {
		if (!is_primes[p]) continue;
		ll i = 2;
		while(p * i <= sqrt_a) is_primes[p * i++] = false;
	}

	map<ll, ll> num_to_gcd;
	ll prime, exponent;
	REPD(i, 0, n) {
		auto prime_factors = get_prime_factors(as[i], is_primes);
		ll multiple_count = 1;
		REPI(prime_info, prime_factors) {
			tie(prime, exponent) = prime_info;
			multiple_count *= exponent + 1LL;
		}
		REPD(j, 0, multiple_count) {
			ll j0 = j;
			ll multiple = 1;
			REPI(prime_info, prime_factors) {
				tie(prime, exponent) = prime_info;
				REPD(k, 0, j0 % (exponent + 1LL)) multiple *= prime;
				j0 /= exponent + 1LL;
			}
			if (multiple > min_a) continue;
			if (num_to_gcd.count(multiple) == 0) num_to_gcd[multiple] = as[i];
			num_to_gcd[multiple] = get_gcd(num_to_gcd[multiple], as[i]);
		}
	}
	ll res = 0;
	ll num, gcd;
	REPI(num_gcd, num_to_gcd) {
		tie(num, gcd) = num_gcd;
		if (num == gcd) ++res;
	}

	cout << res << endl;

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#define mod 1000000007
#define N 200005
#define int long long

using namespace std;

int n, b[N], a[N], z[N], mp[N], ans = 0, anss[N], us[N];

void Msort(int l, int r) {
	int mid = (l + r) / 2;
	if(l == r) return ;
	Msort(l, mid);
	Msort(mid + 1, r);
    int l1 = l, r1 = mid + 1;
    for(int i=l; i<=r; i++) {
    	if(l1 <= mid && r1 <= r) {
    		if(a[l1] <= a[r1]) {
    			z[i] = a[l1];
    			l1++;
			}
			else {
				z[i] = a[r1];
				r1++;
				ans += (mid - l1 + 1);
			}
		}
		else {
			if(l1 <= mid) z[i] = a[l1], l1++;
			if(r1 <= r) z[i] = a[r1], r1++;
		}
	}
	for(int i=l; i<=r; i++) a[i] = z[i];
}

signed main(void) {
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> b[i];
		mp[b[i]] = i;
		a[i] = b[i];
	}
	Msort(1, n);
	if(ans != n-1) {
		cout << -1;
		return 0;
	}
	int now = 1, cnt = 0, flag = 0;
	while(1) {
		while(now <= n && b[now] == now) now++;
		if(now > n) break;
		anss[++cnt] = mp[now] - 1;
		if(us[mp[now]-1]) flag = 1;
		us[mp[now]-1] = 1;
		if(anss[cnt] <= 0 || anss[cnt] > n-1) flag = 1;
		int p = mp[now];
		mp[b[p-1]] = p; mp[b[p]] = p-1;
		swap(b[p], b[p-1]);
   }
   if(flag || cnt != ans) {
   	    cout << -1;
   	    return 0;
   }
   for(int i=1; i<=cnt; i++) cout << anss[i] << '\n';
   for(int i=cnt+1; i<=n-1; i++) cout << 1 << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int main(){
        vector<int> h;
        vector<string> name;
        string temp;
        int n, f_max = 0, s_max, temp_no;

        cin >> n;
        for(int i = 0; i < n; i++){
                cin >> temp >> temp_no;
                name.push_back(temp);
                h.push_back(temp_no);
        }

        for(int i = 1; i < n; i++){
                if(h[i] > h[f_max])
                        f_max = i;
        }

        if(f_max == 0)
                s_max = 1;
        else
                s_max = 0;

        for(int i = 0; i < n; i++){
                if(i != f_max){
                        if(h[i] > h[s_max])
                                s_max = i;
                }
        }

        cout << name[s_max];

        return 0;

}

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

void solveC() {
	int n;
	cin >> n;
	vector<vector<int>> arr(n, vector<int>(2, 0));
	for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1];

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				int x1 = arr[j][0] - arr[i][0], y1 = arr[j][1] - arr[i][1];
				int x2 = arr[k][0] - arr[j][0], y2 = arr[k][1] - arr[j][1];
				if (y2 * x1 == x2 * y1) {
					cout << "Yes" << "\n";
					return ;
				}
			}
		}
	}

	cout << "No" << "\n";
}

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

int main() {
	// code();

	solveC();
}


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

int main(){
  int N;
  cin>>N;
  vector<vector<ll>> V(N+1);
  for(int i=0;i<N+1;i++){
    V[i] = {};
  }
  for(int i=0;i<N;i++){
    ll X;
    int C;
    cin>>X>>C;
    V[C].push_back(X);
  }

  vector<pair<ll,ll>> pv={};
  int lpv=0;
  for(int i=0;i<N+1;i++){
    int l = V[i].size();
    if(l == 0)continue;
    pair<ll,ll> p;
    sort(V[i].begin(),V[i].end());
    p.first=V[i][0];
    p.second=V[i][l-1];
    pv.push_back(p);
    lpv++;
  }

  ll dp[lpv][2];
  dp[0][0] = abs(pv[0].second) + abs(pv[0].first-pv[0].second);
  dp[0][1] = abs(pv[0].first) + abs(pv[0].first-pv[0].second);
  for(int i=1;i<lpv;i++){
    dp[i][0] = min(dp[i-1][0] + abs(pv[i].second-pv[i-1].first)
                   + abs(pv[i].first-pv[i].second),
                   dp[i-1][1] + abs(pv[i].second-pv[i-1].second)
                   + abs(pv[i].first-pv[i].second) );
    dp[i][1] = min(dp[i-1][0] + abs(pv[i].first-pv[i-1].first)
                   + abs(pv[i].first-pv[i].second),
                   dp[i-1][1] + abs(pv[i].first-pv[i-1].second)
                   + abs(pv[i].first-pv[i].second) );
  }
  ll ans = min(dp[lpv-1][0] + abs(pv[lpv-1].first),
               dp[lpv-1][1] + abs(pv[lpv-1].second) );
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define COUNT(c,v) count(ALL(c),(v))
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) (((b)>>(i)) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VLD = vector<ld>;
using VVLD = vector<VLD>;
using VVVLD = vector<VVLD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

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

    ll N; cin >> N;
    VLL X(N),C(N); REP(i,N) cin >> X[i] >> C[i];

    map<ll,VLL> mp;
    // mp[0].push_back(0);
    mp[N+1].push_back(0);
    REP(i,N) mp[C[i]].push_back(X[i]);

    ll M = SZ(mp);
    VVLL dp(M+1,VLL(2,INF));
    dp[0][0] = 0;
    ll i = 1;
    VLL prev = {0,0};
    for (auto& [_, X] : mp) {
        ll L = INF, R = -INF;
        for (ll x : X) { chmin(L, x); chmax(R, x); }
        chmin(dp[i][0], dp[i-1][0] + llabs(prev[0] - R) + llabs(L - R));
        chmin(dp[i][0], dp[i-1][1] + llabs(prev[1] - R) + llabs(L - R));
        chmin(dp[i][1], dp[i-1][0] + llabs(prev[0] - L) + llabs(L - R));
        chmin(dp[i][1], dp[i-1][1] + llabs(prev[1] - L) + llabs(L - R));
        i++;
        prev[0] = L; prev[1] = R;
    }
    ll ans = MIN(dp[M]);
    COUT(ans);

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const double PI = 3.141592653589793238;
int main() {
  ll N, M;
  cin >> N >> M;
  set<ll> s;
  for (ll i = 0; i < N; ++i) {
    ll A;
    cin >> A;
    s.insert(A);
  }
  for (ll i = 0; i < M; ++i) {
    ll B;
    cin >> B;
    if (s.find(B) != s.end()) s.erase(B);
    else s.insert(B);
  }
  ll cnt = 0;
  for (auto i = s.begin(); i != s.end(); ++i) {
    ++cnt;
    cout << *i << (cnt == s.size() ? "\n" : " ");
  }
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define yes() cout << "Yes" << endl
#define no() cout << "No" << endl
using ll = long long;
using ld = long double;
using P = pair<int,int>;

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

    vector <int> memo(1001,0);

    rep(i,n+m){
        int x;
        cin>>x;

        memo[x]++;
    }
    rep(i,1001){
        if(memo[i]==1)cout<<i<<" ";
    }
    cout<<endl;

}


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

const int INF = 1001001001;

int h, w;
int a[2005][2005];
bool visited[2005][2005];
int memo[2005][2005];

int f(int i, int j){
	if(i == h-1 && j == w-1) return 0;
  	if(visited[i][j]) return memo[i][j];

  	visited[i][j] = true;
  	int res = -INF;
  	if(j+1 < w) res = max(res, a[i][j+1]-f(i, j+1));
    if(i+1 < h) res = max(res, a[i+1][j]-f(i+1, j));

  	return memo[i][j] = res;
}

int main(){
  	cin >> h >> w;
	rep(i, h)rep(j, w){
    	char x;
      	cin >> x;
      	if(x == '+') a[i][j] = 1;
       	else a[i][j] = -1;
    }

  	int score = f(0, 0);

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

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

#define ll long long
#define ull unsigned long long
#define gcd __gcd
#define INF LONG_LONG_MAX

void solve(){
	int n,m;
	cin>>n>>m;
	vector<string> arr(n);
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	vector<vector<int> > dp(n,vector<int> (m,0));
	vector<vector<int> > vst(n,vector<int> (m,0));
	queue<tuple<int,int,int> > qu;
	tuple<int,int,int> temp;
	int a=0;
	if((n+m)%2){
		a=1;
	}else{
		a=0;
	}
	int cnt=0;
	char ch=arr[0][0];
	qu.push(make_tuple(n-1,m-1,a));
	while(qu.size()){
		cnt++;
		temp=qu.front();
		qu.pop();
		int u,v,w;
		u=get<0>(temp);
		v=get<1>(temp);
		w=get<2>(temp);
		if(arr[u][v]=='!'){
			continue;
		}
		if(u==n-1&&v==m-1){
			if(w){
				if(arr[u][v]=='+'){
					dp[u][v]++;
				}else{
					dp[u][v]--;
				}
			}else{
				if(arr[u][v]=='+'){
					dp[u][v]--;
				}else{
					dp[u][v]++;
				}
			}
		}else
		if(u==n-1){
			if(w){
				if(arr[u][v]=='+'){
					dp[u][v]++;
				}else{
					dp[u][v]--;
				}
			}else{
				if(arr[u][v]=='+'){
					dp[u][v]--;
				}else{
					dp[u][v]++;
				}
			}
			dp[u][v]+=dp[u][v+1];
		}else
		if(v==m-1){
			if(w){
				if(arr[u][v]=='+'){
					dp[u][v]++;
				}else{
					dp[u][v]--;
				}
			}else{
				if(arr[u][v]=='+'){
					dp[u][v]--;
				}else{
					dp[u][v]++;
				}
			}
			dp[u][v]+=dp[u+1][v];
		}else{
			if(w){
				if(arr[u][v]=='+'){
					dp[u][v]++;
				}else{
					dp[u][v]--;
				}
				dp[u][v]+=min(dp[u+1][v],dp[u][v+1]);
			}else{
				if(arr[u][v]=='+'){
					dp[u][v]--;
				}else{
					dp[u][v]++;
				}
				dp[u][v]+=max(dp[u+1][v],dp[u][v+1]);
			}
		}
		arr[u][v]='!';
		if(u-1>=0&&vst[u-1][v]!=1){
			qu.push(make_tuple(u-1,v,w^1));
			vst[u-1][v]=1;
		}
		if(v-1>=0&&vst[u][v-1]!=1){
			qu.push(make_tuple(u,v-1,w^1));
			vst[u][v-1]=1;
		}
	}
	if(ch=='+'){
		dp[0][0]++;
	}else{
		dp[0][0]--;
	}
	// for(int i=0;i<n;i++){
	// 	for(int j=0;j<m;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	if(dp[0][0]==0){
		cout<<"Draw\n";
	}else{
		if(dp[0][0]>0){
			cout<<"Takahashi\n";
		}else{
			cout<<"Aoki\n";
		}
	}
}

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


//arc111_c.cpp
//Sat Jan  9 22:32:39 2021

#include <bits/stdc++.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	vector<int> konohitonotaijyu(n);
	vector<P> taijyu;
	rep(i,n){
		int tmp;
		cin >> tmp;
		taijyu.push_back(P(tmp,i));
		konohitonotaijyu[i] = tmp;
	}
	vector<int> cargo(n);
	rep(i,n){
		cin >> cargo[i];
	}

	//何番さんが何番の荷物持ってるか
	vector<int> cn(n);
	rep(i,n){
		cin >> cn[i];
		cn[i]--;
	}
	//何番の荷物を何番さんが持ってるか
	vector<int> mn(n);
	rep(i,n){
		mn[cn[i]]=i;
	}

	sort(taijyu.begin(),taijyu.end());
	vector<int> order;
	rep(i,n){
		order.push_back(taijyu[i].second);
	}

	vector<P> ans;
	rep(i,n){
		int from = order[i];
		if (cn[from]==from)continue;
		if (cargo[cn[from]]>=konohitonotaijyu[from]){
			if (i==n-1)break;
			cout << -1 << endl;
			return 0;
		}
		int to = mn[order[i]];
		ans.push_back(P(from,to));
		int fromnimotu = cn[from];
		int tonimotu = cn[to];
		int x = fromnimotu;
		cn[from] = tonimotu;
		cn[to] = fromnimotu;
		mn[fromnimotu] = to;
		mn[tonimotu] = from;
	}

	cout << ans.size() << endl;

	rep(i,ans.size()){
		cout << ans[i].first+1 << " " << ans[i].second+1 << endl;
	}
}

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

int main() {
	int n;
	cin>>n;
	vector<int> A(n + 1), B(n + 1), P(n + 1), par(n + 1);
	vector<vector<int>> cycles(n + 1);
	int cid = 0;
	for(int i = 1; i <= n; ++i) {
		cin>>A[i];
	}
	for(int i = 1; i <= n; ++i) {
		cin>>B[i];
	}
	for(int i = 1; i <= n; ++i) {
		cin>>P[i];
		par[i] = P[i];
	}
	vector<int> vs(n + 1, 0);
	for(int i = 1; i <= n; ++i) {
		if(!vs[i]) {
			int x = i;
			while(!vs[x]) {
				cycles[cid].push_back(x);
				vs[x] = 1;
				x = par[x];
			}
			cid += 1;
		}
	}
	vector<pair<int, int>> ans;
	bool imps = 0;
	for(auto cycle: cycles) {
		set<pair<int, int>> wts;
		for(auto x: cycle) {
			// cout<<"x = "<<x<<endl;
			if(B[par[x]] >= A[x] && par[x] != x) {
				imps = 1;
			}
			wts.insert({B[par[x]], x});
		}
		while(!imps && !wts.empty()) {
			auto tp = --wts.end();
			int cur = tp->second;
			int nxt = par[cur];
			wts.erase(tp);
			if(nxt == cur) {
				continue;
			}
			// cout<<" next "<<nxt<<" "<<cur<<endl;
			par[cur] = par[nxt];
			par[nxt] = nxt;
			ans.push_back({cur, nxt});
			wts.insert({B[par[cur]], cur});
			if(B[par[cur]] >= A[cur] && par[cur] != cur) {
				imps = 1;
				break;
			}
		}
	}
	if(imps) {
		cout<<"-1\n"<<endl;
		return 0;
	}
	cout<<ans.size()<<endl;
	for(auto x: ans) {
		cout<<x.first<<" "<<x.second<<endl;;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <climits>

using namespace std;

template<class T>
using V = vector<T>;
template<class T>
using VV = V<V<T>>;

using ld = long double;
#define ll long long
using ull = unsigned ll;
using PLL = pair<ll, ll>;
using VLL = V<ll>;
using VB = V<bool>;
using VVB = VV<bool>;
using VVLL = VV<ll>;
using Gr = VVLL;
using MLL = map<ll, ll>;
#define UMLL unordered_map<ll, ll, custom_hash>

#define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

#define R &
#define CR const R

#define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i)
#define FOR(i, n) FORI(i, 0, n)
#define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i)
#define RFOR(i, n) RFORI(i, n, 0)
#define FORA(i, a) for(auto i : a)
#define FORAR(i, a) for(auto R i : a)
#define FORACR(i, a) for(auto CR i : a)
#define ALL(obj) begin(obj), end(obj)
#define Count(q) while(q--)
#define OK cerr << "OK\n";

#define mp make_pair
#define pb push_back

//#define DEBUG

template<class T>
T sqr(T x)
{
    return x * x;
}

void YES(bool g, ostream R os, bool upper = true)
{
    if(g)
        if(upper)
            os << "YES";
        else
            os << "Yes";
    else
        if(upper)
            os << "NO";
        else
            os << "No";

    os << "\n";
}

template<class T>
void show(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        os << i << " ";
    os << "\n";
}

template<class T>
void show2d(T CR t, ostream R os = cerr)
{
    FORACR(i, t)
        show(i, os);
    os << "\n";
}

constexpr ll MOD = 1e9 + 7; //998244353;
constexpr ll len = 'z' - 'a' + 1;

constexpr ll INF = 1e15, MINF = -INF;

constexpr ld PI = atanl(1.0L) * 4;
constexpr ld eps = 1e-9, EPS = 1e-9;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator() (uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

//arr
void init() {}

void solve(istream R is, ostream R os)
{
    ll n;
    is >> n;

    string s;
    is >> s;

    char t = s[0];
    bool g = 1;

    FORA(i, s)
        g &= i == t;

    if(g)
    {
        os << "-1\n";
        return;
    }

    if(s.front() != s.back())
    {
        os << "1\n";
        return;
    }

    g = 0;
    FOR(i, n - 1)
        if(t != s[i] && t != s[i + 1])
        {
            g = 1;
        }

    if(g)
        os << "2\n";
    else
        os << "-1\n";
}

void tester(istream R is, ostream R os)
{
    auto seed = time(nullptr);
    //cerr << "seed: " << seed << "\n";
    srand(seed);
    fast
    init();
    ll q = 1;
    //is >> q;

    os << setprecision(999);
    Count(q)
        solve(is, os);
}

int main()
{
    //ifstream in("input.txt");
    //ofstream out("output.txt");

    tester(cin, cout);
}

#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pb push_back
#define mp make_pair
#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define w(x) int x;cin>>x;while(x--)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vvi vector<vector<int>>
#define precision(x,k) fixed<<setprecision(k)<<x
#define inf 1e16
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int a,b,c;
   vector<int>v[10];
   for(int i=0;i<=9;i++)
   {
       int x=i;
       v[i].push_back(x);
       if(i!=0)
       x=(x*i)%10;
       while(x!=i)
       {
         v[i].push_back(x);
         x=(x*i)%10;
       }
   }
 /*  for0(i,10)
  {
      for0(j,v[i].size())
       cout<<v[i][j]<<" ";
       cout<<"\n";
   }*/
   cin>>a>>b>>c;
   int r=a%10;
 //  cout<<r<<"\n";
   int ans1= b%(v[r].size());
   if(ans1==0)
   ans1=v[r].size();
   ans1=v[r][ans1-1];
  // cout<<ans1<<"\n";
   int p[10];
   for(int i=0;i<10;i++)
   p[i]=0;
   int j=ans1;
   int i=1;
   while(p[j]==0)
   {//cout<<j<<" "<<i<<"\n";
    p[j]=i;
    i++;
    int k=j;
    j=b%(v[k].size());
    if(j==0)
    j=v[k].size();
    j=v[k][j-1];
   }
   int st=p[j]-1;
   int sz=i-p[j];
 //  cout<<st<<" "<<sz<<"\n";
   int ans;
   if(c<=st)
   ans=c;
   else{
   ans=(c-st)%sz;
   if(ans==0)
   ans=sz;
   ans=ans+st;
   }
  // cout<<ans<<"\n";
   int final_ans;
   for(int i=0;i<10;i++)
  { //cout<<p[i]<<" ";
      if(p[i]==ans)
     final_ans=i;
  }
  cout<<final_ans<<"\n";
    return 0;
}


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

using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define reps(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define uniq(a) (a).erase(unique(all(a)), (a).end())
#define bit(n) (1LL << (n))
#define dump(a) cerr << #a " = " << (a) << endl
using vll = vector<ll>;
using pll = pair<ll, ll>;
template <typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr ll DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr ll DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
ll sign(ll a) { return (a > 0) - (a < 0); }
ll cdiv(ll a, ll b) { return (a - 1 + b) / b; }
template <typename T> T sq(T a) { return a * a; }
template <typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) {
    os << "(" << a.first << ", " << a.second << ")";
    return os;
}
template <typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) {
    auto [t, u, v] = a;
    os << "(" << t << ", " << u << ", " << v << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &a) {
    os << "(";
    for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
    os << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
    os << "}";
    return os;
}
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) {
    os << "{";
    for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); }
    os << "}";
    return os;
}
struct setup {
    static constexpr ll PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    if (s[0] != s[s.length() - 1]) {
        cout << 1 << endl;
        return 0;
    }
    rep(i, s.length() - 1) {
        if (s[i] != s[0] && s[i + 1] != s[0]) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i,a,b) for(int i = a; i<b ; i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define pb push_back
#define M 1000000007
int mod(int x){
return ((x%M + M)%M);
}
int add(int a,int b){
return mod(mod(a)+mod(b));
}
int mul(int a,int b){
return mod(mod(a)*mod(b));
}
// ****************************************************************************
void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n==1){
        cout<<"-1\n";
        return;
    }
    if(s[0]!=s[n-1]){
        cout<<"1\n";
        return;
    }
    bool f = false;
    fo(i,1,n-2){
        if(s[i]!=s[0] && s[i+1]!=s[0])
        f=true;
    }
    if(f)
    cout<<"2\n";
    else cout<<"-1\n";

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


#include<bits/stdc++.h>
#define R register
#define ll long long
using namespace std;
const int MAXN = 1e5+5;
ll n,k,m,a[MAXN],b[MAXN],ans;
struct node
{
	int id;
	bool operator < (const node &x)const
	{
		return b[id]*n-m*a[id]>b[x.id]*n-m*a[x.id];
	}
};
bool check(ll x)
{
	ll tot=0;
	for(R int i=1;i<=k;++i)
	{
		ll num=m*a[i]-x;
		if(num<0) continue;
		{
			if(n*num/n>=num&&n*num/n<=num+2*x)
				tot+=num/n;
			else if(n*(num/n+1)>=num&&n*(num/n+1)<=num+2*x)
				tot+=num/n+1;
			else return false;
		}
	}
	return tot<=m;
}
void solve(ll x)
{
	ll tot=0;
	for(R int i=1;i<=k;++i)
	{
		ll num=m*a[i]-x;
		if(num<0) b[i]=0;
		else
		{
			if(n*num/n>=num&&n*num/n<=num+2*x)
				b[i]=num/n;
			else if(n*(num/n+1)>=num&&n*(num/n+1)<=num+2*x)
				b[i]=num/n+1;
		}
		tot+=b[i];
	}
	ll d=m-tot;
	for(R int i=1;i<=k;++i)
		b[i]+=d/k;
	d%=k;
	for(R int i=1;i<=k;++i)
	{
		if(!d) break;
		while(abs((b[i]+1)*n-m*a[i])<=ans)
		{
			--d;
			b[i]++;
		}
	}
	priority_queue <node> q;
	for(R int i=1;i<=k;++i) q.push(node{i});
	while(d--)
	{
		b[q.top().id]++;
		q.pop();
	}
	for(R int i=1;i<=k;++i)
		printf("%lld ",b[i]);
}
int main()
{
	scanf("%lld %lld %lld",&k,&n,&m);
	for(R int i=1;i<=k;++i) scanf("%d",&a[i]);
	ll l=0,r=n*m;
	ans=n*m;
	while(l<=r)
	{
		ll mid=l+r>>1;
		if(check(mid))
		{
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	solve(ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
std::mt19937 rnd(time(0));
inline int sj(int n)
{
	unsigned int x=rnd();
	return x%n+1;
}
#define rand fst
template<typename typC> void read(register typC &x)
{
	register int c=getchar(),fh=1;
	while ((c<48)||(c>57))
	{
		if (c=='-') {c=getchar();fh=-1;break;}
		c=getchar();
	}
	x=c^48;c=getchar();
	while ((c>=48)&&(c<=57))
	{
		x=x*10+(c^48);
		c=getchar();
	}
	x*=fh;
}
template<typename typC, typename... Args> void read(typC &first, Args& ... args) {
	read(first);
	read(args...);
}
template<typename typC> void read(register typC *a,int num)
{
	for (register int i=1;i<=num;i++) read(a[i]);
}
template<typename typC> void write(register typC x)
{
	if (x<0) putchar('-'),x=-x;
	static int st[100];
	register int tp=1;
	register typC y;st[1]=x%10;x/=10;
	while (x) y=x/10,st[++tp]=x-y*10,x=y;++tp;
	while (--tp) putchar(st[tp]|48);
}
template<typename typC> void write(register typC *a,register int num)
{
	for (register int i=1;i<=num;i++) write(a[i]),putchar(i==num?10:32);
}
template<typename typC> typC ab(register typC x)
{
	if (x<0) return -x;
	return x;
}
#define space(x) write(x),putchar(32)
#define enter(x) write(x),putchar(10)
const int p=998244353;
const db eps=1e-9;
inline void inc(register int &x,const int y)
{
	if ((x+=y)>=p) x-=p;
}
inline void dec(register int &x,const int y)
{
	if ((x-=y)<0) x+=p;
}
inline int ksm(register int x,register int y)
{
	register int r=1;
	while (y)
	{
		if (y&1) r=(ll)r*x%p;
		x=(ll)x*x%p;
		y>>=1;
	}
	return r;
}
priority_queue<int> ONLYYFORRCOPYY;
priority_queue<int,vector<int>,greater<int> > ONLYYFORRCOPYY__;
struct Q
{
	int u,v;
	Q(int a=0,int b=0):u(a),v(b){}
	bool operator<(const Q &o) const {return v<o.v;}
};
typedef pair<ll,int> pa;
const int N=1e6+2,M=1e6+2,inf=1e9;
char s[N];
int a[N],b[N];
pa c[N];
int T,n,m,i,j,k,x,y,z,ans,la,ksiz,ks;
int main()
{
	//ios::sync_with_stdio(false);
	cout<<setiosflags(ios::fixed)<<setprecision(15);
	T=1;
	read(k,n,m);read(a,k);
	for (i=1;i<=k;i++) ans+=(b[i]=(ll)a[i]*m/n),c[i]=pa((ll)a[i]*m-(ll)b[i]*n,i);
	ans=m-ans;
	sort(c+1,c+k+1);reverse(c+1,c+k+1);
	for (i=1;i<=ans;i++) ++b[c[i].second];
	write(b,k);
}