// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int G[500][500];
int ACC[501][501];

int main() {
  int n, m, q; in(n),in(m),in(q);
  loop(i,0,m) {
    int l, r; in(l),in(r);
    l--;r--;
    G[l][r]++;
  }

  loop(y,0,n) {
    loop(x,0,n) {
      ACC[y+1][x+1] = ACC[y+1][x] + ACC[y][x+1] - ACC[y][x] + G[y][x];
    }
  }

  // loop(y,0,n+1) {
  //   loop(x,0,n+1) {
  //     print(ACC[y][x], " ");
  //   }
  //   print("");
  // }

  loop(i,0,q) {
    int l,r; in(l),in(r);
    int cnt = ACC[r][r];
    cnt += ACC[l-1][l-1];
    cnt -= ACC[l-1][r];
    cnt -= ACC[r][l-1];
    // print(ACC[r][r]);
    // print(ACC[l-1][l-1]);
    // print(ACC[l-1][r]);
    // print(ACC[r][l-1]);
    print(cnt);
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = LLONG_MAX;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> A(N+1);
    for(int i = 0; i < N; i++) cin >> A[i];
    while(K--){
        vector<ll> A_(N+1);
        for(int i = 0; i < N; i++){
            ll l = i-A[i], r = i + A[i];
            l = max(l, 0LL), r = min(r, N-1);
            A_[l]++;
            A_[r+1]--;
        }
        ll t = 0;
        bool flag = true;
        for(int i = 0; i < N; i++) {
            t += A_[i];
            A[i] = t;
            if(flag && A[i] != N) flag = false;
        }
        if(flag) break;
    }
    for(int i = 0; i < N; i++) cout << A[i] << " "; cout << endl;
}


#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

vi MP(string s){
  vi A(s.size()+1);
  A[0] = -1;
  int j = -1;
  rep(i,s.size()) {
    while(j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i+1] = j;
  }
  return A;
}

vi Manacher(string s){
  vi R(s.size());
  int i = 0, j = 0;
  while(i < s.size()){
    while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
    i += k; j -= k;
  }
  return R;
}

vi Z_algorithm(string &s){
  vi Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while(i < s.size()){
    while(i+j < s.size() && s[j] == s[i+j]) j++;
    Z[i] = j;
    if(j == 0){++i; continue;}
    int k = 1;
    while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
    i += k; j -= k;
  }
  return Z;
}

const int MAX = 1e6+1;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;
  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }
  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }
  return ret;
}

int main(){
  int A, B; cin >> A >> B;
  A--; B--;
  int H, W; H = W = 100;
  char a[H][W];
  rep(h,H) rep(w,W) {
    if(h < H/2) a[h][w] = '#';
    else a[h][w] = '.';
  }

  for(int h = 0; h < H; h += 2) for(int w = 0; w < W; w += 2) {
    if(h < H/2 && A > 0){
      a[h][w] = '.';
      A--;
    }
    if(h > H/2 && B > 0){
      a[h][w] = '#';
      B--;
    }
  }
  printf("%d %d\n", H, W);
  rep(h,H) rep(w,W) {
    cout << a[h][w];
    if(w == W-1) cout << endl;
  }
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;

    vector<string> ans(100, "");
    for(int i = 0; i < 50; i++) {
        rep(j, 100) ans[i] += "#";
    }
    for(int i = 50; i < 100; i++) {
        rep(j, 100) ans[i] += '.';
    }

    a--;
    b--;

    for(int i = 1; i < 50; i += 2){
        if(a == 0) break;
        for(int j = 1; j < 100; j += 2){
            if(a == 0) break;
            ans[i][j] = '.';
            a--;
        }
    }
    for(int i = 51; i < 100; i += 2){
        if(b == 0) break;
        for(int j = 1; j < 100; j += 2){
            if(b == 0) break;
            ans[i][j] = '#';
            b--;
        }
    }
    cout << "100 100" << endl;
    rep(i, 100) cout << ans[i] << endl;
}


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

int main() {

  int N, K;
  cin >> N >> K;
  int x = 1;

  for (int i = 0;N > i;i++){

    cin >> x;

    if (x < K){
      x *= 2;
    }
    else{
      x += K;
    }
  }
  cout << x << endl;
}

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

int main () {
  int N,K,A;
  cin >> N >> K;
  A = 1;
  for (int i=0;i<N;i++) {
    if ( A*2 < A + K ) A = A*2;
    else A = A + K;
  }
  cout << A << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    for(ll i=n;i>=0;i--){
        int k=sqrt(i);
        if(k*k==i){
            cout<<i<<endl;
            break;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1000000007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int dp[1111111][2];

int main(){
    string S;
    cin >> S;
    int N = S.size();
    S += '0';

    for(int i=0; i<1111111; i++)
        dp[i][0] = dp[i][1] = 1<<30;
    dp[0][0] = 0;

    for(int i=0; i<N; i++){
        int d = S[N-1-i] - '0';
        dp[i+1][0] = min(dp[i+1][0], dp[i][0] + d);
        dp[i+1][1] = min(dp[i+1][1], dp[i][0] + (10 - d));
        dp[i+1][0] = min(dp[i+1][0], dp[i][1] + (d + 1));
        dp[i+1][1] = min(dp[i+1][1], dp[i][1] + (10 - (d + 1)));
    }
    int ans = min(dp[N][0], dp[N][1] + 1);
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }

const int MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

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

  int n,q;
  cin >> n >> q;
  vector<tuple<int,int,int>> stx(n);
  rep(i,n){
    cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]);
  }
  sort(stx.begin(),stx.end());

  set<P> st;
  rep(i,q){
    int x;
    cin >> x;
    st.emplace(x,i);
  }

  vector<int> ans(q,-1);
  rep(i,n){
    int s = get<1>(stx[i]);
    int t = get<2>(stx[i]);
    int x = get<0>(stx[i]);
    //xの昇順で考えてぶつかったら，その人をerase
    auto first = st.lower_bound(P(s-x,0));//引っかかる人
    auto end = st.upper_bound(P(t-x-1,q));//引っかからない人

    for(auto it = first; it !=end; ++it) ans[it->second] = x;

    st.erase(first,end);
  }

  rep(i,q) cout << ans[i] << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 const INF = 1001001001;

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

int N,Q;
cin >> N >> Q;

map<int,vi> add;
map<int,vi> era;
map<int,int> mp;

rep(i,N) {
    int s,t,x;
    cin >> s >> t >> x;
    add[max(0,s-x)].push_back(x);
    era[max(1,t-x)].push_back(x);
    mp[max(0,s-x)] = 0;
    mp[max(1,t-x)] = 0;
}
rep(i,Q) {
    int d;
    cin >> d;
    mp[d] = 1;
}

set<int> st;

for(auto x : mp) {

    for(auto erx : era[x.first]) {
        st.erase(erx);
    }
    for(auto adx : add[x.first]) {
        st.insert(adx);
    }
    if(x.second == 1) {
        if(!st.empty()) {
            cout << *st.begin() << endl;
        }
        else {
            cout << -1 << endl;
        }
    }
}

return 0;
}


#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ ";
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ ";
	for(auto s:S) os<<s<<" ";  return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 1e6 + 100;
const int INF = 1e9;

int U[N] , V[N] , C[N];
int n , m;

vpii G[N];

int dis[N];

