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

int main(){
    int N,K;
    cin >> N >> K;
    if(N%K){
        cout << "1";
    }else{
        cout << "0";
    }
}

#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, a[100010];
string S;

signed main(){
    cin >> N >> S;
    REP(st, 4){
        if(st & 1){
            a[0] = 1;
            if(st & 2) a[N - 1] = 1;
            else a[N - 1] = 0;
        }else{
            a[0] = 0;
            if(st & 2) a[N - 1] = 1;
            else a[N - 1] = 0;
        }
        REP(i, N){
            if(a[i] == 0){
                if(S[i] == 'o') a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
                else a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
            }else{
                if(S[i] == 'o') a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
                else a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
            }
        }
        if(st & 1){
            if(a[0] == 0) continue;
            if(st & 2){
                if(a[N - 1] == 0) continue;
            }else{
                if(a[N - 1] == 1) continue;
            }
        }else{
            if(a[0] == 1) continue;
            if(st & 2){
                if(a[N - 1] == 0) continue;
            }else{
                if(a[N - 1] == 1) continue;
            }
        }
        REP(i, N){
            if(a[i] == 0) cout << "S";
            else cout << "W";
        }
        cout << endl;
        return 0;
    }
    PRINT("-1");
    return 0;
}


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

int main(){

    ll n, q;
    string s;
    cin >> n >> q >> s;
    vector<ll> dp(n, 0);
    for(ll i = 0; i < n-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            dp[i+1] = (dp[i] + 1);
        }
        else{
            dp[i+1] = dp[i];
        }
    }

    while(q){
        ll l,r;
        cin >> l >> r;
        cout << dp[r-1] - dp[l-1] << endl;
        q--;
    }

}

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;

    vector<int> cnt;
    cnt.push_back(0);
    int tmp=0;
    for(int i=1;i<n;i++){
        if(s.at(i-1)=='A' && s.at(i)=='C') {
            tmp++;
            cnt.push_back(tmp);
        }else{
            cnt.push_back(tmp);
        }
    }

    for(int i=0;i<q;i++){
        int r,l;
        cin >> r >> l;

        int ans=cnt.at(l-1)-cnt.at(r-1);
        cout << ans << endl;
    }
}


