# include <bits/stdc++.h>
# ifndef ngng628_library
# define ngng628_library
# define int long long
# define float long double
# define fi first
# define se second
# define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i,n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i,n) for(int i=((int)(n)); i>0; --i)
# define repr(i,b,e) for(int i=(b), i##_len=(e); i<i##_len; ++i)
# define reprs(i,b,e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define all(x) std::begin(x), std::end(x)
# define rall(x) std::rbegin(x), std::rend(x)
# define pb push_back
# define eb emplace_back
# define len(x) ((int)(x).size())
# define lb(v,x) distance(std::begin(v), lower_bound(all(v), (x)))
# define ub(v,x) distance(std::begin(v), upper_bound(all(v), (x)))
using namespace std;
template<class T> using vec = vector<T>;
using pii = pair<int, int>;
using vi = vec<int>;
using vb = vec<bool>;
using vs = vec<string>;
using vvi = vec<vi>;
constexpr int INF = (1LL<<62)-(1LL<<31);
constexpr float EPS = 1e-10;
template<class T> T scan() { T ret; cin >> ret; return ret; }
template<class T> istream& operator>>(istream& is, vec<T>& v) { for (auto& x : v) is >> x; return is; }
template<class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.fi >> p.se; }
template<class T> string join(const vec<T> &v){ stringstream s; rep (i, len(v)) s<<' '<<v[i]; return s.str().substr(1); }
template<class T> ostream& operator<<(ostream& os, const vec<T>& v){ if (len(v)) return os << join(v); }
template<class T> ostream& operator<<(ostream& os, const vec<vec<T>>& v){ rep (i, len(v)) if (len(v[i])) os << join(v[i]) << (i-len(v)+1 ? "\n" : ""); return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << p.fi << " " << p.se; }
template<class T, class U, class V> ostream& operator<<(ostream& os, const tuple<T, U, V>& t){ return os << get<0>(t) << " " << get<1>(t) << " " << get<2>(t); }
void print(){ cout << "\n"; }
template<class T, class... A>void print(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; print(args...); }
void eprint() { cerr << "\n"; }
template<class T, class... A>void eprint(const T& v, const A&...args){ cerr << v; if(sizeof...(args))cerr << " "; eprint(args...); }
void drop(){ cout << "\n"; exit(0); }
template<class T, class... A>void drop(const T& v, const A&...args){ cout << v; if(sizeof...(args))cout << " "; drop(args...); }
template<class T> constexpr bool chmax(T &a, const T& b) { return a < b && (a = b, true); }
template<class T> constexpr bool chmin(T &a, const T& b) { return a > b && (a = b, true); }
constexpr int ctoi(const char c) { return ('0' <= c and c <= '9') ? (c - '0') : -1; }
# endif  // ngng628_library

