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

int main() {
  int a;
  while (cin >> a) if (a > 8) return cout << ":(" << "\n", 0;
  cout << "Yay!" << "\n";
}

//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

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

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define memset(a,first,last,val) fs(i,first,last,1) a[i]=val
#define nl cout<<"\n";
#define chk(x) cout<<#x<<x<<" ", nl
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define mid(a,b) ((a+b)/2)
#define pb push_back
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

vl vb;
int N;

class triplet{ll f, s, t;};

vl in(ll n){
    vl ar;
    ll x;
    f(i,n)
    cin>>ar[i];
    return ar;
}
vll in_pr(ll n){
    vll ar;
    ll x,y;
    f(i,n)
    {cin>>x>>y;
    ar[i]={x,y};
    }return ar;
}
void out(vl v, char ch='\0'){
    fl(i,v)
    cout<<i<<ch;
}

void printArray(vector<int> arr, int n)
{
    ll num=0;
    for (int i = 0; i < n; i++)
    num*=10, num+=i;

    if(n==N)
    vb.pb(num);

}

int printfactorialof(int n){
    if(n<=1)
        return 1;

    return n*printfactorialof(n-1);
}

void solve(){
    ll a,b;
    cin>>a>>b;
    if(a+b <= 16){
        if(a<=8 && b<=8)
            cout<<"Yay!",nl
        else
        {
            cout<<":(",nl
        }

    }
}

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


#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
class StrongDisassembly{

    private:
        ll V;
        vector<vector<ll>> E;
        vector<vector<ll>> inv_E;
        ll *number;
        bool *used_dfs;
        ll to_write_num = 0;

        void dfs(ll now){
            used_dfs[now] = 1;
            for(ll next : E[now]){
                if(used_dfs[next]){
                    continue;
                }
                dfs(next);
            }
            number[now] = to_write_num++;
        }

        void dfs(ll now, bool *used, vector<ll> &ret){
            used[now] = 1;
            ret.push_back(now);
            for(ll next : inv_E[now]){
                if(used[next]){
                    continue;
                }
                dfs(next, used, ret);
            }
        }

        void write_num(){
            for(ll i = 0; i < V; i++){
                if(!used_dfs[i]){
                    dfs(i);
                }
            }
        }

    public:
        StrongDisassembly(const vector<vector<ll>> &e){
            V = e.size();
            E = e;
            inv_E = vector<vector<ll>>(V);
            number = new ll[V];
            used_dfs = new bool[V];
            for(ll i = 0; i < V; i++){
                used_dfs[i] = 0;
                inv_E.push_back(vector<ll>(0));
            }
            for(ll i = 0; i < V; i++){
                for(ll next : e[i]){
                    inv_E[next].push_back(i);
                }
            }
            write_num();
        }

        map<ll, vector<ll>> disassembly(){
            map<ll, vector<ll>> ret;
            vector<ll> vec;
            bool used[V] = {};
            for(ll i = 0; i < V; i++){
                vec.push_back(i);
            }
            sort(vec.begin(), vec.end(), [&](ll a, ll b){
                    return number[a] > number[b];
                    }
                );
            for(ll vertex : vec){
                if(used[vertex]){
                    continue;
                }
                vector<ll> to_insert;
                dfs(vertex, used, to_insert);
                ret[ret.size() - 1] = to_insert;
            }
            return ret;
        }
};
int main(){
    ll V, E;
    cin >> V >> E;
    vector<vector<ll>> v(V);
    for(ll i = 0; i < E; i++){
        ll s, t;
        cin >> s >> t;
        v[s].push_back(t);
    }
    StrongDisassembly S(v);
    auto ret = S.disassembly();
    map<ll, ll> group;
    for(auto ite = ret.begin(); ite != ret.end(); ite++){
        for(ll u : ite->second) group[u] = ite->first;
    }
    ll Q;
    cin >> Q;
    for(ll i = 0; i < Q; i++){
        ll u, v;
        cin >> u >> v;
        cout << (group[u] == group[v] ? 1 : 0) << endl;
    }
    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long,pair<long long,long long>>> edges;
const long long MAXN = 2e5+5;
long long par[MAXN];
long long sz[MAXN];
pair<pair<long long,long long>,long long> arr[MAXN];
pair<pair<long long,long long>,long long> arr2[MAXN];
long long getpar(long long a){
    if(par[a] == a){
        return a;
    }
    return par[a] = getpar(par[a]);
}
void merge(long long a,long long b){
    a = getpar(a);
    b = getpar(b);
    if(a==b){
        return;
    }
    if(sz[b]>sz[a]){
        swap(a,b);
    }
    sz[a]+=sz[b];
    par[b] = a;
}
int main(){
    long long n;
    cin>>n;
    for(long long i=1;i<=n;i++){
        cin>>arr[i].first.first>>arr[i].first.second;
        arr2[i].first.first = arr[i].first.second;
        arr2[i].first.second = arr[i].first.first;
        arr[i].second = i;
        arr2[i].second = i;
    }
    sort(arr+1,arr+n+1);
    sort(arr2+1,arr2+n+1);
    for(long long i=1;i<n;i++){
        edges.push_back(make_pair(arr[i+1].first.first-arr[i].first.first,make_pair(arr[i].second,arr[i+1].second)));
        edges.push_back(make_pair(arr2[i+1].first.first-arr2[i].first.first,make_pair(arr2[i].second,arr2[i+1].second)));
    }
    sort(edges.begin(),edges.end());
    for(long long i=1;i<=n;i++){
        par[i] = i;
        sz[i] = 1;
    }
    long long ans = 0;
    for(auto x:edges){
        long long w = x.first;
        long long from = x.second.first;
        long long to = x.second.second;
        if(getpar(from)== getpar(to)){
            continue;
        }
        merge(from,to);
        ans+=w;
    }
    cout<<ans<<endl;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 12;
const int S = 1e5+5501;

int dp[N][S];
int p[N], c[N];

int rek(int pos, int tot) {
  if (tot <= 0) return 0;
  if (pos < 0) return 1e4;
  int &ret = dp[pos][tot];
  if (ret != -1) return ret;
  ret = rek(pos-1, tot);
  for (int i = 1; i < p[pos]; ++i) {
    ret = min(ret, i+rek(pos-1, tot-i*(pos+1)));
  }
  return ret = min(ret, p[pos]+rek(pos-1, tot-p[pos]*(pos+1)-c[pos]));
}

void solve() {
  memset(dp, -1, sizeof(dp));
  int d, g; scanf("%d%d", &d, &g);
  g /= 100;
  for (int i = 0; i < d; ++i) {
    scanf("%d%d", p+i, c+i);
    c[i] /= 100;
  }
  printf("%d", rek(d-1, g));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}

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

int main()
{
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; ++i)
		cin >> p[i] >> c[i];
	int ans = 1e9;
	for (int mask = 0; mask < 1 << D; ++mask)
	{
		int sum = 0, num = 0;
		for (int i = 0; i < D; ++i)
		{
			if (mask & 1 << i)
			{
				sum += (i + 1) * 100 * p[i] + c[i];
				num += p[i];
			}
		}
		if (sum >= G)
		{
			ans = min(ans, num);
		}
		else
		{
			for (int i = D - 1; i >= 0; --i)
			{
				if (mask & 1 << i)
				{
					continue;
				}
				for (int j = 0; j < p[i]; j++)
				{
					if (sum >= G)
					{
						break;
					}
					sum += 100 * (i + 1);
					num++;
				}
			}
			ans = min(ans, num);
		}
	}
	cout << ans << endl;
}


#include <iostream>
using namespace std;

int main(){
        int a,b;
        cin >> a;
        b = a;
        for(int i=1;i < 3;i++){
                b = b * a;
        }
        cout << b << endl;
        return 0;
}

#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    PRINT(180*(n-2));
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int a, b;
  cin >> a >> b;
  if(a > 8 || b > 8) {
    cout << ":(\n";
  } else {
    cout << "Yay!\n";
  }
  return 0;
}

#include <iostream>
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    if (N % K != 0) printf("%d\n", 1);
    else printf("%d\n", 0);
}


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

typedef std::vector<int> TTree;
struct TPath
{
    int Id1;
    int Id2;
    int Cost;
    TPath(int AId1, int AId2, int ACost)
     : Id1(AId1), Id2(AId2), Cost(ACost)
    {}
};
bool Compare(const TPath& Left, const TPath& Right)
{
    if(Left.Cost  < 0) return false;
    if(Right.Cost < 0) return true;
    return Left.Cost < Right.Cost;
}

int main()
{
    int n;
    std::cin >> n;
    std::vector<TTree*> Table(n, NULL);
    for(std::size_t i = 0; i < n; ++i){
        Table[i] = new std::vector<int>(1, i);
    }
    std::vector<TPath> PathList;
    PathList.reserve(n*n);

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            int Cost;
            std::cin >> Cost;
            PathList.push_back(TPath(i, j, Cost));
        }
    }
    std::sort(PathList.begin(), PathList.end(), Compare);

    int Total = 0;
    for(std::vector<TPath>::const_iterator It = PathList.begin();
        It != PathList.end(); ++It)
    {
        const TPath& Path = *It;
        TTree* Tree1 = Table[Path.Id1];
        TTree* Tree2 = Table[Path.Id2];
        if(Tree1 == Tree2){
            continue;
        }
        Tree1->insert(Tree1->end(), Tree2->begin(), Tree2->end());
        for(std::size_t j = 0; j < Tree2->size(); ++j){
            int Id = (*Tree2)[j];
            Table[Id] = Tree1;
        }
        delete Tree2;
        Total += Path.Cost;
        // std::cout << "[" << Path.Id1 << "]" << "[" << Path.Id2 << "] = " << Path.Cost << std::endl;
    }
    std::cout << Total << std::endl;
    return 0;
}