int main(){
	fio; cout<<fixed<<setprecision(25);
	cin >> n >> m;

	map<pii , int> exist;
	int idx = n+1 , u , v , c;
	for(int i = 1;i <= m;++i){
		cin >> u >> v >> c;
		if(exist.find(mp(u , c)) == exist.end()){
			exist[mp(u , c)] = idx++;
		}
		if(exist.find(mp(v , c)) == exist.end()){
			exist[mp(v , c)] = idx++;
		}
		G[u].pb(mp(exist[mp(u , c)] , 1));
		G[exist[mp(u , c)]].pb(mp(u , 0));
		G[v].pb(mp(exist[mp(v , c)] , 1));
		G[exist[mp(v , c)]].pb(mp(v , 0));
		G[exist[mp(u , c)]].pb(mp(exist[mp(v , c)] , 0));
		G[exist[mp(v , c)]].pb(mp(exist[mp(u , c)] , 0));
	}
	for(int i =1 ;i < idx ; ++i){
		dis[i] = INF;
	}
	deque<pii> Q;
	// priority_queue<pair<pii, int> , vector<pair<pii,int> > , greater<pair<pii,int> > >Q;
	// Q.push(mp(mp(0 , -1) , 1));
	Q.pb(mp(0 , 1));
	dis[1] = 0;
	//it.F is distance
	//it.S is vertex
	while(Q.size() > 0){
		auto it = Q.front();
		// trace(it);
		if(it.S == n){
			cout << it.F << endl;
			return 0;
		}
		Q.pop_front();
		for(auto e : G[it.S]){
			int w = e.S + it.F;
			if(dis[e.F] > w){
				dis[e.F] = w;
				if(e.S == 1){
					Q.pb(mp(dis[e.F] , e.F));
				}
				else{
					Q.push_front(mp(dis[e.F] , e.F));
				}
			}
		}
	}
	cout << -1 << endl;

	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 400005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next,val;
}E[MAXN * 10];
int head[MAXN],sumE;
int N,M,Ncnt;
int c[MAXN],dis[MAXN];
vector<int> to[MAXN];
bool vis[MAXN];
priority_queue<pii > Q;
void add(int u,int v,int c) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    E[sumE].val = c;
    head[u] = sumE;
}
void Solve() {
    read(N);read(M);
    int q,p;
    Ncnt = M;
    for(int i = 1 ; i <= M ; ++i) {
	read(q);read(p);read(c[i]);
	to[q].pb(i);to[p].pb(i);
    }
    for(int i = 1 ; i <= N ; ++i) {
	sort(to[i].begin(),to[i].end(),[](int a,int b) {return c[a] < c[b];});
	int nw = ++Ncnt;
	for(int j = 0 ; j < to[i].size() ; ++j) {
	    int p = j;
	    while(p < to[i].size() - 1 && c[to[i][p + 1]] == c[to[i][j]]) ++p;
	    for(int h = j + 1 ; h <= p ; ++h) {
		add(to[i][j],to[i][h],0);
		add(to[i][h],to[i][j],0);
	    }
	    add(to[i][j],nw,0);
	    add(nw,to[i][j],1);
	    j = p;
	}
    }
    for(int i = 1 ; i <= Ncnt ; ++i) dis[i] = 1e9;
    for(auto t : to[1]) {dis[t] = 1;Q.push(mp(-1,t));}
    while(!Q.empty()) {
	pii now = Q.top();Q.pop();
	if(vis[now.se]) continue;
	int u = now.se;vis[u] = 1;
	for(int i = head[u] ; i ; i = E[i].next) {
	    int v = E[i].to;
	    if(dis[v] > dis[u] + E[i].val) {
		dis[v] = dis[u] + E[i].val;
		Q.push(mp(-dis[v],v));
	    }
	}
    }
    int ans = 1e9;
    for(auto t : to[N]) ans = min(ans,dis[t]);
    if(ans >= 1e9) {
	puts("-1");return;
    }
    else {out(ans);enter;}
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  for (auto x : v) ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  string separator = " ";
  template <class T>
  inline void read(T& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(string& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(vector<T>& v) {
    for (auto& x : v) read(x);
  }
  template <class Head, class... Tail>
  inline void read(Head& head, Tail&... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(vector<T> v) {
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  template <class Head, class... Tail>
  inline void writeln(Head head, Tail... tail) {
    write(head, tail...);
    write("\n");
  }
  void set_separator(string s) { separator = s; }
} io;

int main() {
  int N;
  string S;
  io.read(N, S);
  using Pss = pair<string, string>;
  map<Pss, ll> left, right;
  ll ans = 0;
  REP(b, 1 << N) {
    string l_r, l_b, r_r, r_b;
    REP(i, N)
    if ((b >> i) & 1) {
      l_r += S[i];
      r_r += S[2 * N - 1 - i];
    } else {
      l_b += S[i];
      r_b += S[2 * N - 1 - i];
    }
    left[Pss(l_r, l_b)]++;
    right[Pss(r_r, r_b)]++;
  }
  for (auto l : left)
    ans += l.second * right[Pss(l.first.second, l.first.first)];
  io.writeln(ans);
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

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

  int G[n][n];
  int visited[n];
  int d[n];
  int p[n];
  REP(y, n) {
    REP(x, n) {
      int cost;
      cin >> cost;

      if (cost == -1) {
        G[y][x] = 1 << 15;
      } else {
        G[y][x] = cost;
      }
    }
    visited[y] = 0;
    d[y] = 1 << 15;
    p[y] = -1;
  }

  d[0] = 0;

  REP(_, n) {
    int mincost = 1 << 15;
    int minv = -1;
    REP(v, n) {
      if (!visited[v] && d[v] < mincost) {
        minv = v;
        mincost = d[v];
      }
    }
    visited[minv] = 1;
    REP(to, n) {
      if (!visited[to] && G[minv][to] < (1 << 15) && G[minv][to] < d[to]) {
        d[to] = G[minv][to];
        p[to] = minv;
      }
    }
  }

  ll sum = 0;
  REP(i, n) {
    if (p[i] != -1) {
      sum += G[i][p[i]];
    }
  }

  cout << sum << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int jd(vi D, int N){
  while(N > 0){
    for(int x : D){
      if (N%10 == x ){
        return 0;
      }
    }
    N /= 10;
  }
  return 1;
}

int main() {
  int N, K; cin >> N >> K;
  vi D(K); rep(i,K) cin >> D[i];
  int ans=0;
  while(ans <= 0){
    ans = jd(D, N);
    if(ans==0) N++;
  }
  cout << N << endl;
}

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N; cin >> N;
	int K; cin >> K;
	map<char, bool> mp;
	for (int i = 0; i < K; ++i) {
		char a; cin >> a;
		mp[a] = true;
	}

	for (int i = N; i < N * 100; ++i) {
		string s = to_string(i);
		bool flags = 0;
		for (int j = 0; j < s.length(); ++j) {
			if (mp[s[s.length() - j - 1]] == 1) {
				flags = 1;
				break;
			}
		}
		if (!flags) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i%2 == 0) {
            if (a%2==1) a--;
            b += a/2;
            a /= 2;
        }
        else {
            if (b%2==1) b--;
            a += b/2;
            b /= 2;
        }
    }
    printf ("%d %d",a,b);
}

// ref: https://img.atcoder.jp/abc113/editorial.pdf
// ref: https://atcoder.jp/contests/abc113/submissions/3540482

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    const int mod = 1000000007;

    int H, W, K; cin >> H >> W >> K;
    vector<vector<int>> dp(H+1, vector<int>(W, 0)); dp[0][0] = 1;

    for(int hi=0; hi<H; ++hi){
        for(int wi=0; wi<W; ++wi){
            for(int ls=0; ls< 1<<(W-1); ++ls){ // lines: ls

                bool isConnected=false; // check if the two horizontal lines are connected.
                for(int i=0; i<W-2; ++i){
                    if( (ls>>i)&1 && (ls>>(i+1))&1 ){ isConnected=true; break; }
                }
                if(isConnected){ continue; }

                if( wi>=1 && (ls>>(wi-1))&1 ){
                    dp[hi+1][wi-1] += dp[hi][wi];
                    dp[hi+1][wi-1] %= mod;
                }else if( wi<=W-2 && (ls>>wi)&1 ){
                    dp[hi+1][wi+1] += dp[hi][wi];
                    dp[hi+1][wi+1] %= mod;
                }else{
                    dp[hi+1][wi+0] += dp[hi][wi];
                    dp[hi+1][wi+0] %= mod;
                }
            }
        }
    }
    cout << dp[H][K-1] << endl;

    return 0;
}


#include <stdio.h>
int main() {
int a;
scanf("%d",&a);
a=a*a*a;
printf("%d\n",a);
return 0;
}

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;

int main(){
    string s;
    std::cin >> s;
    std::cout << s.substr(0,s.size()-8) << std::endl;
}


#include<bits/stdc++.h>

template< typename G >
struct StronglyConnectedComponents {
    using UnWeightedGraph=std::vector<std::vector<int>>;
  const G &g;
  UnWeightedGraph gg, rg;
  std::vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return comp[k];
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};
int main(){
    int N,M;
    std::cin>>N>>M;
    std::vector<std::vector<bool>> to(N,std::vector<bool>(N,false));
    std::vector<std::vector<int>> graph(N),t;
    std::vector<int> ans;
    for(int _=0;_<M;++_){
        int u,v;
        std::cin>>u>>v;
        u--;v--;
        if(ans.empty()){
            graph[u].push_back(v);
            StronglyConnectedComponents<std::vector<std::vector<int>>> scc(graph);
            scc.build(t);
            std::vector<std::vector<int>> tmp(N);
            for(int i=0;i<N;++i) tmp[scc[i]].push_back(i);
            int ok=-1;
            for(int i=0;i<N;++i) if(tmp[i].size()>1) ok=i;
            if(ok!=-1){
                int now=v;
                while(now!=u){
                    ans.push_back(now);
                    for(auto e:graph[now]) if(scc[e]==ok){
                        now=e;
                        break;
                    }
                }
                ans.push_back(u);
            }
            for(int i=0;i<N;++i) if(to[v][i]) to[u][i]=true;
        }
        else if(std::find(ans.begin(),ans.end(),u)!=ans.end()&&
                std::find(ans.begin(),ans.end(),v)!=ans.end()){
            int ch=std::find(ans.begin(),ans.end(),v)-ans.begin();
            int sz=ans.size();
            std::vector<int> tmp;
            while(ans[ch]!=u){
                tmp.push_back(ans[ch]);
                ch=(ch+1)%sz;
            }
            tmp.push_back(u);
            ans=tmp;
        }
    }
    if(ans.empty()){
        std::cout<<-1<<std::endl;
        return 0;
    }
    std::cout<<ans.size()<<std::endl;
    for(auto a:ans) std::cout<<a+1<<std::endl;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

template<int BUFSIZE>
struct ans_buf {
  char buf[BUFSIZE];
  int i;
  ans_buf(): i(0) {}
  void putZ(uint64_t v, char delim='\n') {
    uint64_t k = 1;
    while(k <= v/10) k*=10;
    for(; k>0; v%=k, k/=10) buf[i++] = (v/k)+'0';
    buf[i++] = delim;
  }
  void out() { std::fwrite(buf, 1, i, stdout); }
};

int const MAXN = 1000;
int N, M;
std::vector<int> G[MAXN];
bool used[MAXN];

int nv[MAXN], n;
bool dfs(int v) {
  used[v] = true;
  for(auto c: G[v]) {
    nv[v] = c;
    if(c == n) return true;
    if(!used[c] && dfs(c)) return true;
  }
  return false;
}

int main() {
  N = getZ(); M = getZ();
  for(int i = 0; i < M; ++i) G[getZ()-1].push_back(getZ()-1);
  for(int i = 0; i < N; ++i) {
    std::fill_n(used, N, false);
    if(dfs(n = i)) break;
    n = -1;
  }
  if(n < 0) fin(n);
  for(;;) {
    std::fill_n(used, N, false);
    used[n] = true;
    for(int k = nv[n]; k!=n; k=nv[k]) used[k] = true;
    bool ok = true;
    for(int i = 0; i < N; ++i) if(used[i]) {
      for(auto c: G[i]) if(used[c] && c != nv[i]) {
        nv[i] = n = c;
        ok = false;
        break;
      }
      if(!ok) break;
    }
    if(ok) break;
  }
  int ans = 0;
  for(int i = 0; i < N; ++i) if(used[i]) ++ans;
  ans_buf<4000> buf;
  buf.putZ(ans);
  for(int i = 0; i < N; ++i) if(used[i]) buf.putZ(i+1);
  buf.out();
  return 0;
}


# include<bits/stdc++.h>
# include<ext/pb_ds/assoc_container.hpp>
# include<ext/pb_ds/tree_policy.hpp>
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
# pragma GCC optimize ("Ofast")

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

# define int long long
typedef long long ll;
typedef pair<int, int> pii;

# define S second
# define F first
# define kill(x) return(cout << x << '\n', 0LL)
# define debug(x) cerr<< #x << " = " << (x) << endl
# define ddebug(x, y) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << endl
# define tdebug(x, y, z) cerr<< #x << " = " << (x)  << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl
# define bin(x) cerr<< #x << " : " << bitset<4>(x) << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define uop(x, y) pii(min(x, y), max(x, y))

const int MAXN = 2000 + 10;
int MOD,
    fact[3 * MAXN],
    inv[3 * MAXN],
    r2[3 * MAXN],
    r3[3 * MAXN];

int _pow(int a, int p)
{
    if (!p)
        return 1;
    return _pow(sq(a) % MOD, p >> 1) * (p & 1 ? a : 1) % MOD;
}

int rev(int a)
{
    return _pow(a, MOD - 2);
}

int ch(int n, int k)
{
    return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

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

    int n;
    cin >> n >> MOD;

    fact[0] = 1;
    for (int i = 1; i <= n * 3 + 10; i ++)
        fact[i] = fact[i - 1] * i % MOD;

    for (int i = 0; i <= n * 3 + 10; i ++)
    {
        r2[i] = rev(_pow(2, i));
        r3[i] = rev(_pow(3, i));
        inv[i] = rev(fact[i]);
    }

    int ans = 0;
    for (int i = 0; i <= n; i ++)
        for (int j = i; i + (j - i) / 3 <= n; j += 3)
        {
            int k = n - i - (j - i) / 3;

            int x = ch(3 * n, j)
                    * ch(3 * n - j, 2 * i) % MOD
                    * fact[2 * i] % MOD
                    * r2[i] % MOD
                    * inv[i] % MOD
                    * fact[3 * k] % MOD
                    * r3[k] % MOD
                    * inv[k] % MOD;
            ans = (ans + x) % MOD;
        }
    cout << ans << endl;

	return 0;
}

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

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

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

i64 pow(i64 x, i64 n, i64 m) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= m;
		(x *= x) %= m;
		n >>= 1;
	}
	return ret;
}

i64 inv(i64 n, i64 m) {
	return pow(n, m - 2, m);
}

int main() {
	i64 n, m; scanf("%lld%lld", &n, &m);

	i64 N = 1;
	for(i64 i = 1; i <= 3 * n; i++) N = N * i % m;

	std::vector<int> tan(3 * n + 1);
	for(i64 i = 0; i < tan.size(); i++) tan[i] = inv(i, m);

	int offset = 3 * n;
	auto dp = make_v<int>(3 * n + 1, 6 * n + 1); dp[0][offset] = N;
	for(int i = 0; i < 3 * n; i++) {
		for(int j = 0; j < 6 * n; j++) {
			i64 from = dp[i][j];
			if(!from) continue;

			if(i + 1 <= 3 * n) (dp[i + 1][j + 1] += from * tan[i + 1] % m) %= m;
			if(i + 2 <= 3 * n)(dp[i + 2][j - 1] += from * tan[i + 2] % m) %= m;
			if(i + 3 <= 3 * n)(dp[i + 3][  j  ] += from * tan[i + 3] % m) %= m;
		}
	}

	i64 ans = 0;
	for(int i = offset; i < 6 * n + 1; i++) (ans += dp[3 * n][i]) %= m;
	printf("%lld\n", ans);
	return 0;
}


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

const int maxN = 200010;
typedef long long ll;

int vis[2][maxN];
vector<int> G[2][maxN];

queue<int> Q;
void bfs(int u, int d, int c){
	while(!Q.empty()) Q.pop();
	vis[d][u] = c; Q.push(u);
	while(!Q.empty()){
		u = Q.front(); Q.pop();
		for(int i = 0; i < G[d][u].size(); ++i){
			int v = G[d][u][i];
			if(!vis[d][v]) vis[d][v] = c, Q.push(v);
		}
	}
}

map<ll, int> mp;

int main (){
	int n, k, l, u, v, i, c0 = 0, c1 = 0;
	scanf("%d%d%d", &n, &k, &l);
	while(k--){
		scanf("%d%d", &u, &v);
		G[0][u].push_back(v);
		G[0][v].push_back(u);
	}
	while(l--){
		scanf("%d%d", &u, &v);
		G[1][u].push_back(v);
		G[1][v].push_back(u);
	}
	for(i = 1; i <= n; ++i) if(!vis[0][i]) bfs(i, 0, ++c0);
	for(i = 1; i <= n; ++i) if(!vis[1][i]) bfs(i, 1, ++c1);
	for(i = 1; i <= n; ++i) ++mp[vis[0][i] * 1ll * maxN + vis[1][i]];
	for(i = 1; i <= n; ++i){
		printf("%d", mp[vis[0][i] * 1ll * maxN + vis[1][i]]);
		if(i < n) printf(" ");
	}
	return 0;
}

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

#define INF 1e9+7

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		vector<vector<int> > cost(m,vector<int>(m,INF));
		vector<vector<int> > timea(m,vector<int>(m,INF));

		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			a--;
			b--;
			cin>>cost[a][b]>>timea[a][b];
			cost[b][a]=cost[a][b];
			timea[b][a]=timea[a][b];
		}

		for(int i=0;i<m;i++){
			cost[i][i]=0;
			timea[i][i]=0;
		}

		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
					timea[i][j]=min(timea[i][j],timea[i][k]+timea[k][j]);
				}
			}
		}

		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int p,q,r;
			cin>>p>>q>>r;
			p--;
			q--;
			if(r==0)cout<<cost[p][q]<<endl;
			if(r==1)cout<<timea[p][q]<<endl;
		}
	}
	return 0;
}