int32_t main() {
   int n;
   cin >> n;
   vi x(n);
   cin >> x;

   vi primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
   auto prime_to = [&](int a, int b) {
      for (int prime : primes) {
         if (a % prime == 0 and b % prime == 0) {
            return false;
         }
      }
      return true;
   };

   int ans = INF;
   rep (bit, 1 << 15) {
      if (!bit) continue;
      int prod = 1;
      rep (i, 15) if ((bit >> i) & 1) prod *= primes[i];

      for (int e : x) {
         if (prime_to(e, prod)) goto Eat;
      }
      chmin(ans, prod);
      Eat:;
   }

   print(ans);
}

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

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

    int N; cin >> N;
    vector<ll> X(N);
    rep(i,N) cin >> X[i];
    vector<ll> P = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    int M = P.size();
    ll ans = 1e18;
    rep(i,1<<M){
        ll cur = 1;
        rep(j,M) if(i & (1 << j)) cur *= P[j];
        bool ok = true;
        rep(j,N) if(__gcd(X[j], cur) == 1) ok = false;
        if(ok) ans = min(ans, cur);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <functional>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef pair<int, int> pii;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
#define ll long long
#define ld long double
#define rep(i, a) for (ll i = 0; i < a; i++)
#define repe(i, a, b) for (ll i = a; i < b; i++)
#define bac(i, a) for (ll i = a; i >= 0; i--)
#define bace(i, a, b) for (ll i = a; i >= b; i--)
#define pb push_back
#define in insert
#define ff first
#define ss second
#define setbit(x) __builtin_popcountll(x)
#define init(c, a) memset(c, a, sizeof(c))
#define all(c) c.begin(), c.end()
#define sz(c) (ll) c.size()
#define lb lower_bound
#define ub upper_bound
#define maxe *max_element
#define mine *min_element
#define rev reverse
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
//priority_queue<pii, vector<pii>, greater<pii> > pq;

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

ll n;
bool check(ll N, ll n)
{
    if ((N / n - (n - 1)) % 2 == 0)
        return 1;
    else
        return 0;
}
void solve()
{
    cin >> n;
    n *= 2;
    // 2a+n-1=N/n
    // a = (N/n-(n-1))/2
    ll ans = 0;
    for (ll i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            if (n / i != i)
            {
                if (check(n, i))
                    ans++;
                if (check(n, n / i))
                    ans++;
            }
            else
            {
                if (check(n, i))
                    ans++;
            }
        }
    }
    cout << ans << '\n';
}
int main()
{
    fast;
    int t = 1;
    while (t--)
        solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        long long n;
        cin>>n;
        set <long long> divs;
        for(long long i=1;i*i<=2*n;i++){
            if((2*n)%i==0){
                divs.insert(i);
                divs.insert(-i);
                divs.insert((2*n)/i);
                divs.insert(-(2*n)/i);
            }
        }
        int ans=0;
        for(auto x:divs){
            if(x>0){
                if(((2*n)/x+1-x)%2==0)ans++;
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define pb push_back
#define ph push
// vector definition
#define vi vector<int>
#define vf vector<float>
#define vll vector<long long>
// set definition
#define si set<int>
#define sf set<float>
void solve(){
 	int a,b;
  cin>>a>>b;
  int x=(a+b)/2;
  int y=a-x;
  cout<<x<<" "<<y<<'\n';
}
int main(){
     cin.tie(0);
    cout.tie(0);
    int t;t=1;
    while(t--){
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int S,P;cin>>S>>P;
  for(int i=1;i*i<=P;i++)if(P%i==0&&i+P/i==S)return puts("Yes"),0;
  puts("No");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    ll memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(ll i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
    x=modpow(x,mod-2);
    return x;
}
void solve(){

}
int dp[1010][1010];
int main(){
    int n,m,a[1001],b[1001];
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];
    rep(i,n+1)rep(j,m+1)dp[i][j]=INF;
    dp[0][0]=0;
    rep(i,n+1){
        rep(j,m+1){
            if(j<m){
                chmin(dp[i][j+1],dp[i][j]+1);
            }
            if(i<n){
                chmin(dp[i+1][j],dp[i][j]+1);
            }
            if(i<n&&j<m){
                if(a[i]==b[j])chmin(dp[i+1][j+1],dp[i][j]);
                else chmin(dp[i+1][j+1],dp[i][j]+1);
            }
        }
    }
    cout<<dp[n][m]<<endl;
    return 0;
}

#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 ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mx 1000005
#define fiint(a,b) memset(a,b,sizeof(a))
#define bitcount __builtin_popcount
#define fori(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cout<<x<<endl;
#define cases(t) int t; cin>>t; while(t--)
#define inf1 INT_MAX
#define all(a) a.begin(),a.end()
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<int,int>
#define pint pair<int,int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mp make_pair

#define sz(x) (int)x.size()
#define PI    3.14159265359

//const long long INF=1e18;

bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; }

int factorial[10000001]={0};

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

int powerFunction(int x,int y){
    int res = 1;
     int p = mod;
    x = x;
    while (y > 0){
        if (y & 1)
            res = (res*x)%p ;
        y = y>>1;
        x = (x*x)%p ;
    }
    return res;
}

void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
    factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}

int nCr(int n, int r)
{
    if(r < 0 || r > n){
        return 0;
    }
    int temp = factorial[n];
    temp *= (powerFunction(factorial[r], MOD-2)%MOD);
    temp %= MOD;
    temp *= (powerFunction(factorial[n-r], MOD-2)%MOD);
    temp %= MOD;
    return temp;
}

int n,m;
vec a(2000)  , b(2000) ;
int dp[2000][2000];
int find(int i , int j)
{
    if(i >= n || j >= m)
        return (n - i) + (m - j) ;

    if(dp[i][j] != -1)
        return dp[i][j];

        int x = find(i+1 , j) + 1;
        int y = find(i , j+1) + 1 ;
        int z = find(i+1 , j+1) + (int)(a[i] != b[j]);
        //int c = find(i + 1 , j + 1 )  +2;
        dp[i][j] = min( z ,  min(x,y ));
        //cout<<dp[i][j] <<" "<<i <<" "<<j<<endl;

    return dp[i][j];
}

signed main()
{
    cin>>n>>m;
    for(int i = 0  ; i < n ;i++) cin>>a[i];
    for(int j = 0 ; j < m ;j++) cin>>b[j];
    for(int i = 0 ; i < 2000 ; i++)
        for(int j = 0 ; j < 2000 ; j++)
                dp[i][j] = -1;
    int  mi = find(0,0);
   // cout<<mi<<endl;
    cout << mi <<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

const int MAX = 55 * 55;
const int MOD = 998244353;
int fat[MAX];

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

inline int sub(int a, int b) {
    a -= b;
    if (0 > a) a += MOD;
    return a;
}

inline int mult(int a, int b) {
    return (1LL * a * b) % MOD;
}

int f_exp(int x, int e) {
    if (e <= 0) return 1;
    if (e & 1) return mult(x, f_exp(x, e - 1));
    return f_exp(mult(x, x), e / 2);
}

inline int inv(int x) {
    return f_exp(x, MOD - 2);
}

inline int comb(int n, int k) {
    if (k > n) return 0;
    return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}

void preprocess() {
    fat[0] = 1;
    fori (i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
}

int row_max[MAX];
int col_max[MAX];
vector<int> adj[2][MAX];
bool visited[2][MAX];
int n, k;
int mat[55][55];

int bfs(int id, int start) {
    queue<int> q;
    q.push(start);
    visited[id][start] = true;

    int size = 0;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        size++;

        for (auto &each : adj[id][cur]) {
            if (!visited[id][each]) {
                visited[id][each] = true;
                q.push(each);
            }
        }
    }

    return size;
}

void solve() {
    preprocess();

    cin >> n >> k;
    fori (i, 1, n + 1) {
        fori (j, 1, n + 1) {
            cin >> mat[i][j];
            row_max[i] = max(row_max[i], mat[i][j]);
            col_max[j] = max(col_max[j], mat[i][j]);
        }
    }

    fori (i, 1, n + 1) {
        fori (j, i + 1, n + 1) {
            bool row_ok = true;
            bool col_ok = true;
            fori (f, 1, n + 1) {
                if (mat[i][f] + mat[j][f] > k) row_ok = false;
                if (mat[f][i] + mat[f][j] > k) col_ok = false;
            }

            if (row_ok) {
                adj[0][i].push_back(j);
                adj[0][j].push_back(i);
            }

            if (col_ok) {
                adj[1][i].push_back(j);
                adj[1][j].push_back(i);
            }
        }
    }

    int prod[2];
    prod[0] = prod[1] = 1;

    fori (i, 0, 2) {
        fori (j, 1, n + 1) {
            if (!visited[i][j]) {
                int size = bfs(i, j);
                prod[i] = mult(prod[i], fat[size]);
            }
        }
    }

    cout << mult(prod[0], prod[1]) << endl;
}

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

// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &bb) {
    for (int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &bb) {
    for (int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

using namespace std;

ll dp[110][130000];

int main() {
    ll n, k, m; cin >> n >> k >> m;
    dp[0][0] = 1;
    rip(i,n+1,1) {
        rip(j,130000, 0) {
            dp[i][j] = dp[i-1][j];

            if(j-i >= 0) {
                dp[i][j] += dp[i][j-i];
                dp[i][j] %= m;
            }
            if(j - i*(k+1) >= 0) {
                dp[i][j] -= dp[i-1][j - i*(k+1)]+m;
                dp[i][j] %= m;
            }
        }
    }
    rip(i, n, 0) {
        ll ans = 0;
        rip(j, 130000, 0) {
            ans += 1LL * dp[i][j] * dp[n-i-1][j] % m;
        }
        printf("%lld\n", (ans%m*(k+1)%m-1+m)%m);
    }
}


#include <bits/stdc++.h>

int main(){
  int N;
  std::cin>>N;
  int A, B, A_max = 0;
  int B_min = 1000;
  for (int i = 0; i<N; ++i){
    std::cin>>A;
    if(A>A_max)
      A_max = A;
  }
  for (int i = 0; i<N; ++i){
    std::cin>>B;
    if(B<B_min)
      B_min = B;
  }
  int c = 0;
  for (int i = A_max; i<=B_min; i++)
    ++c;
  std::cout<<c<<std::endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;

int a[1010], b[1010];
int main() {
  int n;
  cin >> n;

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

  int ans = 0;
  for (int i = 1; i <= 1000; i++)
  {
    bool ok = true;
    rep(j,n) {
      if(!(a[j] <= i && i <= b[j])) ok = false;
    }
    if (ok) ans++;
  }
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
// #pragma GCC2 optimize(2)
#define cio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
vector<ll> v;
int main()
{
   // cout<<"kdhfj"<<endl;
    cio;
    int a,b,c;
    cin>>a>>b>>c;
    if(c%2==0)
    {
		int aa=abs(a);
		int bb=abs(b);
		if(aa>bb)cout<<">"<<endl;
		else if(aa==bb)cout<<"="<<endl;
		else cout<<"<"<<endl;
	}
	else
	{
		int aa=a;
		int bb=b;
		if(aa>bb)cout<<">"<<endl;
		else if(aa==bb)cout<<"="<<endl;
		else cout<<"<"<<endl;
	}
}

#include <bits/stdc++.h>

using namespace std;

main() {
	int N, W; scanf("%d %d", &N, &W);
  	printf("%d", N / W);
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;

struct part {
    int v, l;
    part(int v=0, int l=0): v(v), l(l) {}
};

int main() {
    // 全探索、重さでソート、最長路、二分探索
    int N, M;
    cin >> N >> M;
    vector<int> W(N);
    rep(i, N) cin >> W[i];
    sort(W.begin(), W.end());
    vector<part> LV(M);
    int maxV = 0, minV = 1e9;
    rep(i, M) {
        int l, v;
        cin >> l >> v;
        maxV = max(maxV, v);
        minV = min(minV, v);
        LV[i].v = v;
        LV[i].l = l;
    }
    if (W[N-1] > minV) {
        cout << -1 << '\n';
        return 0;
    }
    sort(LV.begin(), LV.end(), [&] (const part& x, const part& y) { return x.v < y.v; });
    map<int, ll> mp;
    rep(i, M) {
        int key = LV[i].v;
        int value = LV[i].l;
        if (mp[key] < value) {
            mp[key] = value;
        }
    }
    int maxL = 0;
    for (auto &p : mp) {
        if (p.second > maxL) {
            maxL = p.second;
        }
        p.second = maxL;
    }
    mp[INF] = maxL;
    vector<int> pos(N);
    rep(i, N) pos[i] = i;
    ll ans = 1e16;
    do {
        vector<P> ws(N);
        rep(i, N) ws[i].first = W[pos[i]];
        vector<vector<ll>> dist(N, vector<ll> (N));
        rep(i, N) for (int j = i+1; j < N; j++) {
            // iからjまでの重さが十分の距離があるか
            int temp = 0, d = 0;
            for (int k = i; k <= j; k++) {
                temp += ws[k].first;
                if (k != j) d += ws[k].second;
            }
            if (temp <= minV) continue;
            auto it = mp.lower_bound(temp);
            if (it == mp.begin()) continue;
            it--;
            dist[i][j] = it -> second;
        }
        vector<ll> dp(N);
        rep(i, N) for (int j = i+1; j < N; j++) {
            dp[j] = max(dp[j], dp[i] + dist[i][j]);
        }
        ans = min(ans, dp[N-1]);
    } while (next_permutation(pos.begin(), pos.end()));
    cout << ans << '\n';
    return 0;
}

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m, c[10], dl[10], vis[10], ans = 0x3f3f3f3f, lx[10], db[10];
struct judge {
    int l;
    int v;
};
judge a[100010];
bool tmp(judge x, judge y)
{
    if (x.l != y.l) return x.l < y.l;
    else return x.v > y.v;
}
int findl(int x)
{
    int b, e, t;
    b = 1, e = m, t = b + e >> 1;
    while (b < e)
    {
        if (a[t].v >= x) e = t-1;
        else b = t ;
        t = b + e +1>> 1;
    }
    if (a[b].v >= x) return 0;
    return a[b].l;
}
void fact()
{
    memset(lx, 0, sizeof lx);
    for (int i = 1; i <= n; i++)
    {
        db[i] = db[i - 1] + c[dl[i]];
    }
    for (int i = 2; i <= n; i++)
        for (int j = 1; j < i; j++)
        {
            int l = findl(db[i] - db[j - 1]);
            lx[i] = max(lx[i], lx[j] + l);
        }
    ans = min(ans, lx[n]);
}
void dfs(int i)
{
    if (i == n + 1)
    {
        fact();
        return;
    }
    for (int j = 1; j <= n; j++)
    {
        if (!vis[j])
        {
            vis[j] = 1;
            dl[i] = j;
            dfs(i + 1);
            vis[j] = 0;
        }
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)  cin >> c[i];
    for (int i = 1; i <= m; i++)  cin >> a[i].l >> a[i].v;
    sort(a + 1, a + m + 1, tmp);
    for (int i = m - 1; i > 0; i--) a[i].v = min(a[i].v, a[i + 1].v);
    for (int i = 1; i <= n; i++) if (c[i] > a[1].v) { cout << -1; return 0; }
    dfs(1);
    cout << ans;
}


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

vector<vector<int>> edge;
vector<int> v;
vector<int> d;

int dfs(ll now, ll pre, ll target) {
    int res = 0;
    int ma = -1, mi = 1000000;
    int dma = -1, dmi = 1000000;
    int cnt = 0;
    for (int nxt : edge[now]) {
        if (nxt == pre) continue;
        cnt++;
        res += dfs(nxt, now, target);
        mi = min(mi, v[nxt]);
        ma = max(ma, v[nxt]);
        dmi = min(dmi, d[nxt]);
        dma = max(dma, d[nxt]);
    }
    d[now] = dmi+1;
    bool put = false;
    if (cnt == 0) {
        return 0;
    }else if (cnt == 1) {
        if (mi >= 2*target) {
            v[now] = 0;
            put = true;
        }else {
            v[now] = mi+1;
        }
    }else {
        if (ma+dmi+2 <= 2*target+1) {
            v[now] = mi+1;
        }else if (ma+1 >= 2*target+1){
            v[now] = 0;
            put = true;
        }else {
            v[now] = ma+1;
        }
    }
    if (now == 0 && !put) {
        if (v[now] > target) put = true;
    }
    if (put) {
        res++;
        d[now] = 0;
    }
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    edge.resize(N);
    v.resize(N);
    d.resize(N);
    for (int i = 0; i < N-1; i++) {
        int u, v;
        cin >> u >> v;
        u--;v--;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }

    ll l = 0, r = N;
    while (r-l > 1) {
        ll c = (l+r)/2;
        fill(v.begin(), v.end(), c+1);
        fill(d.begin(), d.end(), N*10);
        ll need = dfs(0, -1, c);
        //cout << need << endl;
        if (need <= K) r = c;
        else l = c;
    }
    cout << r << endl;

    return 0;
}

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

using namespace std;
const ll mod = 1e15+7;
const ll N = 2e5+5;
const int base = 313;
ll n, m, t, k, T, ans, siz, tong, a[N], b[N], d[N], c[N], h[N], P[N][20];
string s[N];
vector<ll> adj[N];
vector<pll> kq;

ll pw(ll k, ll n)
{
    ll total = 1;
    for(; n; n >>= 1)
    {
        if(n & 1)total = total * k % mod;
        k = k * k % mod;
    }
    return total;
}

void dfs(ll u, ll p)
{
    for(int i = 1; i <= 18; i ++)P[u][i] = P[P[u][i-1]][i-1];
    for(ll v : adj[u])
    {
        if(v == p)continue;
        h[v] = h[u] + 1;
        P[v][0] = u;
        dfs(v, u);
    }
}
ll par(ll u, ll dist)
{
    if(h[u] < dist)return 1;
    for(int i = 18; i >= 0; i --)
    {
        if((dist >> i) & 1)
        {
            u = P[u][i];
        }
    }
    return u;
}
void bfs(ll u, ll len)
{
    queue<ll> q;
    d[u] = 0;
    q.push(u);
    while(!q.empty())
    {
        ll u = q.front();
        q.pop();
        if(d[u] == len)continue;
        for(ll v : adj[u])
        {
            if(d[v] > d[u] + 1)
            {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
}

bool check(ll len)
{
    ll cnt = 0;
    fill_n(d, n+2, mod);
    for(pll x : kq)
    {
        if(d[x.se] <= len)continue;
        ll root = par(x.se, len);
        bfs(root, len);
        ++cnt;
        //cout << root <<" "<<x.se<<'\n';
        if(cnt > k)return false;
    }
    return true;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i < n; i ++)
    {
        ll x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1, 0);
    for(int i = 1; i <= n; i ++)kq.pb({h[i], i});
    sort(kq.rbegin(), kq.rend());
    ll lf = 0, rt = n, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(check(mid))rt = mid - 1;
        else lf = mid + 1;
    }
    cout << lf;
}
int main()
{
    if(fopen(task".INP", "r"))
    {
       freopen(task".INP", "r", stdin);
       freopen(task".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
5 1
1 2
2 3
3 4
4 5

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

*/


#include <bits/stdc++.h>
#define int ll
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n)  FF(i,0,n)
#define F1(i,n)  FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCOL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const int N=2E5+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=1E9+7;
const double eps=1E-8;
void gen(){

}
void sol(){
    int n;cin>>n;n*=2;
    vector<int> a(n);
    F(i,n) cin>>a[i];
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ALL(ord),[&](int i,int j){return a[i]<a[j];});
    vector<int> b(n);
    F(i,n) b[ord[i]]=(i<n/2)?1:0;
    string res(n, ' ');
    vector<int> st;
    F(i,n){
        if(!st.empty()&&b[i]!=b[st.back()]){
            res[st.back()] = '(';
            res[i] = ')';
            st.pop_back();
        }
        else {
            st.push_back(i);
        }
  }
  cout <<res<< '\n';
}
int32_t main(){
    #ifdef LOCAL
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #endif // LOCAL
    #ifndef LOCAL
    #endif // LOCAL
    IOS;
    int t=1;
    gen();
    //cin>>t;
    FF(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        sol();
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll t;
cin>>t;
while(t--){
  ll x;
  cin>>x;
  if(x%2==1){
    cout<<"Odd"<<'\n';
    continue;
    }
  if(x>=4 && x%4==0){
    cout<<"Even"<<'\n';
    continue;
   }
  if(x%2==0){
    cout<<"Same"<<'\n';
    continue;
    }

}
}


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

typedef long long LL;
typedef pair<int, int> P;

const int maxn = 500 + 10;
const int M_MAX = 10 * maxn * maxn;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;
const double eps = 1e-6;

struct edge {
    int to, cost, next;
}e[5000010];

int n, m;
int h[1000010], d[1000010], len = 1;

int p(int x, int y) { return (x - 1) * m + y; }

void addedge(int v, int u, int cost) {
    e[len].to = u;
    e[len].cost = cost;
    e[len].next = h[v];
    h[v] = len++;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < m; j++) {
            int c; cin >> c;
            addedge(p(i, j) , p(i, j + 1), c);
            addedge(p(i,j+1), p(i, j), c);
        }
    }
    for(int i = 1; i < n; i++) {
        for(int j = 1; j <= m; j++) {
            int c; cin >> c;
            addedge(p(i, j), p(i+1, j), c);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i, j), p(i, j) + n*m, 1);
            addedge(p(i,j) + n*m, p(i,j), 0);
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1);
        }
    }
    for(int i = 1; i <= 2 * n * m; i++) d[i] = INF;
    d[1] = 0;
    priority_queue<P> que;
    que.emplace(make_pair(0, 1));
    while(!que.empty()) {
        P pe = que.top(); que.pop();
        int v = pe.second;
        if(-d[v] != pe.first) continue;
        for(int i = h[v]; i; i = e[i].next) {
            if(d[e[i].to] > e[i].cost + d[v]) {
                d[e[i].to] = e[i].cost + d[v];
                que.emplace(make_pair(-d[e[i].to], e[i].to));
            }
        }
    }
    cout << d[n*m] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}

#include <stdio.h>
inline int read() {
    int b = getchar(), c = 0;
    int m = b == 45;
    if (m) b = getchar();
    while (b > 47) {
        c = c * 10 + b - 48;
        b = getchar();
    }
    return m ? - c : c;
}
int p[200001];
int main() {
    int a[400002];
    int n = read(), m = read();
    long s = 0;
    for (int i = 1; i <= n + n; i++) a[i] = read();
    for (int i = 0; i < m + m; i++) p[read()] = 1;
    p[1] = 1;
    for (int i = 1; i < 200001; i++) {
        if (p[i]) s += a[i] - a[i + n];
    }
    puts(s ? "No" : "Yes");
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD
#define MODSUB(SUB_X,SUB_Y)  ((SUB_X-SUB_Y)+MOD)%MOD
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD
#define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)998244353;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
ll dp[105][105][10050],arr[105],sum,n,fact[105];
ll recur(int pos,int cnt,int s)
{
    if(pos==n)
    {
        if((sum-s)==s)
        {
            int cnt2=n-cnt;
            return (fact[cnt]*fact[cnt2])%MOD;
        }
        return 0;
    }
    ll &ret=dp[pos][cnt][s];
    if(~ret) return ret;
    ret=0;
    ret+=recur(pos+1,cnt+1,s+arr[pos]);
    ret=(ret+recur(pos+1,cnt,s))%MOD;
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    memset(dp,-1,sizeof(dp));
    fact[0]=1;
    for(int i=1; i<=100; i++)
        fact[i]=(fact[i-1]*i)%MOD;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        sum+=arr[i];
    }
    cout<<recur(0,0,0)<<endl;

    return 0;
}

/* In the name of *Allah* *
 *   Thank You *Parsa*    */

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops, avx, avx2, fma")

#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<ios>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<numeric>
using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;
typedef long double ld;

const int inf_int = 1 << 30;
const ll inf_longlong = 1LL << 62;
const int MOD = 998244353;

const int N = 100 + 5;
int n, w[N];
int dp[N][N * N], fact[N];

void init() {
	fact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = 1LL * fact[i - 1] * i % MOD;
}

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

void read_input() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> w[i];
}

void solve() {
	dp[0][0] = 1;

	for (int i = 1; i <= n; i++) {
		for (int k = i; k; k--) {
			for (int j = w[i]; j < N * N; j++) {
				add(dp[k][j], dp[k - 1][j - w[i]]);
			}
		}
	}
	int ans = 0, sum = accumulate(w + 1, w + n + 1, 0);
	if (sum % 2) {
		cout << 0 << '\n';
		return;
	}
	for (int i = 1; i < n; i++) {
		add(ans, 1LL * dp[i][sum / 2] * fact[i] % MOD * fact[n - i] % MOD);
	}
	cout << ans << '\n';
}

void write_output() {
}

int main() {
	ios:: sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	init();

	int test_cases = 1; //cin >> test_cases;
	while (test_cases--) {
		read_input(), solve(), write_output();
	}
	return 0;
}
// Thanks *Allah*


#include<bits/stdc++.h>
using namespace std;
const int maxn=2020;
int n,m;
int fa[maxn];
int fnd(int x)
{
	if(fa[x]==x)
	{
		return x;
	}
	return fa[x]=fnd(fa[x]);
}
void merge(int x,int y)
{
	fa[fnd(x)]=fnd(y);
}
set<int> s1,s2;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n+m;i++)
	{
		fa[i]=i;
	}
	merge(1,n);
	merge(1,n+1);
	merge(1,n+m);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			char c;
			cin>>c;
			if(c=='#')
			{
				merge(i,j+n);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		s1.insert(fnd(i));
	}
	for(int i=n+1;i<=n+m;i++)
	{
		s2.insert(fnd(i));
	}
	cout<<min((int)s1.size(),(int)s2.size())-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
namespace IO
{
    const int buffer_size=1e5+5;
    char buf[buffer_size],*S,*T;
    bool flag_EOF;
    inline char read_char()
    {
        if(S==T)
            T=(S=buf)+fread(buf,1,buffer_size,stdin);
        return S!=T?*(S++):EOF;
    }
    inline int read_int()
    {
        int flag=1;
        char c=read_char();
        while(c<'0'||c>'9')
        {
            if(c==EOF)
            {
                flag_EOF=true;
                return 0;
            }
            flag=(c=='-'?-1:1);
            c=read_char();
        }
        int x=0;
        while(c>='0'&&c<='9')
        {
            x=x*10+(c^48);
            c=read_char();
        }
        return x*flag;
    }
    inline void read_string(char *s)
    {
        char x;
        do
        {
            x=read_char();
            if(x==EOF)
			{
				flag_EOF=true;
            	return;
            }
        }while(x<'a'||x>'z');
        int len=0;
        while(x>='a'&&x<='z')
        {
            s[len++]=x;
            x=read_char();
        }
        s[len]='\0';
    }
    char fw[buffer_size];
    int pw;
    inline void flush()
    {
        fwrite(fw,1,pw,stdout);
        pw=0;
    }
    inline void write_char(char x)
    {
        if(pw==buffer_size)
            flush();
        fw[pw++]=x;
    }
    char st[13];
    int top;
    inline void write_int(int x)
    {
        if(!x)
        {
            write_char('0');
            return;
        }
        if(x<0)
        {
            write_char('-');
            x=-x;
        }
        while(x)
        {
            st[++top]=x%10+'0';
            x/=10;
        }
        while(top>0)
            write_char(st[top--]);
    }
    inline void write_string(const char *s)
    {
        for(int i=0;s[i];++i)
            write_char(s[i]);
    }
}
char s[10],t[10];
int cnt[15];
const int power[10]={1,10,100,1000,10000,100000};
inline bool check()
{
	static int c[15];
	for(int i=1;i<=9;++i)
		c[i]=0;
	int s1=0;
	for(int i=1;i<=5;++i)
		++c[s[i]-'0'];
	for(int i=1;i<=9;++i)
		s1+=i*power[c[i]];
	for(int i=1;i<=9;++i)
		c[i]=0;
	int s2=0;
	for(int i=1;i<=5;++i)
		++c[t[i]-'0'];
	for(int i=1;i<=9;++i)
		s2+=i*power[c[i]];
	return s1>s2;
}
int main()
{
	int k;
	scanf("%d%s%s",&k,s+1,t+1);
	for(int i=1;i<=9;++i)
		cnt[i]=k;
	for(int i=1;i<=4;++i)
	{
		--cnt[s[i]-'0'];
		--cnt[t[i]-'0'];
	}
	long long cnt_win=0,cnt_all=0;
	for(int i=1;i<=9;++i)
		for(int j=1;j<=9;++j)
		{
			s[5]=i+'0',t[5]=j+'0';
			if(i==j&&cnt[i]>=2)
			{
				cnt_all+=cnt[i]*(cnt[i]-1ll);
				if(check())
					cnt_win+=cnt[i]*(cnt[i]-1ll);
			}
			else if(i!=j&&cnt[i]>=1&&cnt[j]>=1)
			{
				cnt_all+=1ll*cnt[i]*cnt[j];
				if(check())
					cnt_win+=1ll*cnt[i]*cnt[j];
			}
		}
	printf("%.10lf\n",1.0*cnt_win/cnt_all);
    IO::flush();
    return 0;
}


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

int main()
{
	int A, B, W;
	scanf("%d%d%d", &A, &B, &W);
	W *= 1000;

	int ansmin = 0xfffffff;
	int ansmax = -1;
	for (int n = 1; n <= 1000 * 1000; n++) {
		if (A * n <= W && W <= B * n) {
			ansmin = std::min(ansmin, n);
			ansmax = std::max(ansmax, n);
		}
	}

	if (ansmax == -1) {
		puts("UNSATISFIABLE");
	}
	else {
		printf("%d %d\n", ansmin, ansmax);
	}

	return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repa(i,a,n) for (long long i = (a); i < (long long)(n); i++)
#define Rrep(i,n) for (long long i = (long long)(n)-1; i >= 0; i--)
#define Rrepa(i,a,n) for (long long i = (long long)(n)-1; i >= a; i--)
using ll = long long;
class Prints {
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};
Prints print;
//一次元配列はprint().pvec(vec,要素数);
//二次元配列はprint().pmat(vec,要素数1,要素数2);

int main() {
    string S;
    cin >> S;
    string flg = "Yes";
    rep(i,S.size()){
        if (i % 2 == 0){
            if (S[i] < 'a' or 'z' < S[i]){
                flg = "No";
            }
        }
        else{
            if (S[i] < 'A' or 'Z' < S[i]){
                flg = "No";
            }
        }

        //print()(i,flg);
    }
    cout << flg << endl;
}


#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define prnt(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
using namespace std;
void solve()
{
     string s;
     cin>>s;
     for(ll i = 0;i<s.length();i+=2)
     {
         if(s[i]>='a'&&s[i]<='z')
            continue;
         else
         {
             cout<<"No\n";
             return;
         }
     }
     for(ll i = 1;i<s.length();i+=2)
     {
         if(s[i]>='A'&&s[i]<='Z')
            continue;
         else
         {
             cout<<"No\n";
             return;
         }
     }
     cout<<"Yes\n";
}
signed main()
{
    speed;
    int t=1;
    //cin>>t;
    while(t--)
    {
         solve();
    }
    return 0;
}

#include <bits/stdc++.h>
#define fr first
#define se second
#define ll long long
#define pb push_back
using namespace std;

const ll INF = 1e16 + 1;
const ll N = 2e3 + 5;
const ll mod = 1e9 + 7;
const long double eps = 1E-7;

ll n, m, cnt;
int main()
{
	string s;
	cin >> s;
	for ( int i=0; i<s.size(); i+=2 ){
		if ( s[i] >= 'A' and s[i] <= 'Z' ){
			cout << "No";
			return 0;
		}
	}
	for ( int i=1; i<s.size(); i+=2 ){
		if ( s[i] >= 'a' and s[i] <= 'z' ){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}


#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define unless(x) if(!(x))
#define until(x) while(!(x))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
const int big=1000000007;
//const int big=998244353;
const double EPS=1e-8; //適宜変える
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

int main(){
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
    std::cout.precision(10);
/*------------------------------------*/

    ll n,k;cin >> n >> k;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,n)rep(j,n)cin >> a[i][j];
    ll ng=-1;
    ll ok=inf;
    //中央値をok以下にできる
    while(abs(ng-ok)>1){
        ll x=(ng+ok)/2;
        vector<vector<ll>> sum(n+1,vector<ll>(n+1));
        rep(i,n)rep(j,n){
            sum[i+1][j+1]=(a[i][j]<=x ? -1:1);
        }
        dbg(x,sum);
        rep(i,n)rep(j,n+1)sum[i+1][j]+=sum[i][j];
        rep(i,n+1)rep(j,n)sum[i][j+1]+=sum[i][j];
        bool can=false;
        rep(i,n-k+1)rep(j,n-k+1){
            if(sum[i+k][j+k]+sum[i][j]-sum[i+k][j]-sum[i][j+k]<=0)can=true;
        }
        (can ? ok:ng)=x;
    }
    cout << ok << newl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
typedef long long ll;
typedef std::vector<int> P;
typedef unsigned un;
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 f*x;
}
using std::min;
using std::max;
template<typename T>bool umin(T& a,T t){if(a>t)return a=t,1;return 0;}
template<typename T>bool umax(T& a,T t){if(a<t)return a=t,1;return 0;}

const int MAXN = 111;
int a[MAXN],b[MAXN];
char s[MAXN];
int main()
{
	int n=read();
	scanf("%s",s+1);
	for(int i=1;i<=n+1;++i)a[i]=read();
	for(int k=10000;k;--k)
	{
		bool fail=0;
		for(int i=1;i<=k&&!fail;++i)
		{
			b[1]=(a[1]/k+(i<=a[1]%k));
			for(int j=2;j<=n+1;++j)
			{
				b[j]=(a[j]/k+(i<=a[j]%k));
				if(s[j-1]=='>')fail|=b[j-1]<=b[j];
				else fail|=b[j-1]>=b[j];
			}
		}
		if(!fail)
		{
			printf("%d\n",k);
			for(int i=1;i<=k;puts(""),++i)
				for(int j=1;j<=n+1;++j)printf("%d ",a[j]/k+(i<=a[j]%k));
			return 0;
		}
	}
	puts("0");
	return 0;
}


#include <stdio.h>
#define mod 998244353
typedef long long ll;

int main(void) {
  ll i, j, k, n;
  scanf("%lld%lld", &n, &k);
  ll dp[n + 1][n + 1];
  for(i = 0; i <= n; ++i) dp[i][0] = 0, dp[i][i] = 1;
  for(i = 2; i <= n; ++i) for(j = i - 1; j; --j) {
    dp[i][j] = dp[i - 1][j - 1];
    if(j * 2 <= i) dp[i][j] += dp[i][j * 2];
    dp[i][j] %= mod;
  }
  printf("%lld", dp[n][k]);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define pi pair<int, int>
#define mp make_pair
#define F first
#define S second

ll MOD = 1e9+7;

ll mod_exp(ll a, ll b) {
    ll r = 1;
    while (b) {
        if (b&1) r = (r*a)%MOD;
        a = (a*a)%MOD;
        b >>= 1;
    }
    return r;
}

ll inv(ll a) {
    return mod_exp(a, MOD-2);
}

struct mat {
    int n, m;
    vector<vll> a;
    mat(int n, int m) {
        this->n = n;
        this->m = m;
        a.rsz(n, vll(m, 0));
    }
    mat(vector<vll> a) {
        this->a = a;
        n = a.size();
        m = a[0].size();
    }
    mat operator* (const mat& other) {
        mat ans(n, other.m);
        F0R(i, n) F0R(j, other.m) F0R(k, m) ans.a[i][j] = (ans.a[i][j]+a[i][k]*other.a[k][j])%MOD;
        return ans;
    }
    vll* operator[](int i) {
        return &a[i];
    }
};

mat identity(int n) {
    mat ans(n, n);
    F0R(i, n) ans.a[i][i]=1;
    return ans;
}

mat exp(mat a, ll pow) {
    mat res = identity(a.n);
    while (pow) {
        if (pow&1) res = res*a;
        a = a*a;
        pow >>= 1;
    }
    return res;
}

int n, m, k, x, y;
ll half = inv(2);
vll a;
vector<vi> adj;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    a.rsz(n);
    F0R(i, n) cin >> a[i];
    adj.rsz(n);
    F0R(i, m) {
        cin >> x >> y;
        adj[x-1].pb(y-1);
        adj[y-1].pb(x-1);
    }
    mat mt(n, n);
    F0R(i, n) {
        ll s = inv(2*m);
        mt.a[i][i]=((2*m-adj[i].size())*s)%MOD;
        for (int nb : adj[i]) {
            mt.a[nb][i] = (s)%MOD;
        }
    }
    // cout << inv(2) << ' ' << inv(4) << '\n';
    // F0R(i, n) {F0R(j, n) cout << mt.a[i][j] << ' '; cout << '\n';}
    mt = exp(mt, k);
    mat nodes(1, n);
    F0R(i, n) nodes.a[0][i]=a[i];
    nodes = nodes*mt;
    F0R(i, n) cout << nodes.a[0][i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
int N, a[505];
void solve() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i];
	vector<int> ans;
	for (int stp = 1; stp <= N * N; stp++) {
		bool flg = 1;
		for (int i = 2; i <= N && flg; i++) flg &= a[i - 1] < a[i];
		if (flg) break;
		int cur = (stp & 1) ? 1 : 2;
		for (int i = cur; i < N; i += 2)
			if (a[i] > a[i + 1]) cur = i;
		swap(a[cur], a[cur + 1]);
		ans.push_back(cur);
	}
	printf("%lu\n", ans.size());
	for (int i : ans) printf("%d ", i);
	putchar('\n');
}
int main () {
#ifndef ONLINE_JUDGE
    freopen("cpp.in", "r", stdin);
#endif
	int T; cin >> T;
	while (T--) solve();
    return 0;
}

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

#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
template <class T> void chmin(T &a, const T &b) {
    if (a > b) a = b;
}
template <class T> void chmax(T &a, const T &b) {
    if (a < b) a = b;
}

void solve() {
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P[i];

    rep(i, N) P[i]--;

    vector<int> output;
    int parity = 0;

    auto operate = [&](int pos) -> void {
        output.push_back(pos);
        swap(P[pos], P[pos + 1]);
        parity ^= 1;
    };

    for (int k = N - 1; k > 0; k--) {
        int now = find(all(P), k) - P.begin();
        while (1) {
            if (now == k && (now == N - 1 || P[now] + 1 == P[now + 1])) break;

            if (now % 2 == parity) {
                operate(now);
                now++;
            } else {
                if (now - 1 >= 0) {  // operate twice
                    operate(now - 1);
                    now--;

                    operate(now + 1);
                } else {  // corner case
                    if (k != 1) {
                        operate(now + 1);
                    } else {  // manual operation
                        operate(1);
                        operate(0);
                        operate(1);
                        operate(0);
                        operate(1);
                        break;
                    }
                }
            }
        }
    }

    cout << output.size() << "\n";
    rep(i, output.size()) cout << output[i] + 1 << "\n";
}

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

    int T;
    cin >> T;
    rep(i, T) solve();

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define ppl pair<pll,ll>
#define plp pair<ll,pll>
#define pi 3.14159265358979323846264338327950
const ll MOD=1e9+7;
using namespace std;
ll n,m,q,x[55];
ll w[55],val[55];

ll POWER(ll base,ll expo)
{
    ll ret=1;
    while(expo)
    {
        if(expo&1)ret=ret*base;
        expo>>=1;
        base=base*base;
    }
    return ret;
}

bool cmp(const pll &a, const pll &b)
{
    if(a.fi == b.fi)return (a.se < b.se);

    return a.fi > b.fi;
}

ll fun(vector<ll>& v)
{
    ll y = v.size();
    ll ans = 0;
    vector<ll> used(n+1,0);
    for(ll i=0;i<y;i++){
        ll mx_v = 0,in = -1;
        for(ll j=1;j<=n;j++){
            if(!used[j] && w[j] <= v[i] && val[j] > mx_v){
                mx_v = val[j];
                in = j;
            }
        }
        if(in != -1){
            ans += mx_v;
            used[in] = 1;
        }
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll test_cases=1; //cin>>test_cases;
    while(test_cases--)
    {
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        cin>>n>>m>>q;
        for(ll i=1;i<=n;i++)
            cin>>w[i]>>val[i];
        for(ll i=1;i<=m;i++)cin>>x[i];
        while(q --){
            ll l,r; cin>>l>>r;
            vector<ll> v;
            for(ll i=1;i<l;i++)
                v.pb(x[i]);
            for(ll i=r+1;i<=m;i++)
                v.pb(x[i]);
            sort(v.begin(),v.end());
            cout<<fun(v)<<endl;
        }
    }
    return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  vector< pair<int, int> > vs(n);
  vector< int > xs(m);

  range(i, 0, n) {
    cin >> vs[i].second >> vs[i].first;
  }

  rwhole(sort, vs);

  cin >> xs;

  while (q--) {
    int l = input() - 1, r = input();
    vector< int > ss;
    range(i, 0, l) ss.emplace_back(xs[i]);
    range(i, r, m) ss.emplace_back(xs[i]);

    whole(sort, ss);

    i64 ans = 0;
    range(i, 0, n) {
      range(j, 0, ss.size()) {
        if (ss[j] >= vs[i].second) {
          ans += vs[i].first;
          ss[j] = -1;
          break;
        }
      }
    }

    cout << ans << endl;
  }
}

signed main() {
  solve();
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> vis(n, -1);
    vector<bool> dfn(n, false);
    vector<int> sz(n, 0);
    vector<vector<int>> adj(n, vector<int>(n));
    long long res = 0;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
        adj[u][v] = adj[v][u] = 1;
    }
    vector<int> p;
    function<void(int)> dfs1 = [&](int now) {
        dfn[now] = true;
        for (auto to : g[now]) {
            if (!dfn[to]) {
                p.push_back(to);
                dfs1(to);
            }
        }
    };
    function<long long(int)> dfs2 = [&](int dep) -> long long {
        if (dep == p.size()) {
            return 1;
        }
        vector<bool> can(3, true);
        for (auto to : g[p[dep]]) {
            if (vis[to] != -1) {
                can[vis[to]] = false;
            }
        }
        if (!can[0] && !can[1] && !can[2]) return 0;
        long long ret = 0;
        if (!dep) {
            vis[p[dep]] = 0;
            ret += 3LL * dfs2(dep + 1);
            vis[p[dep]] = -1;
        } else {
            for (int c = 0; c < 3; c++) {
                if (can[c]) {
                    vis[p[dep]] = c;
                    ret += dfs2(dep + 1);
                    vis[p[dep]] = -1;
                }
            }
        }
        return ret;
    };
    for (int i = 0; i < n; i++) {
        if (!dfn[i]) {
            p.clear();
            p.push_back(i);
            dfs1(i);
            auto tmp = dfs2(0);
            if (tmp) {
                if (res) res *= tmp;
                else res += tmp;
            }
        }
    }
    cout << res;
    return 0;
}

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast")
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
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()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr int INF = 0x7f7f7f7f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
	int n, m;
	cin >> n >> m;
	VII g(n);
	_rep(i, 0, m){
		int u, v;
		cin >> u >> v;
		g[--u].eb(--v);
		g[v].eb(u);
	}
	vector<int> be;//在同一个连通块的点
	VI vis(n), col(n);
	auto find = [&](auto&& self, int x) -> void{
		be.eb(x);
		vis[x] = 1;
		for(int& v : g[x])
			if(!vis[v]) self(self, v);
	};
	int res = 0;
	auto dfs = [&](auto&& self, int id) -> void{
		if(id == (int)be.size()){
			res++;
			return;
		}
		int u = be[id];
		_rep(i, 1, 4){
			bool ok = true;
			for(int& v : g[u]) if(col[v] == i) ok = false;
			if(!ok) continue;// 当前节点不能染成颜色i
			col[u] = i;
			self(self, id + 1);
			col[u] = 0;
		}
	};
	ll ans = 1;
	_rep(i, 0, n){
		if(!vis[i]){
			be.clear();
			find(find, i);// 求出连通块
			dfs(dfs, 0);
			ans *= res;
			res = 0;
		}
	}
	cout << ans << endl;
	return 0;
}
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline
// 最好用用"\n"代替endl


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

int main() {
    int x, y, z;
    cin >> x >> y >> z;

    int ans = 0;
    srep(i,1,1001001){
        if(i*x < y*z) ans = i;
    }

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

#include <bits/stdc++.h>
#define ll long long
#define mod 1e9 + 7
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll x, y, z;
    cin >> x >> y >> z;
    if (ceil(((long double)(y * z) / (long double)x)) == floor(((long double)(y * z) / (long double)x))) {
        cout << floor(((long double)(y * z) / (long double)x)) - 1;
    } else {
        cout << floor(((long double)(y * z) / (long double)x));
    }
    return 0;
}


#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;

#define NUM_CAN 20

struct state
{
  int x;
  int y;
  int score;
  string path;
  set<int> used;
};
bool operator< (const state &state1, const state &state2){
    return state1.score < state2.score;
};

int main()
{
  struct timeval tmp_time;
  gettimeofday(&tmp_time, NULL);
  long long program_init_time = tmp_time.tv_sec*1000000+tmp_time.tv_usec;
  long long fin_time, current_time;
  fin_time = program_init_time + 1700000;

  int si, sj, count;
  cin >> si >> sj;
  vector<vector<int>> tiling(50,vector<int>(50)), grids(50,vector<int>(50));
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> tiling.at(i).at(j);
  }
  for (int i = 0; i < 50; i++)
  {
    for (int j = 0; j < 50; j++) cin >> grids.at(i).at(j);
  }
  vector<int> dx{1,-1,0,0}, dy{0,0,1,-1};
  string dir = "DURL";
  queue<state> que;
  priority_queue<state> next_que, rest, blank;
  state now_state;
  int best_score;
  string best_path;
  now_state.x = si, now_state.y = sj;
  now_state.score = grids.at(si).at(sj);
  now_state.path = "";
  now_state.used.insert(tiling.at(si).at(sj));
  best_score = now_state.score;
  best_path = now_state.path;
  que.push(now_state);
  count = 0;
  while (!que.empty())
  {
    while (!que.empty())
    {
      count++;
      now_state = que.front();
      que.pop();
      for (int i = 0; i < 4; i++)
      {
        if (now_state.x+dx.at(i) < 0 || now_state.x+dx.at(i) >= 50 || now_state.y+dy.at(i) < 0 || now_state.y+dy.at(i) >= 50)
          continue;
        if (now_state.used.count(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))))
          continue;
        now_state.score += grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
        now_state.path += dir.at(i);
        now_state.used.insert(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)));
        now_state.x += dx.at(i), now_state.y += dy.at(i);
        if (best_score < now_state.score)
        {
          best_score = now_state.score;
          best_path = now_state.path;
        }
        next_que.push(now_state);
        now_state.x -= dx.at(i), now_state.y -= dy.at(i);
        now_state.score -= grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i));
        now_state.path.pop_back();
        now_state.used.erase(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)));
      }
      if (count % 100 == 0)
      {
        gettimeofday(&tmp_time, NULL);
        current_time = tmp_time.tv_sec*1000000 + tmp_time.tv_usec;
        if (current_time > fin_time)
          break;
      }
    }
    if (count % 100 == 0)
    {
      if (current_time > fin_time)
        break;
    }
    for (int i = 0; i < NUM_CAN; i++)
    {
      if (next_que.empty())
        break;
      que.push(next_que.top());
      next_que.pop();
    }
    while (!next_que.empty())
    {
      rest.push(next_que.top());
      next_que.pop();
    }
    while (que.size() < NUM_CAN && !rest.empty())
    {
      que.push(rest.top());
      rest.pop();
    }
    // next_que = blank;
  }
  cout << best_path << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using P = pair<int,int>;