#include<cstdio>
const int mod=1000000007;
long long power(long long a,int k){
    long long ans=1,y=a;
    while(k){
        if(k%2)
            ans=ans*y%mod;
        y=y*y%mod;
        k=k/2;
    }
    return ans;
}
long long fun[1<<17],ans=1;
int main(){
    long long n,m;
    scanf("%lld%lld",&n,&m);
    fun[0]=1;
    for(int i=1;i<1<<17;i++){
        fun[i]=fun[i-1]*i%mod;
    }
    for(int i=2;i*i<=m;i++){
        if(m%i==0){
            long long s=0;
            while (m%i==0) {
                m=m/i;
                s++;
            }
            ans=ans*fun[n+s-1]%mod*power(fun[n-1], mod-2)%mod*power(fun[s], mod-2)%mod;
        }
    }
    if(m>1)
        ans=ans*n%mod;
    printf("%lld\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
const int mod=(1e9)+7;
const int M=(1e7)+9;
int n,m,tot,d[maxn],iv[maxn],ivjc[maxn],jc[maxn];
int dp[40][maxn],ans;
vector<int> g[maxn];
struct Haxi {
	int to[maxn],tot,head[M],nxt[maxn],w[maxn];
	void insert(int x,int y) {
		tot++; nxt[tot]=head[x%M];
		head[x%M]=tot; to[tot]=x; w[tot]=y;
	}
	int find(int x) {
		for (int i=head[x%M];i;i=nxt[i])
			if (to[i]==x) return w[i];
		return 0;
	}
} Map;
int C(int x,int y) {
	if (x<y||y<0) return 0;
	return (ll)jc[x]*ivjc[y]%mod*ivjc[x-y]%mod;
}
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {

	read(n); read(m);
	iv[0]=jc[0]=ivjc[0]=iv[1]=jc[1]=ivjc[1]=1;
	for (int i=2;i<maxn;i++) {
		jc[i]=(ll)jc[i-1]*i%mod;
		iv[i]=(ll)(mod-mod/i)*iv[mod%i]%mod;
		ivjc[i]=(ll)ivjc[i-1]*iv[i]%mod;
	}
	for (int i=1;(ll)i*i<=m;i++)
		if (m%i==0) {
			d[++tot]=i;
			if (m/i!=i) d[++tot]=m/i;
		}
	sort(d+1,d+tot+1);
	int x;
	for (int i=1;i<=tot;i++) {
		Map.insert(d[i],i);
		x=d[i];
		for (int j=1;(ll)j*j<=d[i];j++)
			if (x%j==0) {
				g[Map.find(j)].push_back(i);
				if (x/j!=j) g[Map.find(x/j)].push_back(i);
			}
	}
	int mx=min(n,35);
	dp[0][1]=1;
	for (int i=0;i<mx;i++)
	for (int j=1;j<=tot;j++) if (dp[i][j]) {
		for (int k=0;k<g[j].size();k++) if (g[j][k]!=j) {
			update(dp[i+1][g[j][k]],dp[i][j]);
		}
	}
	for (int i=0;i<=mx;i++) {
		update(ans,(ll)dp[i][tot]*C(n,i)%mod);
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?

  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;
using tTree = __gnu_pbds::tree<ll, __gnu_pbds::null_type, less<ll>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

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

#define FACSIZE 200002

ll invfac[FACSIZE];
ll fac[FACSIZE];

template <class T>
bool chmax(T &, const T &);
template <class T>
bool chmin(T &, const T &);
ll gcd(ll, ll);
ll powLL(ll x, ll y);

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
ll comb(ll, ll);
void make_fact(ll);
void make_invfact(ll);
void fact_init();

char f(ll i, char center, char left, string &s)
{
  char c;

  if (center == 'S')
  {
    if (s[i] == 'o')
    {
      return left;
    }
    else
    {
      if (left == 'S')
        return 'W';
      else
        return 'S';
    }
  }
  else
  {
    if (s[i] == 'o')
    {
      if (left == 'S')
        return 'W';
      else
        return 'S';
    }
    else
      return left;
  }

  return c;
}

int main(void)
{
  ll n;
  cin >> n;
  string s;
  cin >> s;

  vector<string> cand(4);
  cand[0] = "SS";
  cand[1] = "SW";
  cand[2] = "WS";
  cand[3] = "WW";

  for (ll k = 0; k < 4; k++)
  {
    //cout << k << endl;
    string ans = cand[k];
    for (ll i = 1; i < n - 1; i++)
    {
      //cout << i << endl;
      auto c = f(i, ans[i], ans[i - 1], s);
      ans += c;
    }
    auto center = ans[n - 1];
    auto left = ans[n - 2];

    if (f(n - 1, center, left, s) == ans[0])
    {
      if (f(0, ans[0], ans[n - 1], s) == ans[1])
      {
        cout << ans << endl;
        return 0;
      }
    }
  }

  cout << -1 << endl;

  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return mod_mul(t, t);
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = mod_mul(t, t);
    return (k % mod) * (x % mod);
  }
}
ll mod_add(ll a, ll b)
{
  return ((a % mod) + (b % mod)) % mod;
}

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

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void fact_init()
{
  make_fact(FACSIZE - 1);
  make_invfact(FACSIZE);
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

ll comb(ll n, ll r)
{

  return mod_mul(mod_mul(fac[n], invfac[r]), invfac[n - r]);
}
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

ll qp(ll a, ll b)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * mod_mul(ans, a) % mod;
    a = 1LL * mod_mul(a, a) % mod;
  } while (b >>= 1LL);
  return ans;
}
ll qp(ll a, ll b, ll mo)
{
  ll ans = 1LL;
  do
  {
    if (b & 1LL)
      ans = 1LL * (ans % mo) * (a % mo);
    a = 1LL * (a % mo) * (a % mo);
  } while (b >>= 1LL);
  return ans;
}
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
ll powLL(ll x, ll y)
{
  ll ans = 1LL;
  for (ll i = 0LL; i < y; i++)
    ans *= x;
  return ans;
}

#include <iostream>
#include <string>

int main() {
  std::string s, t; std::cin >> s >> t;
  std::cout << (t+s) << std::endl;

  return 0;
}


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

#define int long long int

int32_t main()
{
    string str;
    cin>>str;
    cout<<2018<<str.substr(str.find('7')+1)<<endl;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string ans = "Yes";
    for(int i=0; i<s.size(); i++)
    {
        if(i%2==0 && s.at(i) != 'h') ans = "No";
        else if(i%2==1 && s.at(i) != 'i') ans = "No";
    }
    if(s.length()%2==1) ans = "No";
    cout << ans << '\n';

    return 0;
}


/**
 * @brief 8クイーン問題を扱う
 *
 * @date 2016/02/29
 */

//****************************************
// 必要なヘッダファイルのインクルード
//****************************************

#include <iostream>
#include <vector>

//****************************************
// 型シノニム
//****************************************

using array1D = std::vector<int>;
using array2D = std::vector<array1D>;

//****************************************
// 大域変数の定義
//****************************************

static const int N = 8;                 /**< マスの数 */
static const int FREE = 0, NOFREE = 1;  /**< クイーンが配置できるか否か */

//****************************************
// 構造体の定義
//****************************************

struct board {
    array1D row;    /**< row[x]がNOFREEならば行xは被襲撃位置 */
    array1D col;    /**< col[x]がNOFREEならば列xは被襲撃位置 */
    array1D dpos;   /**< dpos[x]がNOFREEならば左下の列xは被襲撃位置 */
    array1D dneg;   /**< dneg[x]がNOFREEならば右下の列xは被襲撃位置 */

    array2D state;  /**< 盤面の状態  */

    board() : row(N, FREE), col(N, FREE),
              dpos(2 * N - 1, FREE), dneg(2 * N - 1, FREE),
              state(N, array1D(N, FREE)) { }

    /**< 盤面の状態を印刷する */
    void print()
    {
        for (int y = 0; y < N; y++) {
            for (int x = 0; x < N; x++) {
                if (state[y][x] && row[y] != x) { return; }
            }
        }
        for (int y = 0; y < N; y++) {
            for (int x = 0; x < N; x++) {
                std::cout << ((row[y] == x) ? "Q" : ".");
            }
            std::cout << std::endl;
        }
    }

    /**< @brief 座標(x, y)にQueenを配置する */
    void move(int x, int y)
    {
        row[y] = x;
        col[x] = dpos[y + x] = dneg[y - x + N - 1] = NOFREE;
    }

    /**< @brief 座標(x, y)からQueenを取り除く */
    void undo(int x, int y)
    {
        row[y] = col[x] = dpos[y + x] = dneg[y - x + N - 1] = FREE;
    }

    /**< @brief 座標(x, y)にQueenを配置可能かどうか調べる */
    bool canMove(int x, int y)
    {
        return !(col[x] || dpos[y + x] || dneg[y - x + N - 1]);
    }

    /**
     * @brief 再帰的に盤面を探索し、Queenが配置できる場所を探す
     * @param 探索対象のy座標
     */
    void visit(int y)
    {
        // Queenの配置に成功した
        if (y >= N) { print(); return; }

        for (int x = 0; x < N; x++) {
            // 座標(x, y)が配置不可能な場合、continue
            if (!canMove(x, y)) { continue; }

            move(x, y);    // 座標(x, y)にQueenを配置する

            visit(y + 1);  // 次の行へ再帰

            undo(x, y);    // 座標(x, y)からQueenを取り除く
        }
    }

    /**< @brief 座標(x, y)にQueenを初期段階で配置する */
    void initqueen(int x, int y)
    {
        state[y][x] = true;
    }
};

//****************************************
// 関数の定義
//****************************************

int main()
{
    using namespace std;
    board B;

    int k; cin >> k;
    for (int i = 0; i < k; i++) {
        int r, c; cin >> r >> c;
        B.initqueen(c, r);
    }

    B.visit(0);

    return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int x, y, add = 1;
  cin >> x >> y;

  if ((x > 0 && y > 0) || (x < 0 && y < 0)) {
    if (x < y)
      add = 0;
    else
      add = 2;
  } else if (x == 0 && y > 0)
    add = 0;
  else if (x < 0 && y == 0)
    add = 0;

  cout << abs(abs(x) - abs(y)) + add << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> num(N, -1);
    for (int i=0; i<M; i++) {
        int si, ci;
        cin >> si >> ci;
        si--;
        if ((num[si] != -1) && (num[si] != ci)){
            cout << -1;
            return 0;
        }
        num[si] = ci;
    }
    if (N == 1) {
        if (num[0] == -1) {
            cout << 0;
            return 0;
        } else {
            cout << num[0];
            return 0;
        }
    } else {
        for (int j=0; j<N; j++){
            if (j == 0 && num[j] == 0) {
                cout << -1;
                return 0;
            }
            if (j == 0 && (num[j] == -1)){
                num[j] = 1;
            }

            if (num[j] == -1) {
                num[j] = 0;
            }
        }
    }

    // // bool first_val = true;
    // for (int j=0; j<N; j++) {
    //     if ((j == 0) && (num[j] == 0) && (N != 1)){
    //         cout << -1;
    //         return 0;
    //     } else if ((j == 0) && (num[j]==-1)) {
    //         num[j] = 1;
    //     }

    //     // if (num[j] != -1) first_val = false;
    //     // if ((j==0) && (num[j] == -1)) num[j] = 1;
    //     if (num[j] == -1){
    //         num[j] = 0;
    //     }
    // }

    int ans = 0;
    for (int k=0; k<N;k++) {
        ans = ans * 10 + num[k];
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
int n,offset,j,pre,ans;
string s,t;
deque<int> q;
int main()
{
	cin>>n>>s>>t;
	q.push_back(n);j=n-1;
	for (int i=n-1;i>=0;i--)
	{
		pre=j;
		while(j>=0 && (j>i || s[j]!=t[i])) j--;
		if (j<0)
		{
			printf("-1\n");
			return 0;
		}
		if (pre==j)
		{
			while(!q.empty() && q.back()-offset>=i) q.pop_back();
			q.push_back(i+offset);
 		}
 		else
 		{
 			offset++;
 			if (i!=j)
 			{
 				ans=max(ans,(int)q.size());
 				q.push_front(j+offset);
			 }
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
char s[1010101];
char t[1010101];
stack <int> p[26];
int q[1010101],qs=1,qe=0;
int cc[1010101];
int main()
{
	int n,la,now,c=0,ans=0;
	scanf("%d",&n);
	now=n;
	la=n+1;
	scanf("%s",s+1);
	scanf("%s",t+1);
	for(int i=1;i<=n;i++)
		p[s[i]-'a'].push(i);
	for(int i=n;i>=1;i--)
	{
		while(now>i)
			now--;
		while(!p[t[i]-'a'].empty()&&p[t[i]-'a'].top()>now)
			p[t[i]-'a'].pop();
		if(p[t[i]-'a'].empty())
		{
			printf("-1");
			return 0;
		}
		now=p[t[i]-'a'].top();
		if(now==la||now==i)
		{
			la=now;
			continue;
		}
		la=now;
		while(qs<=qe&&q[qs]-cc[qs]-c+1>i)
		{
			ans=max(ans,cc[qs]+c);
			qs++;
		}
		c++;
		q[++qe]=now;
		cc[qe]=1-c;
	}
	for(int i=qs;i<=qe;i++)
		ans=max(ans,cc[i]+c);
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vii         vector<pair<int,int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define endl '\n'
#define int long long int
using namespace std;

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

    string s;cin >> s;
    int n = s.length();
    int k;cin >> k;
    vector<vi> dp(n+1, vi(n+1));
    vector<vi> prev(n+1, vi(n+1));
    for(int change = 0; change <= k; change++){
        for(int len = 1; len <= n; len++){
            for(int start =0; start <= n - len; start++){
                dp[start][len] = max(dp[start+1][len-1], dp[start][len-1]);
                if(s[start] == s[start + len -1]){
                    dp[start][len] = max(1 + (len != 1) + dp[start+1][max(len-2,0LL)], dp[start][len]);
                }else if(change > 0){
                    dp[start][len] = max(1 + (len != 1) + prev[start+ 1][max(len-2,0LL)], dp[start][len]);
//                cout << dp[start][len] <<  " ";
                }
            }
//            cout << endl;
        }
        swap(dp, prev);
    }
    cout << prev[0][n];
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int MOD = pow(10,9)+7;

    int H, W, K; cin>>H>>W>>K;
    if(W==1){
        cout<<1<<endl;
        return 0;
    }

    // 一列における棒の組み合わせをbit全探索で先に作っておく
    // [[],[0],[1],[0,2],...]
    // これの意味は0: 0-1の間, 1: 1-2の間に棒をおく、という感じである。

    vector<vector<int>> combi_list;
    for(int i=0;i< (1<<(W-1));i++){
        bitset<7> s(i);
        vec_int temp_combi;
        for(int i=0;i<W-1;i++){
            if(s[i]==1){
                temp_combi.push_back(i);
            }
        }
        // 作ったものが合法かをチェックする
        int prev=-100;
        int flag = 0;
        for(auto a: temp_combi){
            if(a-prev==1){
                flag=1;
                break;
            }
            prev=a;
        }
        if(flag==1)continue;

        combi_list.push_back(temp_combi);

    }
    /*
    for(auto aa: combi_list){
        cout<<"aa"<<endl;
        for(auto bb: aa){
            cout<<bb<<endl;
        }
    }
    */

    int DP[H+1][W];
    rep(i,H+1){
        rep(j,W){
            DP[i][j]=0;
        }
    }
    DP[0][0] = 1;

    for(int i=1;i<H+1;i++){
        for(int j=0;j<W;j++){
            // 最初にそのまま落ちてくるパターン
            int pattern = 0;
            for(auto aa: combi_list){
                int flag = 1;
                for(auto bb: aa){
                    if(bb==j||bb==j-1){
                        flag=0;
                        break;
                    }
                }
                if(flag==0)continue;
                pattern++;
            }
            DP[i][j] += DP[i-1][j]*pattern;

            // 一個左の棒から落ちてくるパターン
            pattern = 0;
            for(auto aa: combi_list){
                int flag = 0;
                for(auto bb: aa){
                    if(bb==j-1){
                        flag=1;
                        break;
                    }
                }
                if(flag==0)continue;
                pattern++;
            }
            if(j>0){
                DP[i][j] += DP[i-1][j-1]*pattern;
            }
            // 一個右の棒から落ちてくるパターン
            pattern = 0;
            for(auto aa: combi_list){
                int flag = 0;
                for(auto bb: aa){
                    if(bb==j){
                        flag=1;
                        break;
                    }
                }
                if(flag==0)continue;
                pattern++;
            }
            if(j<W-1){
                DP[i][j] += DP[i-1][j+1]*pattern;
            }

            DP[i][j] = DP[i][j]%MOD;
        }
    }

    cout<<DP[H][K-1]<<endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iterator>
#include <fstream>
#include <math.h>

#include <random>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <list>
#include <bitset>
#include <unordered_set>
#include <unordered_map>

#include <random>
#include <ctime>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define FOR(i, from, to) for (int i = from; i < to; i++)
#define ROF(i, from, to) for (int i = from; i > to; i--)

const long double PI = 3.141592653589793238463;
const int INF = 0x3f3f3f3f;
const int INFS = 1000000000;
const ll M = 1000000007;
const ll LLINF = 1000000000000000000;
const double EPS = 1e-8;

#define int long long

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

    int n;
    cin >> n;
    vector<int> x(n);
    map<int, int> mp = {};
    FOR(i, 0, n) {
        cin >> x[i];
        mp[x[i]] = i;
    }
    int l;
    cin >> l;
    vector<vector<int> > st(n, vector<int>(21));
    FOR(i, 0, n)
        st[i][0] = mp[*(--upper_bound(x.begin(), x.end(), x[i] + l))];
    FOR(j, 1, 21) {
        FOR(i, 0, n) {
            st[i][j] = st[st[i][j - 1]][j - 1];
            // cout << i << ' ' << j << ' ' << st[i][j] << endl;
        }
    }
    int m, a, b, cr, ans;
    cin >> m;
    while (m--) {
        cin >> a >> b;
        if (a > b)
            swap(a, b);
        --a; --b;
        ans = 0;
        cr = a;
        ROF(j, 20, -1) {
            if (st[cr][j] < b) {
                cr = st[cr][j];
                ans += (1 << j);
            }
        }
        ++ans;
        cout << ans << "\n";
    }

    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

#define LOG_MAX 30
// 1つ先が無い(木の根など)場合、値を負かn以上とする
template <typename T>
class Doubling {
    const size_t n;
    vector<vector<T>> next;
public:
    Doubling() {}
    Doubling(vector<T> first_row)
    : n(first_row.size()),
      next(LOG_MAX, vector<T>(n)) {
        copy(first_row.begin(), first_row.end(), next[0].begin());
        for (size_t i=1; i<LOG_MAX; i++) {
            for (size_t j=0; j<n; j++) {
                next[i][j] = (
                    (0 <= next[i-1][j] && (size_t)next[i-1][j] < n)
                    ? next[i-1][(size_t)next[i-1][j]]
                    : next[i-1][j]
                );
            }
        }
    }

    T query(T i, int step=1) {
        for (int k=LOG_MAX-1; k>=0; k--) {
            if ((step >> k) & 1) i = next[(size_t)k][(size_t)i];
            if (i < 0 || n <= (size_t)i) break;
        }
        return i;
    }
};

int main() {
    int n, q;
    cin >> n;
    long x[n], l;
    for (auto &xi:x) cin >> xi;
    cin >> l >> q;
    vector<int> first_row(n);
    for (int i=0; i<n; i++) {
        int ub = upper_bound(x+i, x+n, x[i] + l) - x;
        first_row[i] = ub - 1;
    }
    Doubling<int> db(first_row);
    for (int i=0, a, b; i<q; i++) {
        cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        int l=0, r=n-1;
        while (r - l > 1) {
            int m = (l + r + 1) / 2,
                dest = db.query(a, m);
            if (b > dest) l = m;
            else r = m;
        }
        cout << r << '\n';
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <tuple>
#include <bitset>
#include <random>
#define REP(i,n) for(int i=0;i<n;i++)
#define INF 1000000007
using namespace std;
using pii=pair<int,int>;

int main() {
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  int dx=tx-sx,dy=ty-sy;
  string ans="";
  string right(dx,'R'),left(dx,'L'),up(dy,'U'),down(dy,'D');
  ans=ans+up+right+down+left+'L'+up+'U'+'R'+right+'D'+'R'+down+'D'+'L'+left+'U';
  cout<<ans<<endl;

  return 0;
}

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#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 <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  rep(i,c-a)cout<<"R";
  rep(i,d-b)cout<<"U";
  rep(i,c-a)cout<<"L";
  rep(i,d-b)cout<<"D";
  cout<<"L";
  rep(i,d-b+1)cout<<"U";
  rep(i,c-a+1)cout<<"R";
  cout<<"D"<<"R";
  rep(i,d-b+1)cout<<"D";
  rep(i,c-a+1)cout<<"L";
  cout<<"U"<<endl;
}


#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	bool ok=(a[0]==0);
	rep(i,n-1) if(a[i+1]-a[i]>=2) ok=false;
	if(!ok){
		puts("-1");
		return 0;
	}

	lint ans=0;
	int pre=0;
	for(int i=1;i<=n;i++){
		if(i==n || a[i-1]+1!=a[i]){
			ans+=a[i-1];
			pre=i;
		}
	}
	printf("%lld\n",ans);

	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

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

int n, a[3], p;

int main() {
	cin >> n;
	for_(i,0,n) cin >> a[i];

	p = gcd(a[0], a[1]);
	if (n == 3) p = gcd(a[2], p);

	vector< int > c;
	for_(i,1,0 || i*i <= p) {
		if (p % i == 0) {
			c.push_back(i);
			if (p/i != i) c.push_back(p/i);
		}
	}

	sort(c.begin(), c.end());

	for_(i,0,(int)c.size()) {
		bool ok = 1;
		for_(j,0,n) ok &= (a[j] % c[i] == 0);
		if (ok) cout << c[i] << endl;
	}

	return 0;
}


//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

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

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long

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

const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, x, now;

struct e {
   int l, r, b;
}a[N];

bool cmp (e a, e b) {
   return (a.r * (x - a.b) + a.l * a.b) > (b.r * (x - b.b) + b.l * b.b);
}

inline bool check (int h) {
   now = h;
   int ans = 0;
   int res = -inf;
   bool ok = 0;
   for (int i = 1; i <= n; i ++) {
      if (h >= x) {
         h -= x;
         ans += (x - a[i].b) * a[i].r;
      }
      else {
         int sum = 0;
         ok = 1;
         for (int j = i; j <= n; j ++) {
            sum -= a[j].l * a[j].b;
         }
         for (int j = i; j <= n; j ++) {
            sum += a[j].l * a[j].b;
            res = max (res, ans + sum + (h - a[j].b) * a[j].l);
            res = max (res, ans + sum + (h - a[j].b) * a[j].r);
            sum -= a[j].l * a[j].b;
         }
         for (int j = 1; j < i; j ++) {
            int in = ans - (x - a[j].b) * a[j].r + sum + a[i].l * a[i].b;
            if (h < a[j].b) in += (h - a[j].b) * a[j].l;
            else in += (h - a[j].b) * a[j].r;
            in += (x - a[i].b) * a[i].r;
            res = max (res, in);
         }
         break;
      }
   }
   if (!ok) res = ans;
   return (res >= 0);
}

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}

inline void Solve () {
   cin >> n >> x;
   for (int i = 1; i <= n; i ++) cin >> a[i].b >> a[i].l >> a[i].r;
   sort (a + 1, a + n + 1, &cmp);
   int l = 0, r = inf, pos = -1;
   while (l <= r) {
      int mid = l + r >> 1;
      if (check (mid)) r = mid - 1, pos = mid;
      else l = mid + 1;
   }
   cout << pos;
}

signed main () {
   #ifdef QWERTY
      freopen("input", "r", stdin);
   #endif
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
   boost ();
   int tt = 1;
   //cin >> tt;
   while (tt --) {
      Solve ();
   }
   return 0;
}

#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
	int n;
	ll x;cin >> n >> x;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	if(a[0]>x) {
		ans += a[0]-x;
		a[0] = x;
	}
	rep(i,n-1){
		//cout << " " << ans << endl;
		if(a[i]+a[i+1]>x){
			ans += a[i+1] - (x-a[i]);
			a[i+1] = x-a[i];
		}
	}
	//rep(i,n) cout << a[i] << endl;
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include<math.h>
#include <algorithm>
using namespace std;
int main()
{
int a;
long long k;
cin>>a;
k=a+a*a+a*a*a;
cout<<k;
}

# include<iostream>
# include<math.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a;
    b=pow(a,1)+pow(a,2)+pow(a,3);
    cout<<b<<"\n";

}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    int n,a[9]={111,222,333,444,555,666,777,888,999};
    cin>>n;
    for(int i=0;i<9;i++){
    	if(n<=a[i]) {
	cout<<a[i]<<endl;
	return 0;
	}

    }

   return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

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

  int s=0;
  int t=0;
  for (auto c:x) {
    if (c == 'S') {
      s++;
    } else {
      if (s > 0) s--;
      else t++;
    }
  }
  cout << t+s << endl;

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
typedef pair<int, int> i_i;

bool dfs(vector<vector<int> > &g);

int sx, sy, gx, gy;
int w, h;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main()
{

    while (cin >> w >> h, (w|h) ) {
        w++;
        h++;
        vector<vector<int> > graph(w, vector<int>(h, 0));
        cin >> sx >> sy >> gx >> gy;
        int blocks;
        cin >> blocks;
        loop(i, blocks){
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            if (d) {
                for (int j = x; j < x+2; j++) {
                    for (int k = y; k < y+4; k++) {
                        graph[j][k] = c;
                    }
                }
            } else {
                for (int j = x; j < x+4; j++) {
                    for (int k = y; k < y+2; k++) {
                        graph[j][k] = c;
                    }
                }
            }
        }
        cout << ((dfs(graph))?"OK":"NG") << endl;
    }
    return 0;
}

bool dfs(vector<vector<int> > &g)
{
    int cl = g[sx][sy];
    vector<vector<bool> > check(w, vector<bool>(h, false));
    queue<i_i > q;
    q.push(mp(sx,sy));
    while(!q.empty()){
        int x = q.front().first, y = q.front().second;
        q.pop();
        if(x == gx && y == gy){
            return true;
        }
        if(check[x][y]){
            continue;
        } else {
            check[x][y] = true;
        }

        loop(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 < nx && nx < w && 0 < ny && ny < h){
                if (g[nx][ny] == cl){
                    q.push(mp(nx,ny));
                }
            }
        }

    }
    return false;
}

#include <bits/stdc++.h>
#define ll long long
#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;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

bool b[501];
int main(){
	int n, m, t1,t2;
	while(1){
		stack<int> s[501];
		scanf("%d%d", &n, &m);
		if(!n)break;
		fill(b, b+501, false);
		rep(i,m){
			scanf("%d%d", &t1, &t2);
			s[t1].push(t2);
			s[t2].push(t1);
		}
		while(!s[1].empty()){
			t1 = s[1].top();s[1].pop();
			b[t1] = 1;
			while(!s[t1].empty()){
				t2 = s[t1].top();s[t1].pop();
				b[t2] = true;
			}
		}
		int ans = 0;
		rrep(i,n)if(b[i]&&i!=1)ans++;
		printf("%d\n", ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#include <algorithm>
#include <complex>

using namespace std;
typedef long long ll;
typedef complex<long double> point;
const ll N = 2e5+5,mod=1e9+7,inf=1e9+5;
long double pi=3.14159265359;
ll a[N],b[N],inv[N],fact[N];
int n,c;
ll fp(int base,int exp){
    if(exp==0)return 1;
    ll ans=fp(base,exp/2);
    ans=(ans*ans)%mod;
    if(exp%2)
        ans=(ans*base)%mod;
    return ans;
}
ll ncr(int n,int r){
return ((fact[n]*inv[n-r])%mod*inv[r])%mod;
}
int main()
{
    iostream::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
     int n,m,mm;
     inv[0]=fact[0]=1;
     for(int i=1;i<2e5;i++){
        fact[i]=(i*fact[i-1])%mod;
        inv[i]=fp(fact[i],mod-2);
     }

     cin>>n>>m;
     mm=m;
     ll ans=1;
     for(int i=2;i*i<=m;i++){
            int c=0;
        while(m%i==0){
            m/=i;
     c++;
        }

        ans*=ncr(n+c-1,c);
        ans%=mod;
     }
     if(m>1){
        ans*=n;

        ans%=mod;
     }
     cout<<ans;

    return 0;
}

#include <cstdio>
#include <iostream>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#define inver(a) power(a, mod - 2)

using namespace std;

inline char nc()
{
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
	x=0; int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f;
}

typedef long long ll;

const int mod = 998244353;
const int MAXK = 2000 + 5;
const int MAXN = 2000 + 5;
int K, N;

inline int add(int x) {return x >= mod ? x - mod : x;}
ll power(ll x, ll y)
{
	ll re = 1;
	while(y)
	{
		if(y & 1) re = re * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return re;
}

const int maxn = MAXN + MAXK;
int fac[maxn];
int inv[maxn];
void init_binom(int n)
{
	fac[0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		fac[i] = (ll)fac[i - 1] * i % mod;
	}
	inv[n] = inver(fac[n]);
	for(int i = n; i >= 1; --i)
	{
		inv[i - 1] = (ll)inv[i] * i % mod;
	}
}
int binom(int x, int y)
{
	if(x < y) return 0;
	return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int F(int x, int y)
{
	if(x == 0 && y == 0) return 1;
	return binom(x + y - 1, x);
}

int sol(int k, int n, int m)
{
	int an = 0;
	for(int j = 0, p = 1; j <= m && j <= n; ++j)
	{
		an = (an + (ll)binom(m, j) * F(n - j, k - 2 * m + j) % mod * p) % mod;
		p = add(p << 1);
	}
	return an;
}

int main()
{
	read(K), read(N);
	init_binom(K + N);
	for(int i = 2; i <= 2 * K; ++i)
	{
		int m = 0;
		for(int a = 1, b = i - 1; a < b; ++a, --b)
		{
			if(b <= K) ++m;
		}
		if(i & 1) printf("%d\n", sol(K, N, m));
		else printf("%d\n", add(sol(K - 1, N, m) + sol(K - 1, N - 1, m)));
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  vector<ll> csum{0};
  partial_sum(va.begin(), va.end(), back_inserter(csum));
  map<ll, ll> cnts;
  for (auto s : csum) {
    cnts[s % m]++;
  }

  ll ans = 0;
  for (auto &p : cnts) {
    ans += (p.second * (p.second - 1)) / 2;
  }

  cout << ans << '\n';
  return 0;
}

#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
const double PI = 3.14159265358979323846264338327950288;

ll A[100010];
ll sum[100010];
int main()
{
	int N;
	ll M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> A[i];
	ll ans = 0;
	map<ll, ll> mp;
	for (int i = 0; i < N; i++) {
		sum[i + 1] = (sum[i] + A[i]) % M;
	}
	sort(sum, sum + N + 1);
	ll cnt = 1;
	for (int i = 0; i < N; i++) {
		if (sum[i] == sum[i + 1]) {
			cnt++;
		}
		else {
			ans += cnt * (cnt - 1) / 2;
			cnt = 1;
		}
	}
	ans += cnt * (cnt - 1) / 2;
	cout << ans << endl;
}


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

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

  double a=3.14;

  cout << 2*R*a << endl;
}

#include <bits/stdc++.h>
using namespace std;
//型名省略
typedef long long ll;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
//マクロ
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define rep2(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define all(A) A.begin(), A.end()
//正誤判定
void Yes(bool ans){cout << (ans? "Yes" : "No") << endl;}
void YES(bool ans){cout << (ans? "YES" : "NO") << endl;}

//main関数
int main() {
    double PI = 3.1415926536;
    ll r; cin >> r;
    cout << 2 * r * PI << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#include<stdlib.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
vector<long long> Prime;
void SieveOfEratosthenes(long long e) //setup vector<long long>Prime(~x)
{
	bool *x=new bool[e];
	for (long long i = 0; i <= e; i++)x[i] = false;
	for (long long i = 2; i <= e; i++)
	{
		if (x[i]);
		else
		{
			Prime.push_back(i);
			for (long long l = i; l <= e; l += i)x[l] = true;
		}
	}
	return;
}
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}
/*
(char)'1' - (int)48 = (int)1;
???1111181
*/
////////////////////////////////////////////////////

int main()
{
	vector<pair<int, int > > ans;
	for (int i = 1; i <= 150; i++)
	{
		for (int l = i+1; l <= 150; l++)
		{
			pair<int, int> now;
			now.first = i*i + l*l;
			now.second = i;
			ans.push_back(now);
		}
	}
	bool enn = true;
	while (enn)
	{
		enn = false;
		for (int i = 1; i < ans.size(); i++)
		{
			if (ans[i].first == ans[i - 1].first&&ans[i].second < ans[i-1].second)
			{
				swap(ans[i], ans[i - 1]);
				enn = true;
			}
			if (ans[i].first < ans[i - 1].first)
			{
				swap(ans[i], ans[i - 1]);
				enn = true;
			}
		}
	}

	int h,w;
	while (cin>>h>>w&&h)
	{
		int t = h*h + w*w;

		rep(i, ans.size())
		{
			if (ans[i].first==t&&h<ans[i].second)
			{
				cout << ans[i].second << " " << sqrt(ans[i].first - (ans[i].second*ans[i].second)) << endl;
				break;
			}
			else if (ans[i].first > t)
			{
				cout << ans[i].second << " " << sqrt(ans[i].first - (ans[i].second*ans[i].second)) << endl;
				break;

			}
		}

	}

}

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

char s[1000010];
char t[1000010];

int n;

queue<int> q;

int main() {
	scanf("%d", &n); scanf("%s", s); scanf("%s", t);
	if(strcmp(s, t) == 0) { puts("0"); return 0; }
	int k = n - 1;
	int ans = 0;
	int last = -1;
	for(int i = n - 1; i >= 0; --i) {
		k = min(k, i);
		while(k >= 0 && s[k] != t[i]) --k;
		if(k < 0) { puts("-1"); return 0; }
		if(k==last) continue; last=k;
		while(q.size() && i < q.front() - (int)q.size() + 1) q.pop();
		q.push(k);
		ans = max(ans, (int)q.size());
	}
	printf("%d\n",ans);
	return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

string S;

signed main(){
    cin >> S;
    rep(i, 8) S.pop_back();
    cout << S << endl;
}

#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    std::string s;
    std::cin >> s;

    std::cout << s.substr(0, s.length() - 8) << std::endl;
}


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

int main(void)
{
    vector<ll> cost(5);
    ll N;
    cin >> N;
    for (int i = 0; i < 5; i++)
    {
        cin >> cost[i];
    }

    ll result = (ll) ceil((double) N / *min_element(cost.begin(), cost.end())) + 4;
    cout << result << endl;

    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int mod = 1000000007;
  long long sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    sum %= mod;
  }

  long ans = 0;

  for(int j = 0; j < n; j++){
    sum -= a[j];
    if(sum < 0) sum += mod;
    ans += a[j] * sum;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10);
	putchar(x%10+48);
}
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;

		b>>=1;
	}
	return ans%p;
}

int main()
{
	int a=rd,b=rd,k=rd;
	fo(i,1,k)
	{
		if(i%2==1)
		{
		if(a%2==1)a--;a/=2,b+=a;}
		else{if(b%2==1)b--;b/=2,a+=b;}
	}
	printf("%d %d\n",a,b);
	return 0;
}

#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(string &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll a,b,k ;
	cin >> a >> b >> k ;
	for(int i=0;i<k;i++){
		if(i&1){
			b -= (b&1) ;
			a += b/2 ;
			b /= 2 ;
		}else{
			a -= (a&1) ;
			b += a/2 ;
			a /= 2 ;
		}
	}
	cout << a << " " << b << endl ;
}


#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  vector<bool> used(N, false);
  for (ll i = N - 1; i >= 0; --i) {
    if (used.at(i)) {
      continue;
    }
    used.at(i) = true;
    ll pow2 = 1;
    while (pow2 <= A.at(i)) {
      pow2 *= 2;
    }
    ll need = pow2 - A.at(i);
    ll l = lower_bound(A.begin(), A.end(), need) - A.begin() - 1;
    ll r = upper_bound(A.begin(), A.end(), need) - A.begin();
    r = min(r, i);
    // cout << "nned" << need << endl;
    // cout << l << ' ' << r << endl;
    if (l == r) {
      continue;
    }
    while (l + 1 != r) {
      ll m = (l + r) / 2;
      if (used.at(m)) {
        l = m;
      }
      else {
        r = m;
      }
    }
    // cout << "l" << l << "r" << r << endl;
    if (r == N) {
      continue;
    }
    if (A.at(r) != need) {
      continue;
    }
    if (used.at(r)) {
      continue;
    }
    used.at(r) = true;
    ans += 1;
    // for (ll j = l; j < r; ++j) {
    //   if (!used.at(j)) {
    //     used.at(j) = true;
    //     ans += 1;
    //     break;
    //   }
    // }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,ans=0;cin>>n;
    multiset<ll> st;
    for(ll i=0,x;i<n;i++)cin>>x,st.insert(x);
    while(!st.empty()){
        auto itr= st.end();
        itr--;
        ll val = *itr;
        st.erase(itr);

        ll p=0;
        while(val >= (1ll<<p) )p++;

        ll req = (1ll<<p) - val;

        itr=st.find(req);
        if(itr==st.end())continue;

        ans++;
        st.erase(itr);
    }

    cout<<ans;
}


#include <bits/stdc++.h>
#define re register
#define SIZE 305
#define INF 0x7f7f7f
using namespace std;
int n;
int a[SIZE];
int cnt[5];
double dp[SIZE*3][SIZE*2][SIZE],ans=0;
inline double dfs(int i,int j,int k)
{
	if(dp[i][j][k]!=-1)
		return dp[i][j][k];
	dp[i][j][k]=0;
	double x=i*1.0,y=j*1.0,z=k*1.0;
	double m=x+y+z;
	if(i+j+k<n)
		dp[i][j][k]+=dfs(i+1,j,k)*(x+1)/(m+1);
	if(i-1>=0)
		dp[i][j][k]+=dfs(i-1,j+1,k)*(y+1)/m;
	if(j-1>=0)
		dp[i][j][k]+=dfs(i,j-1,k+1)*(z+1)/m;
	return dp[i][j][k];
}
int main()
{
	scanf("%d",&n);
	for(re int i=1;i<=n;++i)
		scanf("%d",&a[i]),++cnt[a[i]];
	for(re int i=0;i<=cnt[3]+cnt[2]+cnt[1]+1;++i)
		for(re int j=0;j<=cnt[3]+cnt[2]+1;++j)
			for(re int k=0;k<=cnt[3]+1;++k)
				if(i>cnt[3]+cnt[2]+cnt[1] || j>cnt[3]+cnt[2] || k>cnt[3])
					dp[i][j][k]=0;
				else
					dp[i][j][k]=-1;
	dp[cnt[1]][cnt[2]][cnt[3]]=1;
	for(re int i=0;i<=cnt[3]+cnt[2]+cnt[1];++i)
		for(re int j=0;j<=cnt[3]+cnt[2];++j)
			for(re int k=0;k<=cnt[3];++k)
			{
				if(i==0 && j==0 && k==0)
					continue;
				ans+=(double) (dfs(i,j,k)*n)/(double) (i+j+k);
			}
	printf("%.10lf\n",ans);
	return 0;
}

//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

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

int n;
int vis[302][302][302];
double cache[302][302][302];
double dp(int one,int two,int three)
{
    int tot=one+two+three;
    if(!tot)
        return 0;
    if(one<0 || two<0 || three<0)
        return -1;
    if(vis[one][two][three])
        return cache[one][two][three];

    double ans=0;
    double x=n*1.0/(n-(n-tot)*1.0);
    ans=x*((n-tot)*1.0/n + (one*1.0/n)*(1+dp(one-1,two,three))
                +(two*1.0/n)*(1+dp(one+1,two-1,three))
                    +(three*1.0/n)*(1+dp(one,two+1,three-1)));
    vis[one][two][three]=1;
    return cache[one][two][three]=ans;
}
int32_t main()
{
    IOS;
    cin>>n;
    int freq[4]={};
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        freq[a]++;
    }
    cout<<fixed<<setprecision(12);
    cout<<dp(freq[1],freq[2],freq[3]);
}


#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    reverse(A.begin(), A.end());
    vector<ll> dp(N,INF);
    for(int i = 0; i < N; i++){
        auto iter = upper_bound(dp.begin(), dp.end(), A[i]);
        ll idx = iter - dp.begin();
        dp[idx] = A[i];
    }
    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
}

//
// Created on 2020/08/10.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
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; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;

int main() {

    int n;
    cin>>n;
    vector<int>L;
    int init;
    cin>>init;
    L.push_back({init});
    for (int i = 1; i < n; ++i) {
        int a;
        cin>>a;
        int ok = L.size() - 1;
        int ng = -1;
        int mid = (ok + ng) / 2;
        while(1 < abs(ok - ng)){
            if(L[mid] < a){
                ok = mid;
            }else{
                ng = mid;
            }
            mid = (ok + ng) / 2;
        }
        if(L[ok] < a){
            L[ok] = a;
        }else if(L[ok] >= a){
            L.push_back(a);
        }}
    cout<<L.size()<<endl;
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;

int d,dep,m;
ll ans;
int c[20],c0[20];
ll f[20],a[20];

void dfs(int k,ll w,ll s){
	if (k==m){
		ans+=1ll*(w==d)*s;
		return;
	}
	if (abs(w-1ll*d)>a[k]*20) return;
	int i,cnt;
	for (i=0;i<20;i++){
		if (!k) cnt=c0[i];
		else cnt=c[i];
		if (!a[k]) cnt=i<10;
		if (!cnt) continue;
		dfs(k+1,w+a[k]*1ll*(i-10),s*1ll*cnt);
	}
}

void solve(int n){
	m=0;
	int i;
	for (i=0;i<n;i++){
		if (i>n-i-1) break;
		a[m++]=f[n-i-1]-f[i];
	}
	dfs(0,0,1);
}

int main(){
	int i,j;
	f[0]=1; for (i=1;i<=18;i++) f[i]=f[i-1]*10ll;
	for (i=0;i<=9;i++)
		for (j=0;j<=9;j++) c[i-j+10]++;
	for (i=0;i<=9;i++)
		for (j=1;j<=9;j++) c0[i-j+10]++;
	scanf("%d",&d);
	for (dep=1;dep<=19;dep++) solve(dep);
	printf("%lld\n",ans);
	return 0;
}

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long p10[20];
long long calc(int a,int b,int c,long long d){
	if(b>c){
		if(d==0)return 1;
		else return 0;
	}
	if(b==c){
		if(d==0)return 10;
		else return 0;
	}
	if(ABS(d)>=p10[c+1])return 0;
	long long ret=0;
	for(int i=-10;i<10;i++){
		int ks=10-ABS(i);
		if(b==0&&i>=0)ks--;
		ret+=calc(a,b+1,c-1,d-i*(p10[c]-p10[b]))*ks;
	}
	return ret;
}
int main(){
	p10[0]=1;
	for(int i=1;i<20;i++)p10[i]=p10[i-1]*10;
	int a;scanf("%d",&a);
	long long ret=0;
	for(int i=2;i<=18;i++){
		ret+=calc(i,0,i-1,a);
	//	printf("%d\n",ret);
	}
	printf("%lld\n",ret);
}


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

int main(){
  ll n;
  cin>>n;
  ll mi=ll(1e18);
  for(int i=0;i<5;i++){
    ll a;
    cin>>a;
    mi=min(mi,a);
  }
  ll x=n/mi;
  if(n%mi==0) x--;
  cout<<5+x<<endl;
}

#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;

int main(){
  ll n,a,b,c,d,e;
  cin>>n>>a>>b>>c>>d>>e;
  ll m=min(a,min(b,min(c,min(d,e))));

  cout<<(n-1)/m+5;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

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;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;

int N,M;
vector<int>G[100005];
vector<int>G2[300005];
bool used[100005];
vector<int>xx;
void dfs(int x){
	used[x]=true;
	for(int i:G[x])if(!used[i]){
		dfs(i);
	}
	xx.push_back(x);
}
int bfs(){
	queue
que;
	int dis[300005];
	fill(dis,dis+300000,inf);
	dis[0]=0;que.push({0,0});
	while(!que.empty()){
		P p=que.front();que.pop();
		if(dis[p.second]>N>>M;
	rep(i,M){
		int a,b,c;cin>>a>>b>>c;a--;b--;c--;
		edge[c].push_back({a,b});
	}
	int now=100000;
	rep(i,1000000){
		for(P j:edge[i]){
			G[j.first].push_back(j.second);
			G[j.second].push_back(j.first);
		}
		for(P j:edge[i]){
			if(!used[j.first]){
				dfs(j.first);
				for(int k:xx){
					G2[now].push_back(k);
					G2[k].push_back(now);
				}
				now++;
				xx.clear();
			}
			if(!used[j.second]){
				dfs(j.second);
				for(int k:xx){
					G2[now].push_back(k);
					G2[k].push_back(now);
				}
				now++;
				xx.clear();
			}
		}
		for(P j:edge[i]){
			used[j.first]=false;
			used[j.second]=false;
			G[j.first].clear();
			G[j.second].clear();
		}
	}
	int ans=bfs();
	cout<<(ans==inf?-1:ans/2)<<endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  vector<int> arr(N);
  for(int i=0;i<N;i++){
    int num=0;
    while(vec.at(i)%2==0){
      vec.at(i) = vec.at(i)/2;
      num+=1;
    }
    arr.at(i)=num;
  }
  int ans=arr.at(0);
  for(int i=1;i<N;i++){
    ans = min(ans, arr.at(i));
  }
  cout<<ans<<endl;
}

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

int main()
{
	int N;
	cin >> N;
	int num[N];
	int i = 0, count = 0;
	while (i < N)
		cin >> num[i++];
	int flag=0;
	while (true)
	{
		i = 0;
		while (i < N)
		{
			if (num[i] % 2 != 0)
				flag = 1;
			num[i] /= 2;
			i++;
		}
		if (flag == 1)
			break;
		count++;
	}
	cout << count << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const int maxn = 1e5+5;
vector<int>tar;
ll v[maxn];
ll b[65];
void ins(ll x) {
    for (int i = 0 ; i < tar.size() ; i++) {
        if (x & (1LL<<(tar[i]))) {
            if (b[i]) {
                x ^= b[i];
            }
            else {
                b[i] = x;
                break;
            }
        }
    }
}
void go() {
    int n;
    cin >> n;
    ll sum = 0;
    f1(n) {
        cin >> v[i];
        sum ^= v[i];
    }
    for (int i = 60 ; i >= 0 ; i--) {
        if (sum & (1LL<<i)) {

        }
        else {
            tar.pb(i);
        }
    }
    f1(n) {
        ins(v[i]);
    }
    ll ans = 0;
    for (int i = 0 ; i < tar.size() ; i++) {
        if (b[i] && !(ans & (1LL<<tar[i]))) {
            ans ^= b[i];
        }
    }
    cout << ans + (sum ^ ans) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n;
	vector<long long> a(n), base;
	for(auto & e : a) cin >> e;
	long long all = 0;
	for(auto & e : a) all ^= e;
	for(auto & e : a) e &= ~all;
	for(auto e : a){
		for(auto b : base) e = min(e, e ^ b);
		if(e){
			base.push_back(e);
		}
	}
      sort(base.rbegin(), base.rend());
	long long up = 0;
	for(auto b : base) up = max(up, up ^ b);
	cout << all + 2 * up << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,M;
  cin>>N>>M;
  VI A(N-1+M),B(N-1+M);
  rep(i,N-1+M) cin>>A[i]>>B[i];
  VVI X(N,VI(0));
  VI I(N);
  rep(i,N-1+M){
    X[A[i]-1].pb(B[i]-1);
    I[B[i]-1]++;
  }
  int S=0;
  rep(i,N) if(I[i]==0) S=i;
  VI T(0);
  T.pb(S);
  queue<int> Q;
  Q.push(S);
  VI F(N);
  F[S]++;
  while(!Q.empty()){
    int now=Q.front();
    Q.pop();
    rep(i,X[now].size()){
      int nxt=X[now][i];
      if(!F[nxt]){
        I[nxt]--;
        if(!I[nxt]){
          Q.push(nxt);
          T.pb(nxt);
        }
      }
    }
  }
  VI Z(N);
  rep(i,N){
    int now=T[i];
    if(!Z[now]) Z[now]=1;
    rep(j,X[now].size()){
      int nxt=X[now][j];
      Z[nxt]=max(Z[nxt],Z[now]+1);
    }
  }
  VI ans(N);
  rep(i,N){
    rep(j,X[i].size()){
      int nxt=X[i][j];
      if(Z[i]+1==Z[nxt]) ans[nxt]=i+1;
    }
  }
  ans[S]=0;
  rep(i,N) cout<<ans[i]<<endl;
}

#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>

typedef long double ld;
typedef long long ll;

using namespace std;

int n, m;

#define MAXN (1 << 17)
#define INF (1 << 30)

vector<int> a[MAXN];
vector<int> rev[MAXN];
int p[MAXN];
int v[MAXN];
int f[MAXN];

int curt;

void dfs(int cur) {
	v[cur] = 1;
	curt++;
	for (int i = 0; i < a[cur].size(); i++) {
		int nnext = a[cur][i];
		if (!v[nnext]) {
			dfs(nnext);
		}
	}
	curt++;
	f[cur] = curt;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n + m - 1; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		a[t1].push_back(t2);
		rev[t2].push_back(t1);
		p[t2] = t1;
	}

	int s = 1;
	while (p[s]) {
		s = p[s];
	}
	dfs(s);
/*	for (int i = 1; i <= n; i++) {
		cerr << f[i] << " ";
	}
	cerr << endl;
*/	for (int i = 1; i <= n; i++) {
		int best = INF;
		int bestind = 0;
		for (int j = 0; j < rev[i].size(); j++) {
			int nnext = rev[i][j];
			if (f[nnext] < best) {
				best = f[nnext];
				bestind = nnext;
			}
		}
		cout << bestind << endl;
	}

	return 0;
}


/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __
.' ____ \ [  |      (_)                [  |
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |,
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/

*/
// clang-format off
/* }}} */

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
// clang-format on
/* }}} */

signed main() {
  string s;
  cin >> s;
  int j, o, i; j = o = i = 0;
  int res = 0;
  for (char c : s) {
    // cerr << j << " " << o << " " << i << endl;
    if (c == 'J') {
      if (o == 0 && i == 0) {
        j++;
      } else {
        if (j > 0 && o > 0 && i > 0) {
          if (j >= o && i >= o) {
            chmax(res, o);
          }
        }
        j = o = i = 0;
        j++;
      }
    } else if (c == 'O') {
      if (j > 0 && i == 0) {
        o++;
      } else {
        if (j > 0 && o > 0 && i > 0) {
          if (j >= o && i >= o) {
            chmax(res, o);
          }
        }
        j = o = i = 0;
      }
    } else if (c == 'I') {
      if (j > 0 && o > 0) {
        i++;
      } else {
        if (j > 0 && o > 0 && i > 0) {
          if (j >= o && i >= o) {
            chmax(res, o);
          }
        }
        j = o = i = 0;
      }
    }
  }

  if (j > 0 && o > 0 && i > 0) {
    if (j >= o && i >= o) {
      chmax(res, o);
    }
  }
  print(res);

  return 0;
}

//#define USE_CPP11
// #define USE_PRINTF

#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <complex>
#include <memory>
#include <sstream>

#ifdef USE_CPP11
#include <unordered_map>
#include <unordered_set>
#include <functional>
#endif

#define PRINT(obj) cout << obj << endl
#define REP(i, n) for(int (i) = 0; (i) < (n); i++)
#define SPACE " "

typedef long long ll;

const int INF = 1e9 + 10;

using namespace std;

namespace Scanner {
#ifdef USE_PRINTF
  int    nextInt()    { int    d; scanf("%d" , &d); return d; }
  float  nextFloat()  { float  f; scanf("%f" , &f); return f; }
  double nextDouble() { double f; scanf("%lf", &f); return f; }
  string nextString() { string s; scanf("%s" , &s); return s; }
  ll     nextll()     { ll     l; scanf("%ll", &l); return l; }
#else
  int    nextInt()    { int    d; cin >> d; return d; }
  float  nextFloat()  { float  f; cin >> f; return f; }
  double nextDouble() { double f; cin >> f; return f; }
  string nextString() { string s; cin >> s; return s; }
  ll     nextll()     { ll     l; cin >> l; return l; }
#endif

  string getLine() {
    string input;
    getline(cin, input);
    return input;
  }
};

namespace myLibrary {
  vector<string> split(const string& str, char delim) {
    vector<string> ret;
    size_t current = 0, found;
    while ((found = str.find_first_of(delim, current)) != string::npos) {
      ret.push_back(string(str, current, found - current));
      current = found + 1;
    }
    ret.push_back(string(str, current, str.size() - current));
    return ret;
  }

#ifdef USE_CPP11
  ///
  /// higher-order functional
  /// This is something like map in haskell, python, etc.
  /// Sample usage:
  ///   vector<int> a = {1, 2, 3, 4, 5};
  ///   vector<int> b = myLibrary::_Map<int, int>(a, [](int n){
  ///     return n * n;
  ///   });
  /// Result:
  ///   b = 1, 4, 9, 16, 25
  ///
  template<typename T_IN, typename T_OUT, class Functor>
  vector<T_OUT> _Map(vector<T_IN> src, Functor func) {
    vector<T_OUT> ret;
    for (int i = 0; i < src.size(); i++) {
      ret.push_back(func(src[i]));
    }
    return ret;
  }
#endif

};

/// BEGIN //////////////////////////////////////////////////////////

int main() {
  while (true) {
    int m    = Scanner::nextInt();
    int nmin = Scanner::nextInt();
    int nmax = Scanner::nextInt();

    if (m + nmin + nmax == 0) {
      break;
    }

    vector<int> Ps(m);
    REP(i, m) {
      int p = Scanner::nextInt();
      Ps[i] = p;
    }

    int ans, ans_diff = -1;
    for (int i = nmin - 1; i <= nmax - 1; i++) {
      int diff = Ps[i] - Ps[i + 1];
      if (diff >= ans_diff) {
        ans_diff = diff;
        ans = i;
      }
    }
    PRINT(ans + 1);
  }

  return 0;
}
/// END   //////////////////////////////////////////////////////////


#include <stdio.h>
int main()
{
	int n,a[5000];
	while(1){
		int max=-100001;
		scanf("%d",&n);
		if(n==0)
			break;
		for(int i=0;i<n;i++)
			scanf("%d",&a[i]);
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=i;j<n;j++){
				sum+=a[j];
				if(max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
	}
	return 0;
}

#include <algorithm>
#include <cstdio>
#include <deque>
#include <numeric>
#include <vector>

using namespace std;

template <typename C>
vector<int> compact(const C& container) {
  vector<int> compacten;
  int sign = 1;
  int acc = 0;
  for (auto n : container) {
    if (n == 0) { continue; }
    if (sign * n > 0) {
      acc += n;
    } else {
      compacten.push_back(acc);
      acc = n;
      sign *= -1;
    }
  }
  compacten.push_back(acc);
  return compacten;
}

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) { break; }

    deque<int> seq;
    for (int i = 0; i < n; ++i) {
      int x;
      scanf("%d", &x);
      seq.push_back(x);
    }
    int max_elem;
    if ((max_elem = *max_element(seq.begin(), seq.end())) <= 0) {
      printf("%d\n", max_elem);
      continue;
    }
    while (seq.size() != 0 && seq.front() <= 0) { seq.pop_front(); }
    while (seq.size() != 0 && seq.back() <= 0) { seq.pop_back(); }

    auto compacten_seq = compact(seq);
    vector<int> partial_sums = { compacten_seq.back() };
    for (int i = compacten_seq.size() - 1; i > 0; i -= 2) {
      int s = partial_sums.back() + compacten_seq[i - 1];
      partial_sums.push_back(compacten_seq[i - 2] + (s < 0 ? 0 : s));
    }
    printf("%d\n", *max_element(partial_sums.begin(), partial_sums.end()));
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N, A, B, C, D, E; cin >> N >> A >> B >> C >> D >> E;

  int k = min(min(min(min(A,B),C),D),E);
  int ans = (N+k-1)/k+4;

  cout << ans << endl;

}

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

std::vector<std::string> split(std::string &str, char delim) {
	std::vector<std::string> result;
	std::istringstream is(str);
	std::string buf;
	while (getline(is, buf, delim)) {
		result.push_back(buf);
	}
	return result;
}

bool inputDataSet(std::vector<int> *l, int *v1, int *v2) {
	std::string line;
	if (!getline(std::cin, line)) { return false; }
	std::vector<std::string> tokens = split(line, ',');
	if (tokens.size() != 12) { return false; }
	for (int i = 0; i < 10; ++i) {
		std::istringstream is(tokens[i]);
		if (!(is >> (*l)[i])) { return false; }
	}
	std::istringstream is1(tokens[10]), is2(tokens[11]);
	if (!((is1 >> *v1) && (is2 >> *v2))) { return false; }
	return true;
}

template <class Iterator>
int sum(Iterator first, Iterator last) {
	int sum = 0;
	for (; first != last; ++first) { sum += *first; }
	return sum;
}

int main() {
	std::vector<int> l(10);
	int v1, v2;
	while (inputDataSet(&l, &v1, &v2)) {
		const int x1 = 0, x2 = sum(l.begin(), l.end());
		v2 = -v2;
		if (v1 == v2) { continue; }	// ツ堕環妥篠堕ャツ度 0 ツづ按づァツ古ーツ債キツつオツづ按つ「
		const double x = static_cast<double>(x1) + static_cast<double>(-(x1 - x2) * v1) / static_cast<double>(v1 - v2);	// ツ渉ャツ青板つェツ静伉偲個づつウツづェツづゥツづ債「ツづゥ
		int n = 0, sum = 0;
		for (std::vector<int>::iterator it = l.begin(); it != l.end() && static_cast<double>(sum) < x; ++it) {
			sum += *it;
			++n;
		}
		std::cout << n << std::endl;
	}
	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    for (Int i = 0; i < 7; ++i) {
        if (week[i] == s) {
            cout << 7 - i << endl;
        }
    }
    return 0;
}

#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	string str;
	cin>>str;
	if(str=="SUN")
		cout<<7<<"\n";
	if(str=="MON")
		cout<<6<<"\n";
	if(str=="TUE")
		cout<<5<<"\n";
	if(str=="WED")
		cout<<4<<"\n";
	if(str=="THU")
		cout<<3<<"\n";
	if(str=="FRI")
		cout<<2<<"\n";
	if(str=="SAT")
		cout<<1<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int k,x;
		cin>>k>>x;
		for(int i=(x-k+1);i<=x+k-1;i++){
			cout<<i<<" ";
		}
	}
	return 0;
}

#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int A[3];
unsigned int use[100000001];
priority_queue<int,vector<int>,greater<int> > ans;
int main()
{
  int n;
  cin >>n;
  int Min = 1e+9;
  for(int i = 0;i < n;i++){
    cin >>A[i];
    if(Min >A[i]){
      Min = A[i];
    }
  }
    if(n ==2){
      for(int i = 1;i <=Min;i++){
	  if(A[0]%i==0&&use[i]!=1&&A[1]%i==0){
	    use[i] = 1;
	    ans.push(i);
	}
      }
    }
      if(n == 3){
	for(int i = 1;i <=Min;i++){
	    if(A[0]%i==0&&use[i]!=1&&A[1]%i==0&&A[2]%i==0){
	      use[i] = 1;
	      ans.push(i);
	    }
	}
      }
      while(!ans.empty()){
	cout <<ans.top()<<endl;
	ans.pop();
      }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
long long g=0,n,a,mx=0,k;
cin>>n>>k;
for(int i=0;i<n;i++){
    cin>>a;
    mx=max(mx,a);
    g=__gcd(g,a);
}
if(k>mx){
    cout<<"IMPOSSIBLE";
}
else{
 if(k%g==0){
 cout<<"POSSIBLE";
}
else{
    cout<<"IMPOSSIBLE";
}
}
}

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

using std::begin;
using std::end;

int gcd(int n, int m) {
  if(n < m) return gcd(m, n);
  if(m == 0) return n;

  return gcd(m, n % m);
}

void print_kouyakusu(int n) {
  std::vector<int> v;
  for(int i{1}; i <= std::sqrt(n); ++i) {
    if(n % i == 0) {
      v.push_back(i);
      if(i * i != n) {
        v.push_back(n / i);
      }
    }
  }
  std::sort(begin(v), end(v));
  for(int e: v) {
    std::cout << e << std::endl;
  }
}

int main(int, char**) {
  int n;
  std::cin >> n;
  if(n == 2) {
    int a, b;
    std::cin >> a >> b;

    int d{gcd(a, b)};

    print_kouyakusu(d);
  } else {
    int a, b, c;
    std::cin >> a >> b >> c;

    int d{gcd(a, b)};
    int d2{gcd(c, d)};

    print_kouyakusu(d2);
  }

  return 0;
}


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

int64_t MOD;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int main(){
    int N;
    cin >> N >> MOD;
    create_mod_tables(10000);

    static int64_t dp[6010][4001];
    dp[3*N][N] = 1;
    for(int i=3*N; i>0; i--) for(int j=0; j<=2*N; j++){
        add(dp[i-1][min(2*N, j+1)], dp[i][j]);
        if(i>=2 && j > 0) add(dp[i-2][j-1], dp[i][j] * (i-1));
        if(i>=3) add(dp[i-3][j], dp[i][j] * (i-1) * (i-2));
    }

    int64_t ans = 0;
    for(int j=N; j<=2*N; j++) add(ans, dp[0][j]);
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int N, mod, i2[10009], i3[10009];//[100][100][100];//[270 * 3][270 * 3][270 * 4];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

int power (int a, int b)
{
    int p = 1;
    for (int i=0; (1<<i) <= b; i++)
    {
        if (b & (1 << i)) p = mul (p, a);
        a = mul (a, a);
    }
    return p;
}

int fac[2000009], inv[2000009];
void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i);
inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);}
int comb (int N, int K){if (K > N || N < 0 || K < 0) return 0; int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &mod), Prec(4 * N + 100);
/*dp[0][0][N] = 1;
for (int i=0; i<3 * N; i++)
{
    int ni = (i + 1) & 1;
    memset (dp[ni], 0, sizeof (dp[ni]));
    for (int j=0; j<=i; j++)
        for (int k=0; k<=4 * N; k++)
            if (dp[i & 1][j][k] > 0)
            {
                ///k = N + cnt1 - cnt2
                ///j = how many numbers smaller than or equal to i i have left
                adto (dp[ni][j + 1][k], dp[i & 1][j][k]);///don't group this one
                if (j >= 2)
                    adto (dp[ni][j - 2][k], mul (dp[i & 1][j][k], j * (j - 1)));
                if (j >= 1 && k > 0)
                    adto (dp[ni][j - 1][k - 1], mul (dp[i & 1][j][k], j));
                adto (dp[ni][j][k + 1], dp[i & 1][j][k]);
            }
}*/
int ans = 0;
//for (int k=N; k<=4 * N; k++)
  //  adto (ans, dp[(3 * N) & 1][0][k]);
i2[0] = i3[0] = 1;
int invv3 = power (3, mod - 2);
for (int i=1; i<=3 * N; i++)
    i2[i] = mul (i2[i - 1], inv[2]),
    i3[i] = mul (i3[i - 1], invv3);
for (int cnt1 = 0; cnt1 <= 3 * N; cnt1 ++)
    for (int cnt2 = 0; cnt2 <= cnt1 && 2 * cnt2 + cnt1 <= 3 * N; cnt2 ++)
        if ((3 * N - cnt1 - 2 * cnt2) % 3 == 0)
        {
            int cnt3 = (3 * N - cnt1 - 2 * cnt2) / 3;
            int curr = mul (mul (fac[3 * N], i2[cnt2]), i3[cnt3]);
            curr = mul (curr, inv[cnt1]), curr = mul (curr, inv[cnt2]), curr = mul (curr, inv[cnt3]);
            //printf ("%d %d %d -> %d\n", cnt1, cnt2, cnt3, curr);
            adto (ans, curr);
        }
printf ("%d\n", ans);
return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int k;
    string s;

    cin>> k>> s;

    if(s.size()> k)
    s= s.substr(0, k) +"...";

    cout<< s<< '\n';

    return 0;
}

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

int k;
string s;
cin>>k>>s;

if(s.length()<=k) cout<<s<<endl;

else{

        for(int i=0;i<k;i++)   cout<<s[i];

        cout<<"."<<"."<<"."<<endl;

}

}


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }

	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);

	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
		pr(t); pr(ts...);
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) {
		pr("{",x.f,", ",x.s,"}");
	}
	template<class T> void pr(const T& x) {
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
		pr("}");
	}

	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) {
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...);
	}
}