#include <iomanip>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
using ld = long double;

const ld PI = acos(-1);

struct point {
    ld x, y;
};

int main() {
    int N;
    cin >> N;
    vector<point> coo(N);
    for (auto& p : coo) cin >> p.x >> p.y;

    for (int i = 0; i < N; ++i) {
        vector<ld> degs;
        for (int j = 0; j < N; ++j) {
            if (i == j) continue;
            degs.push_back(atan2(coo[i].y - coo[j].y, coo[i].x - coo[j].x));
        }
        sort(degs.begin(), degs.end());
        degs.push_back(degs.front() + PI * 2);

        ld ans = 0;
        for (int j = 0; j < N; ++j) {
            ans = max(ans, degs[j + 1] - degs[j] - PI);
        }
        cout << fixed << setprecision(10) << ans / (PI * 2) << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

//点a,bの距離の2乗
ld dist2(pdd a, pdd b){
    ld x = b.first - a.first;
    ld y = b.second - a.second;
    return x*x + y*y;
}

//点a,bの距離
ld dist(pdd a, pdd b){
    return sqrt(dist2(a, b));
}

//内積a・b
ld dot(pdd a, pdd b){
    ld x = a.first * b.first;
    ld y = a.second * b.second;
    return x+y;
}

//a,bを横に並べた行列の行列式
ld det(pdd a, pdd b){
    ld x = a.first * b.second;
    ld y = a.second * b.first;
    return x-y;
}

//b-a
pdd dif(pdd a, pdd b){
    pdd p;
    p.first = b.first - a.first;
    p.second = b.second - a.second;
    return p;
}

//点a,bの中点
pdd mid(pdd a, pdd b){
    pdd p;
    p.first = (a.first + b.first)/2;
    p.second = (a.second + b.second)/2;
    return p;
}

int main(){
    int N;
    cin >> N;
    pdd p[N];
    map<pdd, int> mp;
    rep(i, N){
        cin >> p[i].first >> p[i].second;
        mp[p[i]] = i;
    }
    sort(p, p+N);
    pdd q[N+1];
    int k = 1;
    q[0] = p[0];
    rep2(i, 1, N-1){
        if(i < N-1 && p[i-1].first == p[i].first) continue;
        while(k > 1 && det(dif(q[k-1], p[i]), dif(q[k-1], q[k-2])) <= 0) k--;
        q[k] = p[i], k++;
    }
    int t = k;
    rep3(i, N-2, 0){
        if(i > 0 && p[i+1].first == p[i].first) continue;
        while(k > t && det(dif(q[k-1], p[i]), dif(q[k-1], q[k-2])) <= 0) k--;
        q[k] = p[i], k++;
    }
    k--;
    ld ans[N];
    fill_n(ans, N, 0);
    ld pi = 3.141592653589793238;
    rep(i, k){
        int j = (k+i-1)%k, l = (i+1)%k;
        pdd x[2];
        x[0] = mid(q[i], q[j]);
        x[1] = mid(q[i], q[l]);
        ld r[3], R[3];
        rep(a, 2){
            r[a] = dist(q[i], x[a]);
            R[a] = dist2(q[i], x[a]);
        }
        r[2] = dist(x[0], x[1]);
        R[2] = dist2(x[0], x[1]);
        ld cos = -(R[0]+R[1]-R[2])/(2*r[0]*r[1]);
        if(cos > 1) cos = 1;
        elif(cos < -1) cos = -1;
        ld the = acos(cos);
        int n = mp[q[i]];
        ans[n] = the/(2*pi);
    }
    rep(i, N) cout << setprecision(15) << ans[i] << endl;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  ll ans = 0;
  for(int i=0; i<=k; i++) { // push
    int j = k-i; // pop
    if(j >= n) {
      priority_queue<ll, vector<ll>, greater<ll>> q;
      rep(l, n) q.push(v[l]);
      rep(l, i) {
        if(q.empty()) break;
        if(q.top() >= 0) break;
        q.pop();
      }
      ll tmp = 0;
      while(!q.empty()) {
        tmp += q.top();
        q.pop();
      }
      chmax(ans, tmp);
    } else {
      for(int l=0; l<=j; l++) {
        priority_queue<ll, vector<ll>, greater<ll>> q;
        rep(m, l) q.push(v[m]);
        rep(m, j-l) q.push(v[n-1-m]);
        rep(m, i) {
          if(q.empty()) break;
          if(q.top() >= 0) break;
          q.pop();
        }
        ll tmp = 0;
        while(!q.empty()) {
          tmp += q.top();
          q.pop();
        }
        chmax(ans, tmp);
      }
    }
  }
  cout << ans << endk;
  return 0;
}

#include <cstdio>
using namespace std;

int n;
int m;
int maxcnt;
int maxidx;
int a[1000];
int cnt[1000];

int main() {
    scanf("%d %d", &n, &m);
    for (int i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }

    for (int i=0; i<m; i++) {
        int b;

        scanf("%d", &b);
        for (int i=0; i<n; i++) {
            if (a[i] <= b) {
                cnt[i]++;
                if (maxcnt < cnt[i]) {
                    maxcnt = cnt[i];
                    maxidx = i;
                }
                break;
            }
        }
    }

    printf("%d\n", maxidx+1);
}


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

int main() {
    ll x; cin >> x;
    ll nokori = x % 11;
    ll ans = (x-nokori) / 11;
    ans *= 2;
    if(nokori > 6){
        ans += 2;
    } else if(nokori > 0) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string s;
    cin >> s;
    rep(i,s.size()-8){
        cout << s[i];
    }
}


#include<iostream>
#include<string>
using namespace std;
int main(){
	int i,n;
	string a;
	cin>>a;
	n=a.size();
	for(i=n-1;i>=0;i--){
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string ans = "";
  while(n != 0){
    int t = n%(-2);
    if(t == -1) t = 1;
    ans.push_back('0'+t);
    n = (n-t)/(-2);
  }
  if(ans.size() == 0) ans = "0";
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int M = 120000;
typedef long long ll;
int n,m,k;
char grid[8][10][10]={{"aa.","..a","..a"},
{"aabc","ddbc","bcaa","bcdd"},
{"aabba","bcc.a","b..cb","a..cb","abbaa"},
{
    "aabc..",
    "ddbc..",
    "..aabc",
    "..ddbc",
    "bc..aa",
    "bc..dd"
},
{
    "aabbcc.",
    "dd.dd.a",
    "..d..da",
    "..d..db",
    "dd.dd.b",
    "..d..dc",
    "..d..dc"
}};
char ans[1001][1001];
void out(int x){
    fo(i,0,x-1) {
        ans[i][x]='\0';
        printf("%s\n",ans[i]);
    }
}
void ass(int x,int y,int num){
    fo(i,0,num+2)
        fo(j,0,num+2)
            ans[i+x][j+y]=grid[num][i][j];
}
int main(){
    while(cin>>n){
        if(2==n) puts("-1");
        else {
            fo(i,0,n-1)
                fo(j,0,n-1)
                    ans[i][j]='.';
            int i;
            for(i=0;n-i*4>7;++i) {
                ass(i*4,i*4,1);
            }
            ass(i*4,i*4,n-i*4-3);
            out(n);
        }
    }
    return 0;
}

// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0,y=1;while(nc=gc(),(nc<48||nc>57)&&nc!=-1)if(nc==45)y=-1;Bi=1;
		x=nc-48;while(nc=gc(),47<nc&&nc<58)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*y;
	}
	in db gf() {int a=read(),b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi):a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
}
using namespace fast_io;
const int N=1e3+5;
int n;
char ans[1005][1005];
string s3[3]={
"aab",
"b.b",
"baa",
};
string s4[4]={
"bacc",
"babb",
"ccda",
"aada",
};
string s5[5]={
"accbb",
"ad..a",
"bd..a",
"b.ddc",
"aabbc",
};
string s6[6]={
"oorrzz",
".a.b.c",
".a.b.c",
"d.e.f.",
"d.e.f.",
"oorrzz"
};
string s7[7]={
"..bbcca",
"ccdd..a",
".a..d.b",
".a..d.b",
"b....dc",
"b....dc",
"ccbbaa.",
};
int main()
{
	n=read();if(n<3) return puts("-1"),0;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans[i][j]=0;
	if(n==3) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s3[i-1][j-1];sr[++C]='\n';}return ot(),0;}
	if(n==4) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s4[i-1][j-1];sr[++C]='\n';}return ot(),0;}
	if(n==5) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s5[i-1][j-1];sr[++C]='\n';}return ot(),0;}
	if(n==6) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s6[i-1][j-1];sr[++C]='\n';}return ot(),0;}
	if(n==7) {for(int i=1;i<=n;i++){for(int j=1;j<=n;j++) sr[++C]=s7[i-1][j-1];sr[++C]='\n';}return ot(),0;}
	if(n%4==0) for(int i=1;i<=n;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4];
	if(n%4==1)
	{
		for(int i=1;i<=n-5;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4];
		for(int i=n-4;i<=n;i++) for(int j=n-4;j<=n;j++) ans[i][j]=s5[i-n+4][j-n+4];
	}
	if(n%4==2)
	{
		for(int i=1;i<=n-6;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4];
		for(int i=n-5;i<=n;i++) for(int j=n-5;j<=n;j++) ans[i][j]=s6[i-n+5][j-n+5];
	}
	if(n%4==3)
	{
		for(int i=1;i<=n-7;i+=4) for(int j=i;j<=i+3;j++) for(int k=i;k<=i+3;k++) ans[j][k]=s4[(j-1)%4][(k-1)%4];
		for(int i=n-6;i<=n;i++) for(int j=n-6;j<=n;j++) ans[i][j]=s7[i-n+6][j-n+6];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++) sr[++C]=(ans[i][j]?ans[i][j]:'.');
		sr[++C]='\n';ot();
	}
	return 0;
}
//Author: disangan233
//In my dream's scene,I can see the everything that in Cyaegha.
/*
----------
aab
b.b
baa
----------
bacc
babb
ccda
aada
----------
accbb
ad..a
bd..a
b.ddc
aabbc
----------
aabb..
b..aa.
ba....
.a..aa
..a..b
..a..b
----------
..bbcca
ccdd..a
.a..d.b
.a..d.b
b....dc
b....dc
ccbbaa.
----------

*/


