/* be name khoda */

// #define stream_enable
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 1010;

ll n;
char R[maxn][maxn];
string G[8][7] = {{},{},{},
    {"aab",
     "b.b",
     "baa"},
    {"aacd",
     "bbcd",
     "cdaa",
     "cdbb"},
    {"aabba",
     "bcc.a",
     "b..cb",
     "a..cb",
     "abbaa"},
    {"aabcc.",
     "b.b..c",
     "baa..c",
     "c..aab",
     "c..b.b",
     ".ccbaa"},
    {"aabbaa.",
     "ccd...a",
     "d.d...a",
     "dcc...b",
     "...ccdb",
     "...d.da",
     "...dcca"}};

void MAIN() {

    cin >> n;
    if (n == 2) {cout << "-1\n"; return;}
    memset(R, '.', sizeof R);
    ll i = n;
    while (i >= 8) {
        i -= 4;
        fori (j, 4) fori (k, 4) R[i + j][i + k] = G[4][j][k];
    }
    fori (j, i) fori (k, i) R[j][k] = G[i][j][k];
    fori (i, n) {
        fori (j, n) {
            cout << R[i][j];
        }
        cout << '\n';
    }

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n <= 2) {
        cout << "-1\n";
    } else if (n % 3 == 0) {
        rep (i, n) {
            rep (j, n) {
                if (i / 3 == j / 3 && ((i % 3 == 0) ^ (j % 3 == 0))) cout << 'a';
                else cout << '.';
            }
            cout << "\n";
        }
    } else if (n == 7) {
        cout << "abb...a\n"
             << "a.a...a\n"
             << "bba...c\n"
             << "...abbc\n"
             << "...a.ab\n"
             << "...bbab\n"
             << "bbaacc.\n";
    } else if (n == 11) {
        cout << "bccaabbccaa\n"
             << "babb...abbc\n"
             << "ca.a...a.ac\n"
             << "cbba...bbab\n"
             << "baccbcc...b\n"
             << "ba.ab.b...a\n"
             << "accaccb...a\n"
             << "a...baacaab\n"
             << "b...b.bc.cb\n"
             << "b...aabaaca\n"
             << "ccaabbccbba\n";
    } else {
        int a, b;
        for (int i = n / 5; i >= 0; i--) {
            if ((n - 5 * i) % 4 == 0) {
                a = i;
                b = (n - 5 * i) / 4;
                break;
            }
        }
        // eprintf("a=%d, b=%d\n", a, b);
        vector<string> s4 = {"aaca", "bbca", "acbb", "acaa"},
                       s5 = {"aacca", "c.bba", "cb..c", "ab..c", "accaa"};
        rep (i, n) {
            rep (j, n) {
                if (i / 5 == j / 5 && i / 5 < a) {
                    // cout << 1;
                    cout << s5[i % 5][j % 5];
                } else if ((i - 5 * a) / 4 == (j - 5 * a) / 4 && i - 5 * a >= 0 && j - 5 * a >= 0) {
                    // cout << 2;
                    cout << s4[(i - 5 * a) % 4][(j - 5 * a) % 4];
                } else {
                    // cout << 3;
                    cout << '.';
                }
            }
            cout << "\n";
        }
    }
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int a;
	cin>>a;
	a=a+pow(a,2)+pow(a,3);
	cout<<a;
	}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    a= a + a*a + a*a*a;
    cout<<a;
    return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

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> B;
	for(int i=n-1;i>=0;i--){
		auto v=a[i];
		for(auto b:B) v=min(v,v^b);
		if(v!=0){
			if(s[i]=='1'){
				puts("1");
				return;
			}
			B.emplace_back(v);
		}
	}
	puts("0");
}

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

#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define rr register
using namespace std;
const int d[10]={6,2,5,5,4,5,6,3,7,6};
int m,n,x[10],f[10011];
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
inline signed max(int a,int b){return a>b?a:b;}
signed main(){
	m=iut(),n=iut(),memset(f,0xcf,sizeof(f));
	for (rr int i=1;i<=n;++i) x[i]=iut();
	sort(x+1,x+1+n),reverse(x+1,x+1+n),f[0]=0;
	for (rr int i=1;i<=n;++i)
	for (rr int j=d[x[i]];j<=m;++j)
	    f[j]=max(f[j],f[j-d[x[i]]]+1);
	while (m){
		for (rr int i=1;i<=n;++i)
		if (m>=d[x[i]]&&f[m]==f[m-d[x[i]]]+1){
			putchar(x[i]+48),m-=d[x[i]];
			break;
		}
	}
	return !putchar(10);
}


//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    struct BIT
    {
        int bit[N];BIT(){memset(bit,0,sizeof bit);}
        int lowbit(int x){return x&-x;}
        void add(int x,int c){while(x<N)bit[x]+=c,x+=lowbit(x);}
        int ask(int x){int ans=0;while(x>=1)ans+=bit[x],x-=lowbit(x);return ans;}
    }bit[2];
    int fm[3][N];int getid(int num){return 1+(num-1)/3;}
    void gg(){puts("No");exit(0);}
    int inv[2],flip[2];
	void main()
	{
        int n=qread();fo(op,0,2) fo(i,1,n) fm[op][i]=qread();
        fo(i,1,n)
        {
            if(getid(fm[0][i])!=getid(fm[1][i]) or getid(fm[1][i])!=getid(fm[2][i])) gg();
            bool x=fm[0][i]<fm[1][i] and fm[1][i]<fm[2][i],y=fm[0][i]>fm[1][i] and fm[1][i]>fm[2][i];
            if(!x and !y) gg();flip[i&1]+=y;
            int id=getid(fm[0][i]);if((id&1)^(i&1)) gg();
            inv[i&1]+=bit[i&1].ask(n-id+1),bit[i&1].add(n-id+1,1);
        }
        if((inv[0]&1)^(flip[1]&1) or (inv[1]&1)^(flip[0]&1)) gg();
        puts("Yes");
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

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

#define pb push_back
#define ff first
#define ss second

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

const int MAXN = 4 * 100 * 1000 + 17;

int n, a[4][MAXN], b[4][MAXN], p[MAXN], q[MAXN], fen[MAXN];
vector<int> v[2];

void add(int x) {
	for (; x <= n; x += x & (-x))
		fen[x]++;
}
int get(int x) {
	int res = 0;
	for (; x; x -= x & (-x))
		res += fen[x];
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= 3; i++)
		for (int j = 1; j <= n; j++)
			cin >> a[i][j], b[i][j] = j * 3 + i - 3, p[b[i][j]] = j, q[b[i][j]] = i;
	for (int j = 1; j <= n; j++) {
		if (p[a[1][j]] != p[a[2][j]] || p[a[2][j]] != p[a[3][j]] || q[a[2][j]] != 2 || p[a[1][j]] % 2 != j % 2)
			return cout << "No" << endl, 0;
		v[j % 2].pb(j);
	}
	for (int k = 0; k < 2; k++) {
		int inv = 0;
		for (int i = v[k].size() - 1; i >= 0; i--)
			(inv += get(p[a[1][v[k][i]]])) %= 2, add(p[a[1][v[k][i]]]);
		int up = 0;
		for (int i = 0; i < v[1 - k].size(); i++)
			if (a[1][v[1 - k][i]] % 3 == 0)
				up++;
		if (up % 2 != inv % 2)
			return cout << "No" << endl, 0;
		for (int i = 1; i <= n; i++)
			fen[i] = 0;
	}
	cout << "Yes" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always

/*
 最小全域木

 どうやってcostでsortするかがpointかな

 組み合わせ考えたらN^2

 解説見た
 ある点と、その点から2本以上の辺を通って着く点との距離は、すべての点で隣だけ見たら求まる

 cost = min(|a - c|, |b - d|)より

 */

class UnionFind {
public:
    vector<int> Parent;
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    int size(int A) {
        return -Parent[root(A)];
    }
    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return true;
        }
        if (size(A) < size(B)) swap(A, B);
        Parent[A] += Parent[B];
        Parent[B] = A;
        return false;
    }
};

bool comp(pair<int, pii> a, pair<int, pii> b) {
    return a.S.F < b.S.F;
}
bool comp2(pair<int, pii> a, pair<int, pii> b) {
    return a.S.S < b.S.S;
}
bool compv(pair<pii, int> a, pair<pii, int> b) {
    return a.S < b.S;
}

int main() {

    int n; cin >> n;
    pair<int, pii> p[n];
    rep(i, n) {cin >> p[i].S.F >> p[i].S.S; p[i].F = i;}

    sort(p, p + n, comp);
    vector<pair<pii, int> > v; //id1, id2, cost
    rep3(i, 1, n) {
        v.eb(pii(p[i].F, p[i - 1].F), p[i].S.F - p[i - 1].S.F);
    }
    sort(p, p + n, comp2);
    //cout << endl; rep(i, n) cout << p[i].F << " " << p[i].S.F << " " << p[i].S.S << endl;
    rep3(i, 1, n) {
        v.eb(pii(p[i].F, p[i - 1].F), p[i].S.S - p[i - 1].S.S);
    }
    sort(all(v), compv);

    //cout << endl; rep(i, SZ(v)) cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;

    UnionFind uni(n);
    ll ans = 0;
    rep(i, SZ(v)) {
        if (uni.connect(v[i].F.F, v[i].F.S) == 1) continue;
        //cout << v[i].F.F << " " << v[i].F.S << " " << v[i].S << endl;
        ans += v[i].S;
    }
    out(ans);

}

#include <bits/stdc++.h>

using namespace std;

const int N = 200010;

int n;
int p[N];
pair<pair<int, int>, int> c[N];
pair< int, pair<int, int> > e[N];