using namespace output;

int main() {
    // ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;

	vector<vi> dum (N, vi (M));
	F0R(i, N) {
		F0R(j, M) {
			cin >> dum[i][j];
		}
	}
	// misread inputs have to reformat
	vector<vi> grid (N, vi (M));
	F0R(i, N) F0R(j, M) grid[i][dum[i][j]-1] = j + 1;

	vector<bool> used (M);

	int worst = N;

	F0R(t, M) {
		int best = N;
		vi count (M);

		F0R(i, N) {
			int lo_ind = M + 1;
			int lo_act = -1;
			F0R(j, M) if (!used[j]) {
				if (grid[i][j] < lo_ind) {
					lo_ind = grid[i][j];
					lo_act = j;
				}
			}
			count[lo_act]++;
		}
		int biggest = 0;
		F0R(i, M) if (count[i] > count[biggest]) biggest = i;

		worst = min(worst, count[biggest]);
		used[biggest] = true;
	}
	print(worst);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b;
    cin >> a >> b;
    a--;
    int cnt = 0;
    while(cnt * a + 1 < b) cnt++;
    cout << cnt << endl;
}

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


//
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int f(int n)
{
  switch(n){
  case 1:
    return 1;
    break;
  case 2:
    return 2;
    break;
  case 3:
    return 4;
    break;
  default:
    int a[30];
    a[0]=1;
    a[1]=2;
    a[2]=4;
    for(int i=3;i<n;++i){
      a[i]=a[i-1]+a[i-2]+a[i-3];
    }
    return a[n-1];
    break;
  }
}