#include <bits/stdc++.h>

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

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

	string s; cin >> s;

	int ans = 0;

	int cnt_J = 0;
	int cnt_O = 0;
	int cnt_I = 0;

	char p = 'X';

	for (int i = 0;i < s.size();i++){
		if(s[i] == 'J') {
			cnt_O = cnt_I = 0;
			if(p != s[i]) cnt_J = 1;
			else cnt_J++;
		} else if(s[i] == 'O') {
			if(cnt_J == 0){
				cnt_J = cnt_O = cnt_I = 0;
			} else {
				if(p == 'I') cnt_J = cnt_O = cnt_I = 0;
				else cnt_O++;
			}
		} else if(s[i] == 'I'){
			if(cnt_O == 0){
				cnt_J = cnt_O = cnt_I = 0;
			} else {
				cnt_I++;
				if(cnt_O <= cnt_J && cnt_O <= cnt_I) ans = max(cnt_O,ans);
			}
		}
		p = s[i];
	}

	cout << ans << endl;

	return 0;

}


//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

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

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, H, W;
	cin >> N >> H >> W;
	int ans = 0;

	cout << (N - H + 1)*(N - W + 1) << endl;

	return 0;
}

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int tmp=a.find("ST");
	while(a.length()>0&&tmp>=0)
	{
		a.erase(tmp,2);
		int x=max(tmp-1,0);
		tmp=a.find("ST",x);
		if(tmp==string::npos)
			tmp=-1;
	}
	cout<<a.length()<<endl;
	return 0;
}


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

int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    string ans="Yes";
    for(int i=0; i<a; i++){
        if(0>s.at(i)-'0'||s.at(i)-'0'>9) ans="No";
    }
    if(s.at(a)!='-') ans="No";
    for(int i=0; i<b; i++){
        if(0>s.at(i+a+1)-'0'||s.at(i+a+1)-'0'>9) ans="No";
    }
    cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    if (s.size() != a + b + 1) {
        cout << "No" << endl;
        return 0;
    }
    for (int i = 0; i < s.size(); i++ ) {
        if (i == a) {
            if (s[i] != '-') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (s[i] < '0' || s[i] > '9') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define MAX 10000
#define INFTY 1<<30 // 2^30
#define N 8
using namespace std;
typedef long long llong;
static const int NIL = -1;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

static const int NOT_FREE = 0;
static const int FREE = 1;
static const int FIXED = 2;

bool X[N][N];
vector<pair<int, int> > ans;

void init()
{
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
      X[i][j] = false;
}

bool can_pos(int x, int y)
{
  for(int i = 0; i < ans.size(); i++)
  {
    int tx = ans[i].first;
    int ty = ans[i].second;
    if(x == tx) return false;
    if(y == ty) return false;
    if((x-tx)*(x-tx) == (y-ty)*(y-ty)) return false;
  }
  return true;
}

void printBoard()
{
  for(int i = 0; i < ans.size(); i++)
    X[ans[i].first][ans[i].second] = true;
  for(int i = 0; i < N; i++)
  {
    for(int j = 0; j < N; j++)
      cout << (X[i][j] ? "Q" : ".");
    cout << endl;
  }
}

bool recursive(int p)
{
  for(; p < N * N; p++)
  {
    int i = p%N;
    int j = p/N;
    if(!(can_pos(i,j))) continue;
    pair<int, int>tmp = make_pair(i, j);
    ans.push_back(tmp);
    if(!recursive((j+1)*N)) ans.pop_back();
  }
  if(ans.size() == N) return true;
  return false;
}

int main()
{
  init();
  int k, r, c; cin >> k;
  for(int i = 0; i < k; i++)
  {
    cin >> r >> c;
    pair<int, int> tmp = make_pair(r, c);
    ans.push_back(tmp);
  }
  if(recursive(0)) printBoard();
  return 0;
}


#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

class Node{
public:
    int parent, rank;
    Node(int i): parent(i), rank(0){}
};

bool sortFunc(const vector<int>& A, const vector<int>& B){
    return A[2] < B[2];
}

int find(vector<Node>& nodes, const int& x){
    if(nodes[x].parent != x){
        int p = find(nodes, nodes[x].parent);
        nodes[x].parent = p;
    }
    return nodes[x].parent;
}

void unite(vector<Node>& nodes, const int& x, const int& y){
    int xp = find(nodes, x), yp = find(nodes, y);
    if(nodes[xp].rank > nodes[yp].rank){
        nodes[yp].parent = xp;
    }
    else if(nodes[yp].rank > nodes[xp].rank){
        nodes[xp].parent = yp;
    }
    else{
        nodes[xp].rank++;
        nodes[yp].parent = xp;
    }
}
int main(){
    int v, e, s, t, w;
    vector<Node> nodes;
    vector<vector<int>> edges;
    scanf("%d %d", &v, &e);
    for(int i = 0; i < v; i++){
        nodes.push_back(Node(i));
    }
    for(int i = 0; i < e; i++){
        scanf("%d %d %d", &s, &t, &w);
        edges.push_back(vector<int>{s, t, w});
    }
    sort(edges.begin(), edges.end(), sortFunc);
    int sum = 0;
    for(vector<int> edge: edges){
        if(find(nodes, edge[0]) == find(nodes, edge[1])) continue;
        sum += edge[2];
        unite(nodes, edge[0], edge[1]);
    }
    printf("%d\n", sum);
}

#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
  int N,K,L;cin>>N>>K>>L;
  UnionFind A(N);
  UnionFind B(N);
  for(int I=0;I<K;I++){
    int X,Y;cin>>X>>Y;X--;Y--;
    A.merge(X,Y);
  }
  for(int I=0;I<L;I++){
    int X,Y;cin>>X>>Y;X--;Y--;
    B.merge(X,Y);
  }
      map<pair<int,int>,int> ma;
    for (int v = 0; v < N; ++v) {
        pair<int,int> p(A.root(v), B.root(v));
        ma[p]++;
    }

    for (int v = 0; v < N; ++v) {
        pair<int,int> p(A.root(v), B.root(v));
        cout << ma[p] << " ";
    }
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()

//UnionFind Template
struct UnionFind{ //構造体の定義
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {} //コンストラクタ
    int find(int x){
        if(d[x]<0) return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return false;
        if(d[x]<d[y]) swap(x,y);//d[x] is smaller. Then, connect d[x] to d[y].
        d[y]+=d[x];
        d[x]=y;
        return true;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return -(d[find(x)]);
    }
    int rootsize(){
        int cnt=0;
        for(auto& v: d){
            if(v<0) cnt++;
        }
        return cnt;
    }
};
//How to use
//UnionFind uf(n); などと書けば使えるようになる.ufというobjectが生成される
//uf.unite(a,b);などで中の関数を使える

int main(){
    int h,w; cin>>h>>w;
    const vector<int> df={-1,1,w,-w};
    vector<string> p(h);
    rep(i,h) cin>>p[i];
    UnionFind uf(h*w);
    rep(i,h*w){
        if(p[i/w][i%w]=='.') continue;
        rep(j,4){
            int a=i+df[j];
            if(a<0 || a>=h*w || (a&w==0 && j==1) || (i%w==0 && j==0)) continue;
            if(p[a/w][a%w]=='#') uf.unite(i,a);
        }
    }
    bool ok=true;
    rep(i,h*w){
        if(uf.size(i)==1 && p[i/w][i%w]=='#') ok=false;
    }
    cout<<(ok? "Yes": "No")<<endl;
    return 0;
}

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> M(H);
  for (int i = 0; i < H; i++) {
    cin >> M[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (M[i][j] == '#') {
        if ((i + 1 < H && M[i + 1][j] == '#') ||
            (0 <= i - 1 && M[i - 1][j] == '#') ||
            (j + 1 < H && M[i][j + 1] == '#') ||
            (0 <= j - 1 && M[i][j - 1] == '#'))
          continue;
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


#include <stdio.h>

typedef struct _Gem{
	int x;
	int y;
	bool hit;
} Gem;

static void
pick_gem(Gem* g, int n, int x, int y)
{
	for (int i = 0; i < n; i++) {
		if (!g[i].hit && g[i].x == x && g[i].y == y) {
			g[i].hit = true;
			return;
		}
	}
}

static bool
check_gem(Gem* g, int n)
{
	for (int i = 0; i < n; i++) {
		if (g[i].hit == false) {
			return false;
		}
	}

	return true;
}

int
main(void)
{

	char line[80];
	int n;
	int m;

	Gem g[20];

	char d[30];
	int l[30];

	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			return 1;
		}
		if (sscanf(line, "%d", &n) != 1) {
			return 1;
		}

		if (n == 0) {
			break;
		}

		for (int i = 0; i < n; i++) {
			if (fgets(line, sizeof line, stdin) == NULL) {
				return 1;
			}
			if (sscanf(line, "%d %d", &(g[i].x), &(g[i].y)) != 2) {
				return 1;
			}
			g[i].hit = false;
		}

		if (fgets(line, sizeof line, stdin) == NULL) {
			return 1;
		}
		if (sscanf(line, "%d", &m) != 1) {
			return 1;
		}

		for (int i = 0; i < m; i++) {
			if (fgets(line, sizeof line, stdin) == NULL) {
				return 1;
			}
			if (sscanf(line, "%c %d", &(d[i]), &(l[i])) != 2) {
				return 1;
			}
		}

		int x = 10;
		int y = 10;
		for (int i = 0; i < m; i++) {
			if (d[i] == 'N') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, x, ++y);
				}
			} else if (d[i] == 'S') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, x, --y);
				}
			} else if (d[i] == 'E') {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, ++x, y);
				}
			} else {
				for (int k = 1; k <= l[i]; k++) {
					pick_gem(g, n, --x, y);
				}
			}
		}
		printf("%s\n", (check_gem(g, n) ? "Yes" : "No"));
	}

	return 0;
}