int group(int a) {
  if (p[a] == -1) {
    return a;
  }
  return p[a] = group(p[a]);
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    c[i] = make_pair(make_pair(x, y), i);
  }
  for (int it = 0; it < 2; it++) {
    sort(c, c + n);
    for (int i = 0; i < n - 1; i++) {
      int x = c[i].second;
      int y = c[i + 1].second;
      int d = abs(c[i + 1].first.first - c[i].first.first);
      e[it * (n - 1) + i] = make_pair(d, make_pair(x, y));
    }
    for (int i = 0; i < n; i++) {
      swap(c[i].first.first, c[i].first.second);
    }
  }
  sort(e, e + 2 * n - 2);
  fill_n(p, n, -1);
  long long ans = 0;
  for (int i = 0; i < 2 * n - 2; i++) {
    int x = group(e[i].second.first);
    int y = group(e[i].second.second);
    int d = e[i].first;
    if (x == y) {
      continue;
    }
    p[x] = y;
    ans += d;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
    ll n;
    cin >> n;
    ll sum = 26;
    ll cnt = 1;
    while (1)
    {
        if (n <= sum)
            break;
        sum = sum * 26 + 26;
        cnt++;
    }
    vector<string> res(cnt);
    rep(i, cnt)
    {
        n--;
        int ans = n % 26;
        res[cnt - i - 1] = (char)('a' + ans);
        n /= 26;
    }
    rep(i, res.size()) cout << res[i];
    cout << endl;
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

int main(){
  ll N;
  cin >> N;
  char a[28];
  string s = "";
  for(char i='a'; i<='z';i++){
	a[int(i) - int('a')] = i;
  }
  while(N){
	N--;
	s += a[N%26];
	N /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int h,w;
int maps[101][101];
int check[101][101];
int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};
int color;
int sy,sx,gy,gx;
int by0[]={0,0,1,1,0,0,1,1};
int bx0[]={0,1,1,0,2,3,2,3};
int by1[]={0,0,1,1,2,3,2,3};
int bx1[]={0,1,1,0,0,0,1,1};

bool solve(int y,int x);

int main(){
  int n,c,d,x,y;
  while(cin>>w>>h,w|h){
    cin>>sx>>sy;
    cin>>gx>>gy;
    cin>>n;
    memset(check,0,sizeof(check));
    for(int i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      x--;y--;
      if(d==0){
	for(int i=0;i<8;i++){
	  maps[y+by0[i]][x+bx0[i]]=c;
	}
      }
      if(d==1){
	for(int i=0;i<8;i++){
	  maps[y+by1[i]][x+bx1[i]]=c;
	}
      }
    }
    sy--;sx--;gy--;gx--;
    color=maps[sy][sx];
    if(solve(sy,sx))cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
}

bool solve(int y,int x){
  check[y][x]=1;
  if(y==gy && x==gx)return true;
  bool b=false;
  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(ny>=0 && ny<h && nx>=0 && nx<w && maps[ny][nx]==color && check[ny][nx]==0){
      b=b | solve(ny,nx);
    }
  }
  return b;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define rep(i,n) for(int i = 0; i < n; i++)
#define MSG(a) cout << #a << " " << a << endl;
template<class T, class C> pair<T,C> mp(T a, C b){ return make_pair(a, b);}

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<vector<bool> > s(n, vector<bool>(n));
		rep(i,n+1) fill(s[0].begin(), s[0].end(), false);

		int m;
		cin >> m;

		rep(i,m)
		{
			int a, b;
			cin >> a >> b;
			s[a-1][b-1] = s[b-1][a-1] = true;
		}

		int res = 0;

		for(int i = 1; i < n; i++)
		{
			if(s[0][i])	res++;
			else
			{
				for(int j = 1; j < n; j++)
				{
					if(s[0][j] && s[j][i])
					{
						res++;
						break;
					}
				}
			}
		}
		cout << res << endl;
	}
}


#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

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

    if(A + B > C + D)
        cout << "Left" << endl;
    else if(A + B == C + D)
        cout << "Balanced" << endl;
    else
        cout << "Right" << endl;

}

#include <stdio.h>

int main (){
	int baris,kolom,warna,x;

	scanf ("%d",&baris);
	scanf ("%d",&kolom);
	scanf ("%d",&warna);

	if (baris > kolom){
        x = (warna - 1)/baris +1;
    }
    else {
        x = (warna - 1)/kolom +1;
    }

	printf ("%d",x);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 100005, MAX_M = 200010;
// code
//#define int long long

int x[MAXN];
int sps[MAXN][20];
int n, q, l;
void Solve() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    cin >> l >> q;
    int jump = n;
    for (int i = n; i >= 1; i--){
		while(x[jump] - x[i] > l) jump--;
		sps[i][0] = jump;
    }
    for (int d = 1; d <= 19; d++){
        for (int i = 1; i + (1 << d) <= n; i++)
            sps[i][d] = sps[ sps[i][d-1] ][d-1];
    }
    while (q--){
        int a, b, ans = 0;
        cin >> a >> b;
        if (a > b) swap(a, b);
        for (int d = 19; d >= 0; d--){
            if (sps[a][d] < b && sps[a][d]){
                a = sps[a][d];
                ans += (1 << d);
            }
        }
        ans ++;
        cout << ans << endl;
    }
}

signed main(){
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll a,b;
    cin>>a>>b;
    //a　白 b 黒
    VV g(100,Vec(100,0));

    rep(i,50){
        rep(j,100){
            g[i][j] = 1;
        }
    }
    a--;b--;
    REP(i,0,a){
        ll h = i/50;
        ll w = i%50;
        g[h*2][w*2] = 0;
    }

    REP(i,0,b){
        ll h = i/50;
        ll w = i%50;
        g[99-h*2][w*2] = 1;
    }

    cout<<100<<" "<<100<<endl;
    rep(i,100){
        string s;
        rep(j,100){
            s += g[i][j]==1?'#':'.';
        }
        cout<<s<<endl;
    }

    return  0;
}


#include<bits/stdc++.h>
#define SORT(v) sort(v.rbegin() , v.rend())
#define si(n) scanf( "%d" , &n)
#define sii(n , m) scanf( "%d %d" , &n , &m)
#define sl(n) scanf( "%lld" , &n)
#define sll(n , m) scanf( "%lld %lld" , &n, &m)
#define ss(cad) scanf( "%s" , cad)
#define sz(x) (int)x.size()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl
#define M 1000000007
#define N_MAX 1000010
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vp;

void mostrar(set<pi> ls){
	for(auto x: ls)
		printf("(%d, %d) ", x.fst, x.scn);
}

int main(){
	int h, w;
	sii(h, w);
	set<pi> lista;
	multiset<int> num;
	for(int i = 1; i <= w; i++){
		lista.insert({i, 1});
		num.insert(1);
	}
	int cnt = 0;
	while(h--){
		int a, b;
		sii(a, b);
		bool sw = 0;
		auto pt = lista.lower_bound(pi(a, -1));
		auto pt2 = pt;
		pi mitad = {-1, -1};
		pi inicio;
		if(pt != lista.begin()){
			sw = 1;
			pt--;
			mitad = *pt;
			inicio = *pt;
			pt++;
		}
		while(pt != lista.end() && pt->fst <= b){
			pt2 = pt;
			mitad = *pt;
			num.erase(num.lower_bound(mitad.scn));
			pt++;
			lista.erase(pt2);
		}
		pt2 = lista.lower_bound(pi(b+1, -1));
		if(mitad.fst != -1 && b != w){
			if(pt2 != lista.end() && pt2->fst != b+1){
				int val = mitad.scn + b-mitad.fst+1;
				//update(val, 1);
				num.insert(val);
				lista.insert({b+1, val});
			}
			else if(pt2 == lista.end()){
				int val = mitad.scn + b-mitad.fst+1;
				//update(val, 1);
				num.insert(val);
				lista.insert({b+1, val});
			}
		}
		if(sw){
			int val = inicio.scn + a-inicio.fst;
			//update(val, 1);
			num.insert(val);
			lista.insert({a, val});
		}
		if(num.empty())
			printf("-1\n");
		else
			printf("%d\n", *num.begin()+cnt);
		//mostrar(lista);
		//cout << endl;
		cnt++;
	}
    return 0;
}