#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}

#define ABC 001
#define ARC 010
#define AGC 100

int main(void){
    int r;
    cin >> r;
    int frag = AGC;
    if(r < 1200){
        frag |= ABC;
        frag |= ARC;
    }else if( r < 2800){
        frag |= ARC;
    }
    if(frag & ABC)cout << "ABC" << endl;
    else if(frag & ARC)cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r; cin >> r;
  if(r < 1200) cout << "ABC" << "\n";
  else if(r < 2800) cout << "ARC" << "\n";
  else cout << "AGC" << "\n";
  return 0;
}


#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;

void solve(ll A, ll B) { cout << max({A + B, A - B, A * B}) << endl; }

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}

#include <iostream>
#include <string>
#include <cmath>

using namespace std;

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

    cout << int(pow(x, 3)) << endl;

    return 0;
}


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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") {
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  set<int> nums;
  int a;
  while (cin >> a) nums.insert(a);
  cout << ((nums.size() == 2) ? "Yes" : "No") << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

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

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("gymnastics.in","r",stdin );
#define outF freopen("gymnastics.out" , "w" , stdout ) ;
#define sum(a)a * (a + 1 ) / 2
#define ll long long

const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e6, oo = 1e7 , M = 4 * N, mod = 1<<30 , K = 12;
int n ;