#include <iostream>
#include <cstring>

using namespace std;

int map[50][50];
int N;
int x,y;

int main(){

  while(1){

    cin >> N;
    if(N == 0) break;

    memset(map,0,sizeof(map));

    for(int i = 0; i < N ; i++){
      cin >> x >> y;
      map[x][y] = 1;
    }

    int M;
    int l;
    char d;
    int tr = 0;

    cin >> M;
    int nx = 10, ny =10;
    for(int i = 0; i < M ; i++){
      cin >> d >> l;
      if(d == 'N'){
	for(int i = 0 ; i < l; i++){
	  ny++;
	  if(map[nx][ny] == 1){
	    tr++;
	    map[nx][ny] = 0;
	  }
	}
      }else if(d == 'E'){
	for(int i = 0 ; i < l; i++){
	  nx++;
	  if(map[nx][ny] == 1){
	    tr++;
	    map[nx][ny] = 0;
	  }
	}

      }else if(d == 'S'){
	for(int i = 0 ; i < l; i++){
	  ny--;
	  if(map[nx][ny] == 1){
	    tr++;
    map[nx][ny] = 0;
	  }
	}
       }else if(d == 'W'){
	for(int i = 0 ; i < l; i++){
	  nx--;
	  if(map[nx][ny] == 1){
	    tr++;
	    map[nx][ny] = 0;
	  }
	}
      }
    }
    if( tr == N ) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

const int inf = 1e9;
const ll inf64 = 1e18;

const int mod = 998244353;

inline int _mul(int a, int b) {
    return (1ll * a * b) % mod;
}

inline int _sum(int a, int b) {
    return a + b < mod ? a + b : a + b - mod;
}

inline int _sub(int a, int b) {
    return a >= b ? a - b : a - b + mod;
}

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

inline void _dec(int &x, int y) {
    if ((x -= y) < 0) {
        x += mod;
    }
}

inline int _binpow(int x, int p) {
    int res = 1;
    int tmp = x;
    while (p > 0) {
        if (p & 1) {
            res = _mul(res, tmp);
        }
        tmp = _mul(tmp, tmp);
        p >>= 1;
    }
    return res;
}

const int N = 3e6 + 5;

int fact[N];
int rfact[N];

void precalc() {
    fact[0] = 1;
    for (int i = 1; i < N; i++) {
        fact[i] = _mul(fact[i - 1], i);
    }
    rfact[N - 1] = _binpow(fact[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--) {
        rfact[i] = _mul(rfact[i + 1], i + 1);
    }
}

inline int CNK(int n, int k) {
    if (n < k) {
        return 0;
    }
    return _mul(fact[n], _mul(rfact[n - k], rfact[k]));
}

inline int F(int n, int k) {
    return CNK(n + k - 1, k);
}

int main() {

    precalc();

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    int n, m;

    cin >> n >> m;

    int res = 0;

    for (int i = m & 1; i <= m; i += 2) {
        _inc(
            res,
            _mul(
                CNK(n, i),
                F(n, (3 * m - i) / 2)
            )
        );
    }

    _dec(
        res,
        _mul(
            n,
            F(n, m - 1)
        )
    );

    cout << res << "\n";

    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  ll ans = 1;
  rep(i, 2*N) {
    if(S[i] == 'B') {
      if(cnt%2) {
        if(cnt == 0) {
          ans = 0;
          break;
        }
        (ans *= cnt) %= mod;
        cnt--;
      } else {
        ans *= 1;
        cnt++;
      }
    } else {
      if(cnt%2) {
        ans *= 1;
        cnt++;
      } else {
        if(cnt == 0) {
          ans = 0;
          break;
        }
        (ans *= cnt) %= mod;
        cnt--;
      }
    }
  }
  function<ll(ll)> fact = [&](ll n) {
    if(n == 0) return 1LL;
    else return (n * fact(n-1)) % mod;
  };
  if(cnt) cout << 0 << endl;
  else cout << (ans * fact(N)) % mod << endl;
  return 0;
}


#include <iostream>
#include <stdlib.h>
#define inf 99999

using namespace std;

bool check(int *label, int n)
{
	for(int i = 1; i <= n; i++){
		if(label[i] == 0){
			return true;
		}
	}

	return false;
}

void dij(int **a, int n, int s, int t)
{
	int *label, current=s, num=1, next, *cost, min;

	cost = (int *)calloc(n+1, sizeof(int));
	label = (int *)calloc(n+1, sizeof(int));

	for(int i = 1; i <= n; i++){
		cost[i] = a[current][i];
	}
	label[current] = num++;

	while(check(label, n)){
		min = inf;
		for(int i = 1; i <= n; i++){
			if(min >= cost[i] && label[i] == 0){
				min = cost[i];
				next = i;
			}
		}
		label[next] = num++;
		for(int i = 1; i <= n; i++){
			if(label[i] == 0 && cost[i] > (a[next][i]+cost[next])){
				cost[i] = a[next][i] + cost[next];
			}
		}
		current = next;
	}
	cout << cost[t] << endl;

	free(cost);
	free(label);

	return ;
}

int main(int argc, char **argv)
{
	int **t, **c, n, m, a, b, p, q;

	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}

		t = (int **)calloc(m+1, sizeof(int));
		c = (int **)calloc(m+1, sizeof(int));
		for(int i = 0; i <= m; i++){
			t[i] = (int *)calloc(m+1, sizeof(int));
			c[i] = (int *)calloc(m+1, sizeof(int));
		}

		for(int i = 0; i < n; i++){
			cin >> a >> b >> p >> q;
			c[a][b] = c[b][a] = p;
			t[a][b] = t[b][a] = q;
		}
		for(int i = 1; i <= m; i++){
			for(int j = 1; j <= m; j++){
				if(i != j && c[i][j] == 0){
					c[i][j] = inf;
				}
				if(i != j && t[i][j] == 0){
					t[i][j] = inf;
				}
			}
		}
		cin >> n;
		for(int i = 0; i < n; i++){
			cin >> a >> b >> p;
			if(p == 0){
				dij(c, m, a, b);
			} else {
				dij(t, m, a, b);
			}
		}

		for(int i = 0; i <= m; i++){
			free(t[i]);
			free(c[i]);
		}
		free(t);
		free(c);
	}

	return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long INTEGER;
typedef double FLOAT;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

const int MM = 100;
int cost[MM][MM];
int toki[MM][MM];

int main() {

entry:;
  int n, m; cin >> m >> n;
  if (n + m == 0) return 0;

  rep (i, n) {
    rep (j, n) {
      cost[i][j] = INF;
      toki[i][j] = INF;
    }
    cost[i][i] = 0;
    toki[i][i] = 0;
  }

  rep (i, m) {
    int a, b, c, t;
    cin >> a >> b >> c >> t;
    --a; --b;
    cost[a][b] = cost[b][a] = c;
    toki[a][b] = toki[b][a] = t;
  }

  rep (k, n) {
    rep (i, n) {
      rep (j, n) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
        toki[i][j] = min(toki[i][j], toki[i][k] + toki[k][j]);
      }
    }
  }

  //rep (i,n) { rep(j,n) { cout << cost[i][j] << ' '; } cout << endl; }

  int k; cin >> k;
  rep (i, k) {
    int a, b, t;
    cin >> a >> b >> t;
    --a; --b;
    if (t) {
      cout << toki[a][b] << endl;
    } else {
      cout << cost[a][b] << endl;
    }
  }

  goto entry;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
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); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int cnt[550][550];
ll sum[110*5][110*5];

int main(){cout<<fixed<<setprecision(10);
		   //O(m+nq)
           int n,m,Q;
           cin>>n>>m>>Q;
           int r,l;
           rep(i,0,m){
             cin>>l>>r;

             cnt[l][r]++;
           }
           rep(i,1,n+1){
            rep(j,1,n+1){
              sum[i][j]=sum[i][j-1]+cnt[i][j];
              //cout<<sum[i][j]<<" ";
            }
            // cout<<endl;
           }
           int p,q;
           ll ans;
           rep(i,0,Q){
             cin>>p>>q;
             ans=0;
             rep(j,p,n+1){
              ans+=sum[j][q];

             }
             cout<<ans<<endl;
           }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define all(a) a.begin(), a.end()
#define mp(a, b) make_pair(a, b)

const int MOD = 1e9+7;
const int INF = 1001001001;
const ll llINF = 1e18+9;
vector<pii> edge[100010];

int main(){
    int N;
    cin >> N;
    rep(i, 0, N-1){
        int a, b, c;
        cin >> a >> b >> c;
        edge[a-1].push_back(mp(b-1, c));
        edge[b-1].push_back(mp(a-1, c));
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    vector<ll> dist(N, llINF);
    dist[K] = 0;
    queue<pair<int, ll>> q;
    q.push(mp(K, 0));
    while (!q.empty()){
        int now = q.front().first;
        ll nowd = q.front().second;
        q.pop();
        for (auto x:edge[now]){
            int fol = x.first;
            ll d = x.second;
            ll nextd = nowd+d;
            if (dist[fol] < nextd) continue;
            dist[fol] = nextd;
            q.push({fol, nextd});
        }
    }
    rep(i ,0 , Q){
        int x, y;
        cin >> x >> y;
        --x, --y;
        ll ans = dist[x] + dist[y];
        cout << ans << endl;
    }
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<iomanip>
#include<iterator>
#include<vector>
#include<map>
#include<utility>
#include<set>
#include<stack>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

    int k,x;
    cin>>k>>x;
    for(int i=1;i<2*k;i++)cout<<x-k+i<<" ";
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=INF,ans=1,aa[220000],o=0;
pair<int,int> pp[220000];
string s,ss[220000];
char ch[220000];
float fl[220000],fcnt=2;
queue<int> que;
signed main(){
    cin>>n>>m;
    if(m-n>=2019){
        cout<<0<<endl;
    }else{
        for(int i=n;i<m;i++){
            for(int j=i+1;j<m+1;j++){
                cnt=min(cnt,(i*j)%2019);
            }
        }
        cout<<cnt<<endl;
    }
}


#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 1e5 + 5;
int dsu[N], sz[N];
bool odd[N], par[N];

int root(int u) {
    while(u != dsu[u]) u = dsu[u];
    return u;
}

int get_par(int u) {
    int p = 0;
    while(u != dsu[u]) {
        p ^= par[u];
        u = dsu[u];
    }
    return p;
}

void uni(int u,int v) {
    int uu = root(u), vv = root(v);
    if(uu == vv) {
        if(get_par(u) == get_par(v))
            odd[uu] = 1;
        return;
    }
    if(sz[uu] > sz[vv]) {
        swap(uu, vv), swap(u, v);
    }
    dsu[uu] = vv;
    sz[vv] += sz[uu];
    odd[vv] |= odd[uu];
    par[uu] = get_par(u) ^ get_par(v) ^ 1;
}

void solve() {
	int n, m;
    sc(n, m);
    fr(i, 1, n) {
        sz[i] = 1;
        dsu[i] = i;
        odd[i] = 0;
        par[i] = 0;
    }
    fr(i, 1, m) {
        int u, v;
        sc(u, v);
        uni(u, v);
    }
    int c1 = 0, c2 = 0, c3 = 0;
    fr(i, 1, n) {
        if(i == dsu[i]) {
            if(sz[i] == 1) {
                c1++;
            }
            else if(odd[i]) {
                c2++;
            }
            else {
                c3++;
            }
        }
    }
    ll ans = 0;
    while(c1) {
        ans += 2 * n - 1;
        n--;
        c1--;
    }
    while(c2) {
        ans += 2 * (c2 + c3) - 1;
        c2--;
    }
    ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3;
    cout << ans;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

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

struct UnionFind{
  int num;//連結成分の数
  vector<int> r,p;//そのグループのサイズ,自分の親っぽいやつ
  UnionFind(){}
  UnionFind(int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}

  int find(int x){//どのグループに所属するか
    return (x==p[x]?x:p[x]=find(p[x]));//xがグループの名前と一致するまでxを親にする
  }

  bool same(int x,int y){//同じグループかどうか
    return find(x)==find(y);
  }

  void unite(int x,int y){//xとyを同じグループにする
    x=find(x);y=find(y);//xとyのグループの名前をどっちかが変える
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);//サイズが大きい方をxとする
    r[x]+=r[y];//yの親をxにする（今までyだったグループ名がxになる）
    p[y]=x;
    num--;
  }

  int size(int x){//グループの大きさ
    return r[find(x)];
  }

  int count() const{//グループの数
    return num;
  }
};

signed main(){
  int n,m;cin>>n>>m;
  vector<int> edge[n];
  UnionFind uf(n);
  while(m--){
    int u,v;cin>>u>>v;u--;v--;
    uf.unite(u,v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  vector<int> arr(n,-1);
  vector<int> ni,no,si;
  for(int i=0;i<n;i++){
    if(uf.size(i)==1){
      si.push_back(i);
      continue;
    }
    if(~arr[i])continue;
    arr[i]=0;
    bool out=false;
    queue<int> que;
    que.push(i);
    while(que.size()){
      int p=que.front();que.pop();
      for(int q:edge[p]){
        if(~arr[q]){
          if(arr[q]==arr[p])out=1;
        }
        else{
          arr[q]=arr[p]^1;
          que.push(q);
        }
      }
    }
    if(out)no.push_back(uf.size(i));
    else ni.push_back(uf.size(i));
  }
  int ans=0;
  int a=ni.size(),c=no.size(),e=si.size();
  ans=2*a*a+2*a*c+c*c+2*e*n-e*e;
  cout<<ans<<endl;
}

/*
解説AC
連結成分なのでどう言う時に繋がっていくかを考える必要があって、それを元のグラフでの連結成分と結びつける問題
実験コードでひらめく感じはしなくて、でも手を動かすのも相当大変
解説記事も全然なくて考察フローがしっかり考えることしかなさそう？えーちょっとまだ分からんな
自分で解説記事書くしかないかなぁ
FA13分ってなんだよ
*/


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < 3; ++i) {
        if (n % 10 == 7){
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
}

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

int main(){
    int N;
    cin >> N;
    string str = to_string(N);
    string res;

    if(str.find("7") != string::npos){
        res = "Yes";
    } else {
        res = "No";
    }

    cout << res << endl;

    return 0;
}


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

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  char buf[1002];
  buf[N] = '\n';
  buf[N+1] = 0;
  if(N >= 4 && N%2 == 0) {
    char const* p[2] = {"abcc",
                        "abdd"};
    for(int i = 0; i < N; ++i) {
      int x = (i/2)*2, y = i%2;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 4; ++j) buf[(x+j)%N] = p[y][j];
      std::cout << buf;
    }
  } else if(N%3 == 0) {
    char const* p[3] = {"aab",
                        "b.b",
                        "baa"};
    for(int i = 0; i < N; ++i) {
      int x = (i/3)*3, y = i%3;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 3; ++j) buf[(x+j)%N] = p[y][j];
      std::cout << buf;
    }
  } else if(N >= 9 || N==5) {
    char const* p[2] = {"abcc",
                        "abdd"};
    int n = N-5;
    for(int i = 0; i < n; ++i) {
      int x = (i/2)*2, y = i%2;
      std::fill_n(buf, N, '.');
      for(int j = 0; j < 4; ++j) buf[(x+j)%n] = p[y][j];
      std::cout << buf;
    }
    std::fill_n(buf, N, '.');
    char const *q[5] = {"aabba",
                        "cca.a",
                        "bbabb",
                        "..bca",
                        "..bca"};
    for(int i = 0; i < 5; ++i) {
      for(int j = 0; j < 5; ++j) buf[n+j] = q[i][j];
      std::cout << buf;
    }
  } else if(N==7) {
    std::cout << "aa.ab..\n"
                 "...aba.\n"
                 "a....ac\n"
                 "a.aa..c\n"
                 "bb..aab\n"
                 ".aa.b.b\n"
                 "..ccbaa\n";
  } else {
    std::cout << "-1\n";
  }
  return 0;
}

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

int main(){
	int n;
	bool no[10001] = {true,true};
	for(int i = 4;i <= 10000;i += 2) no[i] = true;
	for(int i = 3;i * i <= 10000;i += 2){
		for(int j = i * 2;j <= 10000;j += i) no[j] = true;
	}
	vector<int> twin;
	for(int i = 2;i <= 10000;i++){
		if(!no[i] && !no[i - 2]) twin.push_back(i);
	}
	while(cin >> n,n){
		int pos = upper_bound(twin.begin(),twin.end(),n) - twin.begin() - 1;
		cout << twin[pos] - 2 << " " << twin[pos] << endl;
	}
	return 0;
}


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

void input(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

void searchCntl(int nTrgSu, int nTrgKin)
{
  for (int n10000 = 0; n10000 <= nTrgSu; ++n10000)
    for (int n5000 = 0; n5000 <= (nTrgSu - n10000); ++n5000)
    {
      int n1000 = nTrgSu - n10000 - n5000;
      if (nTrgKin == 10000 * n10000 + 5000 * n5000 + 1000 * n1000)
      {
        cout << n10000 << " " << n5000 << " " << n1000 << endl;
        return;
      }
    }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;

  input(nTrgSu, nTrgKin);
  searchCntl(nTrgSu, nTrgKin);

  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    int ans=-1e9;
    ans=max(ans,a+b);
    ans=max(ans,a-b);
    ans=max(ans,a*b);
    cout<<ans<<endl;

    return 0;
}


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

using 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)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int a, b, k; std::cin >> a >> b >> k;
  bool t = true;
  auto process = [](int &x, int &y) {
    if (x & 1)
      x--;
    y += x / 2;
    x /= 2;
  };
  rep(i, k) {
    if (t) {
      process(a, b);
    } else {
      process(b, a);
    }
    t ^= 1;
  }
  std::cout << a << ' ' << b << "\n";
}

#include "bits/stdc++.h"

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

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

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

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

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }

};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }
};

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a, b;
  cin >> a >> b;
  ll k;
  cin >> k;
  for(ll i=0;i<k;i++){
    if(a%2==1)a-=1;
    b += a/2;
    a/=2;
    i++;
    if(i==k)break;
    if(b%2==1)b-=1;
    a += b/2;
    b/=2;
  }
  cout << a << " " << b << endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int MOD=1e9+7;