/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n,m,sz,cnt;
vector<int>g[100005];
int col[100005],id[100005];
void dfs(int x,int ind){
	sz++;
	for(auto to:g[x]){
		if(!col[to]){
			col[to]=3-col[x];
			id[to]=ind;
			dfs(to,ind);
		}
	}
}
bool bin[100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int tot=0;
	for(int i=1;i<=n;i++){
		if(!col[i]){
			col[i]=1;
			id[i]=++tot;
			sz=0;
			dfs(i,tot);
			if(sz==1)cnt++;
		}
	}
	for(int i=1;i<=tot;i++)bin[i]=1;
	for(int i=1;i<=n;i++){
		for(auto to:g[i]){
			if(col[i]==col[to]){
				bin[id[i]]=0;
			}
		}
	}
	int cnt1=-cnt,cnt2=0;
	for(int i=1;i<=tot;i++){
		if(bin[i])cnt1++;
		else cnt2++;
	}
	cout<<(ll)n*n-(ll)(n-cnt)*(n-cnt)+(ll)(tot-cnt)*(tot-cnt)+(ll)cnt1*cnt1<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool isStraight(vector<int> v, int s) {
	for (int i = 1; i < v.size(); ++i) {
		if (v[(s+i)%v.size()] != (v[(s+i-1+v.size())%v.size()]+1)%13) {
			return false;
		}
	}
	return true;
}
bool isStraight(vector<int> v) {
	return isStraight(v, 0) || (v[0] == 0 && isStraight(v, 1));
}
int main() {
	vector<int> a(5);
	while ( scanf("%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4]) != EOF ) {
		for (int i = 0; i < a.size(); ++i) {
			--a[i];
		}
		sort(a.begin(), a.end());
		vector<int> v(1, 1);
		int prev = a[0];
		for (int i = 1; i < a.size(); ++i) {
			if (prev == a[i]) {
				++v[v.size()-1];
			}
			else {
				v.push_back(1);
				prev = a[i];
			}
		}
		sort(v.begin(), v.end(), greater<int>());
		if (v[0] >= 4) {
			cout << "four card" << endl;
		}
		else if (v.size() >= 2 && v[0] >= 3 && v[1] >= 2) {
			cout << "full house" << endl;
		}
		else if ( isStraight(a) ) {
			cout << "straight" << endl;
		}
		else if (v[0] >= 3) {
			cout << "three card" << endl;
		}
		else if (v.size() >= 2 && v[1] >= 2) {
			cout << "two pair" << endl;
		}
		else if (v[0] >= 2) {
			cout << "one pair" << endl;
		}
		else {
			cout << "null" << endl;
		}

	}
}

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>
#include <set>
#include <numeric>

using namespace std;

int t[5];

bool straight()
{
	if(t[0] == 1 && t[1] == 10 && t[2] == 11 && t[3] == 12 && t[4] == 13) return true;
	for (int i = 0; i < 4; i++){
		if(t[i+1]-t[i] != 1) return false;
	}
	return true;
}

int main()
{
	while(~scanf("%d,%d,%d,%d,%d",t,t+1,t+2,t+3,t+4)){
		sort(t,t+5);
		if(t[0] == t[3] || t[1] == t[4])
			puts("four card");
		else if( (t[0] == t[1] && t[2] == t[4]) || (t[0] == t[2] && t[3] == t[4]))
			puts("full house");
		else if(straight())
			puts("straight");
		else if(t[0] == t[2] || t[1] == t[3] || t[2] == t[4])
			puts("three card");
		else if( (t[0] == t[1] && (t[2] == t[3] || t[3] == t[4])) || (t[1] == t[2] && t[3] == t[4]) )
			puts("two pair");
		else if( t[0] == t[1] || t[1] == t[2] || t[2] == t[3] || t[3] == t[4])
			puts("one pair");
		else
			puts("null");
	}
	return 0;
}


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

const int N = 100001;
int f[N], inv[N], k, n;

inline int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

inline int qp(int base, int pow) {
	int res = 1;
	while (pow) {
		if (pow & 1)
		res = res * base, res %= mo;
		base = base * base;
		base %= mo;
		pow >>= 1;
	}
	return res;
}

inline void pre() {
	f[0] = 1;
	for (register int i = 1; i <= 100000; ++i) {
		f[i] = f[i - 1] * i;
		f[i] %= mo;
	}
	inv[100000] = qp(f[100000], mo - 2);
	for (register int i = 99999; i >= 0; --i) {
		inv[i] = inv[i + 1] * (i + 1) % mo;
	}
}

inline int C(int n, int m) {
	if (n < m) return 0;
	return f[n] * inv[n - m] % mo * inv[m] % mo;
}

void solve(int x) {
	int t = 0;
	for (int i = 1; i <= x / 2; ++i) {
		int a = i, b = x - i;
		if (a <= k && b <= k) t++;
	}
//	printf("%lld %lld\n", x, t);
	int flag = 1, w = t, res = 0;
	for (int i = 1; i <= t; ++i) {
		(res += C(n + k - 1 - 2 * i, k - 1) * flag * C(t, i) % mo) %= mo;
		w--;
		flag = -flag;
	}
	int ans = (C(n + k - 1, k - 1) - res + mo) % mo;
	printf("%lld\n", ans);
}

signed main() {
	pre();
	k = read(), n = read();
	for (int i = 2; i <= 2 * k; ++i) {
		solve(i);
	}
	return 0;
}


#include<iostream>
using namespace std;

int main(){
    int n,x,i=3;
    cin >> n;
    while(n>=i){
        x=i;
        if(i%3==0){
            cout << ' ' << i;
        } else if(i%10==3){
            cout << ' ' << i;
        } else {
            while(x!=0){
                x/=10;
                if(x%10==3){
                cout << ' ' << i;
                break;
                }
            }
        }
        i++;
    }
    cout << endl;
}

// @author: arch_

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

int main(void) {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0
            || to_string(i).find("3") != string::npos)
            cout << " " << i;
    } cout << "\n";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vd vector<double>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";cout << '\n';
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;

	vi a(n);
	for(int& x : a)cin >> x;

	vi b(n);
	for(int& x : b)cin >> x;

	reverse(all(b));

	int l=0, r=n-1;
	for(int i=0 ; i<n ; ++i){
		if(a[i] == b[i]){
			if(a[l] != b[i] && b[l] != b[i]){
				swap(b[i], b[l]);
				++l;
			}
			else if(a[r] != b[i] && b[r] != b[i]){
				swap(b[i], b[r]);
				--r;
			}
			else{
				cout << "No\n";
				return;
			}
		}
	}

	for(int i=0 ; i<n ; ++i){
		if(a[i] == b[i]){
			cout << "No\n";
			return;
		}
	}

	cout << "Yes\n";
	for(int& x : b)cout << x << " ";
}

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

	cout << fixed << setprecision(10);

	int tt=1;
	//cin >> tt;

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

#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 n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        --A[i];
    }
    vector<int> B(n);
    for (int i = 0; i < n; ++i) {
        cin >> B[i];
        --B[i];
    }

    const int INF = 1 << 24;
    vector<pair<int,int>> rangesA(n, make_pair(INF, -INF));
    vector<pair<int,int>> rangesB(n, make_pair(INF, -INF));

    for (int i = 0; i < n; ++i) {
        int l = i;
        int x = A[i];
        while (i + 1 < n && A[i + 1] == x) {
            ++i;
        }
        int r = i;
        rangesA[x] = make_pair(l, r);
    }
    for (int i = 0; i < n; ++i) {
        int l = i;
        int x = B[i];
        while (i + 1 < n && B[i + 1] == x) {
            ++i;
        }
        int r = i;
        rangesB[x] = make_pair(l, r);
    }

    bool ok = true;
    for (int i = 0; i < n; ++i) {
        int cntA = rangesA[i].second - rangesA[i].first + 1;
        int cntB = rangesB[i].second - rangesB[i].first + 1;
        if (cntA > 0 && cntB > 0 && cntA > n - cntB) {
            ok = false;
            break;
        }
    }

    if (!ok) {
        cout << "No\n";
        return 0;
    }

    vector<int> cnts(2 * n + 1, 0);

    for (int i = 0; i < n; ++i) {
        int la = rangesA[i].first, ra = rangesA[i].second;
        int lb = rangesB[i].first, rb = rangesB[i].second;
        if (la >= n || lb >= n) {
            continue;
        }

        int r = ra - lb;
        if (r < 0) {
            r += n;
        }
        int l = (la - (rb - lb)) - lb;
        while (l < 0) {
            l += n;
        }
        while (l > r) {
            r += n;
        }
        // cout << i << " : " << l << " - " << r << endl;
        cnts[l] += 1;
        cnts[r + 1] -= 1;
    }
    for (int i = 1; i < cnts.size(); ++i) {
        cnts[i] += cnts[i - 1];
    }

    int offset = -1;
    for (int i = 0; i < n; ++i) {
        if (cnts[i] + cnts[i + n]== 0) {
            offset = i;
            break;
        }
    }

    vector<int> res(n, 0);
    for (int i = 0; i < n; ++i) {
        res[i] = (B[(i - offset + n) % n]);
    }

    cout << "Yes\n";
    for (int i = 0; i < n; ++i) {
        cout << res[i] + 1 << (i == n - 1 ? '\n' : ' ');
    }
    return 0;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>
int INF = (1 << 29);

int main() {
    int N, M;
    cin>> N >> M;
    vvi G(N);
    REP(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
    }
    int shortest = N + 1;
    vi ans;
    REP(i, 0, N){
        vi dist(N, -1), prev(N, -1);
        queue<int> que;
        que.push(i);
        dist[i] = 0;
        while(!que.empty()){
           auto cur = que.front(); que.pop();
           for(int x: G[cur]){
               if(dist[x] == -1){
                   dist[x] = dist[cur] + 1;
                   prev[x] = cur;
                   que.push(x);

               }
            }
        }
        REP(j, 0, N){
            if(j == i || dist[j] == -1) continue;
            for(auto nj: G[j]){
                if(nj == i){
                    vi tmp({i+1});
                    int cur = j;
                    while(cur != i) tmp.push_back(cur+1), cur = prev[cur];
                    if(shortest > tmp.size()){
                        shortest = tmp.size();
                        ans = tmp;
                    }
                }
            }
        }
    }
    if(shortest == N+1) cout << -1 << endl;
    else{
        cout << ans.size() << endl;
        for(auto v: ans) cout << v << endl;
    }
}

#include<iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, vis[1009], vis2[1009],par[1009],go[1009][1009] ;
vector<int> v[1009];
vector<int> ans;
void solve()
{
    int sz=ans.size();
    for(int i=0; i<sz; i++)
    {
        for(int j=i+2; j<sz; j++)
            if(go[ans[i]][ans[j]])
            {
                ans.erase(ans.begin()+i+1,ans.begin()+j);
                solve();
                return ;
            }
        int j=0;
        if(i==sz-1)
            j=1;
        for(; j<i; j++)
            if(go[ans[i]][ans[j]])
            {
                ans.erase(ans.begin()+i+1,ans.end());
                ans.erase(ans.begin(),ans.begin()+j);
                solve();
                return ;
            }
    }
    cout<<ans.size()<<endl;
    for(auto i : ans)
        cout<<i<<"\n";
}
void dfs(int node)
{
    if(vis2[node])
    {
        int x=node;
        while(par[x]!=node)
            ans.push_back(x), x=par[x];
        ans.push_back(x);
        reverse(ans.begin(),ans.end());
        solve();
        exit(0);
    }
    if(vis[node])
        return ;
    vis2[node]++;
    vis[node]++;
    for(auto i : v[node])
    {
        par[i]=node;
        dfs(i);
    }
    vis2[node]--;
}
int main()
{
    IO
    cin>>n>>m;
    while(m--)
    {
        int x, y ;
        cin>>x>>y;
        go[x][y]=1;
        v[x].push_back(y);
    }
    for(int i=1; i<=n; i++)
        dfs(i);
    cout<<-1;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	FOR(i,n) cin >>a[i];
	sort(a,a+n);
	int j=n-1;
	while(j>=1 && a[j]!=a[j-1]) j--;
	if(j==0) {
		cout <<0;
		return 0;
	}
	else {
		int k=j-2;
		while(k>=1 && a[k]!=a[k-1]) k--;
		if(k==0) {
			cout << 0;
			return 0;
		}
		else cout << a[j]*a[k];
	}

	return 0;
}