constexpr int N = 50;
constexpr int Node = 500;
int sx, sy, m = 0;
double start;
int t[50][50];
int p[50][50];
constexpr char dir[4] = {'R','D','L','U'};
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};

// 状態の設定
struct State {
  int score, px, py;
  vector<char> record;
  vector<bool> use;
  State() {
    score = 0;
    use.assign(m,false);
  }
};

bool operator< (const State& s, const State &t){return s.score < t.score;}
bool operator> (const State& s, const State &t){return s.score > t.score;}

int main(){
  // 入力と初期設定
  start = (double)clock();

  cin >> sx >> sy;
  rep(i,N) rep(j,N) {
    cin >> t[i][j];
    m = max(m,t[i][j]);
  }
  m++;
  rep(i,N) rep(j,N) cin >> p[i][j];

  // とりあえずビームサーチ
  State best;
  vector<State> beam_search;
  State is;
  is.px = sx; is.py = sy;
  is.use[t[sx][sy]] = true;
  is.score += p[sx][sy];
  beam_search.push_back(is);
  while(true) {
    if(((double)clock() - start) / CLOCKS_PER_SEC > 1.9) break;
    priority_queue<State,vector<State>,greater<State>> que;
    for(State st : beam_search) {
      int x = st.px, y = st.py;
      rep(i,4) {
        State ns = st;
        int nx = x + dx[i], ny = y + dy[i];
        if(nx < 0 or nx >= N or ny < 0 or ny >= N or ns.use[t[nx][ny]]) continue;
        ns.use[t[nx][ny]] = true;
        ns.px = nx; ns.py = ny;
        ns.score += p[nx][ny];
        ns.record.push_back(i);
        if(que.size() < Node) que.push(ns);
        else if(ns.score > que.top().score) {que.pop(); que.push(ns);}
      }
    }
    beam_search.clear();
    while(que.size()) {
      beam_search.push_back(que.top());
      que.pop();
    }
    if(beam_search.size() and beam_search.back().score > best.score) best = beam_search.back();
  }
  for(auto x : best.record) cout << dir[x];
  cout << endl;
  return 0;

}