int tenjyou(double n)
{
  if(n==(int)n){
    return (int) n;
  }else{
    return (int) n+1;
  }
}

int main()
{
  int n;
  int m=0;
  vector<int> answer;
  while(cin>>n&&n>0){
    double day,year;
    day=tenjyou(f(n)/10.0);
    year=tenjyou(day/365.0);
    answer.push_back(year);
    m+=1;
  }
  for(int i=0;i<m;++i){
    cout<<answer[i]<<endl;
  }
}

#include<iostream>
#include<vector>

using namespace std;

int foot(int);

int main() {

	int n;
	vector<int>floor;

	cin >> n;
	while (n != 0) {
		floor.push_back(n);
		cin >> n;
	}
	floor.push_back(0);

	int i = 0;
	while (floor[i] != 0) {

		int res = 0;
		res = foot(floor[i]) / 3650;
		if( foot(floor[i]) % 3650 != 0) res++;

		cout << res << endl;
		i++;
	}

	cin >> n;

	return 0;
}

int foot(int n) {

	if (n == 1)return 1;
	if (n == 2)return 2;
	if (n == 3)return 4;
	if (n < 1)return 0;

	return foot(n - 1) + foot(n - 2) + foot(n - 3);

}


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

using namespace std;

#define l first
#define r second
#define int long long