void modplus(int &a,int b){
    a+=b;
    a%=MOD;
}
ll eline(int a){
    if(a<=0)return 1ll;
    vector<vector<int>> dp(a,vector<int>(2,0));
    dp[0][0]=1;
    dp[0][1]=1;
    for(int i=1;i<a;i++){
        dp[i][0]=dp[i-1][0]+dp[i-1][1];
        dp[i][1]=dp[i-1][0];
    }
    return dp[a-1][0]+dp[a-1][1];
}
int main(){
    int h,w,g;
    cin>>h>>w>>g;
    g--;
    vector<vector<int>> dp(h+1,vector<int>(w,0));
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int l=-1;l<=1;l++){
                int from=j,to=j+l;
                if(from>to)swap(from,to);
                if(l==0){
                    modplus(dp[i+1][j],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD);
                }else if(0<=j+l&&j+l<w){
                    modplus(dp[i+1][j+l],dp[i][j]*(eline(from-1)*eline(w-to-2)%MOD)%MOD);
                }
            }
        }
    }
    cout<<dp[h][g]<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define p 1000000007
#define maxn 100005
#define int long long
int h,w,a,b,fac[maxn*2+5],inv[maxn*2+5];
inline int qpow(int x,int a)
{
	int ans=1;
	while(a)
	{
		if(a&1) ans=1ll*ans*x%p;
		x=1ll*x*x%p;
		a>>=1;
	}
	return ans;
}
inline void pre(int x=maxn*2)
{
	fac[0]=inv[0]=1;
	for(int i=1;i<=x;++i)
		fac[i]=1ll*fac[i-1]*i%p;
	inv[x]=qpow(fac[x],p-2);
	for(int i=x-1;i;--i)
		inv[i]=1ll*inv[i+1]*(i+1)%p;
}
inline int c(int x,int y)
{
	if(x<y) return 0;
	return 1ll*fac[x]*inv[y]%p*inv[x-y]%p;
}
signed main()
{
	scanf("%lld%lld%lld%lld",&h,&w,&a,&b);
	pre();
	int ans=c(h+w-2,h-1);
	for(int i=1;i<=b;++i)
		ans-=1ll*c(h-a+i-2,i-1)*c(w-i+a-1,a-1),ans%=p;
	ans=(ans%p+p)%p;
	printf("%lld\n",ans);
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T;
  cin >> T;
  vl ANS(T, 0);
  REP(t, T) {
    ll N;
    string S;
    cin >> N;
    vl A(N);
    REP(i, N) cin >> A[i];
    cin >> S;
    vl base;
    RREP(i, N) {
      ll x = A[i];
      sort(ALL(base), REV(ll));
      AUTO(b, base) x = min(x, x ^ b);
      if (x != 0) {
        if (S[i] == '0')
          base.push_back(x);
        else {
          ANS[t] = 1;
          break;
        }
      }
    }
  }
  REP(t, T) cout << ANS[t] << endl;
  return 0;
}