#include <iostream>
#include <string>

using namespace std;

bool isPlain(string secret){
    bool find_the,find_that,find_this;

    find_the = (secret.find("the") != string::npos);
    find_that = (secret.find("that") != string::npos);
    find_this = (secret.find("this") != string::npos);

    return (find_the || find_that || find_this);
}

string decipher(string secret){
    int gap = 1;
    string plain;
    bool check;

    //"the", "that", "this"
    check = isPlain(secret);

    if(check){
        plain = secret;
    }
    else {
        while(gap<=26){
            string::iterator it = secret.begin();
            for (; it != secret.end(); it += 1){
                if('a'<=*it & *it <='z')
                    *it = (*it!='z') ? *it + 1 : 'a';
                //cout << *it;
            }
            //cout << endl;
            gap++;
            if(isPlain(secret)) break;
        }
    }
    return secret;
}

int main (int argc, char const* argv[]){
    string secret, plain;

    //暗号文の取得
    getline(cin,secret);
    while(!secret.empty()){

        //暗号解読
        plain = decipher(secret);
        //平文の出力
        cout << plain << endl;

        getline(cin,secret);
    }

    return 0;
}


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

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return true;
    vector<pair<double,string> > ls;
    for(int i=0;i<n;i++){
        string l;
        int p, a, b, c, d, e, f, s, m;
        cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
        int X = f*s*m - p, Y = a+b+c+(d+e)*m;
        ls.emplace_back(make_pair(double(-X)/Y,l));
    }
    sort(ls.begin(), ls.end());
    for(int i=0;i<n;i++){
        cout << ls[i].second << endl;
    }
    cout << '#' << endl;
    return false;
}

int main(){
    while(!solve());
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n, x[105], y[105];
double mx, z[105], PI = acos(-1.0);
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) scanf("%d%d", &x[i], &y[i]);
	for(i=0; i<n; i++) {
		for(j=k=0; j<n; j++) if(i!=j) z[k++] = atan2(y[j]-y[i], x[j]-x[i]);
		sort(z, z+k);
		mx = z[0] - z[k-1] + 2*PI ;
		for(j=1; j<k; j++) mx = max(mx, z[j] - z[j-1]);
		printf("%.9f\n", max(0., (mx-PI)/2./PI));
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
int main(){
 int n,i,x;
 scanf("%d",&n);
 i=1;
 do {
  x=i;
  if(x%3==0){
   cout << " " << i;
  } else do {
   if ( x%10 == 3 ) {
      cout << " " << i;
      x=0;
   }
  } while (x/=10,x>0);
 } while (++i <= n);
 cout << endl;
};

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

int main() {
  int n; ll m; in(n),in(m);
  vector<ll> A(n);
  loop(i,0,n) in(A[i]);
  loop(i,0,n) A[i]%=m;
  ll rem = 0;
  map<ll, ll> C;
  C[rem]++;
  loop(i,0,n) {
    rem = (rem + A[i]) % m;
    C[rem]++;
  }
  ll ans = 0;
  for (auto &&c: C) {
    ans += (c.second * (c.second - 1)) / 2;
  }
  print(ans);
  return 0;
}


#include <bits/stdc++.h>
#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)
#define lowbit(x) (x & -x)
#define ll long long
#define N 500010
using namespace std;
ll tot = 0, head[N], v[N], dis[N], n, m, cnt;
struct Xiao
{
	int next, to, w;
}f[N * 3];
void add(int x, int y, int z)
{
	f[++tot].to = y;
	f[tot].next = head[x];
	f[tot].w = z;
	head[x] = tot;
}
void spfa()
{
	memset(dis, 127, sizeof dis);
	memset(v, 0, sizeof v);
	queue <int> q;
	q.push(1);
	v[1] = 1;
	dis[1] = 0;
	while (q.size())
	{
		int x = q.front();
		q.pop();
		for (int i = head[x]; i; i = f[i].next)
		{
			int y = f[i].to;
			if (dis[y] > dis[x] + f[i].w)
			{
				dis[y] = dis[x] + f[i].w;
				if (!v[y])
				{
					v[y] = 1;
					q.push(y);
				}
			}
		}
		v[x] = 0;
	}
}
map < pair <int, int>, int > p;
int get(int x, int y)
{
	if (p.find(make_pair(x, y)) != p.end()) return p[make_pair(x, y)];
	else return p[make_pair(x, y)] = ++cnt;
}
int main()
{
	//freopen("railway.in", "r", stdin);
	//freopen("railway.out", "w", stdout);
	sc(n);
	sc(m);
	cnt = n;
	for (int i = 1; i <= m; i++)
	{
		int x, y, z;
		sc(x);
		sc(y);
		sc(z);
		int p1 = get(x, z);
		int p2 = get(y, z);
		add(p2, p1, 0);
		add(p1, p2, 0);
		add(x, p1, 1);
		add(p1, x, 1);
		add(y, p2, 1);
		add(p2, y, 1);
	}
	spfa();
	printf("%lld\n", dis[n] > 2 * n ? -1 : dis[n] / 2);
	return 0;
}

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

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

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

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


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

struct StQuery
{
  StQuery() : m_nLeft(0), m_nRigt(0) { }

  int m_nLeft;
  int m_nRigt;
};

void fnInput(string& rsStr, vector<StQuery>& rvoQuery)
{
  int nStrSiz, nQuerySiz;
  cin >> nStrSiz >> nQuerySiz;
  rvoQuery.resize(nQuerySiz);

  cin >> rsStr;

  for (StQuery& roQuery : rvoQuery)
    cin >> roQuery.m_nLeft >> roQuery.m_nRigt;
}

void fnSubStrACCnt(string sStr, const vector<StQuery>& cnrvoQuery)
{
  const string cnsAC = "AC";
  int nACCnt = 0;
  vector<int> vnACCnt(sStr.size());

  for (int nBgn = 0; nBgn < vnACCnt.size() - 1; nBgn++)
  {
    if (sStr.substr(nBgn, 2) == cnsAC) nACCnt++;
    vnACCnt[ nBgn + 1 ] = nACCnt;
  }

  for (int i = 0; i < cnrvoQuery.size(); i++)
  {
    cout << vnACCnt[ cnrvoQuery[i].m_nRigt - 1 ] - vnACCnt[ cnrvoQuery[i].m_nLeft - 1];
    cout << endl;
  }
}

int main()
{
  string sStr;
  vector<StQuery> voQuery;

  fnInput(sStr, voQuery);
  fnSubStrACCnt(sStr, voQuery);

  return 0;
}

#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main() {

    ll N, Q;
    cin >> N >> Q;

    string S;
    cin >> S;

    vector<ll> F(N + 1), B(N + 1);
    ll tmp = 0, total;

    rep(i, N - 1) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            tmp++;
        }
        F[i + 2] = tmp;
    }

    total = tmp;
    tmp = 0;

    for (ll i = N - 1; i >= 1; i--) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            tmp++;
        }
        B[i] = tmp;
    }

    vector<ll> ans(Q);
    ll x, y;

    rep(i, Q) {
        cin >> x >> y;
        ans[i] = total - B[y] - F[x];
    }

    rep(i, Q) {
        cout << ans[i] << endl;
    }

    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n, k;
	cin >> n >> k;
	deque<ll> d;
	FOR(i, 1, n) {
		int v;
		cin >> v;
		d.push_back(v);
	}
	ll res = 0;
	int lim = min(k, n);
	FOR(i, 0, lim) {
		FOR(j, 0, i) {
			deque<ll> d2 = d;
			vector<ll> jw;
			FOR(left, 1, j) {
				jw.push_back(d2.front());
				d2.pop_front();
			}
			FOR(right, 1, i - j) {
				jw.push_back(d2.back());
				d2.pop_back();
			}
			sort(ALL(jw));
			FOR(index, 0, k - i - 1) {
				if (index <= i - 1 && jw[index] < 0) {
					jw[index] = 0;
				}
			}
			ll tmp = accumulate(ALL(jw), 0LL);
			res = max(res, tmp);
		}
	}

	pv(res)
}

#include<iostream>
using namespace std;

