#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

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

    return 0;

}

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

int main() {
  int n,N,r,s=0;
  cin>>n;
  N=n;
  while(n>0){
    r=n%10;
    s+=r;
    n/=10;
  }
  if(N%s==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int h, w, n;
    cin >> h >> w >> n;

    int div = n / max(h, w);
    int rem = n % max(h, w);

    if (rem) cout << div + 1 << '\n';
    else cout << div << '\n';
    return 0;
}

#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int sx, sy;
    int tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string res;

    int x = tx - sx;
    int y = ty - sy;

    res += string(y, 'U');
    res += string(x, 'R');
    res += string(y, 'D');
    res += string(x, 'L');
    res += 'L';
    res += string(y + 1, 'U');
    res += string(x + 1, 'R');
    res += 'D';
    res += 'R';
    res += string(y + 1, 'D');
    res += string(x + 1, 'L');
    res += 'U';

    // cout << res.length() << endl;
    cout << res << '\n';

    return 0;
}


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

int main()
{
  int sum = 0;
  int a, b, m = 101;

  for (int i = 0; i < 4; i++){
    cin >> a;
    m = min(a, m);
    sum += a;
  }

  sum -= m;

  cin >> a >> b;

  sum += max(a, b);

  cout << sum << endl;
}

#include <iostream>
using namespace std;

int main() {
    double now, next;
    cin >> now >> next;
    cout << next*2 - now << endl;
}


#include <iostream>
using namespace std ;

int main()
{
	int get ;
	cin >> get ;
	cout << (get*get*get) << endl ;
}

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

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

  int FB, F, B;
  FB = N / 15;
  F = N / 3;
  B = N / 5;

  long long ans = 0;

  for(int i = 1; i <= N; i++) {
    ans += i;
  }

  for(int i =1 ; i <= F; i++) {
    ans -= i*3;
  }

  for(int i =1 ; i <= B; i++) {
    ans -= i*5;
  }

  for(int i =1 ; i <= FB; i++) {
    ans += i*15;
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n;
ll Xor, c[N];
ll a[63], b[63];
int tot;
void insert(ll x)
{
	for(int i=62;~i;i--)
	{
		if((x>>i)&1)
		{
			if(!a[i])
			{
				a[i] = x;
				break;
			}
			x ^= a[i];
		}
	}
}
ll Max(ll x)
{
	ll ans = x;
	for(int i=62;~i;i--)
		ans = max(ans,ans^a[i]);
	return ans;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++)
 	{
 		cin >> c[i];
 		Xor ^= c[i];
 	}
 	for(int i=1; i<=n; i++)
 		insert((c[i]&(~Xor)));
 	ll A = Max(0);
 	ll B = Xor^A;
 	ll ans = A + B;
 	cout << ans;
	return 0;
}

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

typedef uint64_t ull;
typedef  int64_t sll;

static const ull MOD = 1000000007LL;

int n;
int k;
int q;

ull a[200019];

ull umin (ull a, ull b) {
	return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
	return (a > b) ? a : b;
}

ull solve () {
	sll i, j, ki;
	ull res = 0;

	ull allxor = 0;
	for (i = 0; i < n; i++) {
		allxor ^= a[i];
	}
	for (i = 0; i < n; i++) {
		a[i] &= ~allxor;
	}

	ull rank = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < n; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == n) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < n; j++) {
			a[j] = umin(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ull x = 0;
	for (i = 0; i < n; i++) {
		x = umax(x, x ^ a[i]);
	}

	res = (x * 2) + allxor;

	return res;
}

int main(void){

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

	printf("%lld\n", solve());

	return 0;
}


#include <stdio.h>

int main(){
	int a, b, c, d;
	int K;
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &K);
	int diff1 = c - a;
	int diff2 = d - b;
	int min = (diff1 * 60) + diff2;
	printf("%d", min - K);

	return 0;
}

#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    vector<string> deck;
    string s;
    for(int i = 0; i < 3; i++) {
        cin >> s;
        reverse(s.begin(), s.end());
        deck.push_back(s);
    }
    int idx = 0, nxt = 0;
    while(!deck[idx].empty()) {
        nxt = deck[idx].back()-'a';
        deck[idx].pop_back();
        idx = nxt;
        // cout << idx << endl;
    }
    cout << char('A'+idx) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main() {
  int H,W,ans=0; cin>>H>>W;
  vector<vector<char>> S(H,vector<char>(W));
  queue<pair<int,int>> Q;
  vector<vector<bool>> seen(H,vector<bool>(W,false));
  rep(i,H){
    rep(j,W){
      cin>>S.at(i).at(j);
      if(S.at(i).at(j)=='#'){
        Q.push(make_pair(i,j));
        seen[i][j]=true;
      }
    }
  }
  Q.push(make_pair(-1,-1));
  while(!Q.empty()){
    int x=Q.front().first,y=Q.front().second;
    Q.pop();
    if(x==-1&&y==-1){
      if(Q.empty())continue;
      ans++;
      Q.push(make_pair(-1,-1));
      continue;
    }
    rep(j,4){
      int nx=x+dx[j],ny=y+dy[j];
      if(nx<0 || nx>= H || ny<0 || ny>=W) continue;
      if(seen[nx][ny]==false){
      Q.push(make_pair(nx,ny));
      seen[nx][ny]=true;
      }
    }
  }
  cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int H, W, ans=1; cin >> H >> W; string A[H];
REP(i, H){ cin >> A[i]; }
int B[H][W]={}; vector< pair<int, int> > C;
REP(i, H){ REP(j, W){
  if(A[i][j]=='#'){  B[i][j]=1; C.push_back(make_pair(i, j)); }
} }
REP(i, H*W){
if((int)C.size()==H*W){ cout << ans-1 << "\n"; return 0; }
int a=C[i].first, b=C[i].second, c=B[a][b]+1;
if(a>0&&!B[a-1][b]){ B[a-1][b]=c; C.push_back(make_pair(a-1, b)); }
if(b>0&&!B[a][b-1]){ B[a][b-1]=c; C.push_back(make_pair(a, b-1)); }
if(a<H-1&&!B[a+1][b]){ B[a+1][b]=c; C.push_back(make_pair(a+1, b)); }
if(b<W-1&&!B[a][b+1]){ B[a][b+1]=c; C.push_back(make_pair(a, b+1)); }
ans=c;
}
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

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

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    Vl cum(N + 1);
    for (ll i = 0; i < N; i++) {
        cum[i + 1] = cum[i] + A[i];
    }
    ll ans = L_INF;
    ll idx1 = 1, idx2 = 3;
    for (ll i = 2; i < N - 1; i++) {
        while (idx1 < i && cum[idx1] < cum[i] - cum[idx1]) {
            ++idx1;
        }
        while (idx2 < N - 1 && cum[idx2] - cum[i] < cum[N] - cum[idx2]) {
            ++idx2;
        }
        ll p1 = cum[idx1 - 1];
        ll p2 = cum[idx1];
        ll q1 = cum[i] - cum[idx1 - 1];
        ll q2 = cum[i] - cum[idx1];
        ll r1 = cum[idx2 - 1] - cum[i];
        ll r2 = cum[idx2] - cum[i];
        ll s1 = cum[N] - cum[idx2 - 1];
        ll s2 = cum[N] - cum[idx2];
        ll t = L_INF;
        t = min(t, max({p1, q1, r1, s1}) - min({p1, q1, r1, s1}));
        t = min(t, max({p2, q2, r1, s1}) - min({p2, q2, r1, s1}));
        t = min(t, max({p1, q1, r2, s2}) - min({p1, q1, r2, s2}));
        t = min(t, max({p2, q2, r2, s2}) - min({p2, q2, r2, s2}));
        ans = min(ans, t);
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
template <class 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, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,q;
	string s;
//	int ans=0;
	int k;
	cin >>n>>s>>q;
	V data(2);//d,dm
	Vi sum(s.size()+1, 0);
	rep(i, s.size()) {
		sum[i] += (s[i] == 'M');
	if(i!=0){
		sum[i] += sum[i - 1];
	}
	}
//	clog << sum << endl;
	ll ans = 0LL;
	rep(i, q) {
		cin >> k;
		ans = 0LL;
		data[0] = 0LL;
		data[1] = 0LL;
		rep(i,s.size()){
			if (i >= k) {
				if (s[i - k] == 'D') {
					data[0]--;
					data[1] -= sum[i-1] - sum[i - k];

				}
			//	clog << "(" << s[i - k] << ") ";
			}
			switch (s[i])
			{
			case 'D':
				data[0]++;
				break;

			case 'M':
				data[1] += data[0];
				break;
			case 'C':
				ans += data[1];
				break;
			}

		//	clog << data << " "<<s[i]<<endl;
		}
		cout << ans << endl;
	}

}


#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;
int cnt = 0;

vector<int> insertion_sort(vector<int> a, int n, int g) {

    for(int i=g; i<n; i++){
        int key = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > key){
            a[j+g] = a[j];
            j -= g;
            cnt++;
        }
        a[j+g] = key;
    }
    return a;
}