#include <iostream>
using namespace std;
int main(){
	int n,a;
	cin >> n;
	int max = -1000001;
	int min =  1000001;
	long sum = 0;
	for(int i=0;i<n;i++){
		cin >> a;
		sum = sum + a;
		if(max<a) max = a;
		if(min>a) min = a;
	}
	cout << min << " " << max << " " << sum << endl;
}


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

int main(void){
    string s;
    cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        int svn = s[0]-'0';
        for(int i=0; i<3; i++){
            if(bit & (1<<i)) svn += s[i+1]-'0';
            else svn -= s[i+1]-'0';
        }
        if(svn == 7){
            for(int i=0; i<3; i++){
                if(bit & (1<<i)) s.insert(2*i+1, "+");
                else s.insert(2*i+1, "-");
            }
            s += "=7";
            goto SKIP;
        }
    }
SKIP:
    cout << s << '\n';
    return 0;
}


#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	int a, b;
	cin >> a >> b;
	int ans;
	ans = (b - 1) /(a - 1);
  if((b-1)%(a-1)!=0) ans++;
	cout << ans << "\n";

	return 0;
}

// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。
vector<pair<long long,long long>> prime_factorize(long long p); // 素因数分解

// class
// ------------------------------------------------
class Combi {
  public:
    Combi();
    long long Combination(long long n, long long k);
    long long nPk_modp(long long n, long long k, long long p);
  private:
    vector<vector<long long>> memo;
    long long n_num;
    long long k_num;
    void Resize(long long n, long long k);
};

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<long> vll;
// code
// ------------------------------------------------
int main() {

    ll k,t;
    cin >> k >> t;

    vll a(t);
    rep(i,t) cin >> a[i];

    rvsort(a);

    ll ans = max((a[0] - 1 - (k - a[0])),0LL);

    cout << ans << endl;

    return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n) {
  int i = 1;
  while(1) {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n) {
  int s = 0;
  while(n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str) {
  for(auto itr = str.begin();itr != str.end() ; itr++) {
    if(97 <= *itr && *itr <= 122) {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str) {
  for(auto itr = str.begin();itr != str.end() ; itr++) {
    if(65 <= *itr && *itr <= 90) {
      *itr = *itr + 32;
    }
  }
  return str;
}

Combi::Combi() {
  n_num = -1;
  k_num = -1;
};
ll Combi::Combination(ll n, ll k) {
  Resize(n,k);

  ll ret;
  if(memo[n][k] != 0) {
    ret = memo[n][k];
  } else if(n == k || k == 0) {
    memo[n][k] = 1;
    ret = 1;
  } else {
    ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
    memo[n][k] = ret;
  }
  return ret;
}

void Combi::Resize(ll n, ll k) {
  if(n_num <= n || k_num <= k) {
    n_num = (n + 1) * 2;
    k_num = (k + 1) * 2;
    memo.resize(n_num);
    for(auto itr = memo.begin(); itr != memo.end(); ++itr) {
      itr->resize(k_num);
    }
  }
}

long long Combi::nPk_modp(long long n, long long k, long long p) {
  ll ans = 1;
  for(long long i = k; i <= n; i++) {
    ans = (ans * i) % p;
  }

  return ans;
};

vector<pair<long long,long long>> prime_factorize(long long p) {
    vector<pair<long long,long long>> ret;

    for(long long x = 2; x * x <= p; ++x) {
        if(p % x != 0) continue;
        long long num = 0;
        while(p % x == 0) {
            num++;
            p /= x;
        }
        ret.push_back(make_pair(x,num));
    }

    if(p != 1) ret.push_back(make_pair(p, 1));

    return ret;
}


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

// ビット演算
namespace Bits {
    // 整数 x を左に i ビットシフトした値を返す
    static Int LeftBitShift(Int x, Int i);
    // 整数 x を右に i ビットシフトした値を返す
    static Int RightBitShift(Int x, Int i);
    // 整数x の 下から i 桁目が1かどうかを返す
    static bool IsFlagUp(Int x, Int i);
    // 整数x の 下から i 桁目が0かどうかを返す
    static bool IsFlagDown(Int x, Int i);

    // 整数 x を左に i ビットシフトした値を返す
    Int LeftBitShift(Int x, Int i) {
        return (x << i);
    }
    // 整数 x を右に i ビットシフトした値を返す
    Int RightBitShift(Int x, Int i) {
        return (x >> i);
    }
    // 整数x の 下から i 桁目が1かどうかを返す
    bool IsFlagUp(Int x, Int i) {
        return ((x & (1 << i)) != 0);
    }
    // 整数x の 下から i 桁目が0かどうかを返す
    bool IsFlagDown(Int x, Int i) {
        return ((x & (1 << i)) == 0);
    }
}
using namespace Bits;

// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}

int main(void) {
    Int n;
    cin >> n;
    VI a(n);
    VVI table(n, VI(n, -1)); // -1 不明, 0 不親切, 1 正直者
    Int x, y;
    for (Int i = 0; i < n; ++i) {
        cin >> a[i];
        for (Int j = 0; j < a[i]; ++j) {
            cin >> x >> y;
            --x;
            table[i][x] = y;
        }
    }
    Int result = 0;
    for (Int i = 0; i < pow(2, n); ++i) {
        // cout << "I = " << i << endl;
        bool correct = true;
        Int rank = 0;
        // ビット列が1の人のみの証言に矛盾がないかを調べる
        for (Int j = 0; j < n; ++j) {
            if (IsFlagUp(i, j)) {
                rank++;
                for (Int k = 0; k < n; ++k) {
                    if (table[j][k] == 0 && IsFlagUp(i, k)) {
                        correct = false;
                    } else if (table[j][k] == 1 && IsFlagDown(i, k)) {
                        correct = false;
                    }
                }
            }
        }
        if (correct) {
            // cout << "CORRECT" << endl;
            result = Max(result, rank);
        } else {
            // cout << "INCORRECT" << endl;
        }
    }
    cout << result << endl;

    /*
    for (Int i = 0; i < n; ++i) {
        for (Int j = 0; j < n; ++j) {
            cout << table[i][j] << " ";
        }
        cout << endl;
    }
    */
    return 0;
}

/*
 * @Author: hesorchen
 * @Date: 2020-07-03 17:05:01
 * @LastEditTime: 2020-09-04 20:28:08
 * @Description: https://hesorchen.github.io/
 */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

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

struct node
{
    int p, y;
};
vector<node> vec[20];
int a[20];
int all[35000][20];
int vis[20];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < (1 << n); i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i & (1 << j))
                all[i][j + 1] = 1;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        for (int j = 1; j <= a[i]; j++)
        {
            int temp1, temp2;
            scanf("%d %d", &temp1, &temp2);
            vec[i].push_back(node{temp1, temp2});
        }
    }
    int ans = 0;

    for (int i = 0; i < (1 << n); i++)
    {
        int flag = 1;
        fill(vis, vis + 18, -1);

        for (int j = 1; j <= n; j++)
        {
            if (!all[i][j])
                continue;
            else
            {
                for (int k = 0; k < a[j]; k++)
                {
                    if (vec[j][k].y != vis[vec[j][k].p] && vis[vec[j][k].p] != -1)
                    {
                        flag = 0;
                        break;
                    }
                    if (vec[j][k].y && !all[i][vec[j][k].p])
                    {
                        flag = 0;
                        break;
                    }
                    if (!vec[j][k].y && all[i][vec[j][k].p])
                    {
                        flag = 0;
                        break;
                    }
                    if (vec[j][k].y)
                        vis[vec[j][k].p] = 1;
                    else
                        vis[vec[j][k].p] = 0;
                }
            }
            if (!flag)
                break;
        }
        if (flag)
        {
            int s = 0;
            for (int j = 1; j <= n; j++)
                s += all[i][j];
            ans = max(ans, s);
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int MAX_H = 12;
const int MAX_W = 12;
char m[MAX_H+1][MAX_W+1];

inline bool check(int x, int y){ return 0<=x&&x<MAX_H && 0<=y&&y<MAX_W; }

void dfs(int hx, int hy)
{
  rep(i, 4){
    int nx = hx + dx[i];
    int ny = hy + dy[i];

    if(!check(nx, ny)) continue;

    if(m[nx][ny] == '1'){
      m[nx][ny] = '0';
      dfs(nx, ny);
    }
  }
}

int main()
{

  while(true){
    rep(i, MAX_H) rep(j, MAX_W) if(!(cin >> m[i][j])) return 0;

    int res = 0;
    rep(i, MAX_H) rep(j, MAX_W) if(m[i][j] == '1'){
      res += 1;
      dfs(i, j);
    }

    cout << res << endl;
  }

  return 0;
}

#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#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 rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

class BIT{
	int N;
	vector<int>bit;
	void add_(int x,int y){
		while(x<=N){
			bit[x]+=y;x+=x&-x;
		}
	}
	int sum_(int x){
		int res=0;
		while(x>0){
			res+=bit[x];x-=x&-x;
		}
		return res;
	}
public:
	int lower_bound(int w){
		if(w<=0)return -1;
		int x=0;
		int k=1;while(k*2<=N)k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&bit[x+k]<w){
				w-=bit[x+k];
				x+=k;
			}
		}
		return x;
	}
	void add(int x,int y){add_(x+1,y);}
	int sum(int l,int r){return sum_(r)-sum_(l);}
	BIT(int x):N(x),bit(x+1){}
};
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int N,Q;cin>>N>>Q;
	BIT bit(N);
	rep(i,N){int a;cin>>a;bit.add(i,a);}
	while(Q--){
		int t;cin>>t;
		if(!t){
			int p,x;cin>>p>>x;bit.add(p,x);
		}else {
			int l,r;cin>>l>>r;cout<<bit.sum(l,r)<<"\n";
		}
	}
}


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

int main()
{

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int cnt=0;
	string s;
	cin>>s;

	int m =0;

	for(int i =0 ;i<3;i++)
	{
		if(s[i]=='R')m++;
		else
		{
			cnt = max(m,cnt);
			m =0;
		}
	}
	cnt = max(m,cnt);

	cout<<cnt;
    return 0;

}

#include <bits/stdc++.h>

using namespace std;

int n;
char x[5];

int main() {
	scanf("%s", x);
	int ans = 0, cur = 0;
	for (int i = 0; x[i]; i++)
		if (x[i] == 'R')
			ans = max(ans, ++cur);
		else
			cur = 0;
	printf("%d\n", ans);
}


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

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

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

const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int d;
ll ans = 0;
ll p[20];

ll Cal(int i , ll d , int len){
    if(i == len / 2)return (d == 0 ? ((len & 1) ? 10 : 1) : 0);
    ll tmp = p[len - i - 1] - p[i];
    ll tmp1 = d / tmp;
    ll ans = 0;
    if(tmp1 >= -9 && tmp1 <= 9)ans += Cal(i+1,d-tmp*tmp1,len) * (10 - abs(tmp1) - (i == 0));
    tmp1 += (d >= 0 ? 1 : -1);
    if(tmp1 >= -9 && tmp1 <= 9)ans += Cal(i+1,d-tmp*tmp1,len) * (10 - abs(tmp1) - (i == 0));
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w  ",stdout);
    }
    p[0] = 1;
    for(int i = 1 ; i <= 19 ; ++i)p[i] = p[i - 1] * 10;
    int d;cin >> d;
    for(int i = 1 ; i <= 18 ; ++i)ans += Cal(0,d,i);
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

template <typename T> void cmin(T &x, const T &y)
{
	if(y < x) x = y;
}

template <typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

ll pw10[19], D, ans;
int bit[19];

void dfs(int l, int r, ll d, ll way)
{
	if(l > r)
	{
		if(d == -D) ans += way;
	}
	else
	{
		if(l == r) dfs(l+1, r-1, d, way*10);
		else
		{
			for(int i=-9; i<=9; i++)
			{
				ll base = d+i*pw10[r]-i*pw10[l];
				ll upb = base + pw10[r];
				ll lob = base - pw10[r];
				if(lob<=-D && -D<=upb) bit[l] = i, dfs(l+1, r-1, base, way*(10-abs(i)-(i<=0&&l==0)));
			}
		}
	}
}

int main()
{
	read(D);
	pw10[0] = 1;
	for(int i=1; i<=18; i++) pw10[i] = pw10[i-1] * 10;
	for(int i=1; i<=18; i++) dfs(0, i, 0, 1);
	printf("%lld\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int h, w, n;
    cin >> h >> w >> n;
    int longer = max(h, w);
    if (n % longer == 0)
        cout << (n / longer) << endl;
    else
        cout << (n / longer + 1) << endl;
}

const int LG = 21;
const int FN = 400005;
const long long MOD = 998244353;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

const int N = 1100000;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for (int i = 0; i <= k; i++)
    {
        ll g = cnk(n - 1, i);
        ll fi = m * inq(m - 1, n - i - 1) % MOD;
        ans = (ans + g * fi) % MOD;
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


#include <iostream>
#include <atcoder/fenwicktree>

using namespace std;
using namespace atcoder;

int main() {
    int N,Q;
    cin >> N >> Q;
    fenwick_tree<long long int> fw(N);
    for(int i=0;i<N;i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }

    for(int i=0;i<Q;i++) {
        int t,c,d;
        cin >> t >> c >> d;
        if(t==0){
            fw.add(c, d);
        }else{
            cout << fw.sum(c, d) << endl;
        }
    }
}

#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <vector>
#define FOR(i,n) for(unsigned i=0; i<n; i++)

using namespace std;

typedef unsigned us;
typedef pair<us, us> point;

int main () {
    us V, E;
    cin >> V >> E;

    set<us> seen;
    seen.insert(0);
    map<us, vector<point> > graph;
    priority_queue<point, vector<point>, greater<point> > q;
    us distance = 0;

    FOR(_, E) {
        us s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back(make_pair(d, t));
        graph[t].push_back(make_pair(d, s));
        if (s == 0) q.push(make_pair(d, t));
        if (t == 0) q.push(make_pair(d, s));
    }

    while (!q.empty() && seen.size() != V) {
        point p = q.top();
        us v = p.second;
        us w = p.first;
        q.pop();

        if (seen.find(v) == seen.end()) {
            seen.insert(v);
            vector<point> neighbours = graph[v];
            FOR(i, neighbours.size()) q.push(neighbours[i]);
            distance += w;
        }
    }

    cout << distance << endl;

}


#include <iostream>
#define SIZE 8

void threaten(int board[][SIZE], int x, int y)
{
	for (int i=0; i<SIZE; i++) {
		board[i][y]++; board[x][i]++;
	}
	for (int i=-x; i<SIZE-x; i++) {
		if (0 <= y+i && y+i < SIZE) board[x+i][y+i]++;
		if (0 <= y-i && y-i < SIZE) board[x+i][y-i]++;
	}
	board[x][y]+=100;
}

void unthreaten(int board[][SIZE], int x, int y)
{
	for (int i=0; i<SIZE; i++) {
		board[i][y]--; board[x][i]--;
	}
	for (int i=-x; i<SIZE-x; i++) {
		if (0 <= y+i && y+i < SIZE) board[x+i][y+i]--;
		if (0 <= y-i && y-i < SIZE) board[x+i][y-i]--;
	}
	board[x][y]-=100;
}

bool solve(int board[][SIZE], int rest)
{
	if (rest==0) return true;

	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) {
			if (board[i][j]>0) continue;
			threaten(board, i, j);
			if (solve(board, rest-1)) return true;
			unthreaten(board, i, j);
		}
	}
	return false;
}

int main()
{
	int board[SIZE][SIZE];
	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) board[i][j] = 0;
	}

	int k; std::cin >> k;
	for (int i=0; i<k; i++) {
		int x, y;
		std::cin >> x >> y;
		threaten(board, x, y);
	}

	solve(board, SIZE-k);

	for (int i=0; i<SIZE; i++) {
		for (int j=0; j<SIZE; j++) {
			if (board[i][j] < 100) std::cout << ".";
			else std::cout << "Q";
		}
		std::cout << std::endl;
	}

	return 0;
}

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