//Don't act like a loser.
//This code is written by huayucaiji
//You can only use the code for studying or finding mistakes
//Or,you'll be punished by Sakyamuni!!!
#include<bits/stdc++.h>
#define int long long
using namespace std;

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

const int MAXN=205,MOD=200;

int n,cnt;
int a[MAXN],route[MAXN][MAXN];
vector<int> v[MAXN];

void out(int x) {
	int sz=v[x].size();
	cout<<sz<<" ";
	for(int i=0;i<sz;i++) {
		cout<<v[x][i]<<" ";
	}
	puts("");
	return ;
}

signed main() {
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	cin>>n;
	for(int i=1;i<=n;i++) {
		a[i]=read()%MOD;
	}

	for(int i=1;i<=n;i++) {
		for(int j=0;j<MOD;j++) {
			if(!route[i][j]&&j!=0) {
				continue;
			}
			if(route[i+1][j]) {
				puts("yes");
				out(route[i+1][j]);
				out(route[i][j]);
				return 0;
			}
			else {
				route[i+1][j]=route[i][j];
			}
		}
		for(int j=0;j<MOD;j++) {
			if(!route[i][j]&&j!=0) {
				continue;
			}
			if(route[i+1][(j+a[i])%MOD]) {
				puts("yes");
				out(route[i+1][(j+a[i])%MOD]);
				v[route[i][j]].push_back(i);
				out(route[i][j]);
				return 0;
			}
			v[++cnt]=v[route[i][j]];
			v[cnt].push_back(i);
			route[i+1][(j+a[i])%MOD]=cnt;
		}
	}

	puts("NO");

	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, a[205];
vector<int> c[205], b;
void dfs(int x, int sum) {
    if (c[sum].size() && b != c[sum]) {
        cout << "Yes\n";
        cout << b.size() << ' ';
        for (int i : b) cout << i << ' ';
        cout << "\n";
        cout << c[sum].size() << ' ';
        for (int i : c[sum]) cout << i << ' ';
        cout << "\n";
        exit(0);
    } else if (b.size())
        c[sum] = b;
    if (x == n + 1) return;
    dfs(x + 1, sum);
    b.push_back(x), dfs(x + 1, (sum + a[x]) % 200), b.pop_back();
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    dfs(1, 0);
    cout << "No\n";
}
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define loops(i, s, n) for (ll i = s; i < (ll)n; i++)
#define loop(i, n) loops(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define pub push_back
#define pob pop_back
#define mp make_pair
#define dump(x) cerr << #x << " = " << (x) << endl;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vl;

// for dp
// 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き
template <typename T>
inline bool chmin(T &a, const T &b)
{
  bool compare = a > b;
  if (a > b)
    a = b;
  return compare;
}
template <typename T>
inline bool chmax(T &a, const T &b)
{
  bool compare = a < b;
  if (a < b)
    a = b;
  return compare;
}

#define in_v(type, name, cnt) \
  vector<type> name(cnt);     \
  loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行

#define set_fix(x) ((std::cerr << std::fixed << std::setprecision(x)), (std::cout << std::fixed << std::setprecision(x)))

//cout for vector
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}