int main(){
  int N;
  int A,AA;
  long long ans=0;
  cin>>N;
  int times=N-1;
  int s;
  cin>>A;
  for(int i=0;i<times;i++){
    cin>>AA;
    if(A>AA){
      s=A-AA;
      ans+=s;
      AA+=s;
      A=AA;
    }else{
      A=AA;
    }
  }
  cout<<ans<<endl;
}


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

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

  int n; cin >> n;
  vector<int> p(n+1);
  cin >> p[0] >> p[1];
  for(int i = 0; i < n-2; i++){
    int a, b; cin >> a >> b;
    p[i+2] = b;
  }
  {
    int a, b; cin >> a >> b;
    p[n] = b;
  }

  int dp[101][101];
  memset(dp, 0, sizeof(dp));

  n = p.size() - 1;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n-l+1; i++){
      int j = i+l-1;
      dp[i][j] = INT_MAX/10;
      for(int k = i; k < j; k++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout << dp[1][n] << endl;
  return 0;
}

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


#include <cstdio>
#include <cstdlib>

typedef struct node {
    long v;
    node *parent;
    node *left;
    node *right;
} Node;

typedef struct {
    Node *root;
} Tree;

Tree T = {NULL};

void insertTree(Node *node) {
    Node *y = NULL;
    Node *x = T.root;
    while (x != NULL) {
        y = x;
        if (node->v < x->v) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    node->parent = y;
    if (y == NULL) {
        T.root = node;
    } else if (node->v < y->v) {
        y->left = node;
    } else {
        y->right = node;
    }
}

Node * find(long v) {
    Node *x = T.root;
    while (x != NULL) {
        if (x->v == v) return x;
        else if (x->v < v) x = x->right;
        else x = x->left;
    }
    return NULL;
}

void Transplant(Node *u, Node *v) {
    if (u->parent == NULL) {
        T.root = v;
    } else if (u == u->parent->left) {
        u->parent->left = v;
    } else {
        u->parent->right = v;
    }
    if (v != NULL) {
        v->parent = u->parent;
    }
}

Node *TreeMinimum(Node *x) {
    while (x->left != NULL) {
        x = x->left;
    }
    return x;
}

void deleteNode(Node *z) {
    if (z->left == NULL) {
        Transplant(z, z->right);
    } else if (z->right == NULL) {
        Transplant(z, z->left);
    } else {
        Node *y = TreeMinimum(z->right);
        if (y->parent != z) {
            Transplant(y, y->right);
            y->right = z->right;
            y->right->parent = y;
        }
        Transplant(z, y);
        y->left = z->left;
        y->left->parent = y;
    }
}

void Preorder(Node *n) {
    if (n != NULL) {
        printf(" %ld", n->v);
        Preorder(n->left);
        Preorder(n->right);
    }
}

void Inorder(Node *n) {
    if (n != NULL) {
        Inorder(n->left);
        printf(" %ld", n->v);
        Inorder(n->right);
    }
}

int main () {
    long n;
    scanf("%ld", &n);
    char command[10];
    long value;
    for (long i=0; i<n; i++) {
        scanf(" %s %ld", command, &value);
        if (command[0] == 'i') {
            Node *node = (Node *)malloc(sizeof(Node));
            node->v = value;
            node->parent = NULL;
            node->left = NULL;
            node->right = NULL;
            insertTree(node);
        } else if (command[0] == 'f') {
            Node *found = find(value);
            if (found != NULL) printf("yes\n");
            else printf("no\n");
        } else if (command[0] == 'd') {
            Node *z = find(value);
            deleteNode(z);
        } else {
            Inorder(T.root);
            printf("\n");
            Preorder(T.root);
            printf("\n");
        }
    }

    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#define NIL -1
#define MAX 610005
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
int n;
int root;
int *p = new int[MAX];       //    p---|  Unit
int *left2 = new  int[MAX]; // left2 --|--------> T
int *right2 = new int[MAX]; //right2---|
int *key = new int[MAX];     // key----|

void Init(){
  rep(i,MAX){
    p[i]=left2[i]=right2[i]=key[i]=NIL;
  }
}

int TREE_MINIMUM(int x){
  while(left2[x] != NIL){
    x = left2[x];
  }
  return x;
}

int TREE_SUCCESSOR(int x){
  if(right2[x] != NIL)return TREE_MINIMUM(right2[x]);
  int y = p[x];
  while(y != NIL && x == right2[y]){
    x = y;
    y = p[y];
  }
  return y;
}

void TREE_DELETE(int z){
  int y,x;
  if(left2[z] == NIL || right2[z] == NIL)y = z;
  else y = TREE_SUCCESSOR(z);

  if(left2[y] != NIL)x = left2[y];
  else x = right2[y];

  if(x != NIL)p[x]=p[y];
  if(p[y] == NIL)root = x;
  else if(y == left2[p[y]])left2[p[y]] = x;
  else right2[p[y]] = x;

  if(y != z)key[z] = key[y];

}

bool SEARCH(int x,int k){
  if(k == key[x])return true;
  if(x == NIL)return false;
  if(k < key[x])return SEARCH(left2[x],k);
  else return SEARCH(right2[x],k);
}

void TREE_INSERT(int z){
  int y = NIL;
  int x = root;

  while(x != NIL){
    y = x;
    if(key[z] < key[x]){
      x = left2[x];
    }
    else x = right2[x];
  }
  p[z]=y;
  if(y == NIL){
    root = z;
  }
  else if(key[z] < key[y]){
    left2[y] = z;
  }else{
    right2[y] = z;
  }

}

int IndexSearch(int x){
  for(int i=0;i<MAX;i++){
    if(key[i] == x)return i;
  }
  return -1;
}

void InorderTreeWalk(int x){
  if(x != NIL){
    InorderTreeWalk(left2[x]);
    printf(" %d",key[x]);
    InorderTreeWalk(right2[x]);
  }
}

void PreorderTreeWalk(int x){
  if(x != NIL){
    printf(" %d",key[x]);
    PreorderTreeWalk(left2[x]);
    PreorderTreeWalk(right2[x]);
  }
}

int main(){
  int val;
  string op;
  long long zr;

  scanf("%d",&n);
  Init();
  root = -1;
  zr=0;
  while(n-- > 0){
    cin >> op;
    if(op == "insert"){
      scanf("%d",&val);
      key[zr]=val;
      TREE_INSERT(zr);
      zr++;
    }else if(op == "print"){
      InorderTreeWalk(root);
      printf("\n");
      PreorderTreeWalk(root);
      printf("\n");
    }
    else if(op == "find"){
      scanf("%d",&val);
      if(SEARCH(root,val)){
    printf("yes\n");
      }else{
    printf("no\n");
      }

    }
    else if(op == "delete"){
      scanf("%d",&val);
      int inthis = IndexSearch(val);
      if(inthis != -1){
      TREE_DELETE(inthis);
      }
    }

  }

  delete [] p;
  delete [] left2;
  delete [] right2;
  delete [] key;

  return 0;
}


#include<iostream>
using namespace std;
typedef pair<char,int> P;
string str;
int len,size=0,cnt=1,ans=0;
P t[1000000];
int main(){
  cin>>str;
  str.push_back('-');
  len=str.size();
  for(int i=1;i<len;i++){
    if(str[i-1]==str[i]){
      cnt++;
    }else{
      t[size++]=P(str[i-1],cnt);
      cnt=1;
    }
  }

  for(int i=0;i+2<size;i++){
    if(t[i].first!='J')continue;
    if(t[i+1].first!='O')continue;
    if(t[i+2].first!='I')continue;
    if(t[i].second<t[i+1].second)continue;
    if(t[i+1].second>t[i+2].second)continue;
    ans=max(ans,t[i+1].second);
  }
  cout<<ans<<endl;
  return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int n, sm = 0;
  cin >> n;
  if(n >= 500){
    sm += n / 500 * 1000;
    n = n % 500;
  }
  if(n >= 5){
    sm += n / 5 * 5;
  }

  cout << sm << "\n";
}


#include "bits/stdc++.h"

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define all(co) co.begin(), co.end()
using namespace std;
//using P = pair<int, int>;

int main() {
	int n;
	while (cin >> n && n) {
		int k; cin >> k;
		vector<string> vec(n);
		rep(i, n) cin >> vec[i];

		set<string> sets;
		vector<bool> used(n);
		function<void(string, int)> dfs = [&](string str, int count) {
			if (count == k) {
				sets.insert(str);
				return;
			}
			rep(i, n) if (!used[i]) {
				used[i] = true;
				dfs(str + vec[i], count + 1);
				used[i] = false;
			}
		};
		dfs("", 0);
		cout << sets.size() << endl;
	}
	return 0;
}

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

using namespace std;

int n,m;
vector<int> came;
string str[11];
set<string> ans;

void serch(int loop,string sans)
{
//	cout << "loop:" << loop << endl;
	if(loop==m)
	{
//		cout << "came:" ;
//		for(int i=0;i<came.size();i++)
//			cout <<  came[i] << " " ;
//		cout << endl;
//		cout << sans << endl;;
		ans.insert(sans);
		return ;
	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<came.size();j++)
		{
//				cout << "j:" << j << " now:" << came[j] << " size:" << came.size() << " " << i << endl;
			if(i==came[j])
			{
				i++;
				j=-1;
			}
		}
		if(i==n)
			break;
//		cout << "next:" << i << endl;
		came.push_back(i);
		serch(loop+1,sans+str[i]);
		came.pop_back();
	}
	return ;
}

int main()
{
	int i,j;
	for(;;)
	{
		cin >> n >> m ;
		if(n==0 && m==0)
			break;

		ans.clear();

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

		serch(0,"");

		cout << ans.size() << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
// #define multicase
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 2e5 + 5;

int x;

void solve() {
    int T = 1;
  #ifdef multicase
    cin >> T;
  #endif
    while(T--) {
        cin >> x;
        cout << (x < 1200 ? "ABC\n" : x < 2800 ? "ARC\n" : "AGC\n");
    }
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();

}

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

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

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

  if(r<1200) cout<<"ABC"<<endl;
  else if(r<2800) cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;

  return 0;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}

vector<pair<long long,long long>> prime_factorize(long long N){
  vector<pair<long long,long long>> res;

  for(long long i=2;i*i<=N;i++){
    if(N%i!=0){
    continue;
    }

    long long ex=0;
    while(N%i==0){
      ex++;
      N/=i;
    }

    res.push_back({i,ex});
  }

  if(N!=1){
  res.push_back({N,1});
  }

  return res;
}

int main() {

  int N;
  cin>>N;

  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0;i<N;i++){
    cin>>vec[i][0]>>vec[i][1];
  }

  vector<int> root(N);
  for(int i=0;i<N;i++){
    root[i]=i;
  }

  double sum=0;

  do{
    double d=0;
    for(int i=0;i<N-1;i++){
      double a=pow((vec[root[i]][0]-vec[root[i+1]][0]),2);
      double b=pow((vec[root[i]][1]-vec[root[i+1]][1]),2);
      d+=pow(a+b,0.5);
    }
    sum+=d;
  }
  while(next_permutation(root.begin(),root.end()));

  int x=1;
  for(int i=2;i<=N;i++){
    x*=i;
  }

  cout<<fixed<<setprecision(10)<<sum/x<<endl;
}

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

int main(){
	int a;
	while(scanf("%d",&a)!=EOF){
		int d[14]={},p=0,m=0;
		char c;
		vector<int> n(5);
		n[0]=a;
		d[n[0]]++;
		rep(i,1,5){
			cin>>c>>n[i];
			d[n[i]]++;
		}
		sort(n.begin(),n.end());
		rep(i,1,14){
			m=max(m,d[i]);
			if(d[i]>=2) p++;
		}
		if(m==4){
			o("four card");
		}else if(m==3 && p==2){
			o("full house");
		}else if(m==3){
			o("three card");
		}else if(p==2){
			o("two pair");
		}else if(p==1){
			o("one pair");
		}else{
			bool f=1;
			rep(i,0,4){
				if(n[i+1]!=n[i]+1 && !(n[0]==1 && n[1]==10 && n[4]==13)){
					f=0; break;
				}
			}
			if(f) o("straight");
			else o("null");
		}
	}
}


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF=1e9;
int main()
{
	int n, m;
	cin>>n>>m;
	vector<P> g[15];
	for(int i=0; i<m; i++){
		int a, b, c;
		cin>>a>>b>>c;
		a--; b--;
		g[a].push_back(P(b, c));
		g[b].push_back(P(a, c));
	}
	int dp[14][1<<14];
	for(int i=0; i<n-1; i++){
		if(i==0) fill(dp[i], dp[i]+(1<<(n-1)), 0);
		else fill(dp[i], dp[i]+(1<<(n-1)), INF);
	}
	int s[1<<15]={};
	for(int i=0; i<(1<<n); i++){
		for(int x=0; x<n; x++){
			if((i&(1<<x))==0) continue;
			for(auto pr:g[x]){
				int y=pr.first;
				if((i&(1<<y))==0) continue;
				s[i]+=pr.second;
			}
		}
		s[i]/=2;
	}
	for(int i=1; i<(1<<(n-1)); i++){
		for(int j=i; j>0; j=(j-1)&i){
			int sum=s[i]-s[i-j]-s[j];
			for(int x=0; x<n-1; x++){
				if((j&(1<<x))==0) continue;
				for(auto pr:g[x]){
					int y=pr.first;
					if(((i-j)&(1<<y))==0) continue;
					dp[y][i]=min(dp[y][i], dp[x][j]+sum-pr.second);
				}
			}
		}
	}
	int ans=INF;
	for(int i=1; i<(1<<(n-1)); i++){
		int sum=s[(1<<n)-1]-s[i]-s[(1<<n)-1-i];
		for(auto pr:g[n-1]){
			int y=pr.first;
			if((i&(1<<y))==0) continue;
			ans=min(ans, dp[y][i]+sum-pr.second);
		}
	}
	cout<<ans<<endl;
	return 0;
}

//#include <bits/c++config.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
//#pragma GCC optimize(2)
using namespace std;
int read() {
	int x=0;
	bool fu=0;
	char ch=0;
	while(ch>'9'||ch<'0') {
		ch=getchar();
		if(ch=='-')fu=1;
	}
	while(ch<='9'&&ch>='0') x=(x*10+ch-48),ch=getchar();
	return fu?-x:x;
}
ll n,m,t1,t2,g[17][17],full[1<<16],dp[17][1<<16];
long long tot;
int main(){
	memset(dp,-0x80,sizeof(dp));
    dp[0][1]=0;
    cin>>n>>m;
    F(i,1,m){
    	cin>>t1>>t2;
    	t1--,t2--;
      	cin>>g[t2][t1];
    	tot+=g[t2][t1];
    	g[t1][t2]=g[t2][t1];
	}
	for(register int i=1;i<(1<<n);i++){
		for(ri j=1;j<n;j++){
			if(i&(1<<j)){
				for(ri k=0;k<j;k++){
					if(i&(1<<k)){
						full[i]+=g[j][k];
					}
				}
			}
		}
	}for(register int S=1;S<(1<<n);S+=2){
		for(register int i=0;i<n;i++){
			if(!(S&(1<<i)))continue;
			for(register int j=1;j<n;j++){
				if(!g[i][j]||(S&(1<<j)))continue;
				dp[j][S|(1<<j)]=max(dp[j][S|(1<<j)],dp[i][S]+g[i][j]);
			}
			ri s2=((1<<n)-1)^S;
			for(register int j=s2;j;j=(j-1)&s2){
				dp[i][S|j]=max(dp[i][S|j],dp[i][S]+full[(1<<i)|j]);
			}
		}
	}
	cout<<tot-dp[n-1][(1<<n)-1];
    return 0;
}


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

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
//template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

template<int N>
struct sieve {
	bool s[N];
	constexpr sieve() : s() {
		for (int i = 0; i < N; i++)
			s[i] = true;
		for (int i = 4; i < N; i += 2)
			s[i] = false;
		for (int i = 9; i < N; i += 6)
			s[i] = false;
		for (int i = 6, e = sqrt(N); i <= e; i += 6) {
			for (int j : {i - 1, i + 1})
				if (s[j])
					for (int k = j * j; k < N; k += j)
						s[k] = false;
		}
	}
};

template<int N>
struct twin {
	int t[N/10], l;
	constexpr twin() : t(), l(1) {
		sieve<N> s;
		t[0] = 5;
		for (int i = 0; i < N; i++)
			if (s.s[i - 2] && s.s[i])
				t[l++] = i;
	}
};

int main() {
	enum {N = 10001};
	twin<N> t;
	for (int n; (n = in());) {
		auto r = upper_bound(t.t, t.t + t.l, n) - 1;
		outl(*r - 2, ' ', *r);
	}
}

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

using namespace std;

template <class T>
using gp_queue=priority_queue<T, vector<T>, less<T>>;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

pair<Weight, Edges> minimum_spanning_tree(const Graph &g, size_t s=0) {
    /* Prim */
    size_t V=g.size();
    Edges T;
    Weight total=0;

    vector<bool> visited(V);
    gp_queue<Edge> q; q.push(Edge(-1, s, 0));
    while (!q.empty()) {
        Edge e=q.top(); q.pop();
        if (visited[e.dst]) continue;

        T.push_back(e);
        total += e.weight;
        visited[e.dst] = true;
        for (const Edge &f: g[e.dst])
            if (!visited[f.dst])
                q.push(f);
    }

    return make_pair(total, T);
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i)
        for (size_t j=0; j<n; ++j) {
            Weight a;
            scanf("%d", &a);

            if (a > -1)
                connect(g, i, j, a);
        }

    printf("%d\n", minimum_spanning_tree(g).first);
    return 0;
}


#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B, ll C) {
  bool pred = (A-C) * (C-B) > 0;
  cout << (pred ? YES : NO) << endl;
}

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

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