vector<int> shell_sort(vector<int> a, int n){
    cnt = 0;
    int m = 11;
    int mm = m;
    int g[] = {1, 2, 8, 32, 128, 512, 2048, 2048*4, 2048*16, 2048*64, 2048*256};
    REP(i, m){
        if(g[m-1-i] > n)
            mm--;
    }
    cout << mm << endl;
    REP(i, mm-1){
        cout << g[mm-1-i] << " ";
        a = insertion_sort(a, n, g[mm-1-i]);
    }
    cout << g[0] << endl;
    a = insertion_sort(a, n, g[0]);

    return a;

}
/*
vector<string> selection_sort(vector<string> s){
    int n = s.size();
    vector<int> a;
    REP(i, n)
        a.push_back(atoi(s[i].substr(1, 1).c_str()));

    REP(i, n){
        int mini = i;
        for(int j = i; j < n ; j++){
            if(a[j] < a[mini])
                mini = j;
        }
        if(i != mini){
            swap(a[i], a[mini]);
            swap(s[i], s[mini]);
        }
    }
    return s;
}

vector<string> bubble_sort(vector<string> s) {
    int n = s.size();
    vector<int> a;
    REP(i, n)
        a.push_back(atoi(s[i].substr(1, 1).c_str()));

    REP(i, n)
        for(int j = n - 1; j > i; j--)
            if(a[j] < a[j-1]){
                swap(a[j], a[j-1]);
                swap(s[j], s[j-1]);
            }

    return s;
}

int find(vector<string> target, string query){
    int i = 0;
    vector<string>::iterator iter = target.begin();
    while(iter != target.end()){
        if (*iter == query)
            break;
        i++;
        iter++;
    }

    return i;
}
*/

int main() {
    int n;
    cin >> n;
    int in[n];
    vector<int> a;
    REP(i, n) { cin >> in[i]; a.push_back(in[i]);}
    a = shell_sort(a, n);
    cout << cnt << endl;
    REP(i, n)
        cout << a[i] << endl;

    return 0;
}

#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int cnt, m;
vi G;

void insertionSort(vi& A, int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(vi& A, int n) {
  cnt = 0;
  G = vi(0);
  int g = 1;
  do {
    G.pb(g);
    g = g*3 + 1;
  } while (g <= n);
  reverse(all(G));
  m = sz(G);
  for (auto& g:G) {
    insertionSort(A, n, g);
  }
}

void dump(vi& A, const string& sep) {
  string sp = "";
  for (auto& a:A) {
    cout << sp << a;
    sp = sep;
  }
  cout << endl;
}

int main(int argc, char **argv)
{
  vi A;
  int n;
  cin >> n;
  A = vi(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  shellSort(A, n);

  cout << m << endl;
  dump(G, " ");
  cout << cnt << endl;
  dump(A, "\n");
  return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,a,b,i;
    cin>>n;
    vector<pair<pair<int,int>,int>> pts;
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        pts.pb(mp(mp(a,b),0));
    }
    for (i=0;i<n;i++)
    {
        cin>>a>>b;
        pts.pb(mp(mp(a,b),1));
    }
    sort(pts.begin(),pts.end());
    set<pair<int,int>> s;
    int ans=0,mark[2*n]={0};
    for (i=0;i<2*n;i++)
    {
        if (pts[i].ss==0)
            s.insert(mp(pts[i].ff.ss,i));
        else
        {
            int choose=-1;
            for (auto e: s)
            {
                if (e.ff<pts[i].ff.ss && mark[e.ss]==0)
                    choose=e.ss;
            }
            if (choose!=-1)
            {
                ans++;
                mark[i]=1;
                mark[choose]=1;
            }
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int m;
    cin >> m;
    vector<P> v(m);
    for (P &p:v)cin >> p.first >> p.second;

    ll n = 0, s = 0;
    for (P p : v) n += p.second;
    for (P p : v) s += (p.first * p.second);

    ll start = 9 * n + s;
    ll fin = s % 9;
    if (fin == 0) fin += 9;

    ll ans = (start - fin) / 9 - 1;
    cout << ans << endl;

}


#include <iostream>
using namespace std;

int main(){
    int n;
    while( cin >> n, n ){
        int pm, pe, pj;
        while( n-- > 0 ){
            cin >> pm >> pe >> pj;
            if( pm == 100 || pe == 100 || pj == 100 ||
                (pm+pe)/2 >= 90 || (pm+pe+pj)/3 >= 80 ){
                cout << 'A' << endl;
            }else if( (pm+pe+pj)/3 >= 70 || ((pm+pe+pj)/3 >= 50 && (pm >= 80 ||pe >=80))){
                cout << 'B' << endl;
            }else{
                cout << 'C' << endl;
            }
        }
    }
    return 0;
}

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

const int N = 5e3 + 11;
int a[N];

int main() {
	ios :: sync_with_stdio(false);
	int n;
	while(cin >> n) {
		if(n == 0) break;
		for(int i = 0; i < n; i ++)
			cin >> a[i];
		int ans = a[0], pre = min(a[0], 0);
		for(int i = 1; i < n; i ++) {
			a[i] += a[i - 1];
			ans = max(ans, a[i] - pre);
			pre = min(pre, a[i]);
		}
		cout << ans << '\n';
	}
	return 0;
}


#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

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

// 約数の列挙
vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }
    return res;
}

int main(){
  ll N;cin>>N;
  ll a,b;cin>>a>>b;
  ll c;
  if(N==2){
    c = gcd(a,b);
  }
  else{
    c = gcd(a, gcd(b,c));
  }

  vector<ll> v = divisor(c);
  sort(v.begin(),v.end());
  rep(i,v.size()){
    cout<<v[i]<<endl;
  }

}

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a,b,c = 100000001;
  if(n == 2)cin >> a >> b;
  if(n == 3)cin >> a >> b >> c;
  int mn = min(a,min(b,c));
  if(n == 2)c = 0;
  for(int i = 1 ; i <= mn ; i++ ){
    if(a%i == 0 && b%i == 0 && c%i == 0)cout << i << endl;
  }
  return 0;
}


#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 n, k;
    cin >> n >> k;
    vector<int> v(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    if (k > *max_element(v.begin(), v.end())) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int g = v[0];
    int flag = 0;
    for (int i = 1; i < n; i++) {
        g = gcd(g, v[i]);
        if (v[i] == k) flag = 1;
    }
    if (abs(v[0] - k) % g == 0) flag = 1;
    if (flag) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}

#include<bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int N;
  cin >> N;
  vpr L, R;
  vector<string> vec(N);
  rep(i, N) {
    string s;
    cin >> s;
    vec[i] = s;
    int sz = s.size();
    int maxl = 0, maxr = 0, l = 0, r = 0;
    rep(j, sz) {
      if(s[j] == ')') l++;
      else l--;
      chmax(maxl, l);
      if(s[sz-j-1] == '(') r++;
      else r--;
      chmax(maxr, r);
    }
    if(maxl <= maxr) L.push_back(make_pair(maxl, i));
    else R.push_back(make_pair(maxr, i));
  }
  sort(ALL(L), less<pair<ll, ll>>());
  sort(ALL(R), greater<pair<ll, ll>>());
  copy(ALL(R), back_inserter(L));
  int cnt = 0;
  for(auto& l : L) {
    int sz = vec[l.second].size();
    rep(j, sz) {
      if(vec[l.second][j] == '(') cnt++;
      else cnt--;
      if(cnt < 0) {
        cout << "No\n";
        return;
      }
    }
  }
  if(cnt == 0) cout << "Yes\n";
  else cout << "No\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int N; cin >> N;
    vector<vector<int>> A(N,vector<int>(N-1));
    rep(i,N){
        rep(j,N-1){
            cin >> A[i][j];
            A[i][j]--;
        }

        // vectorは末尾の削除は早いが、先頭は遅いのでreverse
        reverse(A[i].begin(), A[i].end());
    }

    vector<pair<int,int>> q;
    // 試合を登録
    auto check = [&](int i){
        if (A[i].size() == 0) return;
        int j = A[i].back();
        if (A[j].size() == 0) return;
        if (A[j].back() == i){
            P p(i,j);
            if (p.second < p.first) swap(p.first, p.second);
            q.push_back(p);
        }
    };
    rep(i,N){
        check(i);
    }
    int day = 0;
    while (q.size() > 0){
        day++;
        // 重複を削除する前準備としてソートしておく。
        sort(q.begin(), q.end());
        // 重複を削除
        q.erase(unique(q.begin(),q.end()), q.end());
        vector<pair<int,int>> prevQ;

        // prevQにqを入れて, qを空にする。
        // vectorのswapは早い
        swap(prevQ, q);

        for (auto p : prevQ){
            int i = p.first, j = p.second;
            // 試合を行う。
            // pop_back()は末尾の要素の削除
            A[i].pop_back();
            A[j].pop_back();
        }
        // 翌日の試合を登録
        for (auto p : prevQ){
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }

    rep(i,N){
        // 試合が残ってしまったら-1
        if (A[i].size() != 0){
            puts("-1");
            return 0;
        }
    }

    cout << day << endl;

}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

ll n;
vector<vector<ll>> graph(1000*1000);
vector<ll> vdist(1000*1000,-1);
vector<ll> seen(1000*1000,-1);

ll dfs(ll now)
{
    if(seen.at(now) == 2) return vdist.at(now);
    seen.at(now) = 1;
    ll tmp = 0;
    for(auto next:graph.at(now)){
        if(seen.at(next) == 1){
            cout << -1 << endl;
            exit(0);
        }
        tmp = max(tmp, dfs(next)+1);
    }
    seen.at(now) = 2;
    return vdist.at(now) = tmp;
}

int main()
{
    ll i,j;
    cin >> n;
    for(i = 0;i < n;++i){
        ll p = 0;
        rep(j,n-1){
            ll k;
            cin >> k;
            --k;
            ll ni = min(i,k);
            ll nj = max(i,k);
            ll next = ni*n + nj;
            graph.at(p).push_back(next);
            p = next;
        }
    }
    vdist.at(0) = 0;
    dfs(0);
    cout << vdist.at(0) << endl;
    return 0;
}


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