int main(){

  int n;
  cin >> n;
  ll taka = 0,ao = 0;
  priority_queue<Pl> que;
  vector<Pl> v(n);
  rep(i,n){
    ll a,b;cin >> a >> b;
    que.push(make_pair(a+b,i));
    v[i] = make_pair(a,b);
  }
  rep(i,n){
    Pl k = que.top();que.pop();
    if(!(i & 1))taka += v[k.second].first;
    else ao += v[k.second].second;
  }
  cout << taka-ao << endl;

  return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll k;
	cin>>k;
	vector<ll> vl;
	string s = "~abcdefghijklmnopqrstuvwxyz";
	if(k<=26)
	{
		cout<<s[k]<<endl;
		return 0;
	}
	while(k>=26)
	{
		ll yu = k%26;
		k/=26;
		if(yu == 0)
		{
			yu = 26;
			k--;
		}
		vl.pb(yu);
	}
	if(k>0)
		vl.pb(k);
	reverse(all(vl));
	FOR(i,0,vl.size())
	{
		if(vl[i]>0)cout<<s[vl[i]];
		else cout<<"z";
	}
	cout<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for(ll i=(ll)a;i<=(ll)b;i++)
#define per(i, a, b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define N 2100
#define MAX 1234567890
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define MOD 1000000007

int main()
{
    fastio;

    ll n;
    cin >> n;
    string s = "";
    while(n > 26){
        ll rem = n % 26;
        if(rem == 0) {
            s += 'z';
            rem = 26;
        }
        else s += ('a' + rem - 1);
        n = (n - rem) / 26;
    }
    s += ('a' + n - 1);
    reverse(s.begin(), s.end());

    cout << s << endl;

    return 0;
}


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

using namespace std;

map< int, set<int> > Init(int);
set<int> FindFriends(map< int, set<int> >);

int main(){
  int i, n, m, a, b;
  set<int> friends;
  map< int, set<int> > data;

  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    data = Init(n);

    for(i=0; i<m; ++i){
      cin >> a >> b;
      data[a].insert(b);
      data[b].insert(a);
    }
    friends = FindFriends(data);
    cout << friends.size() << endl;
  }
  return 0;
}