// gcd
ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}

//prime numbers
bool IsPrime(ll num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;

  double sqrtNum = sqrt(num);
  for (ll i = 3; i <= sqrtNum; i += (ll)2)
  {
    if (num % i == 0)
    {
      return false;
    }
  }
  return true;
}
vector<ll> Eratosthenes(ll N)
{
  int arr[N];
  vector<ll> res;
  for (int i = 0; i < N; i++)
  {
    arr[i] = 1;
  }
  for (int i = 2; i < sqrt(N); i++)
  {
    if (arr[i])
    {
      for (int j = 0; i * (j + 2) < N; j++)
      {
        arr[i * (j + 2)] = 0;
      }
    }
  }

  for (int i = 2; i < N; i++)
  {
    if (arr[i])
    {
      res.push_back(i);
    }
  }
  return res;
}

//digit number
int GetDigit(ll num, ll radix)
{
  unsigned digit = 0;
  while (num != 0)
  {
    num /= radix;
    digit++;
  }
  return digit;
}

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

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(ALL(a));
  dump(a);
  dump(n / 2);
  dump(a[n / 2]);
  ld x = n % 2 == 0 ? (double)(a[n / 2 - 1] + a[n / 2]) / (double)4 : a[n / 2] / (double)2;
  // cout << "x: " << x << endl;
  ld res = 0;
  for (int i = 0; i < n; i++)
  {
    // cout << "res: " << res << endl;
    // cout << "min((double)2 * x, (ld)a[i]): " << min((double)2 * x, (ld)a[i]) << endl;
    // cout << "a[i]: " << a[i] << endl;
    res += x + (double)a[i] - min((double)2 * x, (ld)a[i]);
  }
  set_fix(20) << (double)res / (double)n << endl;

  return 0;
}

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

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