int n;
string s;
int q;
long long pr[1500000];
vector<pair<int, int> > keks;
long long prr[1500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (i)
        pr[i] = pr[i - 1]; pr[i] += s[i] == 'M';
        if (s[i] == 'C') keks.push_back({i, pr[i]});
    }
    for (int i = 0; i < keks.size(); i++)
    {
        if (i) prr[i] = prr[i - 1];
        prr[i] += keks[i].second;
    }
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int k = 0;
        cin >> k;
        long long ans = 0;
        int l = -1, l2 = -1;
        for (int j = 0; j < s.size(); j++)
        {
            if (s[j] == 'D')
            {
                while (l + 1 < keks.size() && keks[l + 1].first < j + k) l++;
                while (l2 + 1 < keks.size() && keks[l2 + 1].first < j) l2++;
                ans += prr[l] - (l2 >= 0 ? prr[l2] : 0) - (l - l2) * pr[j];
            }
        }
        cout << ans << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

int n,d1,d2;
int col[603][603],col1[605][605],col2[605][605];
int dx[4803],dy[4803],cnt;
vector<pair<int,int> > typ[2][2];

void Col(int x,int y,int tar)
{
	col[x][y] = tar;
	for(int i = 1;i <= cnt; ++ i)
	{
		int nx = x + dx[i],ny = y + dy[i];
		if(nx >= 1 && nx <= n && ny >= 1 && ny <= n && !col[nx][ny])
			Col(nx,ny,tar ^ 1);
	}
}