map< int, set<int> > Init(int n){
  int i;
  set<int> _data;
  map< int, set<int> > data;
  for(i=1; i<=n; ++i) data.insert(make_pair(i, _data));
  return data;
}

set<int> FindFriends(map< int, set<int> > data){
  set<int> _data, friends;
  set<int>::iterator i, j;
  map< int, set<int> >::iterator k;
  _data = data[1];
  for(i=_data.begin(); i!=_data.end(); ++i){
    if(friends.find(*i) == friends.end())
      friends.insert(*i);
    k = data.find(*i);
    for(j=k->second.begin(); j!=k->second.end(); ++j){
      if(*j != 1 && friends.find(*j) == friends.end())
	friends.insert(*j);
    }
  }
  return friends;
}

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int n, m, **a, s, t, c, *b;

	while(1){
		cin >> n;
		cin >> m;
		if(n == 0 && m == 0){
			break;
		}
		c = 0;
		a = (int **)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		for(int i = 0; i <= n; i++){
			a[i] = (int *)calloc(n+1, sizeof(int));
		}

		for(int i = 0; i < m; i++){
			cin >> s >> t;
			if(s == 1 || t == 1){
				a[s][t] = a[t][s] = 1;
				b[t] = b[s] = 1;
			} else {
				a[s][t] = a[t][s] = 2;
			}
		}

		for(int i = 2; i <= n; i++){
			if(a[1][i] == 1){
				for(int j = 2; j <= n; j++){
					if(a[i][j] == 2 && b[j] == 0){
						b[j] = 1;
					}
				}
			}
		}
		b[1] = 0;
		for(int i = 0; i <= n; i++){
			free(a[i]);
			c += b[i];
		}
		free(a);
		free(b);

		cout << c << endl;
	}

	return 0;
}


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

int main() {
  int n,m,x,y,flg = 0;
  cin >> n >> m >> x >> y;
  vector<int> X(n), Y(m);

  rep(i,n) cin >> X[i];
  rep(i,m) cin >> Y[i];

  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());

  for (int i = x+1; i <= y; i++) {
    if (X[n-1] < i && i <= Y[0]) {
      flg = 1;
      break;
    }
  }
  if (flg) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}


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

int main(){
	int n; cin>>n;
	for(int i=n; i>0; i--){
		double r=sqrt(i);
		if(r==(int)r) {cout<<i<<endl; return 0;}
	}
}

#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<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
using namespace std;

int Getinput(){
    string s; cin >> s;
    if(s == "Vacant") return 0;
    else if(s == "Male") return 1;
    else if(s == "Female") return 2;
}
int main(){
    int N; cin >> N;

    cout << N - 1 << endl;
    if(Getinput() == 0){
        return 0;
    }
    cout << 0 << endl;
    int x = Getinput();
    if(x == 0){
        return 0;
    }

    int low = 0,high = N - 1;
    int stnd = x;

    while(high - low > 2){
        int mid = (high + low) / 2;
        if(mid % 2 == 1) mid--;

        cout << mid << endl;
        int y = Getinput();
        if(y == 0){
            return 0;
        }else if(stnd == y){
            low = mid;
        }else{
            high = mid;
        }
    }

    cout << low + 1 << endl;
    int z = Getinput();
    return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string s, t, u; int n, a, b;
int main() {
	cin >> s >> n;
	for(int i = 0; i < n; i++) {
		cin >> t;
		if(t == "print") cin >> a >> b, cout << s.substr(a, b - a + 1) << endl;
		if(t == "reverse") cin >> a >> b, reverse(s.begin() + a, s.begin() + b + 1);
		if(t == "replace") cin >> a >> b >> u, s.replace(a, b - a + 1, u);
	}
	return 0;
}

#include <bits/stdc++.h>
#include<string>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define len(s) s.length()
#define all(v) v.begin(),v.end()
const ll INF = LONG_MAX;
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

ld dp[15][15];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);

	ll tc = 1;
	// cin >> tc;

	while (tc--) {

		ll m;
		ll i, j;

		ll n;
		ll k;
		ll h1, m1, h2, m2;
		cin >> h1 >> m1 >> h2 >> m2 >> k;

		ll ans = (h2 * 60 + m2 - (h1 * 60 + m1) - k);

		cout << ans << endl;

	}
}


#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,p,a,b,c,d,e,f,m,s;
	char l[32];
	pair<double,string>A[50];
	while(scanf("%d",&n),n)
	{
		for(i=0;i<n;++i)
		{
			scanf("%s%d%d%d%d%d%d%d%d%d",l,&p,&a,&b,&c,&d,&e,&f,&s,&m);
			A[i].second=l;
			A[i].first=-(f*s*m-p)/double(a+b+c+m*(d+e));
		}
		sort(A,A+n);
		for(i=0;i<n;++i)puts(A[i].second.c_str());
		puts("#");
	}
	return 0;
}

#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  /*
  cout<< ("onion">"potato") <<endl;

  return 0;
  */
  int h,i,j;
  int y[50],z[50],n,p,a,b,c,d,e,f,s,m;
  string l[50];
  while(cin>>n&&n){
    for(i=0;i<n;i++){
      cin>>l[i]>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      y[i]=f*s*m-p;
      z[i]=a+b+c+(d+e)*m;
    }
    h=1;
    for(i=0;h;i++){
      h=0;
      for(j=1;j<n-i;j++){
	if(y[j-1]*z[j]<y[j]*z[j-1]){
	  swap(y[j-1],y[j]);
	  swap(z[j-1],z[j]);
	  swap(l[j-1],l[j]);
	  h=1;
	}else if(y[j-1]*z[j]==y[j]*z[j-1]){
	  if(l[j-1]>l[j]){
	    swap(y[j-1],y[j]);
	    swap(z[j-1],z[j]);
	    swap(l[j-1],l[j]);
	    h=1;
	  }
	}
      }
    }
    for(i=0;i<n;i++)
      cout<<l[i]<<endl;
    cout<<"#"<<endl;
  }
  return 0;
}


#include <iostream>
using namespace std;

long long sum(int size,int ary[]);
int min(int size,int ary[]);
int max(int size,int ary[]);
int main(){
	int size=0;
	cin >>size;
	int nums[size];
	for(int i=0;i<size;i++){
		cin >> nums[i];
	}

	int a=0,b=0;
	long long c=0;
	a=min(size,nums);
	b=max(size,nums);
	c=sum(size,nums);
	cout <<a<<" "<<b<<" "<<c<<endl;

	return 0;
}

long long sum(int size,int ary[]){
	long long ret=0;
	for(int i=0;i<size;i++){
		ret +=ary[i];
	}
	return ret;
}

int min(int size,int ary[]){
	int ret=ary[0];
	for(int i=1;i<size;i++){
		if(ary[i]<ret) ret = ary[i];
	}
	return ret;
}

int max(int size,int ary[]){
	int ret=ary[0];
	for(int i=1;i<size;i++){
		if(ary[i]>ret) ret = ary[i];
	}
	return ret;
}

#include <bits/stdc++.h>
#define TOP 0
#define FRONT 1
#define LEFT 2
#define RIGHT 3
#define BACK 4
#define BOTTOM 5
using namespace std;

//TOP,FRONT,LEFT,RIGHT,BACK,BOTTOM
int dice[6]={1,2,4,3,5,6};