int main() {

    int a,b,c;
    cin>>a>>b>>c;

    if(c>=a&&c<=b||c>=b&&c<=a)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


#include <stdio.h>

int main(void)
{
	int n;
	int min, max;
	double sum;

	scanf("%d", &n);

	int num;
	int pointer=0;
	scanf("%d", &num);
	min=max=sum=num;
	for(int i=0; i<n-1; i++){
		scanf("%d", &num);
		if(min>num) min=num;
		if(max<num) max=num;
		sum+=num;
	}

	printf("%d %d %.0lf\n", min, max, sum);

	return 0;
}

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

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

	long long X = 0;
	long long preT = 0;
	cin >> preT;
	for (int i = 0; i < N - 1; ++i) {
		int t; cin >> t;
		if (preT + T < t) {
			X += T;
		}
		else {
			X += (t - preT);
		}

		preT = t;
	}

	cout << X + T << endl;

	return 0;
}


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

using P = pair<int,int>;

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

int main()
{
    int n,Q;
    cin >> n >> Q;
    vector<int> c(n);
    rep(i,n) {
        cin >> c[i];
        c[i]--;
    }
    vector<int> ql(Q),qr(Q);
    vector<vector<int>> table(n);
    rep(i,Q) {
        cin >> ql[i] >> qr[i];
        ql[i]--; qr[i]--;
        table[qr[i]].push_back(ql[i]);
    }

    vector<int> place(n,-1);
    BinaryIndexedTree<int> bit(n);

    map<P,int> mp;
    rep(i,n) {
        if(place[c[i]] != -1) bit.add(place[c[i]], -1);
        place[c[i]] = i;
        bit.add(i, 1);
        for(int l : table[i]) {
            if(l > 0) mp[P(l,i)] = bit.sum(i) - bit.sum(l-1);
            else mp[P(0,i)] = bit.sum(i);
        }
    }

    rep(i,Q) cout << mp[P(ql[i],qr[i])] << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 4e18;

ll n, m, mn = M;
vector<ll> ve[1005];
vector<ll> ans;
vector<ll> now;
ll vv[1005];

void dfs(ll p)
{
    if(now.size() != 0 && p == now[0])
    {
        if(mn > now.size())
        {
            mn = now.size();
            ans = now;
        }
        return;
    }
    else if(vv[p]) return;
    if(now.size() > mn) return;
    vv[p] = true;
    now.push_back(p);
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i]);
    }