int main() {
  int N,i,j,k,ans=0;
  cin>>N;
  vector<int> L(N);
  for (i=0;i<N;i++) cin>>L[i];
  for (i=0;i<N-2;i++) {
    for (j=i+1;j<N-1;j++) {
      if (L[i]==L[j]) continue;
      for (k=j+1;k<N;k++) {
        if (L[i]==L[k] || L[j]==L[k]) continue;
        if (L[i] < L[j]+L[k] && L[j] < L[i]+L[k] && L[k] < L[j]+L[i]) ans++;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
N=1000ならN*Nで順番付けできそう
違うかな
BFSみたいな

1-2
2-1ならOK

1-2
2-3
3-2
ならOK

みたいな
先頭同士でペアが作れるかどうか

a<bでpair{a,b}を格納して、ペアになったらOKとか
TLEなんだが
N^3になるのか
マッチしたやつだけ再検査すればいいのかな
毎回入れなおしがきつい
*/
int main(){
  ll N; cin>>N;
  ll end=N*(N-1);
  end/=2;
  vector<queue<ll>> Q(N+1);
  queue<pair<ll,ll>> next_Q;
  for(ll i=1; i<=N; i++){
    for(ll j=1; j<N; j++){
      ll a; cin>>a;
      Q[i].emplace(a);
    }
  }
  ll day=1,cnt=0;
  //初期
  for(ll i=1; i<=N; i++){
    ll a=i, b=Q[i].front();
    if(a>b) swap(a,b);
    next_Q.push({a,b});
  }
  set<pair<ll,ll>> S;
  while(!next_Q.empty()){
//cout<<"day:"<<day<<" cnt:"<<cnt<<endl;
    ll Qsz=next_Q.size();
//cout<<"Qsz:"<<Qsz<<endl;
    for(ll i=0; i<Qsz; i++){
      auto n=next_Q.front();
      ll n1=n.first, n2=n.second;
//cout<<"n1:"<<n1<<" n2:"<<n2<<endl;
      next_Q.pop();
      auto IT=S.find({n1,n2});
      if(IT!=S.end()){
        Q[n1].pop();
        Q[n2].pop();
        S.erase(IT);
        cnt++;
        ll m1=Q[n1].front();
        if(m1>0){
          if(n1>m1) swap(n1,m1);
          next_Q.push({n1,m1});
        }
        ll m2=Q[n2].front();
        if(m2>0){
          if(n2>m2) swap(n2,m2);
          next_Q.push({n2,m2});
        }
      }
      else S.insert({n1,n2});
    }
    if(cnt==end) break;
    day++;
  }
  if(cnt==end) cout<<day<<endl;
  else cout<<-1<<endl;
}


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

template <typename Graph>
struct StronglyConnectedComponents {
  Graph &g;
  int n;
  vector<vector<int>> gg;
  vector<vector<int>> rg;
  vector<bool> used;
  vector<int> order;
  vector<int> comp;
  StronglyConnectedComponents(Graph &g)
    : g(g), n(g.n), gg(n), rg(n), used(n), order(n), comp(n, -1) {
    for (int v = 0; v < n; v++) {
      for (auto e : g[v]) {
        gg[v].emplace_back(e.to);
        rg[e.to].emplace_back(v);
      }
    }
  }
  void dfs1(int v) {
    if (used[v]) return;
    used[v] = true;
    for (int u : gg[v]) dfs1(u);
    order.push_back(v);
  }
  void dfs2(int v, int c) {
    if (comp[v] != -1) return;
    comp[v] = c;
    for (int u : rg[v]) dfs2(u, c);
  }
  vector<int> build() {
    for (int i = 0; i < n; i++) {
      dfs1(i);
    }
    reverse(order.begin(), order.end());
    int ptr = 0;
    for (int v : order) {
      if (comp[v] == -1) dfs2(v, ptr), ptr++;
    }
    return comp;
  }
};

struct UnWeightedGraph {
  struct Edge {
    int to;
    Edge(int to) : to(to) {}
  };
  vector<vector<Edge>> edges;
  int n;
  UnWeightedGraph(int n) : n(n) {
    edges.assign(n, vector<Edge>());
  }
  void add_edge(int v, int u) {
    edges[v].emplace_back(u);
  }
  vector<Edge> &operator[](int x) {
    return edges[x];
  }
};

int main() {
  int V, E; cin >> V >> E;
  auto graph = UnWeightedGraph(V);
  for (int i = 0; i < E; i++) {
    int s, t; cin >> s >> t;
    graph.add_edge(s, t);
  }
  auto scc = StronglyConnectedComponents<UnWeightedGraph>(graph);
  auto ans = scc.build();
  int Q; cin >> Q;
  for (int i = 0; i < Q; i++) {
    int v, u; cin >> v >> u;
    cout << (ans[v] ==  ans[u]) << '\n';
  }
  return 0;
}

#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
#define DEBUG5(var0, var1, var2, var3, var4) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG4(var1,var2,var3,var4); }
#define DEBUG6(var0, var1, var2, var3, var4, var5) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG5(var1,var2,var3,var4,var5);}
typedef long long ll;

#define MAX_V 100100
int V;
vector <pair <int,ll> > edge[MAX_V];
vector <pair <int,ll> > Redge[MAX_V];
vector <int> vs;
bool used[MAX_V];
int cmp[MAX_V];
void reverse_edge(){
  rep2(i,1,V+1){//1-indexedにしてます
    rep(j,sz(edge[i])){
      Redge[edge[i][j].fir].pb(mp(i,edge[i][j].sec));
    }
  }
}

void dfs(int now){
  used[now] = true;
  rep(i,sz(edge[now])){
    if(!used[edge[now][i].fir]){
      dfs(edge[now][i].fir);
    }
  }
  vs.pb(now);
}

void rdfs(int now,int k){
  used[now] = true;
  cmp[now] = k;
  rep(i,sz(Redge[now])){
    if(!used[Redge[now][i].fir]){
      rdfs(Redge[now][i].fir,k);
    }
  }
}
int scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  rep2(v,1,V+1){//1-indexed
    if(!used[v]){
      dfs(v);
    }
  }
  memset(used,0,sizeof(used));
  reverse_edge();
  int k = 0;
  for(int i = sz(vs)-1;i >= 0;i--){
    if(!used[vs[i]]){
      k += 1;
      rdfs(vs[i],k);
    }
  }
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> V;
  int E;
  cin >> E;
  rep(i,E){
    int x,y;
    cin >> x >> y;
    x += 1;
    y += 1;
    edge[x].pb(mp(y,1));
  }
  scc();
  int Q;
  cin >> Q;
  rep(i,Q){
    int x,y;
    cin >>  x >> y;
    x += 1;
    y += 1;
    if(cmp[x] == cmp[y]){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
  int e;
  while(cin>>e,e){
    int ans=1e9;
    for(int z=0;;z++){
      if(z*z*z>e)break;
      for(int y=0;;y++){
        if(z*z*z+y*y>e)break;
        int a=e-z*z*z-y*y;
        ans=min(ans,a+y+z);
      }
    }
    cout<<ans<<endl;
  }
}

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef vector<pair<int, int> > vpii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second
using namespace std;
int sum[5001];
int main(){
	int N;
	int ans = 0;
	while(cin>>N&&N){
		int index=0;
		ans = INT_MIN;
		FOR(i,1,N+1){
			cin>>sum[i];
			sum[i] += sum[i-1];
		}
		FOR(i,1,N+1){
			FOR(j,i,N+1){
				ans = max(ans,sum[j]-sum[i-1]);
			}
		}
		cout<< ans <<endl;
	}
}


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

int solve(int n, vector<int> & dims){
    int dp[100][101] = {{0}};
    for (int span = 2; span != n + 1; ++span){
        for (int first = 0; first + span != n + 1; ++first){
            for (int last = first + span; last != n + 1; ++last){
                int record = 2000000000;
                for (int mid = first + 1; mid != last; ++mid){
                    record = min(record, dp[first][mid] + dp[mid][last] + dims[first] * dims[last] * dims[mid]);
                }
                dp[first][last] = record;
            }
        }
    }
    return dp[0][n];
}

int main()
{
    int n = 0;
    cin >> n;
    vector<int> dims(n + 1);
    int r = 0;
    int c = 0;
    for (int i = 0; i != n; ++i){
        cin >> r >> c;
        dims[i] = r;
    }
    dims[n] = c;
    cout << solve(n, dims) << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>

using namespace std;

const int kMax = 100 + 5;

int n;
int num[kMax], dp[kMax][kMax];

int main() {
    scanf("%d", &n);
    for(int i = 1;i <= n;++ i) scanf("%d%d", &num[i-1], &num[i]);
    for(int l = 2;l <= n;++ l) {
        for(int i = 1;i <= n - l + 1;++ i) {
            int j = i + l - 1;
            dp[i][j] = (1 << 30);
            for(int k = i;k < j;++ k) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + num[i-1] * num[k] * num[j]);
        }
    }
    printf("%d\n", dp[1][n]);
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_postal_code(void) {
	int a, b;
	string s;
	string msg = "Yes";
	cin >> a >> b >> s;
	if (s.size() != a + b + 1) msg = "No";
	else if (s[a] != '-') msg = "No";
	else {
		for (int i = 0; i < a + b + 1; i++) {
			if (i == a) continue;

			if (s[i] == '-') {
				msg = "No";
				break;
			}
		}
	}
	cout << msg << endl;
}

int main()
{
	b_postal_code();
    return 0;
}

#include<stdio.h>

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	int sum = A + B + 1;
	char str[sum];
	scanf("%s", &str);
	int ctr = 0;
	for(int i = 0; i < sum; i++){
		if(i == A){
			if(str[i] != '-'){
				printf("No\n");
				return 0;
			}
		}else{
			if(str[i] >= '0' && str[i] <= '9'){
				++ctr;
			}
		}
	}
	if(ctr == A+B){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>

using namespace std;

#define N 1001
#define M 20
#define mod 998244353
vector<int> adj[N];

int vis[N],par[N];

int depth[N];
int anc[N][M];

int outSize = 100000;

vector<int> ret;

void dfs(int node) {
  vis[node] = 1;
  for(int i=0;i<adj[node].size();++i) {
    int ch = adj[node][i];
    if(vis[ch] ) {
      if(depth[node]<=depth[ch]) continue;
      int diff = depth[node] - depth[ch];
      int tmp = node;
      for(int j= 0;j<M;++j) {
        if(diff&(1<<j)) {
          tmp = anc[tmp][j];
        }
      }
      if(tmp!=ch || outSize <=diff) {
        continue;
      }
      tmp = node;
      ret.clear();
      outSize = diff;
      while(true) {
        ret.push_back(tmp);
        if(tmp==ch) break;
        tmp = par[tmp];
      }

    } else {
      depth[ch] = depth[node] + 1;
      anc[ch][0] = node;
      for(int j=1;j<M;++j) {
        anc[ch][j] = anc[anc[ch][j-1]][j-1];
      }
      par[ch] = node;
      dfs(ch);
    }
  }
}
void solve() {
  int n,m;scanf("%d %d",&n,&m);
  for(int i=0;i<m;++i) {
    int a,b;scanf("%d %d",&a,&b);
    adj[a].push_back(b);
  }

  for(int st=1;st<=n;++st) {
    memset(vis,0,sizeof(vis));
    depth[st] = 0;
    for(int j=0;j<M;++j) anc[st][j] = 0;
    dfs(st);
  }
  if(outSize==100000) {
    printf("-1\n");
  } else {
    printf("%d\n",ret.size());
    for(int i=0;i<ret.size();++i) {
      printf("%d\n", ret[i]);
    }
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <complex>
#define rep(i, j, n) for (int i = (j); i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; i >= (j); --i)
using namespace std;
using ll = long long;
constexpr ll INF = 1LL << 60;

int n, m, a, b;
vector<int> g[1010];

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

  ll ans = INF;
  vector<int> out;

  rep(i, 0, n)
  {
    // i スタートの最小のサイクル
    vector<int> prev(n, -1);
    vector<bool> seen(n, false);
    queue<int> q;
    bool cycle = false;
    q.push(i);
    while (q.size())
    {
      int v = q.front();
      q.pop();
      for (int nv : g[v])
      {
        if (nv == i)
        {
          prev[i] = v;
          cycle = true;
          break;
        }
        if (!seen[nv])
        {
          seen[nv] = true;
          prev[nv] = v;
          q.push(nv);
        }
      }
      if (cycle)
        break;
    }

    if (cycle)
    {
      int j = i;
      vector<int> tmp;
      while (prev[j] != i)
      {
        tmp.push_back(j);
        j = prev[j];
      }
      tmp.push_back(j);

      if ((int)tmp.size() < ans)
      {
        ans = (int)tmp.size();
        out = tmp;
      }
    }
  }

  if (ans == INF)
    cout << -1 << endl;
  else
  {
    cout << out.size() << '\n';
    for (int o : out)
      cout << o + 1 << '\n';
  }
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    n -= 2;

    cout << n * 180 << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl "\n"
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
vector<long long> divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;

    /*long long N;
    cin >> N;
    vector<long long> res = divisors(N);
    for (int i = 0; i < res.size(); ++i) {
        cout << res[i] << " ";
    }
    cout << endl;*/
}
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int n;
  cin >> n;
  cout << (n-2)*180 << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll M;
deque<ll> d;
deque<ll> c;
deque<ll> e;

int main(){
    cin >> M;
    for(int i=0;i<M;i++){
        ll a,b;
        cin >> a >> b;
        d.push_back(a);
        c.push_back(b);
    }
    ll count = 0;
    while(d.size() > 0){
        if(c[0] == 1){
            e.push_back(d[0]);
            c.pop_front();
            d.pop_front();
            continue;
        }
        ll dd = d[0];
        ll cc = c[0];
        c.pop_front();
        d.pop_front();
        if(dd < 5){
            if(cc % 2 == 1){
                c.push_front(1);
                d.push_front(dd);
            }
            c.push_front(cc/2);
            d.push_front(dd*2);
            count += cc/2;
            continue;
        }
        if(cc % 2 == 1){
            c.push_front(1);
            d.push_front(dd);
        }
        dd = (dd*2)/10 + (dd*2)%10;
        c.push_front(cc/2);
        d.push_front(dd);
        count += cc/2 * 2;
    }
    while(e.size() > 1){
        ll a = e[0];
        ll b = e[1];
        e.pop_front();
        e.pop_front();
        if(a+b < 10){
            count++;
            e.push_front(a+b);
        }else{
            count += 2;
            e.push_front((a+b)/10 + (a+b)%10);
        }
    }
    cout << count << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    ll nofd = 0, sum = 0;
    rep(i,N){
        ll d,c; cin >> d >> c;
        nofd += c;
        sum += d*c;
    }
    cout << (nofd - 1) + (sum-1)/9 << endl;
}


#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  string s[3];
  rep(i, 3) cin >> s[i];
  int cnt = 0;
  rep(i, n)
  {
    if (s[0][i] == s[1][i] && s[1][i] == s[2][i])
      continue;
    if (s[0][i] != s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i])
      cnt += 2;
    else
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
ll direction2[4][2]={{1,0},{0,1},{0,-1},{-1,0}};
bool valid(int a,int b)
{
    if(a>=1&&a<=h&&b>=1&&b<=w)return true;
    else return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x=1000000;
    cin>>n;
    unordered_map<ll,ll>nw,ne;
    string s;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='W')nw[i]=1+nw[i-1];
        else nw[i]=nw[i-1];
        if(s[n-i-1]=='E')ne[n-i-1]=1+ne[n-i];
        else ne[n-i-1]=ne[n-i];
    }
    for(int i=0;i<n;i++){
        x=min(x,(nw[i-1]+ne[i+1]));
        //cout<<nw[i-1]<<" "<<ne[i+1]<<endl;
    }
    cout<<x;
}


#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  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 1000000009
#define EPS 1E-9

int n;
int a, b;

int main()
{
  while((cin >> n) && n){
    int res[2] = {0};
    while(n--){
      cin >> a >> b;

      if(a >  b){ res[0] += a + b;  continue; }
      if(a <  b){ res[1] += a + b;  continue; }
      res[0] += a;
      res[1] += b;
    }

    cout << res[0] << " " << res[1] << endl;
  }

  return 0;
}

#include<bits/stdc++.h>

using namespace std;
int main(){
  while(1){
  int n;
  cin>>n;
    int m;
    cin>>m;
    if(n==0&&m==0){break;}
  vector<vector<int>> v(n+1);//??¨?????????
  vector<int> s(n+1,0);//??????
s[1]=1;
  for(int i=0;i<m;i++){
    int a;
    cin>>a;
    int b;
    cin>>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  vector<vector<int>> r(n+1);//?????°???????????¨
  r[0].push_back(1);
  int num=0;
  while(1){
  int change=0;
  if(r[num].empty()==false){
    for(unsigned int j=0;j<r[num].size();j++){
      for(unsigned int i=0;i<v[r[num][j]].size();i++){
        if(s[v[r[num][j]][i]]==0){
          s[v[r[num][j]][i]]=1;
          r[num+1].push_back(v[r[num][j]][i]);
          change=1;
        }
      }
    }
  }
    if(change==0){break;}
    if(num==1){break;}
    num++;
  }
  int kazu=0;
  for(unsigned int i=0;i<s.size();i++){
    if(s[i]==1){kazu++;}
  }
  cout<<kazu-1<<endl;

}
}


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

int main()
{
    int n;
    cin >> n;cin.get( );
    //n++;
    string ss;
    for(int j=0;j<n;j++)
    {
        getline(cin,ss);
        int len =ss.size();
        for(int i=6;i<len;i++)
        {
            //cout << ss[i];
            if(ss.substr(i-6,7)=="Hoshino")
            {
                ss[i]='a';
            }
            //if(ss[i]=='\0')break;
        }

        /*for(int i=0;i<len;i++){
            if(ss[i]=='\0')break;
            cout <<ss[i];
        }*/
        cout <<ss << endl;
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    vector<int> antenna (5);
    REP(i,5){
        cin >> antenna[i];
    }
    int k;
    cin >> k;
    REP(i,4){
        FOR(j,i,5){
            if (antenna[j] - antenna[i] > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<vector>
#include<sstream>
#include<cstdlib>

using namespace std;

int main(){
	while(1){
		int n,k;
		scanf("%d%d",&n,&k);

		if(n==0)
			break;

		vector<int> card(n);
		for(int i=0;i<n;i++){
			scanf("%d",&card[i]);
		}

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

		vector<int> data;
		do{

			stringstream sst;
			for(int i=0;i<k;i++){
				sst<<card[i];
			}
			data.push_back(atoi(sst.str().c_str()));

			reverse( card.begin()+k,card.end());
		}while( next_permutation(card.begin(),card.end()) );

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

		printf("%d\n",distance(data.begin(),unique(data.begin(),data.end())) );
	}
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>

using namespace std;

#define sz			size()
#define lgt			length()
#define rep(i,n)	for (int i = 0; i < n; i++)
#define ALL(X)		(X).begin(),(X).end()
#define RALL(X)		(X).rbegin(),(X).rend()
#define pb			push_back
#define SORT(a)		sort(ALL(a));
#define RSORT(a)	sort(RALL(a));
#define mp			make_pair
#define dump(x)		cerr<<#x<<" = "<<(x)<<endl;
#define fir			first
#define sec			second

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<string> vs;

int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
vs form(string a,char s){vs v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(b);b="";}else b+=a[i];}v.pb(b);return v;}
vi formint(string a,char s){vi v;string b;rep(i,a.lgt){if(a[i]==s){v.pb(toInt(b));b="";}else b+=a[i];}v.pb(toInt(b));return v;}

const double EPS=1e-10,PI=acos(-1.0);
const int INF=2100000000;

int main(void)
{
	int n, k;
	while (cin >> n >> k, n && k){
		string num[16];
		vector <string> ans;
		for (int i = 0; i < n; i++)	cin >> num[i];

		if (k == 2){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					if (i != j){
//						cout << i << " " << j << endl;
						string tmp;
						tmp += num[i];
						tmp += num[j];
//						cout << "*" << tmp << endl;
						ans.pb(tmp);
					}
				}
			}
		}
		if (k == 3){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						if (i != j && j != k && i != k){
							string tmp;
							tmp += num[i];
							tmp += num[j];
							tmp += num[k];
							ans.pb(tmp);
						}
					}
				}
			}
		}
		if (k == 4){
			for (int i = 0; i < n; i++){
				for (int j = 0; j < n; j++){
					for (int k = 0; k < n; k++){
						for (int l = 0; l < n; l++){
							if (i != j && i != k && i != l && j != k && j != l && k != l){
								string tmp;
								tmp += num[i];
								tmp += num[j];
								tmp += num[k];
								tmp += num[l];
								ans.pb(tmp);
							}
						}
					}
				}
			}
		}

		ans.pb("2100000000");
		SORT(ans);
		int res = 0;
		for (int i = 0; i < ans.sz - 1; i++){
			if (ans[i] != ans[i + 1]) res++;
		}
		cout << res << endl;
	}

	return 0;
}


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

#define rep(i,n) for(int i=0;i<int(n);i++)
#define sint(n) scanf("%d",&n);

using namespace std;

int main(){
	while(1){
		int a,b,c;
		sint(a)
		sint(b)
		sint(c)

		if(a==0){break;}
		int k;
		sint(k)

		int buhin[301]={0};
		rep(i,301){
			buhin[i]=2;
		}

		int e[1000],r[1000],t[1000],u[1000];
		rep(i,k){
			scanf("%d%d%d%d",&e[i],&r[i],&t[i],&u[i]);
			if(u[i]==1){
				buhin[e[i]]=buhin[r[i]]=buhin[t[i]]=1;
			}
		}

		rep(i,k){
			if(u[i]==0){
				if(buhin[e[i]]==1 && buhin[r[i]]==1){
					buhin[t[i]]=0;
				}
				if(buhin[e[i]]==1 && buhin[t[i]]==1){
					buhin[r[i]]=0;
				}
				if(buhin[t[i]]==1 && buhin[r[i]]==1){
					buhin[e[i]]=0;
				}
			}
		}

		rep(i,a+b+c){
			printf("%d\n",buhin[i+1]);
		}
	}
}
/*
2 2 2
4
2 4 5 0
2 3 6 0
1 4 5 0
2 3 5 1
*/

#include <iostream>
using namespace std;
struct results{
        int a;
        int b;
        int c;
        int result;
};
int main(){
        while(true){
        int parts[1000]={0};
        int aa,bb,cc,n;
        cin >> aa >> bb >> cc;
        if(aa+bb+cc==0)
                break;
        cin >> n;
        results data[1000];
        for( int i=0 ; i<n ; i++ )
                cin >> data[i].a >> data[i].b >> data[i].c >> data[i].result;
        for( int all_counter=0 ; all_counter<2 ; all_counter++)
        for( int i=0 ; i<n ; i++ ){
                if(data[i].result){
                        parts[data[i].a]=1;
                        parts[data[i].b]=1;
                        parts[data[i].c]=1;
                }
                else{
                        int level=parts[data[i].a]+parts[data[i].b]+parts[data[i].c];
                        if(level>1){
                                parts[data[i].a]==0?parts[data[i].a]=-1:0;
                                parts[data[i].b]==0?parts[data[i].b]=-1:0;
                                parts[data[i].c]==0?parts[data[i].c]=-1:0;
                        }
                }
        }
        for( int i=0+1 ; i<=aa+bb+cc ; i++ )
                if(parts[i]==-1)
                        cout << 0 << endl;
                else if(parts[i]==0)
                        cout << 2 << endl;
                else
                        cout << 1 << endl;
        }
        return 0;
}


                                                                   //author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
#define mod 2038077799
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
    cin>>n;
    int A[n],B[n];
    int dA[n],dB[n];
    for(int i=0;i<n;i++)cin>>A[i];

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

    for(int i=0;i<n;i++)
    {
        dA[i] = A[(i+1)%n]^A[i];
        dB[i] = B[(i+1)%n]^B[i];
    }
    int hashB=0;
    int base = 1400312813;
    for(int i=0;i<n;i++)
    {
        hashB*=base;
        hashB%=mod;
        hashB+=dB[i];
        hashB%=mod;
    }
    int hashA=0;
    for(int i=0;i<n;i++)
    {
        hashA*=base;
        hashA%=mod;
        hashA+=dA[i];
        hashA%=mod;
    }
    int exp = power(base,n-1,mod);
    vi ans;
    for(int i=0;i<n;i++)
    {
        if(hashA==hashB)
        ans.pb(i);

        int val = exp*dA[i];
        val%=mod;
        hashA+=mod - val;
        hashA%=mod;
        hashA*=base;
        hashA%=mod;
        hashA+=dA[i];
        hashA%=mod;
    }
    for(int i=0;i<ans.size();i++)
    {
        cout<<ans[i]<<" "<<(A[0]^B[(n-ans[i])%n])<<'\n';
    }
return 0;
}

#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e6+100,mod=998244353;
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll fac[N],fm[N];
ll ent(ll k,ll n){
    if (k<0 || k>n) return 0;
    if (k==0 || k==n) return 1;
    return fac[n]*fm[k]%mod*fm[n-k]%mod;
}
int32_t main(){
    fac[0]=1;
    for (int i=1;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        fm[i]=power(fac[i],mod-2);
    }
 //   cout << ent(3,5) << endl;
    ll ans=0;
    ll n,m;
    cin >> n >> m;
    ll z=3*m;
    for (int i=0;i<=min(n,m);i++){
        ll t=z-i;
        if (t%2==1) continue;
        ans+=ent(i,n)*ent(n-1,n-1+t/2)%mod;
    }
    for (int i=2*m+1;i<=3*m;i++){
        ll t=z-i;
        ans-=n*ent(n-2,n-2+t)%mod;
        ans+=mod;
        ans%=mod;
    }
    cout << ans << endl;
}


#include<cstdio>
#include<iostream>
using namespace std;
char masu[50][50] = {{0}};
void saiki(int x,int y){
    masu[y][x] = '0';

    if(masu[y+1][x] == '1') saiki(x,y+1);
    if(masu[y-1][x] == '1') saiki(x,y-1);
    if(masu[y][x+1] == '1') saiki(x+1,y);
    if(masu[y][x-1] == '1') saiki(x-1,y);
}
int main(){
    while(1){
        int cnt = 0;
        for(int i = 0; i < 12; i++){
            if(scanf("%s",masu[i]) == EOF)goto a;
        }
        for(int i = 0; i < 12; i++){
            for(int j = 0; j < 12; j++){
                if(masu[i][j] == '1'){
                    saiki(j,i);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
    a:;
    return 0;
}

#include <bits/stdc++.h>
#define ctz __builtin_ctz

const int N = 648;

int n, D1, D2;
int a[N][N];

void coloring(int dist, int bit) {
	int i, j, L = ctz(dist) / 2; dist >>= 2 * L;
	switch (dist & 3) {
		case 0: throw "gg"; break;
		case 1: for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) a[i][j] |= ((i ^ j) >> L & 1) << bit; break;
		case 2: for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) a[i][j] |= (i >> L & 1) << bit; break;
	}
}

int main() {
	int i, j, c, d, col[4] = {0};
	scanf("%d%d%d", &n, &D1, &D2), d = n * n, n *= 2, coloring(D1, 0), coloring(D2, 1);
	for (i = 0; i < n; ++i)
		for (j = 0; j < n; ++j) ++col[ a[i][j] ];
	c = std::max_element(col, col + 4) - col;
	for (i = 0; i < n && d; ++i)
		for (j = 0; j < n && d; ++j)
			if (a[i][j] == c) --d, printf("%d %d\n", i, j);
	return 0;
}


/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}

bool Check(ll num, ll pos) {
        return (bool)(num & (1LL << pos));
}
 long long int sumXOR(ll arr[], int n)
{
     long long int sum = 0;
    for (int i = 0; i <=60; i++)
    {
        //  Count of zeros and ones
        long long zc = 0, oc = 0;

        // Individual sum at each bit position
        long long int idsum = 0;
        for (int j = 0; j < n; j++)
        {
           /* if (arr[j] % 2 == 0)
                zc++;
            else
                oc++;
            arr[j] /= 2;*/

            if(Check(arr[j],i))zc++;

            else oc++;
        }

        // calculating individual bit sum
        idsum = (oc * ((zc * ((1ll << i)%Mod))%Mod))%Mod;

        // final sum
        sum =(sum+ idsum)%Mod;
    }
    return sum%Mod;
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

        cin>>n;

        long long ara[n+2];

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

         cout<<sumXOR(ara,n)<<endl;

}

#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, long long>;

const long long MOD = 1000000007;

int main() {
  long long N;
  long long a[60] = {0};
  cin >> N;
  rep(i, N) {
    long long temp;
    cin >> temp;
    long long x = 1;
    rep(j, 60) {
      if(temp & x) {
        a[j]++;
        // cout << j << endl;
      }
      x *= 2;
    }
  }
  long long ans = 0;
  long long x = 1;
  rep(i, 60) {
    ans += ((((a[i] * (N-a[i])) % MOD) * x));
    ans %= MOD;
    x *= 2;
    x %= MOD;
  }
  cout << ans << endl;
  return 0;
}


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

static const int MAX = 100;
#define INF 2000000000000ll
int V, E;
long long dp[MAX][MAX];

void Warshall_Floyd() {
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j =0 ; j < V; j++) {
				if (dp[i][k] == INF || dp[k][j] == INF) {
					continue;
				}
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
}

int main() {
	cin >> V >> E;
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < V; j++) {
			if (i == j) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = INF;
			}
		}
	}
	for (int i = 0; i < E; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		dp[from][to] = cost;
	}
	Warshall_Floyd();
	bool minus = false;
	for (int i = 0; i < V; i++) {
		if (dp[i][i] < 0) {
			minus = true;
		}
	}

	if (minus) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (j != 0) {
					cout << " ";
				}
				if (dp[i][j] == INF) {
					cout << "INF";
				}
				else {
					cout << dp[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;
}

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename W>
struct N003 {
   typedef std::vector<long> LI;
   typedef std::vector<W>    LW;
   long n, e;
   LI ss, ds;
   LW ws;
   std::vector<LI> iss;
   N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
      : n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
      iss.resize(n+1);
      for(long i = 0; i < e; ++i) {
         iss[ss[i]].push_back(i);
      }
   }
};

template<typename W>
struct N006 {
   std::vector<std::vector<W>> xss;
   bool negativeCycle;
   N006(const N003<W>& g, W inf) : negativeCycle(false) {
      xss.resize(g.n+1);
      for(auto& xs : xss) xs.resize(g.n+1, inf);
      for(long i = 0; i < g.n+1; ++i) xss[i][i] = 0;
      for(long i = 0; i < g.e; ++i) {
         xss[g.ss[i]][g.ds[i]] = g.ws[i];
      }
      for(long z = 0; z < g.n+1; ++z) {
         for(long x = 0; x < g.n+1; ++x) {
            for(long y = 0; y < g.n+1; ++y) {
               W d = xss[x][y];
               W nd = xss[x][z] + xss[z][y];
               xss[x][y] = std::min(d, nd);
            }
         }
      }
      for(long x = 0; x < g.n+1; ++x) {
         for(long y = 0; y < g.n+1; ++y) {
            if( xss[x][y] >= inf / 2 ) {
               xss[x][y] = inf;
            }
         }
         if( xss[x][x] < 0 ) {
            negativeCycle = true;
         }
      }
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      typedef std::vector<long> LI;
      long v, e;
      scan(v, e);
      LI ss(e+1), ds(e+1);
      LI ws(e+1);
      for(long i = 0; i < e; ++i) {
         scan(ss[i], ds[i], ws[i]);
      }
      N003<long> g(v, ss, ds, ws);
      N006<long> warshallfloyd(g, (1LL << 60));
      if( warshallfloyd.negativeCycle ) {
         puts("NEGATIVE CYCLE");
      }
      else {
         for(long i = 0; i < v; ++i) {
            for(long k = 0; k < v; ++k) {
               if( warshallfloyd.xss[i][k] == (1LL << 60) ) {
                  printf("INF");
               }
               else {
                  printf("%ld", warshallfloyd.xss[i][k]);
               }
               putchar( k == v - 1 ? '\n' : ' ');
            }
         }
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}


#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<functional>
#define pi 3.14159
#define Inf (int)pow(2., 12.)

using namespace std;
typedef std::pair<int, int> mypair;
queue<mypair> qu;
#define M 1000000
const int dy[4] = {0, 1, 0, -1}, dx[4] = {1, 0, -1, 0};
#define N 123456
int num = 0;

int ToInt(string str) {
	int a = 0, n = (int)str.size();
	for(int i = 0; i < n; i++) {
		a += (str[i]-'0') * (int)pow(10., (double)(n-i-1));
	}
	return a;
}

string ToString(int a, int l) {
	string str;
	if(l == 6) str = "000000";
	if(l == 5) str = "00000";
	if(l == 4) str = "0000";
	if(l == 3) str = "000";
	if(l == 2) str = "00";
	if(l == 1) str = "0";
	for(int i = 0; i < l; i++) {
		int n = a / (int)pow(10., (double)(l-i-1));
			str[i] = n + '0';
			a -= n * (int)pow(10., (double)(l-i-1));
			}

	return str;
}
int dia(int h, int w) {
	return h*h + w*w;
}

void tan(int d) {
		for(int i = 1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == d) {
					cout << i << " " << j <<endl;
					return;
				} else if(dia(i, j) > d) break;
			}
		}
		tan(d + 1);
}

int main(){
	int h, w;
	while(cin >> h >> w) {
		if(h + w == 0) break;
		bool bo2 = false;
		for(int i = h+1; i < 150; i++) {
			for(int j = i+1; j < 150; j++) {
				if(dia(i, j) == dia(h, w)) {
					h = i;
					w = j;
					bo2 = true;
					break;
				} else if(dia(i, j) > dia(h,w)) break;
			}
			if(bo2) break;
		}
		if(bo2) cout << h << " " << w <<endl;
		else tan(dia(h, w) + 1);
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    int T=1,t,n,m,k,i;
    // cin>>T;
    while(T--)
    {
        cin>>n>>k;
        int a[10]={0};
        FOR(i,0,k){
          cin>>t;
          a[t]=1;
        }
        vector<int> vs;
        FOR(i,0,10)
            if(a[i]==0)
                vs.pb(i);
        // for(auto it:vs)cout<<it<<" ";cout<<endl;
        int dg=0;
        for(i=n;i>0;i/=10)dg++;
        ll ans=0;
        k = pow(10,dg-1);
        int fl=0;
        int num=n;
        // cout<<dg<<" "<<k<<endl;
        while(ans<num)
        {
            if(k==0){
                ans = ans*10 + vs[0];
                continue;
            }
            m = n/k;
            n = n%k;
            k/=10;
            if(a[m]==0&fl==0){
                ans = ans*10 + m;
                continue;
            }
            dg=0;
            if(fl==0)
            {
                for(auto it:vs)
                    if(it>=m)
                    {
                        dg=it;
                        break;
                    }
                if(dg==0)
                {
                    if(vs[0]!=0)
                        dg=vs[0];
                    else
                    {
                        if(ans==0)
                            dg=vs[1];
                        else
                            dg=vs[0];
                    }
                }
                ans = ans*10+dg;
                fl=1;
            }
            else
            {
                ans = ans*10 + vs[0];
            }
        }
        cout<<ans<<endl;
    }
}

#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb push_back
#define PII pair<ll,ll>
ll const MOD = 998244353;
ll const N = 1000005;
ll const LN = 20;
ll const inf = 8e18;
using namespace std;

ll n, m, a[N];

ll cnt[N];

ll fact[N];
ll ifact[N];
ll bexpo (ll x, ll n, ll m)
{
	ll r = 1;
	x = x % m;
	while (n > 0)
	{
		if (n % 2) { r = (r * x) % m; }
		x = (x * x) % m;
		n = n / 2;
	}
	return r;
}
ll ncr (ll n, ll r)
{
	if (r > n) { return 0; }
	ll ans = fact[n];
	ans = (ans * ifact[r]) % MOD;
	ans = (ans * ifact[n - r]) % MOD;
	return ans;
}
void pre()
{
	fact[0] = 1;
	ifact[0] = 1;
	for (ll i = 1; i < N; i++) { fact[i] = (fact[i - 1] * i) % MOD; }
	ifact[N - 1] = bexpo (fact[N - 1], MOD - 2, MOD);
	for (ll i = N - 2; i > 0; i--)
	{ ifact[i] = (ifact[i + 1] * (i + 1)) % MOD; }
}
int main()
{
	ios::sync_with_stdio (false);
	cin.tie (NULL);
	pre();
	ll n, k;
	cin >> k >> n;
	for (ll i = 2; i <= 2 * k; i++)
	{
		set<ll>st;
		for (ll j = 1; j <= k; j++)
		{
			if (j >= i)
			{
				continue;
			}
			ll oo = i - j;
			if (oo > k) { continue; }
			st.insert (oo);
			st.insert (j);
		}
		cnt[i] = (st.size() + 1) / 2;
	}
	for (ll i = 2; i <= 2 * k; i++)
	{
		if (1)
		{
			ll tot = ncr (n + k - 1, k - 1);
			for (ll j = 1; j <= cnt[i]; j++)
			{
				ll temp = ncr (cnt[i], j);
				temp *= ncr (n - 2 * j + k - 1, k - 1);
				temp %= MOD;
				if (j % 2) { tot -= temp; }
				else { tot += temp; }
				tot %= MOD;
				if (tot < 0) { tot += MOD; }
			}
			cout << tot << '\n';
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

struct LowLink{
    vector<vector<int>>& edges;
    // 関節点
    vector<int> art;
    vector<pair<int,int>> bridge;

    vector<int> used, ord, low;
    int k;

    void dfs(int idx, int par){
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_art = false;
        int cnt = 0;
        for(auto& to : edges[idx]){
            if(ord[to] == -1){
                ++cnt;
                dfs(to, idx);
                low[idx] = min(low[idx], low[to]);
                is_art |= par != -1 && low[to] >= ord[idx];
                if(ord[idx] < low[to])
                    bridge.emplace_back(idx, to);
            }else if(to != par)
                low[idx] = min(low[idx], ord[to]);
        }
        is_art |= (par == -1 && cnt > 1);
        if(is_art)
            art.emplace_back(idx);
    }

    LowLink(vector<vector<int>>& edges) :
        edges(edges),
        ord(edges.size(), -1),
        low(edges.size(), 0),
        k(0)
    {
        for(int i = 0; i < edges.size(); ++i)
            if(ord[i] == -1)
                dfs(i, -1);
        for(auto& b : bridge)
            b = make_pair(min(b.first, b.second), max(b.first, b.second));
        sort(art.begin(), art.end());
        sort(bridge.begin(), bridge.end());
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        vector<int> l(2);
        for(auto& x : l)
            cin >> x;
        sort(l.begin(), l.end());
        v[i] = make_pair(l.front(), l.back());
        edges[l[0]].emplace_back(l[1]);
        edges[l[1]].emplace_back(l[0]);
    }
    LowLink ll(edges);
    for(auto& x : ll.art)
        cout << x << endl;
}

#include <iostream>
#include <vector>
#include <set>

using namespace std;

struct ArticularPoint {
    int n;
    vector<vector<int>> g;
    set<int> points;
    vector<int> parent;
    vector<int> discTime;
    vector<int> lowTime;
    vector<bool> visited;
    vector<bool> isAp;
    int time = 0;

    ArticularPoint(int n): n(n) {
        g.assign(n, vector<int>());
        parent.assign(n, -1);
        discTime.assign(n, 0);
        lowTime.assign(n, n + 1);
        visited.assign(n, false);
        isAp.assign(n, false);
    }

    void addEdge(int from, int to) {
        g[from].push_back(to);
        g[to].push_back(from);
    }

    int solve() {
        dfs(0, -1);
        return points.size();
    }

    void dfs(int u, int p) {
        discTime[u] = time++;
        lowTime[u] = discTime[u];
        visited[u] = true;
        int child = 0;
        for (int v : g[u]) {
            if (!visited[v]) {
                child++;
                parent[v] = u;
                dfs(v, u);
                lowTime[u] = min(lowTime[u], lowTime[v]);
                if (lowTime[v] >= discTime[u]) {
                    isAp[u] = true;;
                }
            }
            else if (v != p) {
                lowTime[u] = min(lowTime[u], discTime[v]);
            }
        }
        //Remove root is it has only one child
        if (p < 0 && child == 1) {
           isAp[u] = false;
        }
    }
};

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

    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        ap.addEdge(from, to);
    }

    int ans = ap.solve();
    for (int i = 0; i < n; i++) {
        if (ap.isAp[i]) {
            cout << i << endl;
        }
    }

    return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    char s[h][w];
    rep(i, h) rep(j, w) cin >> s[i][j];

    rep(i, h) rep(j, w) {
        if (s[i][j] == '.') continue;
        bool ok = false;
        for (int y = -1; y <= 1; y += 2) {
            int dy = i + y;
            if (dy >= 0 && dy < h && s[dy][j] == '#') ok = true;
        }
        for (int x = -1; x <= 1; x += 2) {
            int dx = j + x;
            if (dx >= 0 && dx < w && s[i][dx] == '#') ok = true;
        }
        if (!ok) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"in%s.txt",s);
	freopen(str,"r",stdin);
//	sprintf(str,"out%s.txt",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=110;
int n,m,a[N],b[N],t=0;

int main()
{
	n=rd();m=rd();
	fo(i,1,m)a[i]=rd(),t+=(a[i]&1);
	if(m==1){
		if(a[1]==1)puts("1\n1\n1");
		else printf("%d\n2\n%d %d",a[1],1,a[1]-1);
		return 0;
	}
	if(t>2){puts("Impossible");return 0;}
	fo(i,2,m)if(a[i]&1)a[1]&1?swap(a[m],a[i]):swap(a[1],a[i]);
	t=0;
	if(a[1]>1)b[t=1]=a[1]-1;
	fo(i,2,m)b[++t]=a[i];b[t]++;
	fo(i,1,m)cout<<a[i]<<' ';cout<<endl;
	cout<<t<<endl;
	fo(i,1,t)cout<<b[i]<<' ';cout<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;

typedef pair<int, int> P;

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

void dfs(int sx, int sy) {
  queue<P> que;
  data[sx][sy] = 2;
  que.push(P(sx, sy));

  while(que.size()) {
    P p = que.front();
    que.pop();

    for(int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < 12 && 0 <= ny && ny < 12 && data[nx][ny] == 1 ){
	que.push(P(nx, ny));
	data[nx][ny] = 2;
      }
    }
  }
}

int main(){
  while(~scanf("%1d", &data[0][0])) {
    int cnt = 0, i, j = 1;
    for(i = 0; i < 12; i++, j=0)
      for(;j < 12; j++) {
	scanf("%1d", &data[i][j]);
      }
    for(i = 0; i < 12; i++)
      for( j = 0; j < 12; j++)
	if(data[i][j] == 1){
	  dfs(i, j);
	  cnt++;
	}
    cout << cnt << endl;
  }
  return 0;
}

#include <iostream>
#include <string>
#define MAP 12
using namespace std;

int map[MAP][MAP];

bool valid(int y, int x) {
  if ((0 <= y && y < MAP) && (0 <= x && x < MAP)) {
    if (map[y][x] == 1)
      return true;
  }
  return false;
}

void remove_island(int y, int x) {
  int nx, ny;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};

  map[y][x] = 0;
  for (int i = 0; i < 4; i++) {
    ny = y + dy[i];
    nx = x + dx[i];
    if ((valid(ny, nx)))
      remove_island(ny, nx);
  }
}

int main() {
  char c[13];
  int ans;
  while (1) {
    for (int i = 0; i < MAP; i++) {
      if (!(cin >> c))
        return 0;
      for (int j = 0; j < MAP; j++) {
        map[i][j] = (int)(c[j] - '0');
      }
    }
    ans = 0;
    for (int i = 0; i < MAP; i++) {
      for (int j = 0; j < MAP; j++) {
        if (valid(i, j)) {
          remove_island(i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

void func(ll* x,ll* y){
  *x -= (*x%2);
  *x /= 2;
  *y += *x;
}

int main(){
  ll A,B;
  int K;
  cin >> A>>B>>K;
  bool turn_A = true;
  REP(i,K){
    if(turn_A){func(&A,&B);}
    else{func(&B,&A);}
    turn_A = !turn_A;
  }
  printf("%d %d\n",A,B);
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 300003
#define MOD 1000000007
#define INF 1000000000000000

int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((C-A)*(B-C)>=0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

int main()
{
	string s;
	cin>>s;
	if(s.length()==2)cout<<s<<endl;
	else
	{
		for(int i=2;i>=0;i--)cout<<s[i];
		cout<<endl;
	}
	return 0;
}

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

void solve(){

	int n  ;
	cin>> n ;
	double ans=4*acos(0.0)*(double)n ;
	cout<<ans ;

}

int main(){

	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{
		solve() ;
	}

}


//https://atcoder.jp/contests/abc160/tasks/abc160_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin>>x;
	ll a;
	a=x/500;
	ll fin1;
	fin1=a*1000;
	ll b;
	b=x%500;
	ll c;
	c=b/5;
	ll fin2;
	fin2=c*5;
	ll sum=0;
	sum=fin1+fin2;
	cout<<sum<<"\n";
	return 0;
}

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

double eps = 1e-9;
double pi = acos(-1);

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	int n, x;
	cin >> n;

	ll ans = 0;

	if(n >= 500)
	{
		x = n / 500;
		ans += 1000 * x;
		n = n - x * 500;
	}

	if(n >= 5)
	{
		x = n/5;
		ans += 5 * x;
	}

	cout << ans << en;

	return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

int matrix_rank(vector<unsigned long long> A){
	int n=A.size(),r=0;
	rep(i,64){
		int piv=-1;
		for(int j=r;j<n;j++) if(A[j]>>i&1) {
			piv=j;
			break;
		}
		if(piv==-1) continue;

		for(int j=r;j<n;j++) if(j!=piv && A[j]>>i&1) {
			A[j]^=A[piv];
		}
		swap(A[r],A[piv]);
		r++;
	}
	return r;
}

void solve(){
	int n; cin>>n;
	vector<unsigned long long> a(n);
	rep(i,n) cin>>a[i];
	string s; cin>>s;

	vector<unsigned long long> A;
	int r=0;
	for(int i=n-1;i>=0;i--){
		A.emplace_back(a[i]);
		int r2=matrix_rank(A);
		if(r<r2 && s[i]=='1'){
			puts("1");
			return;
		}
		r=r2;
	}
	puts("0");
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second

#define sz(a) ((int)(a.size()))
using namespace std;
const int mod = 998244353;
int mult(int a, int b)
{
	return a * (ll) b % mod;
}
int add(int a, int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a,  int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
void Add(int &a, int b)
{
	a = add(a , b);
}
vector<ll> b;
void add(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t= b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	if(x == 0)
		return;
	for(int i = 0; i < b.size(); i++)
	{

		if((x ^ b[i]) < b[i])
			b[i] ^= x;
	}
	b.pb(x);
	sort(b.begin() , b.end() , greater<ll>());
}
ll check(ll x)
{
	for(int i = 0; i < b.size(); i++)
	{
		ll t = b[i];
		if((x ^ t) < x)
		{
			x ^= t;
		}
	}
	return x;
}
int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		b.clear();
		vector<ll> a(n);
		for(auto & x : a)
			cin >> x;
		string s;
		cin >> s;
		reverse(a.begin() , a.end());
		reverse(s.begin() , s.end());
		bool pzdc = false;
		for(int i = 0; i < n; i++)
			if(s[i] == '0')
			{
				add(a[i]);
			}
			else
			{
				pzdc |= check(a[i]) != 0;
			}
		cout << pzdc << endl;
	}

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong h, w;
llong a[100][100];
llong b[100][100];
llong v[100][100];
llong u[100][100];
bool dp[100][100][26000];
llong offset = 13000;

int main() {
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            v[i][j] = a[i][j] - b[i][j];
            u[i][j] = b[i][j] - a[i][j];
        }
    }

    dp[0][0][offset] = true;
    dp[0][1][offset] = true;
    dp[1][0][offset] = true;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            for (int k = 0; k < 26000; k++) {
                if (dp[i - 1][j][k] == true) {
                    dp[i][j][k + v[i][j]] = true;
                    dp[i][j][k + u[i][j]] = true;
                }
                if (dp[i][j - 1][k] == true) {
                    dp[i][j][k + v[i][j]] = true;
                    dp[i][j][k + u[i][j]] = true;
                }
            }
        }
    }

    llong ans = 1ll << 60ll;
    for (int k = 0; k < 26000; k++) {
        if (dp[h][w][k] == true) {
            ans = min(ans, llabs(k - offset));
        }
    }

    cout << ans << endl;

    return 0;
}

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

int H, W;
vector<vector<char>> maze(51, vector<char>(51));
vector<vector<bool>> check(51, vector<bool>(51));
bool goal;

queue<pair<int, int>> BFS(queue<pair<int, int>> q, pair<int, int> p) {
  int y = p.first, x = p.second;
  //cout << y << " " << x <<endl;
  if (y == H - 1 && x == W - 1) {
    goal = true;
  }
  pair<int, int> tmp;
  //上
  if (y > 0 && maze[y - 1][x] == '.' && !check[y - 1][x]) {
    check[y-1][x] = true;
    tmp = make_pair(y - 1, x);
    q.push(tmp);
  }
  //下
  if (y < H - 1 && maze[y + 1][x] == '.' && !check[y + 1][x]) {
    check[y+1][x] = true;
    tmp = make_pair(y + 1, x);
    q.push(tmp);
  }
  //左
  if (x > 0 && maze[y][x - 1] == '.' && !check[y][x - 1]) {
    check[y][x-1] = true;
    tmp = make_pair(y, x - 1);
    q.push(tmp);
  }
  //右
  if (x < W - 1 && maze[y][x + 1] == '.' && !check[y][x + 1]) {
    check[y][x+1] = true;
    tmp = make_pair(y, x + 1);
    q.push(tmp);
  }
  return q;
}

int clearMaze() {
  queue<pair<int, int>> q, q2;
  pair<int, int> start = make_pair(0, 0);
  q2.push(start);
  check[0][0] = true;
  int i = 0;
  while (true) {
    if(goal){
      return i;
    }
    if(q2.empty()){
      return -1;
    }
    i++;
    q.swap(q2);
    while (!q.empty()) {
      q2 = BFS(q2, q.front());
      q.pop();
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> H >> W;
  int white = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> maze[i][j];
      if(maze[i][j] == '.'){
        white++;
      }
    }
  }
  int root = clearMaze();
  if(root > 0){
    cout << white - root <<endl;;
  } else{
    cout << -1 <<endl;
  }
}


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

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i)
#define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

signed main() {
  ll N, M, V, P;
  ins(N, M, V, P);

  vector<ll> A(N);
  rep(i, N)
    cin >> A[i];
  all(sort, A); all(reverse, A);

  int ok = -1, ng = N;
  auto f = [&](int mid) {
    if (mid < P) return true;
    if (A[P-1] > A[mid]+M) return false;

    ll tmp = 1LL * ((N-mid)+P-1) * M;
    rep(i, P-1, mid)
      tmp += min(1LL*M, max(0LL, A[mid]+M-A[i]));
    return tmp >= M*V;
  };
  while (abs(ok - ng) > 1) {
    int mid = ok + (ng-ok) / 2;
    (f(mid) ? ok : ng) = mid;
  }
  cout << ok+1 << endl;
  return 0;
}

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

int main() {
  ll N, M, V, P;
  cin>>N>>M>>V>>P;
  vector<ll> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  sort(A.begin(), A.end());
  ll l=0, r=N-1, m;
  ll score;
  ll vote;
  vector<ll> tmparr(N);
  ll zero = 0;
  int index;
  while(l<r) {
    m = (l+r)/2;
    score = M+A[m];
    vote = M*(V-1);
    for(int i=0;i<N;++i) {
      if(i!=m) vote -= min(M, max(zero, score-A[i]));
      tmparr[i] = max(score, A[i]);
    }
    for(int i=N-1;i>=0;--i) {
      if(vote>0) {
        vote -= M-max(score-A[i], zero);
        tmparr[i] = score+1;
      }
    }
    index = upper_bound(tmparr.begin(), tmparr.end(), score)-tmparr.begin();
    if(N-index<P) r = m;
    else l=m+1;
  }
  cout<<N-l<<endl;
}


#include <iostream>

#define MX 1000000000

using namespace std;
int M[100][100],N; //M[i][j]:i©çjÜÅÌRXg

int dijkstra(int s , int g){
  bool visited[100];
  int d[100];
  for(int i=0;i < N;i++) d[i] = MX , visited[i] = false;
  d[s] = 0;
  while(1){
    int u;
    int mincost = MX;
    for(int i=0;i<N;i++)if(!visited[i] && d[i] < mincost) mincost = d[i] , u = i;
    if(mincost == MX) break;
    visited[u] = true;
    for(int v=0;v<N;v++){
      if(visited[v] || M[u][v] == MX) continue;
      if(d[v] > d[u] + M[u][v]) d[v] = d[u] + M[u][v];
    }
  }
  return d[g];
}

int main(){
  int k;
  while(cin >> N >> k){
    for(int i=0;i<N;i++)for(int j=0;j<N;j++) M[i][j] = MX;
    while(k--){
      int x,a,b,c;
      cin >> x;
      if(!(x)){
        int cost;
        cin >> a >> b;
        cost = dijkstra(a-1,b-1);
        if(cost == MX) cout << "-1" << endl;
        else cout << cost << endl;
      }
      else {
        cin >> a >> b >> c;
        if(M[a-1][b-1] > c && M[b-1][a-1] > c) M[a-1][b-1] = M[b-1][a-1] = c;
      }
    }
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>

#define INF (1e+9)
#define LLINF (1e+18)
#define LL long long

#define MAX_V 100

using namespace std;

typedef struct edge{
	int to;
	int cost;
	edge(){

	}
	edge(int _to,int _cost){
		to = _to;
		cost = _cost;
	}
	bool operator<(const edge &a)const{
		if(cost == a.cost) return to > a.to;
		return cost > a.cost;	//for asc
	}
}edge;

int cost[MAX_V + 1];
vector<edge> G[MAX_V + 1];
priority_queue<edge> pque;

int V;
int K;

void solve(int s){
	for(int i = 1;i <= V;i++){
		cost[i] = INF;
	}

	pque.push(edge(s,0));

	while(!pque.empty()){
		edge e = pque.top();pque.pop();
		if(cost[e.to] != INF) continue;
		cost[e.to] = e.cost;
		for(int i = 0;i < G[e.to].size();i++){
			int _to = G[e.to][i].to;
			int _cost = e.cost + G[e.to][i].cost;
			pque.push(edge(_to,_cost));
		}
	}

	return ;
}

int main (void){

	while(true){
		scanf("%d%d",&V,&K);
		if(V == 0 && K == 0) break;
		int query;
		int _u,_v,_cost;
		for(int i = 0;i < K;i++){
			scanf("%d",&query);
			if(query){
				scanf("%d%d%d",&_u,&_v,&_cost);
				G[_u].push_back(edge(_v,_cost));
				G[_v].push_back(edge(_u,_cost));
			}
			else {
				scanf("%d%d",&_u,&_v);
				solve(_u);
				if(cost[_v] == INF)puts("-1");
				else printf("%d\n",cost[_v]);
			}
		}
		for(int i = 1;i <= V;i++) G[i].clear();
	}

	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int h[2], m[2], k;
  cin >>  h[0] >> m[0] >> h[1] >> m[1] >> k;
  int up   = h[0] * 60 + m[0];
  int down = h[1] * 60 + m[1];
  if (down - up - k < 0) {
    P(0);
  } else {
    P(down - up - k);
  }
  return 0;
}

#include <bits/stdc++.h>
#define de(x) cout << #x << "=" << x << ", "
#define dd cout << '\n';
#define XinAi ios::sync_with_stdio(0), cin.tie(0);
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
const int N = 1e4+10;

string dp[N], val[15];
string num = "123456789";
int c[] = {2,5,5,4,5,6,3,7,6}, cs[200], n, m;
string a[15];

void update (string &x, string y, string z)
{
    if (x.size() > y.size() + 1) return;
    if (z[0] > y[0]) z += y, swap(y, z);
    else y += z;
    if (x.size() < y.size()) x = y;
    else
    {
        for (int i=0; i<x.size(); i++)
        {
            if (x[i] > y[i]) return;
            else if (x[i] < y[i])
            {
                x = y;
                break;
            }
        }
    }
}

signed main()
{
    XinAi
    for (int i=0; i<9; i++) cs[num[i]] = c[i];
    cin >> n >> m;
    for (int i=0; i<m; i++) cin >> a[i];
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++)
        {
            if (i!=0 && dp[i]=="") continue;
            update(dp[i+cs[a[j][0]]], dp[i], a[j]);
        }
    cout << dp[n] << '\n';
}