//?\\?????¢??????
void rotN(){
  swap(dice[TOP],dice[FRONT]);
  swap(dice[FRONT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[BACK]);
}

//???????????¢??????
void rotS(){
  //rotN(),rotN(),rotN();
  swap(dice[TOP],dice[BACK]);
  swap(dice[BACK],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[FRONT]);
}

//????????¢??????
void rotE(){
  swap(dice[TOP],dice[LEFT]);
  swap(dice[LEFT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[RIGHT]);
}

//????????¢??????
void rotW(){
  //rotE(),rotE(),rotE();
  swap(dice[TOP],dice[RIGHT]);
  swap(dice[RIGHT],dice[BOTTOM]);
  swap(dice[BOTTOM],dice[LEFT]);
}

//???????????????????¨????????????????
void rotCW(){
  swap(dice[FRONT],dice[RIGHT]);
  swap(dice[RIGHT],dice[BACK]);
  swap(dice[BACK],dice[LEFT]);
}

//??????????????????????¨???????????????????
void rotCCW(){rotCW(),rotCW(),rotCW();}

int main(){
  cin>>dice[TOP]>>dice[FRONT]>>dice[RIGHT];
  cin>>dice[LEFT]>>dice[BACK]>>dice[BOTTOM];

  string str;
  cin>>str;
  for(int i=0;i<str.size();i++){
    if(str[i]=='N') rotN();
    if(str[i]=='S') rotS();
    if(str[i]=='E') rotE();
    if(str[i]=='W') rotW();
  }

  cout << dice[TOP]<<endl;

}


#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, k;
	cin >> n >> k;

	if( n % k == 0 ) cout << 0 << endl;
	else cout << 1 << endl;

	return 0;
}

#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#define endl "\n"
using namespace std;

void solve()
{   int x,y; cin >> x >> y;
    cout << x*y;
}

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


#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

int SolveMaxRectangle(const vector<int>& input_xs, int w) {
  vector<int> xs(input_xs.begin(), input_xs.end());
  xs.push_back(0);

  int max = w;
  stack<pair<int, int>> stack;
  for (int i = 0; i < xs.size(); i++) {
    if (stack.empty()) {
      stack.push(make_pair(xs[i], i));
    } else {
      if (xs[i] >= stack.top().first) {
        stack.push(make_pair(xs[i], i));
      } else {
        int push_index = i;
        while (!stack.empty() && xs[i] < stack.top().first) {
          int r_width = i - stack.top().second + 1;
          int r_area = r_width * stack.top().first;
          UpdateMax(max, r_area);
          push_index = stack.top().second;
          // if (DEBUG) {
          //   cout << "i: " << i << endl;
          //   cout << "stack.top().second: " << stack.top().second << endl;
          //   cout << "v: " << stack.top().first << endl;
          //   cout << "r_area: " << r_area << endl;
          // }
          stack.pop();
        }

        stack.push(make_pair(xs[i], push_index));
      }
    }
  }
  return max;
}

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

  int h, w;
  cin >> h >> w;
  vector<string> board(h);
  for (int r = 0; r < h; r++) {
    cin >> board[r];
  }

  vector<vector<int>> dp1 = Make2DVector(h - 1, w, -1);
  for (int r = 0; r < h - 1; r++) {
    int current = -1;
    for (int c = w - 1; c >= 0; c--) {
      if (c == w - 1) {
        current = board[r][c] == board[r + 1][c];
        dp1[r][c] = 1;
      } else {
        if ((board[r][c] == board[r + 1][c]) == current) {
          dp1[r][c] = dp1[r][c + 1] + 1;
        } else {
          current = board[r][c] == board[r + 1][c];
          dp1[r][c] = 1;
        }
      }
    }
  }

  if (DEBUG) {
    for (int r = 0; r < h - 1; r++) {
      cout << "dp1[" << r << "]: " << dp1[r] << endl;
    }
  }

  int ans = 0;
  for (int c = 0; c < w; c++) {
    vector<int> xs(h - 1);
    for (int r = 0; r < h - 1; r++) {
      xs[r] = dp1[r][c];
    }
    if (DEBUG) {
      cout << "SolveMaxRectangle(" << c << ")" << endl;
      cout << "xs: " << xs << endl;
    }
    int max_rectanle = SolveMaxRectangle(xs, w - c);
    if (DEBUG) cout << "c: " << c << " max_rectangle: " << max_rectanle << endl;
    UpdateMax(ans, max_rectanle);
  }
  cout << ans << endl;
}

/*
Writer: SPD_9X2
https://atcoder.jp/contests/arc081/tasks/arc081_d

長方形にできる必要十分条件は、
内側にある四つ角の周り全てに関して、周りにある黒が偶数個
→そのような条件を満たす四つ角グリッドを考えると最大長方形になる

幅1の長方形に関しては全て作れるので、ans初期値はmax(H,W)
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;
const ll half = 500000004;

int LRIH(vector<int>& lis){

    vector<vector<int>> stk(0);

    int ans = 0;
    int N = lis.size();

    rep(i,0,N){

        if (stk.size() == 0){
            stk.push_back({lis[i],i});
        }else if (stk[stk.size()-1][0] < lis[i]){
            stk.push_back({lis[i],i});
        }else if (stk[stk.size()-1][0] > lis[i]){

            int lastpos = -1;

            while ( (stk.size()>0) && (stk[stk.size()-1][0] > lis[i])){

                int nh = stk[stk.size()-1][0];
                int np = stk[stk.size()-1][1];
                lastpos = np;
                stk.pop_back();

                ans = max(ans , (nh+1)*(i-np+1));
            }

            stk.push_back({lis[i] , lastpos});
        }
    }

    return ans;
}

int main(){

    int H,W;
    cin >> H >> W;

    vector<vector<char>> S(H,vector<char> (W));
    rep(i,0,H){
        rep(j,0,W){
            cin >> S[i][j];
        }
    }

    vector<vector<int>> lis(H-1,vector<int> (W-1,0));

    rep(i,0,H-1){
        rep(j,0,W-1){
            if (S[i][j] == '#') lis[i][j] += 1;
            if (S[i+1][j] == '#') lis[i][j] += 1;
            if (S[i][j+1] == '#') lis[i][j] += 1;
            if (S[i+1][j+1] == '#') lis[i][j] += 1;
            lis[i][j] %= 2;
        }
    }

    vector<vector<int>> hist(H-1,vector<int> (W,0));

    rep(i,0,H-1){
        rep(j,0,W-1){

            if (lis[i][j] == 0){
                if (i==0){
                    hist[i][j] = 1;
                }else{
                    hist[i][j] = hist[i-1][j] + 1;
                }
            }

        }
    }

    int ans = max(H,W);
    rep(i,0,H-1){
        ans = max(ans , LRIH(hist[i]));
    }

    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>

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

const int N(100010);
int a[N], cnt[2], n;

void trans()
{
	for (int i = 1; i <= n; i++) if (a[i] & 1) --a[i]; int g = a[1];
	for (int i = 2; i <= n; i++) g = std::__gcd(g, a[i]);
	for (int i = 1; i <= n; i++) a[i] /= g;
}

int check()
{
	cnt[0] = cnt[1] = 0;
	for (int i = 1; i <= n; i++) ++cnt[a[i] & 1];
	if (cnt[0] & 1) return 1; else if (cnt[1] > 1) return 0;
	else
	{
		for (int i = 1; i <= n; i++) if (a[i] == 1) return cnt[0] & 1;
		return trans(), check() ^ 1;
	}
}

int main()
{
	n = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	puts(check() ? "First" : "Second");
	return 0;
}

#include <iostream>
#include <string>

using namespace std;

string line;
int str_len;

bool is_finish() {
  for(int i=0; i<str_len-3; i++) {
    if(line[i] == 't') {
      if(line[i+1] == 'h') {
        if(line[i+2] == 'e') { return true; }
        else if(line[i+2] == 'i' && line[i+3] == 's') { return true; }
        else if(line[i+2] == 'a' && line[i+3] == 't') { return true; }
      }
    }
  }
  return false;
};

int main() {
  while(getline(cin, line)) {
    str_len = line.length();

    for(int j=0; j<26; j++) {
      if(is_finish()) {
        cout << line << endl;
        break;
      }

      for(int j=0; j<str_len; j++) {
        if('a' <= line[j] && line[j] < 'z') {
          line[j] += 1;
        }
        else if(line[j] == 'z') {
          line[j] = 'a';
        }
      }
    }
  }
  return 0;
}


#include<iostream>
using namespace std;

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

    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];

    for(int i=n-1;i>=0;i--) {
        if(i==0)cout<<a[i];
        else cout<<a[i]<<' ';
    }
    cout<<endl;
}

#include <cstdio>
//#include <iostream>
//#include <string>

using namespace std;

// cl /EHsc xxx.cpp
int main(int argc, char *argv[])
{
	int n;
	scanf("%d", &n);

	int *ary = new int[n];

	int v;
	int t = n;
	while (t)
	{
		scanf("%d", &v);
		ary[--t] = v;
	}

	for (int j = 0; j < n; j++)
	{
		if (j == n-1)
		{
			printf("%d", ary[j]);
		}
		else
		{
			printf("%d ", ary[j]);
		}

	}
	printf("\n");

	delete[] ary;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
	long long v, a, b, c, d, e;
	cin >> v >> a >> b >> c >> d >> e;
	long long slow = min({a, b, c, d, e});
	cout << (v + slow-1)/ slow + 4;
	return 0;
}

#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

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

const ll MOD = 1e9 + 7;
//最大公約数
ll gcd(ll a, ll b){
  if(b == 0)return a;
  else return gcd(b, a % b);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(5);
    ll m = INF * INF;
    rep(i, 5){
        cin >> a[i];
        chmin(m, a[i]);
    }
    ll res = (n + m - 1) / m + 4;
    cout << res << endl;
}