using P = pair<int, int>;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<P> coo;
  REP(i, n) {
    int x, y;
    cin >> x >> y;
    coo.emplace_back(x, y);
  }
  int ans = 0;
  REP(i, n - 2) {
    REP(j, n - 1) {
      REP(k, n) {
        if (i >= j) continue;
        if (j >= k) continue;
        int x1 = coo[i].first, y1 = coo[i].second;
        int x2 = coo[j].first, y2 = coo[j].second;
        int x3 = coo[k].first, y3 = coo[k].second;
        if ((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)) ans++;
        else if (x1  == x2 || y1 == y2)
          continue;
        else if ((float(y3 - y2) / float(y2 - y1)) == (float(x3 - x2) / float(x2 - x1)))
          ans++;
      }
    }
  }
  if (ans >= 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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


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

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

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

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

#define en "\n"

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

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

void Main(){
    int N; cin >> N;
    VVI edge(400400);
    REP(i,N){
        int a,b; cin >> a >> b; a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans = 0;
    vector<bool> vis(400400,false);
    REP(i,400400){
        if(vis[i]) continue;
        stack<Pair> s({Pair(i,0)});
        int nv = 0, ne = 0;
        while(!s.empty()){
            auto [v,ptr] = s.top(); s.pop();
            if(!vis[v]){
                vis[v] = true;
                nv++;
            }
            for(int j=ptr; j<(int)edge[v].size(); j++){
                ne++;
                if(vis[edge[v][j]]) continue;
                s.emplace(v,j+1);
                s.emplace(edge[v][j],0);
                break;
            }
        }

        ne /= 2;
        if(nv == ne+1) ans += nv-1;
        else ans += nv;
    }

    cout << ans << en;
    return;
}

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

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

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

	constexpr int N = 400000;

	int n;
	cin >> n;

	vector<int> a(n), b(n);
	vector<vector<int>> g(N);
	vector<int> cnt(N);
	vector<bool> used(n), visited(N);

	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		--a[i], --b[i];
		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
		cnt[a[i]]++, cnt[b[i]]++;
	}

	queue<int> q;
	int ans = 0;

	for (int i = 0; i < N; i++) {
		if (cnt[i] == 1 && !visited[i]) {
			for (int x : g[i]) {
				if (!used[x]) {
					used[x] = true;
					cnt[a[x] ^ b[x] ^ i]--;
				}
			}
			ans += 1;
			cnt[i] -= 1;
			visited[i] = true;
			q.push(i);
		}
	}

	while (!q.empty()) {
		int x = q.front();
		q.pop();

		for (int i : g[x]) {
			int to = a[i] ^ b[i] ^ x;
			if (cnt[to] == 1 && !visited[to]) {
				for (int u : g[to]) {
					if (!used[u]) {
						used[u] = true;
						cnt[a[u] ^ b[u] ^ to]--;
					}
				}
				ans += 1;
				cnt[to] -= 1;
				visited[to] = true;
				q.push(to);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		ans += !visited[i] && cnt[i] > 0;
	}
	cout << ans << '\n';
	return 0;
}


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

#ifdef LOCAL
    #include "debug.h"
    #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
    #define debug(...) 4
    #define input 4
#endif

using ll = long long;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
struct DSU {
    int par[N];
    int sz[N];
    int find(int x) {
        return x == par[x] ? x : par[x] = find(par[x]);
    } //path compression(logn)

    void merge(int a, int b) {
        a = find(a);
        b = find(b);
        if(a == b) return;
        if(sz[a] < sz[b])
            swap(a, b);

        sz[a] += sz[b];
        par[b] = a;
    }

    void init(int n) {
        for(int i = 0; i <= n; i++)
            par[i] = i, sz[i] = 1;
    }
};
DSU d;
vector<int> g[N];
vector<int> dist[N];
int a[N];
void bfs(vector<int> &dist, int src) {
    queue<int> q;
    q.push(src);
    dist[src] = 0;
    while(q.size()) {
        int at = q.front();
        q.pop();
        for(int j : g[at]) {
            if(dist[j] == -1) {
                dist[j] = dist[at] + 1;
                q.push(j);
            }
        }
    }
}
int dp[1 << 18][18];
int k;
int solve(int mask, int last) {
    if(mask == (1 << k) - 1) {
        return 0;
    }
    if(~dp[mask][last])
        return dp[mask][last];
    int ans = 1e9;
    for(int j = 0; j < k; j++) {
        if(mask & (1 << j))
            continue;
        ans = min(ans, dist[last][a[j]] + solve(mask ^ (1 << j), j));
    }
    return dp[mask][last] = ans;
}
signed main() {
    input;
    cin.tie(nullptr) -> sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while(t--) {
        int n, m;
        cin >> n >> m;
        d.init(n + 1);
        for(int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            g[x].push_back(y);
            g[y].push_back(x);
            d.merge(x, y);
        }
        cin >> k;
        set<int> s;
        for(int i = 0; i < k; i++) {
            cin >> a[i];
            s.insert(d.find(a[i]));
        }
        if(s.size() > 1) {
            cout << "-1\n";
            return 0;
        }
        for(int i = 0; i < k; i++) {
            vector<int> temp(n + 1, -1);
            bfs(temp, a[i]);
            dist[i] = temp;
        }
        int ans = 1e9;
        for(int i = 0; i < k; i++)  {
            memset(dp, -1, sizeof dp);
            ans = min(ans, solve(1 << i, i));
        }

        cout << ans + 1;

    }
}

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18+7;

#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T>
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T>
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T>
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T>
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

/*
方針

*/
ll n,m;
vector<ll>a,b;
ll k;
vector<ll>c;

Graph g;

vector<ll>dist;

ll kyori[20][20];

int main(){
	cin >> n >> m;
	a.resize(m);
	b.resize(m);
	g.resize(n);
	rep(i,m){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	cin >> k;
	c.resize(k);
	rep(i,k){
		cin>>c[i];
		c[i]--;
	}

    ll start,goal;

	rep(i,20)rep(j,20)kyori[i][j]=INF;
	rep(i,k){
		vector<ll>dist(n,INF);
		queue<ll>que;
		que.push(c[i]);
		dist[c[i]]=0;
		while(!que.empty()){
			auto v = que.front();que.pop();
			for(auto x:g[v]){
				if(dist[x]!=INF)continue;
				dist[x]=dist[v]+1;
				que.push(x);
			}
		}
        ll M = 0;
		rep(j,k){
			if(dist[c[j]]==INF){
				cout << -1 << endl;
				return 0;
			}
			kyori[i][j]=dist[c[j]];
            if(chmax(M,kyori[i][j])&&i==0){
                goal = j;
            }
            if(chmax(M,kyori[i][j])&&i==goal){
                start = j;
            }
		}
	}

	//bitDP
	ll ans = INF;
	rep(test,12){
        ll i = (start+test)%k;
		vector<vector<ll> >dp(((1<<k)+1),vector<ll>(k+1,INF));
        dp[(1<<i)][i]=1;
		rep(S,(1<<k)){
			rep(v,k){
				rep(u,k){
					if (S != 0 && !(S & (1 << u))) continue; // u を含まない場合を除く
					if ((S & (1 << v)) == 0) {
						if (v != u) chmin(dp[S | (1 << v)][v], dp[S][u] + kyori[u][v]);
					}
				}
			}
		}
		rep(j,k){
			chmin(ans,dp[(1<<k)-1][j]);
		}

	}
    /*
    rep(test,5){
        ll i = (goal+test*2)%k;
		vector<vector<ll> >dp(((1<<k)+1),vector<ll>(k+1,INF));
        dp[(1<<i)][i]=1;
		rep(S,(1<<k)){
			rep(v,k){
				rep(u,k){
					if (S != 0 && !(S & (1 << u))) continue; // u を含まない場合を除く
					if ((S & (1 << v)) == 0) {
						if (v != u) chmin(dp[S | (1 << v)][v], dp[S][u] + kyori[u][v]);
					}
				}
			}
		}
		rep(j,k){
			chmin(ans,dp[(1<<k)-1][j]);
		}

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

}


#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  vector<P> v(1e3+1, {0, 0});
  rep(i, N){
    ll a;
    cin >> a;
    v[a].fi++;
  }
  rep(i, M){
    ll a;
    cin >> a;
    v[a].se++;
  }

  rep(i, 1e3){
    if((v[i+1].fi xor v[i+1].se) == 1){
      cout << i + 1 << " ";
    }
  }

  return 0;
}

#include<bits/stdc++.h>
#include<stdio.h>
#include<queue>
#define ll long long
#define ull unsigned long long
#define ln "\n"
using namespace std;
#define dbg(x) cout<<#x<<" = "<<x<<" "
#define rep(i,s,n) for(ll i = (s);i<(n);++i)

void solve(){
 ll n;
 cin>>n;
 vector<ll>cnt(n+1,0);
 for(int i=0;i<n;i++)
 {
     cnt[i+1]++;
 }
 for(int i=0;i<n;i++)
 {
     ll x;
     cin>>x;
     cnt[x]--;
 }
 string ans="Yes";
 for(int i=0;i<n;i++)
 {
     if(cnt[i+1]!=0)
     {
         ans="No";
         break;
     }
 }
 cout<<ans<<ln;
}

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


#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define nl "\n"
typedef pair<int,int>ii;
typedef vector<int>vi;
typedef vector<ii>vii;
typedef vector<vi>vvi;
typedef vector<long long>vl;
typedef vector <vl>vvl;
template<class T>
void print(T& a)
{
    for(auto x:a)
        cout<<x<<" ";
    cout<<"\n";
}
int main()
{

    FastIO

    int a[3];
    for(int &x:a)cin>>x;
    sort(a,a+3);

    cout<<a[1]+a[2]<<nl;

    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//const int MOD =  998244353;

const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll X, Y, A, B; cin >> X >> Y >> A >> B;
    Y--;
    ll ans = 0;
    rep(i,100){
        ll str = X;
        ll i_count = 0;
        rep(j,i){
            if ((Y+(A-1)) / A <= str){
                i_count = j;
                break;
            }
            str *= A;
            i_count = j+1;

        }
        //cout << i_count << endl;
        if(Y <= str) continue;
        ll remain = Y - str;

        ll count = remain/B;

        /*cout << i << endl;
        cout << str << endl;
        cout << count << endl;
        */
        ans = max(ans, (ll)(count+i_count));

    }

    cout << ans << endl;

}


/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
LL N;
void solve() {
    if(N&1)W("Odd");
    else if(N%4==0)W("Even");
    else W("Same");
}
void input() {
    R(N);
}
int main(){
    CASET {
        input();
        solve();
    }
    return 0;
}

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

int x[200005], c[200005];
vector<int> v[200005];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++){
        scanf("%d%d", &x[i], &c[i]);
        v[c[i]].emplace_back(x[i]);
    }
    int la1 = 0, la2 = 0;
    long long res1 = 0, res2 = 0;
    for(int i=1;i<=n;i++){
        if(v[i].empty()) continue;
        sort(v[i].begin(), v[i].end());
        int l = v[i][0], r = v[i].back();

        long long ans1 = 1e18, ans2 = 1e18;
        ans1 = min(ans1, abs(la1-r)*1ll+abs(r-l)+res1);
        ans1 = min(ans1, abs(la2-r)*1ll+abs(r-l)+res2);

        ans2 = min(ans2, abs(la1-l)*1ll+abs(l-r)+res1);
        ans2 = min(ans2, abs(la2-l)*1ll+abs(l-r)+res2);

        la1 = l, la2 = r;
        res1 = ans1, res2 = ans2;
    }
    printf("%lld\n", min(res1+abs(la1), res2+abs(la2)));
}


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

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()