int32_t main(){

    //inF;
    // Dont Forget memset

    //calculate constraints please!!!

    fastio;
   map<int , int >mp;
   for(int  i = 0 ; i < 3 ; i++){
    int a ;
    cin >> a;
    mp[a]++;
   }
   cout << (mp.size() == 2 ? "Yes" : "No");

     return 0 ;
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<std::string, std::string>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string S;
std::map<P, ll> mp;
ll ans;

int main()
{
  std::cin >> N >> S;

  std::reverse( S.begin()+N, S.end() );

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[j];

    ++mp[P( t[0], t[1] )];
  }

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[N+j];

    ans += mp[P( t[0], t[1] )];
  }

  std::cout << ans << std::endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;

vector<int> tovec(ll x, int N){
    vector<int> vec;
    rep(i, N){
        if(x % 2 == 0) vec.push_back(0);
        else vec.push_back(1);
        x /= 2;
    }
    return vec;
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    string L, R;
    rep(i, N){
        L += S[i];
        R += S[2*N-1-i];
    }
    ll e[N+1];
    e[0] = 1;
    rep(i, N) e[i+1] = e[i]*2;
    map<pair<string, string>, ll> lmp, rmp;
    rep(i, e[N]){
        vector<int> vec = tovec(i, N);
        string l1, l2, r1, r2;
        rep(i, N){
            if(vec[i] == 0){
                l1 += L[i];
                r1 += R[i];
            }
            else{
                l2 += L[i];
                r2 += R[i];
            }
        }
        pair<string, string> p1 = make_pair(l1, l2), p2 = make_pair(r1, r2);
        if(lmp.count(p1)) lmp[p1]++;
        else lmp[p1] = 1;
        if(rmp.count(p2)) rmp[p2]++;
        else rmp[p2] = 1;
    }
    ll ans = 0;
    map<pair<string, string>, ll>::iterator ite;;
    ite = lmp.begin();
    while(ite != lmp.end()){
        if(rmp.count(ite->first)){
            ans += ite->second * rmp[ite->first];
        }
        ite++;
    }
    cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==v.size()?"":" ");
    return os;
}

int main(){
    string s;
    while(cin>>s){
    int n = s.size();
    vi l(n);
    l[0] = 1;
    rep(i,n-1){
        if(s[i+1]==s[i]) l[i+1]=l[i]+1;
        else l[i+1] = 1;
    }
    int ans = 0;
    dump(s);
    dump(l);
    loop(i,1,n-1){
        if(s[i]=='O' && s[i+1]!='O' && i+l[i]<n && i-l[i] >= 0 && l[i+l[i]]>=l[i] && l[i-l[i]]>=l[i] && s[i+l[i]]=='I' && s[i-l[i]]=='J'){
            ans = max(ans,l[i]);
        }
    }
    cout << ans << endl;
}
}

#include<iostream>

using namespace std;

int main(){
  string in;
  // while(cin >> in){
  cin >> in;
  int num[3] = {0,0,0};
  int lev = 0;
  int status = 3;
  for(int i = 0; i < in.length(); i++){
    if(in[i] == 'J'){
      //cout << num[0] << " " << num[1] << " " << num[2] << endl;
      if(status != 0) num[0] = num[1] = num[2] = 0;
      num[0]++;
      status = 0;
      continue;
    }
    if(in[i] == 'O' && (status == 0 || status == 1)){
      num[1]++;
      status = 1;
      continue;
    }
    if(in[i] == 'I' && (status == 1 || status == 2)){
      num[2]++;
      status = 2;
      if(num[1] <= num[0] && num[1] <= num[2]) lev = max(lev,num[1]);
      continue;
    }
    status = 3;
  }
  cout << lev << endl;
  // }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n,x,t;
  cin>>n>>x>>t;
  int times=(n+x-1)/x;
  int ans=times*t;
  cout<<ans<<endl;
}

#include<iostream>
using namespace std;

char getAns(int m,int e,int j){
	if(m==100||e==100||j==100)return 'A';
	if((m+e)/2>=90)return 'A';
	if((m+e+j)/3>=80)return 'A';
	if((m+e+j)/3>=70)return 'B';
	if((m+e+j)/3>=50&& (m>=80||e>=80))return 'B';
	return 'C';

}
int main(){
	int d;
	while(cin>>d){
		int pm,pe,pj;
		for(;d>0;d--){
			cin>>pm>>pe>>pj;
			cout<<getAns(pm,pe,pj)<<endl;
		}
	}
}


// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

int f(int n) {
  int ret = 0;
  while (n) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

void MAIN() {
  int n; cin >> n;
  if (n % f(n) == 0) cout << "Yes" << '\n';
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}

int main() {
  string s;
  while (getline(cin, s)) {
    string orig;
    for (int i = 0; i <= 'z'-'a'; i++) {
      orig = s;
      for (int j = 0; j < orig.size(); j++) {
        if (orig[j] >= 'a' && orig[j] <= 'z') {
          orig[j] = 'a' + ((orig[j]-'a') + i) % ('z'-'a'+1);
        }
      }
      if (orig.find("the") != string::npos ||
          orig.find("this") != string::npos ||
          orig.find("that") != string::npos) {
        break;
      }
    }
    cout << orig << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++)
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0), b(n, 0);
    ll sum = 0, count = 0;
    bool zero = false;
    rep1(i, n){
        cin >> a[i];
        sum += abs(a[i]);
        b[i] = abs(a[i]);
        if (a[i]<0) count++;
        if (a[i]==0) zero = true;
    }
    ll ans;
    sort(b.begin(), b.end());
    if (count%2==0 || zero) ans = sum;
    else ans = sum - 2*b[0];
    cout << ans << endl;
    //printf("%.12f", ans);
}

#include <bits/stdc++.h>
#define res register int
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1000000007
#define gc getchar()
#define MAXN 200005
#define lc pos<<1
#define rc pos<<1|1
using namespace std;

inline int read()
{
    int ch=gc,f=0;
    int x=0;
    while(ch<'0'||ch>'9')
    {
        f|=ch=='-';
        ch=gc;
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=gc;
    }
    return f?-x:x;
}
struct row
{
	int c,flag;
}r[MAXN];
int n,m;
int a[4][MAXN],t[2],c[MAXN];
inline void hult()
{
	printf("No\n");
	exit(0);
}
inline void op(int i)
{
	if(i<1)
	hult();
	swap(r[i],r[i+2]);
	r[i].flag^=1;
	r[i+1].flag^=1;
	r[i+2].flag^=1;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	a[1][i]=read();
	for(int i=1;i<=n;i++)
	a[2][i]=read();
	for(int i=1;i<=n;i++)
	a[3][i]=read();
	for(int i=1;i<=n;i++)
	{
		int b[3]={a[1][i],a[2][i],a[3][i]};
		sort(b,b+3);
		if(b[2]%3||b[1]!=b[2]-1||b[0]!=b[1]-1)
		hult();
		if(a[2][i]!=b[1])
		hult();
		r[i].c=b[2]/3;
		r[i].flag=b[2]==a[3][i];
		c[i]=r[i].c;
		if(abs(r[i].c-i)&1)
		hult();
		t[i&1]^=b[2]==a[1][i];
	}
    for(res i=1;i<=n;i++)
	{
        while(c[i]!=i)
		{
            t[i&1^1]^=1;
            swap(c[i],c[c[i]]);
        }
    }
    puts(t[0]||t[1]?"No":"Yes");
	return 0;
}


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