int main()
{
	scanf("%d%d%d",&n,&d1,&d2);
	n *= 2;
	for(int i = 0;i <= n; ++ i)
		for(int j = i;j <= n; ++ j)
			if(i * i + j * j == d1)
			{
				dx[++ cnt] = i; dy[cnt] = j;
				dx[++ cnt] = j; dy[cnt] = i;
				dx[++ cnt] = -i; dy[cnt] = -j;
				dx[++ cnt] = -j; dy[cnt] = -i;
				dx[++ cnt] = i; dy[cnt] = -j;
				dx[++ cnt] = j; dy[cnt] = -i;
				dx[++ cnt] = -i; dy[cnt] = j;
				dx[++ cnt] = -j; dy[cnt] = i;
			}
	for(int i = 1;i <= n; ++ i)
		for(int j = 1;j <= n; ++ j)
		{
			if(!col[i][j])
				Col(i,j,2);
			col1[i][j] = col[i][j] - 2;
		}
	cnt = 0;
	for(int i = 0;i <= n; ++ i)
		for(int j = i;j <= n; ++ j)
			if(i * i + j * j == d2)
			{
				dx[++ cnt] = i; dy[cnt] = j;
				dx[++ cnt] = j; dy[cnt] = i;
				dx[++ cnt] = -i; dy[cnt] = -j;
				dx[++ cnt] = -j; dy[cnt] = -i;
				dx[++ cnt] = i; dy[cnt] = -j;
				dx[++ cnt] = j; dy[cnt] = -i;
				dx[++ cnt] = -i; dy[cnt] = j;
				dx[++ cnt] = -j; dy[cnt] = i;
			}
	memset(col,0,sizeof(col));
	for(int i = 1;i <= n; ++ i)
		for(int j = 1;j <= n; ++ j)
		{
			if(!col[i][j])
				Col(i,j,2);
			col2[i][j] = col[i][j] - 2;
			typ[col1[i][j]][col2[i][j]].push_back(make_pair(i,j));
		}
	for(int i = 0;i < 2; ++ i)
		for(int j = 0;j < 2; ++ j)
			if(typ[i][j].size() >= n * n / 4)
			{
				for(int k = 0;k < n * n / 4; ++ k)
					printf("%d %d\n",typ[i][j][k].first - 1,typ[i][j][k].second - 1);
				return 0;
			}
	return 0;
}