//    vv[p] = false;
    now.pop_back();
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < m; i++)
    {
        ll u, v;
        scanf("%lld%lld", &u, &v);
        ve[u].push_back(v);
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll i = 1; i <= n; i++) vv[i] = false;
        dfs(i);
    }
    if(mn == M) printf("-1\n");
    else
    {
        printf("%lld\n", mn);
        for(ll i = 0; i < ans.size(); i++)
        {
            printf("%lld\n", ans[i]);
        }
    }
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    int T;
    cin >> T;
    rep(ti,0,T) {
        int N;
        cin >> N;
        vector<ll> A(N);
        rep(i,0,N) cin >> A[i];
        string S;
        cin >> S;

        // if base[i] != 0, base[i]'s ith bit is 1 and the other base's ith bit is 0.
        vector<ll> base(60);
        bool zero = true;
        rrep(i,0,N) {
            if (S[i] == '0') {
                // remove 1 from A[i]'s bits where base exists.
                rrep(bi,0,base.size()) {
                    if (base[bi] != 0 && (A[i] & (1LL << bi))) {
                        A[i] ^= base[bi];
                    }
                }
                // insert A[i] into base
                rrep(bi, 0, base.size()) {
                    // found
                    if (A[i] & (1LL << bi)) {
                        base[bi] = A[i];
                        // remove 1 in bi'th bit from other base
                        rep(j,0,base.size()) {
                            if (j != bi && (base[j] & (1LL << bi))) {
                                base[j] ^= base[bi];
                            }
                        }
                        break;
                    }
                }
            } else {
                rrep(bi, 0, base.size()) {
                    if (base[bi] != 0 && (A[i] & (1LL << bi))) {
                        A[i] ^= base[bi];
                    }
                }
                // A[i] is not included in base
                if (A[i] != 0) {
                    zero = false;
                    break;
                }
            }
        }
        cout << (zero ? 0 : 1) << endl;
    }
    return 0;
}

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

using namespace std;