int main()
{
    float l[11];
    float v1,v2;
    char s;
    while(1)
    {
        for(int i=1;i<=10;i++){
            cin >> l[i] >> s;
        }
        cin >> v1 >> s >> v2;
        if(cin.eof()) break;

        float t,la;
        float lsum=0;
        for(int i=1;i<=10;++i){
            lsum+= l[i];
        }

        t = lsum/(v1+v2);
        la = v1*t;
        lsum = 0;
        for(int i=1;i<10;i++)
        {
            lsum += l[i];
            if(lsum >= la){ cout << i << endl; break;}
        }
        if(lsum < la)cout << 10 << endl;
    }

    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double row[10],v[2];
	for(;;){
		if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&row[0],&row[1],&row[2],&row[3],&row[4],&row[5],&row[6],&row[7],&row[8],&row[9],&v[0],&v[1]) == EOF){break;}
		int i;
		double t,dis = 0,d = 0;
		for(int i=0; i<10; i++){
			dis+=row[i];
		}
		for(i=0; i<10; i++){
			d+=row[i];
			t = d/v[0];
			if(dis <= t*(v[0]+v[1])){break;}
		}
		cout<<i+1<<endl;
	}
	return 0;
}


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

int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> x1(n+1);
    vector<int> y1(m+1);
    for(int i = 0; i < n; i++) cin >> x1[i];
    for(int i = 0; i < m; i++) cin >> y1[i];

    string ans = "War";
    for(int z = x+1; z <= y; z++){
        bool isok = true;
        for(int i = 0; i < n; i++){
            if(x1[i] >= z) isok = false;
        }

        for(int i = 0; i < m; i++){
            if(y1[i] < z) isok = false;
        }

        if(isok) ans = "No War";
    }

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

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000000000000;
//input
ll N,A,B,C,D,E;

//processing
ll hoge;

//dpTable
//int dp[100050];

int main(){
    cin >> N >> A >> B >> C >> D >> E;
    hoge = min(A,min(B,min(C,min(D,E))));
    ll ans = (N + hoge - 1) / hoge;
    cout << ans + 4 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

void print(ll x){
    cout << x << ".00000000000000" << endl;
}

int main(){
    int N;
    cin >> N;
    ll x[N];
    rep(i, N) cin >> x[i];
    ll d[N-1];
    rep(i, N-1) d[i] = x[i+1]-x[i];
    int M; ll K;
    cin >> M >> K;
    int dp[60][N-1];
    rep(i, N-1) dp[0][i] = i;
    rep(i, M){
        int a;
        cin >> a;
        swap(dp[0][a-2], dp[0][a-1]);
    }
    rep2(i, 1, 59){
        rep(j, N-1) dp[i][j] = dp[i-1][dp[i-1][j]];
    }
    ll ans = x[0];
    print(ans);
    rep(i, N-1){
        int now = i;
        rep(j, 60){
            if(K&(1LL<<j)) now = dp[j][now];
        }
        print(ans += d[now]);
    }
}

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

ll x[100010];
int a[100010], nsw[100010], now[100010], vid[100010], vnum[100010], repl[100010];
bool looked[100010]={};
vector<vector<int>> v;

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> x[i];
	int M;
	ll K;
	cin >> M >> K;
	for(int i=0; i<M; ++i) cin >> a[i];
	for(int i=1; i<N; ++i) nsw[i]=i;
	for(int i=0; i<M; ++i) swap(nsw[a[i]-1], nsw[a[i]]);
	for(int i=1; i<N; ++i) now[nsw[i]]=i;
	int cnt=0;
	for(int i=1; i<N; ++i){
		if(!looked[i]){
			int b=i;
			v.emplace_back();
			do{
				vnum[b]=v[cnt].size();
				v[cnt].emplace_back(b);
				vid[b]=cnt;
				looked[b]=1;
				b=now[b];
			}while(b!=i);
			++cnt;
		}
	}
	for(int i=1; i<N; ++i){
		ll sz=v[vid[i]].size();
		ll r=(K%sz+vnum[i])%sz;
		repl[v[vid[i]][r]]=i;
	}
	cout << x[0] << endl;
	ll ans=x[0];
	for(int i=1; i<N; ++i){
		ans += x[repl[i]]-x[repl[i]-1];
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#define ll long long

using namespace std;

long long gcd(int x, int y){
     if ( x == 0 ) return y;

     return gcd(y%x, x);
}

long long lcm(int x, int y){
     if ( y == 0 ){
          return x;
     }

     return x*y/gcd(x, y);
}

int min(int a, int b){
     return a > b ? b : a;
}

int max(int a, int b){
     return a > b ? a : b;
}

int main()
{
     cin.sync_with_stdio( false );

     int n;
     cin>>n;

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

     for (int i=0;i<n;i++){
          if ( m[a[i]] >= 2 ){
               cout<<"NO"<<endl;
               return 0;
          }
     }

     cout<<"YES"<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    int n;
    cin >> n;
    ll a[n];
    set<ll> s;
    for(int i=0; i<n; i++){
    	cin >> a[i];
    	s.insert(a[i]);
    }
    if(s.size() == n){
    	cout << "YES\n";
    }else{
    	cout << "NO\n";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <complex>
#include <cassert>
#include <cstring>
#include <functional>
#include <bitset>
#include <climits>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define cmn(x,y) x=min(x,y)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(vector<T>& v) : sz((int)v.size()){
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n, make_pair(numeric_limits<T>::max(), sz));
        for(int i = 0; i < sz; i++){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+n] = make_pair(a, k);
        k += n;
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), sz);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), sz);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        for(int i = 0; i < sz; i++){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};

int n;
ll d;
ll saiki(segtree<ll>& sg, int a,int b){
    //cerr << a << " " << b << endl;
    if(b==a+1)return 0;
    auto p = sg.query(a,b);
    ll s = p.first;
    ll ans = 0;
    int ind = p.second;
    if(ind-1>=a){
        ll xx = sg.query(ind-1,ind).first;
        ans += s+d+xx;
        sg.update(ind-1,min(xx,s+d));
        ans += saiki(sg,a,ind);
    }
    if(ind+1<b){
        ll xx = sg.query(ind+1,ind+2).first;
        ans += s+d+xx;
        sg.update(ind+1,min(xx,s+d));
        ans += saiki(sg,ind+1,b);
    }
    return ans;
}