const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;

typedef struct {
    int64_t to, weight;
} edge;

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

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (auto &e : v) {
        is >> e;
    }
    return is;
}

bool print_space_enable = false;
void print() {
    std::cout << '\n';
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    std::cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

template<class T>
vector<T> make_vec(size_t n, T val) {
    return vector<T>(n, val);
}

template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

bool is_overflow(Int a, Int b) {
    return a > INF / b;
}

void solve() {
    Int n;
    cin >> n;
    print((n - 1) / 100 + 1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    //Int _t; cin >> _t; while (_t--) solve();
    return 0;
}

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

int main() {
    string s;
    cin>>s;
    cout<<s[1]<<s[2]<<s[0]<<endl;
}


#include<string>
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;

enum {
	A_one = 4,
	A_two = 12,
	A_three = 24,
	A_four = 24
};

int main(){
	string input;
	cin >> input;
	int len = input.size();
	int exist = 0;
	int notSure = 0;
	int notExist = 0;
	int res = 0;
	if (len != 10) {
		cout << res;
		return 0;
	}
	for (int i = 0; i < len; i++) {
		if (input[i] == 'o') exist++;
		else if (input[i] == '?') notSure++;
		else notExist++;
	}
	if (exist > 4) {
		cout << res;
		return 0;
	}
	else if (exist == 4) {
		res = A_four;
		cout << res;
		return 0;
	}
	else if (exist == 3) {
		if (notSure < 1) {
			res = 3 * A_two;
			cout << res;
			return 0;
		}
		else {
			res = 3 * A_two + notSure * A_three;
			cout << res;
			return 0;
		}
	}
	else if (exist == 2) {
		if (notSure == 0) {
			res = 14;
			cout << res;
			return 0;
		}
		else if (notSure == 1) {
			res = 14 + 3 * A_two;
			cout << res;
			return 0;
		}
		else {
			res = 14 + notSure * 3 * A_two + notSure * (notSure - 1) / 2 * A_three;
			cout << res;
			return 0;
		}
	}
	else if (exist == 1) {
		if (notSure == 0) {
			res = 1;
			cout << res;
			return 0;
		}
		else if (notSure == 1) {
			res = 1 + 14;
			cout << res;
			return 0;
		}
		else if (notSure == 2) {
			res = 1 + 2 * 14 + 3 * A_two;
			cout << res;
			return 0;
		}
		else {
			res = 1 + notSure * 14 + notSure * (notSure - 1) / 2 * 3 * A_two + notSure * (notSure - 1) * (notSure - 2) / 6 * A_three;
			cout << res;
			return 0;
		}
	}
	//exist == 0;
	else {
		if (notSure == 0) {
			cout << res;
			return 0;
		}
		else if (notSure == 1) {
			res = 1;
			cout << res;
			return 0;
		}
		else if (notSure == 2) {
			res = 2 + 14;
			cout << res;
			return 0;
		}
		else if (notSure == 3) {
			res = 3 + 3 * 14 + 3 * A_two;
			cout << res;
			return 0;
		}
		else {
			res = notSure + notSure * (notSure - 1) / 2 * 14 + notSure * (notSure - 1) * (notSure - 2) / 6 * 3 * A_two + notSure * (notSure - 1) * (notSure - 2) * (notSure - 3) / 24 * A_four;
			cout << res;
			return 0;
		}
	}
}

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

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	set<int> avail, not_avail, unsure;
	for (int i = 0; i < 10; i++) {
		if (s[i] == 'o') avail.insert(i);
		else if (s[i] == 'x') not_avail.insert(i);
		else unsure.insert(i);
	}

	int ans = 0;
	for (int i = 0; i < 10; i++) {
		if (not_avail.count(i)) continue;
		for (int j = 0; j < 10; j++) {
			if (not_avail.count(j)) continue;
			for (int k = 0; k < 10; k++) {
				if (not_avail.count(k)) continue;
				for (int l = 0; l < 10; l++) {
					if (not_avail.count(l)) continue;
					set<int> temp;
					if (avail.count(i)) temp.insert(i);
					if (avail.count(j)) temp.insert(j);
					if (avail.count(k)) temp.insert(k);
					if (avail.count(l)) temp.insert(l);
					if (temp.size() == avail.size()) ans++;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;
#include "bits/stdc++.h"
#define el "\n"

typedef long long ll;
const int MM = 2e3+1, MOD = 1e9+7;
int R, C, dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
pair<int, int> st, ed;
vector<pair<int, int>> tele[26];
char gr[MM][MM];
bool vis[MM][MM], used[26];
queue<pair<pair<int, int>, int>> q;

int main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
    cin >> R >> C;
    for(int i = 1; i <= R; i++) {
        for(int j = 1; j <= C; j++) {
            cin >> gr[i][j];
            if(gr[i][j] == 'S') {
                st = {i, j};
            } else if(gr[i][j] == 'G') {
                ed = {i, j};
            } else if(gr[i][j] != '.' && gr[i][j] != '#') {
                tele[gr[i][j] - 'a'].push_back({i, j});
            }
        }
    }
    q.push({st, 0}); vis[st.first][st.second] = true;
    while(!q.empty()) {
        int x = q.front().first.first, y = q.front().first.second, d = q.front().second; q.pop();
        if(x == ed.first && y == ed.second) {
            cout << d << el;
            return 0;
        }
        for(int i = 0; i < 4; i++) {
            int nx = x + dir[i][0], ny = y + dir[i][1];
            if(nx >= 1 && nx <= R && ny >= 1 && ny <= C && vis[nx][ny] == false && gr[nx][ny] != '#') {
                vis[nx][ny] = true;
                q.push({{nx, ny}, d + 1});
            }
        }

        if(gr[x][y] != 'S' && gr[x][y] != 'G' && gr[x][y] != '.' && gr[x][y] != '#') {
            if(used[gr[x][y] - 'a'] == true) continue;
            used[gr[x][y] - 'a'] = true;
            for(pair<int, int> t : tele[gr[x][y] - 'a']) {
                if(t.first == x && t.second == y) continue;
                if(vis[t.first][t.second] == false) {
                    vis[t.first][t.second] = true;
                    q.push({{t.first, t.second}, d + 1});
                }
            }
        }
    }
    cout << -1 <<el;
}

// initialize