#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//-------------------------------------------------------
int A[500000];
int acum[500001];
bool S[500001];
int zero[500001];
long DP[500001];
long DP2[500001];
vector<pair<int,int>> Data;
void Calc(){
	int N = rei();
	for(int i=0;i<N;i++){
		A[i] = rei();
	}
	for(int i=0;i<N;i++){
		acum[i+1] = acum[i] ^ A[i];
	}
	if(acum[N] == 0){
		int z = 0;
		for(int i=0;i<=N;i++){
			if(acum[i] == 0){
				z++;
			}
			else{
				Data.push_back({acum[i],i});
			}
			zero[i] = z;
		}
		sort(Data.begin(),Data.end());
		long ans = 1;
		for(int i=0;i<z-2;i++){
			ans <<= 1;
			ans %= mod;
		}
		int p = 0;
		while(p < Data.size()){
			long c = 1;
			long d = 1;
			while(p+1 < Data.size() && Data[p].first == Data[p+1].first){
				p++;
				d += c * (zero[Data[p].second] - zero[Data[p-1].second]);
				d %= mod;
				c += d;
				c %= mod;
			}
			p++;
			ans += c;
			ans %= mod;
		}
		cout << ans << endl;
	}
	else{
		int c = 0;
		for(int i=0;i<=N;i++){
			if(acum[i] == 0){
				S[c++] = false;
			}
			else if(acum[i] == acum[N]){
				S[c++] = true;
			}
		}
		DP[0] = 1;
		for(int i=1;i<c;i++){
			if(S[i]){
				DP[i] = DP[i-1];
				DP2[i] = (DP[i-1] + DP2[i-1]) % mod;
			}
			else{
				DP[i] = (DP[i-1] + DP2[i-1]) % mod;
				DP2[i] = DP2[i-1];
			}
		}
		cout << DP[c-1] << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}


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

#define MAX 1000000001
long long CNT = 0;

void merge(long long a[], int begin, int end, int mid) {
	queue<long long> left;
	queue<long long> right;
	for (int i = begin; i < mid; i++)left.push(a[i]);
	for (int i = mid; i < end; i++)right.push(a[i]);
	left.push(MAX);
	right.push(MAX);

	int cnt = left.size() - 1;
	for (int i = begin; i < end; i++) {
		if (left.front() < right.front()) {
			a[i] = left.front();
			left.pop();
			cnt--;
		}
		else {
			a[i] = right.front();
			right.pop();
			CNT += cnt;
		}
	}
}

void m_sort(long long a[], int begin, int end) {
	if (begin >= end - 1)return;
	int mid = (begin + end) / 2;

	m_sort(a, begin, mid);
	m_sort(a, mid, end);

	merge(a, begin, end, mid);
}

int main() {
	long long ary[200000];
	int n;

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

	m_sort(ary, 0, n);

	cout << CNT << endl;
	return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class ATravelingBudget {
public:
	void solve(istream& in, ostream& out) {
        int a,b,c,d;
        in >> a >> b >> c >> d;
        int t = min(a,b);
        int v = min(c,d);
        out << t + v << endl;
	}
};

int main() {
	ATravelingBudget solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#ifdef CURIOUSCAT
#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)
#else
#define Pr(f,...)
#endif

typedef long long ll;

template<typename T>
void read(T &x){
	x=0;
	char c;
	for(c=getchar();!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
}

const int N=1e6+50;

int P;
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
void upd(int &a,int b) { a=a+b>=P?a+b-P:a+b; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int C(int n,int m) {
	if(m<0||m>n)return 0;
	if(m==0)return 1;
	if(m==1)return n;
	if(m==2)return n&1?mul(n,(n-1)/2):mul(n/2,n-1);
}

int n,dp[6005][2005],ans;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	read(n); read(P);
	dp[0][0]=1;
	rep(i,0,n*3)rep(j,0,n){
		upd(dp[i+1][j],dp[i][j]);
		upd(dp[i+2][j+1],mul(dp[i][j],C(i+1,1)));
		upd(dp[i+3][j+1],mul(dp[i][j],mul(C(i+2,2),2)));
	}
	rep(j,0,n)ans=add(ans,dp[n*3][j]);
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
#define int long long
using namespace std;
#define mod 1000000007
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
// int parent[2000005];
// //int div1[100005];
// int min_indx[200005];
// int count1 = 0;
// int height = 0;
// int max_indx[200005];
// int f[100005];
// int cost[100005];
// stack<int> stc;
// int ans[100005];
// int count2;
// int sum[100005];
// int max1 = 0;
// //int count1 = 0;
void dfs(int node)
{
    vis[node] = 1;

    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {

            dfs(vec[node][i]);
            child[node] += child[vec[node][i]];
        }
    }

    // stc.pop();
}

// void dfs1(int node)
// {
//     vis[node] = 1;
//     // cout << node << "\n";
//     for (int i = 0; i < vec[node].size(); i++)
//     {
//         if (!vis[vec[node][i]])
//         {
//             sum[vec[node][i]] += sum[node];
//             //  cout << sum[vec[node][i]] << " " << sum[node] << "\n";

//             dfs1(vec[node][i]);
//         }
//     }
// }
// int MAXN = 200005;
// int LOGMAXN = (int)log2(200005) + 1;
// int M[200005][60];
// //int ans[200005];

// void fun(int a, int b, int c)
// {
//     //ll val = 1;

//     while (a <= b)
//     {
//         ans[a] += c;
//         int p = -a;
//         a += (a & p);
//     }
// }
// int find1(int a)
// {
//     int sum = 0;
//     while (a != 0)
//     {
//         sum += ans[a];
//         int p = -a;
//         a -= (a & p);
//     }
//     return sum;
// }
// void process2(int A[], int N)
// {
//     int i, j;

//     for (i = 0; i < N; i++)
//         M[i][0] = i;
//     for (j = 1; 1 << j <= N; j++)
//         for (i = 0; i + (1 << j) - 1 < N; i++)
//             if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
//                 M[i][j] = M[i][j - 1];
//             else
//                 M[i][j] = M[i + (1 << (j - 1))][j - 1];
// }
int fastexpo(int a, int b, int m)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans % m;
}
// int arr[100005] = {0}, arr2[1000005];
//int div1[20000005];
int maxSubArraySum(int a[], int size)
{
    int max_so_far = -100000000000000000, max_ending_here = 0;
    //    cout << max_so_far << " ";
    int max_ind = 0, min_ind = 0, s = 0;
    for (int i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        // max_ind = i, min_ind = i;
        if (max_so_far < max_ending_here)
        {
            max_so_far = max_ending_here;
            max_ind = i;
            min_ind = s;
        }

        if (max_ending_here < 0)
        {
            max_ending_here = 0;
            s = i + 1;
        }
    }
    // cout << max_so_far << "\n";
    //  pair<int, int> p = {min_ind, max_ind};
    return max_so_far;
}
bool ch(string s1, string s2)
{
    for (int i = 0; i < 7; i++)
    {
        if (s1[i] != s2[i])
            return 0;
    }
    return 1;
}
int arr[100005][1010] = {0};
int32_t main()
{
    int l, r;
    cin >> l >> r;
    int p = r - l;
    if (p > 2019)
    {
        cout << 0 << "\n";
    }
    else
    {
        int max1 = 2020;
        for (int i = l; i <= r; i++)
        {
            for (int j = i + 1; j <= r; j++)
            {
                max1 = min(max1, (i * j) % 2019);
            }
        }
        cout << max1 << "\n";
    }

    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() {
    int N; cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    vector<char> U(N);
    REP(i,N) cin >> X[i] >> Y[i] >> U[i];

    int ans = INF;

    vector<vector<pair<int,char>>> H(1e6);//縦方向

    REP(i,N){
        if(U[i]=='U' || U[i]=='D'){
            H[X[i]].push_back({Y[i],U[i]});
        }
    }
    REP(i,H.size()){
        if(H[i].size()==0) continue;
        sort(ALL(H[i]));
        REP(j,H[i].size()-1){
            if(H[i][j].second=='U' && H[i][j+1].second=='D'){
                ans = min(ans, 5*(H[i][j+1].first - H[i][j].first));
            }
        }
    }

    vector<vector<pair<int,char>>> V(1e6);//横方向
    REP(i,N){
        if(U[i]=='R' || U[i]=='L'){
            V[Y[i]].push_back({X[i],U[i]});
        }
    }
    REP(i,V.size()){
        if(V[i].size()==0) continue;
        sort(ALL(V[i]));
        REP(j,V[i].size()-1){
            if(V[i][j].second=='R' && V[i][j+1].second=='L'){
                ans = min(ans, 5*(V[i][j+1].first - V[i][j].first));
            }
        }
    }

    vector<int> XX(N);
    vector<int> YY(N);

    REP(i,N){//45度回転
        XX[i] = X[i]-Y[i]+200000;
        YY[i] = X[i]+Y[i]+200000;
    }

    vector<vector<pair<int,char>>> V1(1e6);//横方向
    REP(i,N){
        if(U[i]=='R' || U[i]=='U'){
            V1[YY[i]].push_back({XX[i],U[i]});
        }
    }
    REP(i,V1.size()){
        if(V1[i].size()==0) continue;
        sort(ALL(V1[i]));
        REP(j,V1[i].size()-1){
            if(V1[i][j].second=='R' && V1[i][j+1].second=='U'){
                ans = min(ans, 5*(V1[i][j+1].first - V1[i][j].first));
            }
        }
    }

    vector<vector<pair<int,char>>> V2(1e6);//横方向
    REP(i,N){
        if(U[i]=='D' || U[i]=='L'){
            V2[YY[i]].push_back({XX[i],U[i]});
        }
    }
    REP(i,V2.size()){
        if(V2[i].size()==0) continue;
        sort(ALL(V2[i]));
        REP(j,V2[i].size()-1){
            if(V2[i][j].second=='D' && V2[i][j+1].second=='L'){
                ans = min(ans, 5*(V2[i][j+1].first - V2[i][j].first));
            }
        }
    }

    vector<vector<pair<int,char>>> H1(1e6);//横方向
    REP(i,N){
        if(U[i]=='R' || U[i]=='D'){
            H1[XX[i]].push_back({YY[i],U[i]});
        }
    }
    REP(i,H1.size()){
        if(H1[i].size()==0) continue;
        sort(ALL(H1[i]));
        REP(j,H1[i].size()-1){
            if(H1[i][j].second=='R' && H1[i][j+1].second=='D'){
                ans = min(ans, 5*(H1[i][j+1].first - H1[i][j].first));
            }
        }
    }

    vector<vector<pair<int,char>>> H2(1e6);//横方向
    REP(i,N){
        if(U[i]=='U' || U[i]=='L'){
            H2[XX[i]].push_back({YY[i],U[i]});
        }
    }
    REP(i,H2.size()){
        if(H2[i].size()==0) continue;
        sort(ALL(H2[i]));
        REP(j,H2[i].size()-1){
            if(H2[i][j].second=='U' && H2[i][j+1].second=='L'){
                ans = min(ans, 5*(H2[i][j+1].first - H2[i][j].first));
            }
        }
    }

    if(ans == INF) cout << "SAFE" << endl;
    else cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
#define pir pair<int,int>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
#define rsort(x,y) sort(x,y),reverse(x,y)
#define fr first
#define se second
using namespace std;
typedef long long ll;
const int Maxn=4100000;
const int inf=0x3f3f3f3f;

int n,x[Maxn],y[Maxn],dir[Maxn],bj[Maxn];
vector<pir> v[Maxn];

int getadir() {
    char ch=getchar();
    while(!isalpha(ch)) ch=getchar();
    switch(ch) {
        case 'U' : return 0;
        case 'R' : return 1;
        case 'D' : return 2;
        case 'L' : return 3;
    }
}

signed main() {
    // freopen("test.in","r",stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&x[i],&y[i]);
        dir[i]=getadir();
    }
    int ans=inf;
    for(int i=1;i<=n;i++) if((dir[i]&1)==0) v[x[i]].push_back(make_pair(y[i],i)),bj[x[i]]=1;
    for(int i=1;i<Maxn;i++) if(bj[i]) {
        sort(v[i].begin(),v[i].end());
        int temp=0;
        for(pir j:v[i]) {
            if(dir[j.se]==2) {
                if(temp) qmin(ans,j.fr-y[temp]);
            }
            else temp=j.se;
        }
    }
    for(int i=1;i<Maxn;i++) if(bj[i]) v[i].clear(),bj[i]=0;
    for(int i=1;i<=n;i++) if(dir[i]&1) v[y[i]].push_back(make_pair(x[i],i)),bj[y[i]]=1;
    for(int i=1;i<Maxn;i++) if(bj[i]) {
        sort(v[i].begin(),v[i].end());
        int temp=0;
        for(pir j:v[i]) {
            if(dir[j.se]==3) {
                if(temp) qmin(ans,j.fr-x[temp]);
            }
            else temp=j.se;
        }
    }
    for(int i=1;i<Maxn;i++) if(bj[i]) v[i].clear(),bj[i]=0;
    for(int i=1;i<=n;i++) v[x[i]+y[i]].push_back(make_pair(x[i],i)),bj[x[i]+y[i]]=1;
    for(int i=1;i<Maxn;i++) if(bj[i]) {
        sort(v[i].begin(),v[i].end());
        int tempx=0,tempy=0;
        for(pir j:v[i]) {
            if(dir[j.se]==0) {
                if(tempy) qmin(ans,(j.fr-x[tempy])*2);
            }
            else if(dir[j.se]==1) tempy=j.se;
            else if(dir[j.se]==2) tempx=j.se;
            else if(tempx) qmin(ans,(j.fr-x[tempx])*2);
        }
    }
    for(int i=1;i<Maxn;i++) if(bj[i]) v[i].clear(),bj[i]=0;
    for(int i=1;i<=n;i++) v[x[i]-y[i]+2000000].push_back(make_pair(x[i],i)),bj[x[i]-y[i]+2000000]=1;
    for(int i=1;i<Maxn;i++) if(bj[i]) {
        sort(v[i].begin(),v[i].end());
        int tempx=0,tempy=0;
        for(pir j:v[i]) {
            if(dir[j.se]==3) {
                if(tempy) qmin(ans,(j.fr-x[tempy])*2);
            }
            else if(dir[j.se]==0) tempy=j.se;
            else if(dir[j.se]==1) tempx=j.se;
            else if(tempx) qmin(ans,(j.fr-x[tempx])*2);
        }
    }
    for(int i=1;i<Maxn;i++) if(bj[i]) v[i].clear(),bj[i]=0;
    if(ans==inf) return 0*puts("SAFE");
    ans*=5;
    printf("%d\n",ans);
    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 rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
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 DP[85][85][30000];

int main() {
  int H, W;
  cin>>H>>W;
  int A[H][W], B[H][W];
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>A[i][j];
    }
  }
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cin>>B[i][j];
    }
  }
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      A[i][j] -= B[i][j];
    }
  }
  DP[0][0][15000+A[0][0]] = 1;
  DP[0][0][15000-A[0][0]] = 1;
  for(int i=0;i<H-1;++i) {
    for(int j=0;j<30000;++j) {
      if(DP[i][0][j]>0) {
        DP[i+1][0][j+A[i+1][0]] = 1;
        DP[i+1][0][j-A[i+1][0]] = 1;
      }
    }
  }
  for(int i=0;i<W-1;++i) {
    for(int j=0;j<30000;++j) {
      if(DP[0][i][j]>0) {
        DP[0][i+1][j+A[0][i+1]] = 1;
        DP[0][i+1][j-A[0][i+1]] = 1;
      }
    }
  }
  for(int i=1;i<H;++i) {
    for(int j=1;j<W;++j) {
      for(int k=0;k<30000;++k) {
        if(DP[i-1][j][k]>0) {
          DP[i][j][k+A[i][j]] = 1;
          DP[i][j][k-A[i][j]] = 1;
        }
        if(DP[i][j-1][k]>0) {
          DP[i][j][k+A[i][j]] = 1;
          DP[i][j][k-A[i][j]] = 1;
        }
      }
    }
  }
  int ans = inf;
  for(int i=0;i<30000;++i) {
    if(DP[H-1][W-1][i]>0) ans = min(ans, abs(i-15000));
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        for(int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if(par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if(u == v)
            return false;
        if(siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
struct edge {
    ll u, v, cost;
    bool operator<(const edge& e) { return cost < e.cost; }
};
ll d;
vector<ll> a;
vector<edge> es;
void calc(int l, int r) {
    if(r - l <= 1) {
        return;
    }
    int m = (l + r) / 2;
    ll mi = LINF, s, t;
    for(ll i = l; i < m; i++) {
        ll k = -i * d + a[i];
        if(mi > k) {
            mi = k;
            s = i;
        }
    }
    mi = LINF;
    for(ll i = m; i < r; i++) {
        ll k = i * d + a[i];
        if(mi > k) {
            mi = k;
            t = i;
        }
    }
    for(ll i = l; i < m; i++) {
        es.push_back({i, t, (t - i) * d + a[t] + a[i]});
    }
    for(ll i = m; i < r; i++) {
        es.push_back({s, i, (i - s) * d + a[i] + a[s]});
    }
    calc(l, m);
    calc(m, r);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n >> d;
    a.resize(n + 1);
    for(ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    calc(1, n + 1);
    UnionFind uf(n + 1);
    sort(all(es));
    ll ans = 0;
    for(auto e : es) {
        if(uf.unite(e.u, e.v)) {
            ans += e.cost;
        }
    }
    cout << ans << endl;
}