#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> Ppp;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 606;
int n,d1,d2;vector<Pii> res;
void solve(int d1, int d2, vector<Ppp> s){//now,real
	vector<Ppp> a,b;
	rep(i,0,SZ(s)-1)if(!((s[i].fi.fi+s[i].fi.se)&1)){
		a.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
	}
	else{
		s[i].fi.fi++;
		b.pb(Ppp(Pii((s[i].fi.fi+s[i].fi.se)/2,(s[i].fi.se-s[i].fi.fi)/2),s[i].se));
	}
	if(SZ(a)<SZ(b))swap(a,b);
	if(d1&d2&1)rep(i,0,SZ(a)-1)res.pb(a[i].se);
	else{
		bool bo=0;if(d2&1)d2=d1,bo=1;if(d1&1)d1=d2,bo=1;
		if(bo)solve(d1/2,d2/2,a);
		else{solve(d1/2,d2/2,a);solve(d1/2,d2/2,b);}
	}
}
int getdis(Pii a, Pii b){return (a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se);}
int main() {
	read(n);read(d1);read(d2);
	vector<Ppp>d;rep(i,0,n*2-1)rep(j,0,n*2-1)d.pb(Ppp(Pii(i,j),Pii(i,j)));
	solve(d1,d2,d);
//	rep(i,0,SZ(res)-1)rep(j,i,SZ(res)-1)assert(d1!=(getdis(res[i],res[j]))&&d2!=(getdis(res[i],res[j])));
//	assert(SZ(res)>=n*n);
	rep(i,0,n*n-1)printf("%d %d\n",res[i].fi,res[i].se);
	return 0;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 2e5 + 10;

int n, arr[2][MAXN], l[2][MAXN], r[2][MAXN], ansl, ansr, cnt[MAXN], ans[MAXN];

int main() {
    IO::read(n);
    ansr = INT_MAX;
    rep(_, 0, 1) rep(i, 1, n) IO::read(arr[_][i]);
    rep(_, 0, 1) rep(i, 1, n) {
        if (arr[_][i] != arr[_][i - 1]) l[_][arr[_][i]] = i;
        if (arr[_][i] != arr[_][i + 1]) r[_][arr[_][i]] = i;
    }
    rep(i, 1, n) {
        if (l[0][i] && l[1][i]) {
            ansl = max(ansl, r[0][i] - l[1][i] + 1);
            // ansr = min(ansr, abs(l[0][i] - r[1][i]));
            ansr = min(ansr, l[0][i] - r[1][i] + n - 1);
        }
    }
    // printf("l = %d, r = %d\n", ansl, ansr);
    if (ansl > ansr) return puts("No"), 0;
    puts("Yes");
    rep(i, 1, n) {
        ans[(i + ansl - 1) % n + 1] = arr[1][i];
    }
    rep(i, 1, n) printf("%d ", ans[i]);
    return 0;
}

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

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

int main() {
	int h, w; cin >> h >> w;
	char s[h+2][w+2];
	for(int i = 0; i < w+2; i++) s[0][i] = '.';
	for (int i = 1; i <= h; i++)
	{
		s[i][0] = '.';
		for (int j = 1; j <= w; j++)
		{
			cin >> s[i][j];
		}
		s[i][h+1] = '.';
	}
	for(int i = 0; i < w+2; i++) s[h+1][i] = '.';

	bool res = true;
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if(s[i][j] == '.') continue;
			bool tmp = false;
			for (int k = 0; k < 4; k++)
			{
				if(s[i+dx[k]][j+dy[k]] == '#')
					tmp = true;
			}
			if(!tmp) res = false;
		}
	}

	if(res) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}