int main(){
    cin >> n >> d;
    vector<ll>v(n+1);
    rep(i,n)cin >> v[i];
    segtree<ll> sg(v);
    ll ans = saiki(sg,0,n);
    cout << ans << endl;
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include<iomanip>
#define _for(i,a,b) for(int i = (a);i < (b);i++)
#define mset(x) memset(x,0,sizeof(x));
using namespace std;

int main() {
	long long int n,ans;
	cin>>n;
	ans = n * n *n;
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

int main(){
    int n;
    cin >> n;
    if(n < 1200) cout << "ABC" << endl;
    else if(n < 2800) cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


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

int main(void){
    vector<int>X(26,0);
    string S;cin>>S;
    for(long long i=0;i<S.size();i++){
        X[(int)S[i]-97]++;
    }
    for(long long i=0;i<26;i++){
        if(X[i]==0){
            int ans=i+97;
            cout<<(char)ans<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 100000000;
typedef pair<char, int> P;

int main() {
	string S;
	cin >> S;
	string alpha = "abcdefghijklmnopqrstuvwxyz";
	vector<P> vec(26);
	rep(i,26) {
		vec.at(i).first = alpha.at(i);
		vec.at(i).second = 1;
	}
	rep(i, S.size()) {
		rep(j, 26) {
			if (S.at(i)==vec.at(j).first)
			{
				vec.at(j).second = 0;
				break;
			}
		}
	}
	rep(i, 26) {
		if (vec.at(i).second)
		{
			cout << vec.at(i).first << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}


#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector <int> vi;

int main(void){
	map <char, int> m;
	vi x;
	int num[] = {1,5,10,50,100,500,1000};
	for (int i=0; i<7; i++)
		m["IVXLCDM"[i]] = num[i];

	while (true){
		string roman;
		cin>>roman;
		if (cin.eof()) break;

		int tmp, tmp2= m[roman[0]];
		for (int i=0; i<(int)roman.size(); i++){
			tmp = m[roman[i]];
			if (i!=0 && tmp2<tmp)
				x[i-1] = -tmp2;
			x.push_back(tmp);
			tmp2 = tmp;
		}

		int s=0;
		for (int i=0; i<(int)x.size(); i++)
			s += x[i];
		cout<<s<<endl;
		x.clear();
	}
}

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
const string ara = "IVXLCDM\0";
const int integer[8] = {1,5,10,50,100,500,1000};
int Input(int num[],string in);
void Output(int p,int num[]);

int main(void){
  string in;
  int num[1000];

  while( cin >> in ){
    for(int i = 0 ; i < 1000; i++)num[i] = 0;
    int p = Input(num,in);
    Output(p,num);
  }
  return 0;
}

int Input(int num[],string in){

  int p = 0;
  for(int i = 0 ; i < (int)in.size(); i++){
    for(int j = 0 ; ara[j] != '\0'  ; j++ ){
      if(in[i] == ara[j]){
	num[p++] = integer[j];
	break;
      }
    }
  }
  return p;
}

void Output(int p,int num[]){
  int ans  = 0;
  for(int i = 0 ;i < p ; i++){

    if(num[i] < num[i+1]){
      ans += (num[i+1] - num[i]);
      i++;
    } else ans+=num[i];
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0;
    dp[a-1][0]=1;
    ll nck[1001][1001];
    rep(i,0,1001)nck[i][0]=1;
    rep(i,0,1001)nck[i][i]=1;
  ll gya[1001];
  rep(i,1,1001)gya[i]=gyaku(i);
    rep(i,1,1001){
        rep(j,1,i){
            nck[i][j]=nck[i-1][j-1]+nck[i-1][j];
            nck[i][j]%=mod;
        }
    }
    rep(i,a-1,b){
        int t=0;
        rep(j,0,n+1){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=mod;
            if(t==1)continue;
            ll sum=1;
            ll now=n-j;
            rep(k,0,c){
                if(now<0){
                    sum=-1;
                    break;
                }
                sum*=nck[now][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
                now-=i+1;

            }
            if(sum==-1){
                t=1;
                continue;
            }
            rep(k,c,d+1){
                if(j+(i+1)*k>n)break;
                dp[i+1][j+(i+1)*k]+=dp[i][j]*sum;
                dp[i+1][j+(i+1)*k]%=mod;
                sum*=nck[n-(j+(i+1)*k)][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
            }

        }
    }
    cout<<dp[b][n]<<endl;

}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e3+5;
const int MOD=1e9+7;

int n, a, b, c, d;
int cache[N][N], cache2[N][N];
int fact[N], invfact[N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}

int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int num(int r, int take)
{
	int &ans=cache2[r][take];
	if(ans!=-1)
		return ans;
	return modinv(pow(fact[r], take, MOD));
}

int dp2(int n, int r, int take)
{
	int ans=fact[n] * invfact[n-r*take];
	ans%=MOD;
	int den=num(r, take);
	ans*=den;
	ans%=MOD;
	return ans;
}

int dp(int remaining, int freq)
{
	if(remaining==0)
		return 1;
	if(freq==b+1)
		return 0;
	int &ans=cache[remaining][freq];
	if(ans!=-1)
		return ans;
	ans=dp(remaining, freq+1);
	for(int i=c;i<=d;i++)
	{
		int take=i*freq;
		if(take>remaining)
			break;
		int ways=dp2(remaining, freq, i);
		ways*=dp(remaining-take, freq+1);
		ways%=MOD;
		ways*=invfact[i];
		ways%=MOD;
		ans+=ways;
	}
	ans%=MOD;
	return ans;
}

int32_t main()
{
	IOS;
	precompute();
	memset(cache, -1, sizeof(cache));
	memset(cache2, -1, sizeof(cache2));
	cin>>n>>a>>b>>c>>d;
	int ans=dp(n, a);
	cout<<ans;
	cerr<<(double)clock()/CLOCKS_PER_SEC;
	return 0;
}


#include "bits/stdc++.h"
#define ll long long
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll c[4];
double dp[301][301][301];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, a;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> a, c[a]++;
    dp[0][0][0] = 0;
    for (ll i = 0; i <= n; i++)
    {
        for (ll j = 0; j <= n; j++)
        {
            for (ll k = 0; k <= n; k++)
            {
                double z = n - (i + j + k), val = 1;
                if (z == n)
                    continue;
                if (i + j + k > n)
                    continue;
                if (i > 0)
                    val += (1.0 * i / n) * dp[i - 1][j + 1][k];
                if (j > 0)
                    val += (1.0 * j / n) * dp[i][j - 1][k + 1];
                if (k > 0)
                    val += (1.0 * k / n) * dp[i][j][k - 1];
                if (z > 0)
                    val /= (1.0 - 1.0 * z / n);
                dp[i][j][k] = val;
            }
        }
    }

    cout << setprecision(9) << fixed << dp[c[3]][c[2]][c[1]];
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

ll N;

//dp
vector<vector<vector<double>>> table;

double dp(ll i,ll j,ll k){
  //cout<<i<<" "<<j<<" "<<k<<endl;
  if(i==0&&j==0&&k==0) return 0;
  if(table.at(i).at(j).at(k)>-1) return table.at(i).at(j).at(k);

  table.at(i).at(j).at(k)=0;
  if(i>0) table.at(i).at(j).at(k)+=dp(i-1,j,k)*i/N;
  if(j>0) table.at(i).at(j).at(k)+=dp(i+1,j-1,k)*j/N;
  if(k>0) table.at(i).at(j).at(k)+=dp(i,j+1,k-1)*k/N;
  table.at(i).at(j).at(k)+=1;

  return table.at(i).at(j).at(k)/=(double)(i+j+k)/N;
}

int main()
{
  cin>>N;
  vector<ll> vec(4,0); rep(i,N) {ll a; cin>>a; vec.at(a)++;}

  //dp
  table=vector<vector<vector<double>>>(N+1,vector<vector<double>>(N+1,vector<double>(N+1,-1)));

  cout<<fixed<<setprecision(15)<<dp(vec.at(1),vec.at(2),vec.at(3))<<endl;
  /*
  rep(i,2) {
    if(i!=0) cout<<" ";
    cout<<table.at(0).at(0).at(i);
  }
  cout<<fixed<<setprecision(15)<<endl;
  */

  return 0;
}


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

int main(){
    int n;
    cin>>n;
    deque<int>q;
    rep(i,n){
        int a; cin>>a;
        int x=lower_bound(q.begin(),q.end(), a)-q.begin();
        if(x==0)q.push_front(a);
        else q[x-1]=a;
    }
    cout<<q.size()<<endl;
}

// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000;

int aa[N], ii[N], ft[N];

void update(int i, int n, int x) {
	while (i < n) {
		ft[i] = max(ft[i], x);
		i |= i + 1;
	}
}

int query(int i) {
	int x = 0;
	while (i >= 0) {
		x = max(x, ft[i]);
		i &= i + 1, i--;
	}
	return x;
}

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> aa[i];
		ii[i] = i;
	}
	sort(ii, ii + n, [] (int i, int j) { return aa[i] > aa[j] || aa[i] == aa[j] && i < j; });
	int ans = 0;
	for (int h = 0; h < n; h++) {
		int i = ii[h];
		int k = query(i) + 1;
		ans = max(ans, k);
		update(i, n, k);
	}
	cout << ans << '\n';
	return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int dp[111];

signed main(){
    int N;
    while(cin>>N,N){
        dp[0]=1;
        for(int i=1;i<=N;i++){
            dp[i]=0;
            for(int j=1;j<=3;j++)if(i-j>=0)dp[i]+=dp[i-j];
        }
        cout<<((dp[N]+9)/10+364)/365<<endl;
    }
    return 0;
}

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

int main(){
  int n,cou=0;
  string str;
  cin >> n;
  while(n>cou){
    int cou_out=0,ans=0,ining=0;
    while(cou_out < 3){
      cin >> str;
      if(str == "HIT"){
	ining++;
	if(ining == 4){
	  ans++;
	  ining--;
	}
      }
      else if(str == "OUT"){
	cou_out++;
      }
      else if(str == "HOMERUN"){
	ans += ining+1;
	ining = 0;
      }
    }
    cou++;
    cout << ans << endl;
  }
}


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

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

int main() {

  int H,W;
  scanf("%d%d",&H,&W);

  Graph A( H , vector<int> (W,0) );
  Graph count( H , vector<int> (W,0) );
  queue< pair<int,int> > que;

  rep(y,H){
    rep(x,W){

      char a;
      cin >> a;
      if( a == '#' ){
       A[y][x]=1;
       que.push( make_pair(x,y) );
      }

    }
  }

  vector<int> dx = { 0, 1, 0, -1 };
  vector<int> dy = { 1, 0, -1, 0 };
  int res = 0;

  while( !que.empty() ){

        pair<int,int> v = que.front();
        que.pop();

        int x = v.first;
        int y = v.second;

        rep(i,4) {

            int nv_x = x + dx[i];
            int nv_y = y + dy[i];

            //通れるか？
            if ( nv_x < 0 || nv_x >= W ) continue;
            if ( nv_y < 0 || nv_y >= H ) continue;
            if ( A[nv_y][nv_x] == 1 ) continue;

            A[nv_y][nv_x] = 1;
            count[nv_y][nv_x] = count[y][x] +1;
            res = count[nv_y][nv_x];
            que.push( make_pair(nv_x,nv_y) );

        }
    }

  printf("%d\n", res );
  return 0;

}

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int min(int a, int b) { return(a < b) ? a : b; }

class Solution
{
public:
	int minDistance(const string &word1, const string &word2)
	{
		const size_t m = word1.size() + 1;
		const size_t n = word2.size() + 1;

		vector<vector<int> > k(m, vector<int>(n));

		for (size_t i = 0; i < m; ++i)
			k[i][0] = i;

		for (size_t j = 0; j < n; ++j)
			k[0][j] = j;

		for (size_t i = 1; i < m; ++i)
		{
			for (size_t j = 1; j < n; ++j)
			{
				if (word1[i - 1] == word2[j - 1])
					k[i][j] = k[i - 1][j - 1];
				else
					k[i][j] = min(k[i - 1][j - 1], min(k[i - 1][j], k[i][j - 1])) + 1;
			}
		}
		return k[m - 1][n - 1];
	}
};

int main() {
	string a, b;
	cin >> a >> b;
	Solution A;
	cout << A.minDistance(a, b) << endl;
}


#include <iostream>
using namespace std;

int main( void )
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ( ( ( e - a ) <= ( 4 * k ) ) && ( ( d + e - a - b ) <= ( 3 * k ) ) &&
         ( ( d + e - a - b ) <= ( 2 * k ) ) && ( ( e - a ) <= ( k ) ) )
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}

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

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

  int k;
  cin >> k;

  for (int i = 0; i < 5;i ++){
    for (int j = i+1; j < 5; j++){
      if(abs(a.at(i)-a.at(j)) >k){
        cout << ":(";
            return 0;
      }
    }
  }
  cout << "Yay!";
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000

int main(){
vector<int>a;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;

	scanf("%d %d",&x,&n);

if(n==1){
scanf("%d", &k);
printf("%d\n",k);
if(k==1){
printf("1\n1\n");
}
else{
printf("2\n1 %d\n",k-1);
}
return 0;
}

x=0;
y=0;
z=0;

	f(i, n){
		scanf("%d", &k);
if(k%2==1){
x++;
if(y>0)z=k;
else y=k;
}
else a.push_back(k);
	}

if(x>2){
printf("Impossible\n");
return 0;
}

else if(x>1){
printf("%d",y);
f(i,a.size())printf(" %d",a[i]);
printf(" %d\n",z);

if(z==1){
printf("%d\n",a.size()+1);

printf("%d",y+1);
f(i,a.size())printf(" %d",a[i]);
printf("\n");
}
else{
printf("%d\n",a.size()+2);

printf("%d",y+1);
f(i,a.size())printf(" %d",a[i]);
printf(" %d",z-1);
printf("\n");
}
}

else if(x>0){
printf("%d",y);
f(i,a.size())printf(" %d",a[i]);
printf("\n");

printf("%d\n",a.size()+1);

printf("%d",y+1);
f(i,a.size()-1)printf(" %d",a[i]);
printf(" %d\n",a[a.size()-1]-1);
}

else{
printf("%d",a[0]);
f(i,a.size()-1)printf(" %d",a[i+1]);
printf("\n");

printf("%d\n",a.size());

printf("%d",a[0]+1);
f(i,a.size()-2)printf(" %d",a[i+1]);
printf(" %d\n",a[a.size()-1]-1);
}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int a[3][MAXN];
int f[2][MAXN];
void add(int p, int index) {
    for (;p < MAXN; p += p&-p)
        ++f[index][p];
}
int find(int p, int index) {
    int res = 0;
    for (;p; p -= p&-p)
        res += f[index][p];
    return res;
}
int32_t main () {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < 3; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];
    vector <int> vctr;
    bool b[2] = {0, 0};
    for (int i = 0; i < n; ++i) {
        int mx = max(a[0][i], max(a[1][i], a[2][i]));
        int mn = min(a[0][i], min(a[1][i], a[2][i]));
        if (mx - mn > 2)
            return cout << "No", 0;
        if (mx % 3)
            return cout << "No", 0;
        if (2 * a[1][i] != a[0][i] + a[2][i])
            return cout << "No", 0;
        if ((mx - i) % 2 == 0)
            return cout << "No", 0;
        vctr.push_back(mx / 3);
        if (a[0][i] == mx)
            b[i & 1] = 1 - b[i & 1];
        // cout << (a[0][i] == mx) << ' ';
    }
    // cout << b[0] << ' ' << b[1];
    for (int i = n - 1; i >= 0; --i) {
        if (find(vctr[i], i & 1) & 1)
            b[(i + 1) & 1] = 1 - b[(i + 1) & 1];
        add(vctr[i], i & 1);
        // cout << vctr[i] << ' ';
    }
    if (b[0] || b[1])
        return cout << "No", 0;
    cout << "Yes";
    return 0;
}


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

int main () {
  int R;
  int G;
  cin >> R >> G ;
  cout << (G - R) + G << endl;
}

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

  int main() {
  double R = 0;
  cin >> R;//現在のレーティング
  double G = 0;
  cin >> G;//したいレーティング
  //(R + ans) / 2 = G
  //R + ans = 2*G
  double ans  = 0;
  ans = 2*G - R;
    cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a, b;
    cin >> a >> b;
    cout << max(a * b, max(a + b, a - b)) << endl;
}

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

int main () {
  int A, B;
  cin >> A >> B;

  int tasu = A + B;
  int hiku = A - B;
  int kake = A * B;

  if (tasu >= hiku && tasu >= kake) {
    cout << tasu << endl;
  }
  else if (hiku >= kake && hiku >= tasu) {
    cout << hiku << endl;
  }
  else {
    cout << kake << endl;
  }
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

typedef pair<double, double> pd;
typedef vector<pd> vpd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll N;
string S;

vll Ms;
vvll dp;

ll search(ll k){
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  REP(i,N){
    if(i-k>=0){
      if(S[i-k]=='D'){
        dp[i][0]--;
        dp[i][1] -= (Ms[i-1]-Ms[i-k]);
      }
    }
    switch(S[i]){
      case 'D':
        dp[i+1][0] = dp[i][0] + 1;
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2];
        break;
      case 'M':
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1] + dp[i][0];
        dp[i+1][2] = dp[i][2];
        break;
      case 'C':
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2] + dp[i][1];
        break;
      default:
        dp[i+1][0] = dp[i][0];
        dp[i+1][1] = dp[i][1];
        dp[i+1][2] = dp[i][2];
        break;
    }
  }

  //mat_print(dp);

  return dp[N][2];
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  IN(N);
  IN(S);
  Ms.resize(N, 0);
  if(S[0]=='M') Ms[0]++;
  dp.resize(N+1, vll(3, 0));
  FOR(i,1,N){
    Ms[i]=Ms[i-1];
    if(S[i]=='M') Ms[i]++;
  }

  ll Q;
  IN(Q);
  REP(q,Q){
    ll k;
    IN(k);
    OUT(search(k));
  }

  return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, (int)vec.size() - 1)std::cout << vec[i] << " ";
	if(!vec.empty())std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int h,w,a[510][510];
std::vector<std::pair<P,P>> vec;
int main(){
	std::cin>>h>>w;
	rep(i,h){
		rep(j,w)std::cin>>a[i][j];
	}
	rep(i,h){
		if(i%2==0){
			rep(j,w-1){
				if(a[i][j]%2){
					vec.push_back({{i,j},{i,j+1}});
					a[i][j]--;
					a[i][j+1]++;
				}
			}
			if(a[i][w-1]%2&&i!=h-1){
				vec.push_back({{i,w-1},{i+1,w-1}});
				a[i][w-1]--;
				a[i+1][w-1]++;
			}
		}
		else{
			for(int j=w-1;j>0;j--){
				if(a[i][j]%2){
					vec.push_back({{i,j},{i,j-1}});
					a[i][j]--;
					a[i][j-1]++;
				}
			}
			if(a[i][0]%2&&i!=h-1){
				vec.push_back({{i,0},{i+1,0}});
				a[i][0]--;
				a[i+1][0]++;
			}
		}
	}
	std::cout<<vec.size()<<std::endl;
	for(auto i:vec)std::cout<<i.first.first+1<<" "<<i.first.second+1<<" "<<i.second.first+1<<" "<<i.second.second+1<<std::endl;
	return 0;
}